whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curc...@apache.org
Subject [whimsy] branch master updated: Annotate with realm data for links
Date Sat, 27 May 2017 00:29:08 GMT
This is an automated email from the ASF dual-hosted git repository.

curcuru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  d08911b   Annotate with realm data for links
d08911b is described below

commit d08911b7aec6352ffba2938036a14e21f1af537b
Author: Shane Curcuru <asf@shanecurcuru.org>
AuthorDate: Fri May 26 20:29:03 2017 -0400

    Annotate with realm data for links
---
 tools/wwwdocs.rb         | 55 +++++++++++++++++++++++++++++++++++++++++++++---
 www/committers/tools.cgi | 31 +++++++++++++++++++--------
 2 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/tools/wwwdocs.rb b/tools/wwwdocs.rb
index c09af24..13e5991 100755
--- a/tools/wwwdocs.rb
+++ b/tools/wwwdocs.rb
@@ -1,11 +1,20 @@
 #!/usr/bin/env ruby
 # Scan all /www scripts for WVisible PAGETITLE and categories
 $LOAD_PATH.unshift File.realpath(File.expand_path('../../lib', __FILE__))
+require 'whimsy/asf'
 SCANDIR = "../www"
 ISERR = '!'
+AUTHMAP = { # From whimsy-vm4.apache.org.yaml
+  'ASF Committers' => 'text-muted',
+  'ASF Members and Officers' => 'text-primary',
+  'ASF Members and Incubator PMC' => 'text-info',
+  'ASF Members' => 'text-warning',
+  'ASF Secretarial Team' => 'text-danger'
+}
+AUTHPUBLIC = 'glyphicon-eye-open'
 
 # Return [PAGETITLE, [cat,egories] ] after WVisible; or same as !Bogosity error
-def scanfile(f)
+def scan_file(f)
   begin
     File.open(f).each_line.map(&:chomp).each do |line|
       if line =~ /\APAGETITLE\s?=\s?"([^"]+)"\s?#\s?WVisible:(.*)/i then
@@ -19,11 +28,51 @@ def scanfile(f)
 end
 
 # Return data only about WVisible cgis, plus any errors
-def scandir(dir)
+def scan_dir(dir)
   links = {}
   Dir["#{dir}/**/*.cgi".untaint].each do |f|
-    l = scanfile(f.untaint)
+    l = scan_file(f.untaint)
     links[f.sub(dir, '')] = l if l
   end
   return links
 end
+
+# Process authldap so we can annotate links with access hints
+def get_auth()
+    node = ASF::Git.find('infrastructure-puppet')
+    if node
+      node += '/data/nodes/whimsy-vm4.apache.org.yaml'
+    else
+      raise Exception.new("Cannot find Git: infrastructure-puppet")
+    end
+    yml = YAML.load(File.read("#{node}"))
+    authldap = yml['vhosts_whimsy::vhosts::vhosts']['whimsy-vm-443']['authldap']
+    # Unwrap so we can easily compare base path
+    auth = {}
+    authldap.each do |ldap|
+      ldap['locations'].each do |loc|
+        auth[loc] = ldap['name']
+      end
+    end
+    return auth
+end
+
+# Annotate scan entries with hints only for paths that require auth
+def annotate_scan(scan, auth)
+  annotated = scan.reject{ |k, v| v[1] =~ /\A#{ISERR}/ }
+  annotated.each do |path, ary|
+    realm = auth.select { |k, v| path.match(/\A#{k}/) }
+    if realm.values.first
+      ary << AUTHMAP[realm.values.first]
+    end
+  end
+  return annotated
+end
+
+# Common use case # TODO these could be static generated files nightly
+def get_annotated_scan(dir)
+  scan = scan_dir(dir)
+  auth = get_auth()
+  return annotate_scan(scan, auth)
+end
+
diff --git a/www/committers/tools.cgi b/www/committers/tools.cgi
index d26c180..ff109e4 100755
--- a/www/committers/tools.cgi
+++ b/www/committers/tools.cgi
@@ -19,17 +19,23 @@ _html do
       -> {
         _ 'This page shows a '
         _em 'partial'
-        _ ' listing of the useful data and tools that Whimsy provides to Apache committers.'
-        _br
-        _ 'It is generated automatically from tools that opt-in. Future improvements 
-        include automatically noting which tools require which auth (public|committer|member|officer).'
-        _br
-        _ 'If you find this useful, please let us know at dev@whimsical!.'
+        _ ' listing of tools that Whimsy provides. If you find this useful, please email
dev@whimsical!'
+        _ul do
+          _li do
+            _span.glyphicon :aria_hidden, class: "#{AUTHPUBLIC}"
+            _ 'Publicly available'
+          end
+          AUTHMAP.each do |realm, style|
+            _li do
+              _span.glyphicon.glyphicon_lock :aria_hidden, class: "#{style}"
+              _ "#{realm}"
+            end
+          end
+        end
       }
     ) do
-      scan = scandir("../#{SCANDIR}") # TODO Should be a static generated file
-      scan.reject{ |k, v| v[1] =~ /\A#{ISERR}/ }
-        .group_by{ |k, v| v[1][0] }
+      scan = get_annotated_scan("../#{SCANDIR}")
+      scan.group_by{ |k, v| v[1][0] }
         .each do | category, links |
         _ul.list_group do
           _li.list_group_item.active do
@@ -37,6 +43,13 @@ _html do
           end
           links.each do |l, desc|
             _li.list_group_item do
+              if 2 == desc.length
+                _span.glyphicon :aria_hidden, class: "#{AUTHPUBLIC}"
+              else
+                _span class: desc[2] do
+                  _span.glyphicon.glyphicon_lock :aria_hidden
+                end
+              end
               _a "#{desc[0]}", href: l
               _ ' - '
               _code! do

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message