class ASF::Authorization

parse the -authorization-template files contained within infrastructure-puppet/modules/subversion_server/files/authorization

Public Class Methods

find_by_id(value) click to toggle source

Return the set of authorizations a given user (availid) has access to.

# File lib/whimsy/asf/auth.rb, line 9
def self.find_by_id(value)
  new.select {|auth, ids| ids.include? value}.map(&:first)
end
new(file='asf',auth_path=nil) click to toggle source

Select a given -authorization-template, valid values are asf and pit. The optional auth_path parameter allows the directory path to be overridden This is intended for testing only

# File lib/whimsy/asf/auth.rb, line 17
def initialize(file='asf',auth_path=nil)
  # TODO - should this read the Git repo directly?
  # Probably not: this file is read frequently so would need to be cached anyway
  # The Git clone is updated every 10 minutes which should be sufficiently recent
  if auth_path
    require 'wunderbar'
    Wunderbar.warn "Overriding Git infrastructure-puppet auth path as: #{auth_path}"
    @auth = auth_path
  else
    auth = ASF::Git.find('infrastructure-puppet')
    if auth
      @auth = auth + '/modules/subversion_server/files/authorization'
    else
      # SVN copy is no longer in use - see INFRA-11452
      raise Exception.new("Cannot find Git: infrastructure-puppet")
    end
  end
  @file = file
end

Public Instance Methods

each() { |pmc, split(',')| ... } click to toggle source

Iteratively return each non_LDAP entry in the authorization file as a pair of values: a name and list of ids.

# File lib/whimsy/asf/auth.rb, line 39
def each
  read_auth.scan(/^([-\w]+)=(\w.*)$/).each do |pmc, ids|
    yield pmc, ids.split(',')
  end
end
path() click to toggle source

Return the auth path used to find asf-auth and pit-auth

# File lib/whimsy/asf/auth.rb, line 56
def path
  @auth
end
projects() click to toggle source

Return an array of the ou=project entries in the authorization file

# File lib/whimsy/asf/auth.rb, line 46
def projects
  arr = []
  #incubator={ldap:cn=incubator,ou=project,ou=groups,dc=apache,dc=org;attr=member}
  read_auth.scan(/^\w[^=]+={ldap:cn=(\w[^,]+),ou=project,ou=groups/).each do |group|
    arr << group[0]
  end
  arr
end
to_h() click to toggle source

backwards compatibility for Ruby versions <= 2.0

# File lib/whimsy/asf/auth.rb, line 62
def to_h
  Hash[self.to_a]
end