Class: Gitolite::Dtg::GitoliteAdmin

Inherits:
Object
  • Object
show all
Defined in:
lib/gitolite-dtg/gitolite_admin.rb

Constant Summary collapse

CONF =
"gitolite.conf"
CONFDIR =
"conf"
BRANCH =
"master"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ GitoliteAdmin

Intialize with the path to the gitolite-admin repository



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 14

def initialize(path, options = {})
  @path = path
  @gl_admin = Grit::Repo.new(path)

  @conf = options[:conf] || CONF
  @confdir = options[:confdir] || CONFDIR
  @branch  = options[:branch] || BRANCH

  # Load the configuration
  load_data
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 6

def config
  @config
end

#gl_adminObject

Returns the value of attribute gl_admin.



6
7
8
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 6

def gl_admin
  @gl_admin
end

Class Method Details

.is_gitolite_admin_repo?(dir) ⇒ Boolean

Checks to see if the given path is a gitolite-admin repository A valid repository contains a conf folder, keydir folder, and a configuration file within the conf folder

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 35

def self.is_gitolite_admin_repo?(dir)
  # First check if it is a git repository
  begin
	repo = Grit::Repo.new(dir)
  rescue Grit::InvalidGitRepositoryError
	return false
  end

  # If we got here it is a valid git repo,
  # now check directory structure
  cbl = repo.tree / 'conf/gitolite.conf'
  if cbl != nil
	return true
  else
	return false
  end
end

Instance Method Details

#authorize(repo_name, username, resource_path, wanted_access) ⇒ Object

repo_name - the repository name username - the authenticated user name resource_path - the path relative to the repository root that

the user is requesting access to

wanted_access - the type of access the user is requesting. can

be 'R' or 'W'


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 59

def authorize(repo_name, username, resource_path, wanted_access)
	if @config == nil
		return false
	end
	repo = @config.repos[repo_name]
	if repo != nil
		repo.permissions.each do |perm_hash|
			perm_hash.each do |perm, list|
			  #process a permission line
			  list.each do |refex, users|
				
				ul = []
			  	users.each do |user|
					if user[0,1]=='@'
					    gname = user.gsub('@', '')
					    if ((@config.special_groups.include? gname) == false)
							grp = @config.flat_groups[gname]
							ul.concat(grp)
						else
							ul.push(user)
					    end
					else
						ul.push(user)
					end
			  	end
			  	ul.uniq!
			  	
			  	user_matches = false
			  	if ((ul.include? "@all") || ((ul.include? "@raven") && (username != nil)) || (ul.include? username))
					user_matches = true
			  	end
			  	
			  	if user_matches == false
					next
				end
				
				
				refex_applies = false;
				if refex == ''
					refex_applies = true;
				else
					dirs = []
					dirs.push(refex)
					dirs.push(resource_path)

					common_prefix = dirs.abbrev.keys.min_by {|key| key.length}.chop
					common_directory = common_prefix.sub(%r{/[^/]*$}, '')
					
					if common_directory != ''
						refex_applies = true
					end
				end
				if !refex_applies
					next # if rule refex does not refer to the resource the user requested, go to the next rule
				end
				
			  	
			  	access_matches = false
			  	if (perm.include? wanted_access)
					access_matches = true
			  	end
			  	
			  	# authorization cases. at this point, user_matches==true and refex_applies==true:
			  	if (perm == "-")
					return false
				elsif (user_matches && access_matches)
					#print "Access allowed by matching rule: " + perm + " "
					#print list
					#print "\n"
					return true
				else
					next
			  	end

			  end
			end
		end
	end
	return false
end

#reload!Object

This method will destroy the in-memory data structures and reload everything from the file system



28
29
30
# File 'lib/gitolite-dtg/gitolite_admin.rb', line 28

def reload!
  load_data
end