gitgolem 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ require 'optparse'
2
+
3
+ # Parsing command line options.
4
+ module Golem::Parser
5
+ # Parse arguments and run the specified command (or +environment+ if non given).
6
+ def self.run(args)
7
+ options = {}
8
+ ::OptionParser.new do |opts|
9
+ opts.banner = "Usage: golem [options] command [arguments]"
10
+ opts.separator ""
11
+ opts.separator "Options:"
12
+ opts.on("-c", "--config FILE", "path to config file") {|val| options[:cfg_path] = val}
13
+ opts.on("-d", "--db URL", "database to use (e.g. 'simple' or 'postgres://', etc.)") {|val| options[:db] = val}
14
+ opts.on("-u", "--user-home PATH", "path to user's home (e.g. the authorized key will be written here)") {|val| options[:user_home] = val}
15
+ opts.on("-r", "--repositories DIR", "path to repositories (may be relative to user_home)") {|val| options[:repository_dir] = val}
16
+ opts.on("-b", "--base DIR", "path to base (place of conf, hooks by default)") {|val| options[:base_dir] = val}
17
+ opts.on("-B", "--bin DIR", "path to executable (defaults to base/bin)") {|val| options[:bin_dir] = val}
18
+ opts.on("-H", "--hooks DIR", "path to hooks (defaults to base/hooks)") {|val| options[:hooks_dir] = val}
19
+ opts.on("-h", "--help", "show this message") {puts opts; exit}
20
+ opts.on("-v", "--verbose", "show output (defaults to false, note: not every command supports it)") {Golem::Parser.verbose = true}
21
+ opts.separator ""
22
+ opts.separator "Environment variables (options always take precedence):"
23
+ opts.separator "\tGOLEM_CONF is used as config file path if exists"
24
+ opts.separator "\tGOLEM_BASE is used as base dir"
25
+ opts.separator "\tHOME is used as user-home path"
26
+ opts.separator ""
27
+ opts.separator "Commands:"
28
+ Golem::Command::COMMANDS.each do |cmd|
29
+ usage = Golem::Command.usage(cmd).split("\n")
30
+ opts.separator "\tgolem #{cmd.to_s} " + usage.shift
31
+ opts.separator usage.collect {|l| "\t\t" + l}.join("\n") if usage.length > 0
32
+ opts.separator "\t\tsynonyms: " + Golem::Command::ALIASES[cmd].join(', ') if Golem::Command::ALIASES.key?(cmd)
33
+ end
34
+ end.parse! args
35
+ Golem::Config.auto_configure(options.delete(:cfg_path)) do
36
+ options.each do |key, val|
37
+ send((key.to_s + "=").to_sym, val)
38
+ end
39
+ end
40
+ Golem::Command.run(args.shift || "environment", {:verbose => (@verbose || false)}, *args)
41
+ end
42
+
43
+ # @private
44
+ def self.verbose=(val) # :nodoc:
45
+ @verbose = !!val
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module Golem
2
+ # Versions.
3
+ module Version
4
+ # Major version.
5
+ MAJOR = 0
6
+ # Minor version.
7
+ MINOR = 1
8
+ # Patch version.
9
+ PATCH = 1
10
+ # Version string.
11
+ STRING = [MAJOR, MINOR, PATCH].join(".")
12
+ end
13
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'golem'
15
+
16
+ class Test::Unit::TestCase
17
+ class << self; attr_accessor :cfg, :users, :repos, :keys end
18
+ attr_accessor :cfg, :users, :repos, :keys
19
+
20
+ def setup
21
+ self.cfg = self.class.cfg || {}
22
+ self.users = self.class.users || []
23
+ self.repos = self.class.repos || {}
24
+ self.keys = self.class.keys || {}
25
+ Golem.configure(cfg) do |cfg|
26
+ cfg.db = 'static'
27
+ Golem::DB.setup do |db|
28
+ users.each {|u| db.add_user u}
29
+ repos.each {|u, r| (r.is_a?(Array) ? r : [r]).each {|r| db.add_repository r, u}}
30
+ keys.each {|u, k| (k.is_a?(Array) ? k : [k]).each {|k| db.add_key u, k}}
31
+ end
32
+ end if users.length > 0
33
+ end
34
+
35
+ def teardown
36
+ Golem::Config.instance_variable_set("@vars", nil) #need to reset
37
+ Golem::DB.instance_variable_set("@db", nil) #need to reset
38
+ end
39
+ end
40
+
41
+ class WithTestDb < Test::Unit::TestCase
42
+ self.users = ["test_user1", "test_user2"]
43
+ self.repos = {"test_user1" => ["test_repo1", "test_repo2"], "test_user2" => "test_repo3"}
44
+ self.keys = {"test_user1" => ["test_key1", "test_key2"], "test_user2" => "test_key3"}
45
+ undef_method :default_test
46
+
47
+ def self.inherited(base)
48
+ base.users = users
49
+ base.repos = repos
50
+ base.keys = keys
51
+ end
52
+ end
53
+
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ class TestAccess < WithTestDb
4
+ def test_access
5
+ repos.each do |user, repos|
6
+ (repos.is_a?(Array) ? repos : [repos]).each do |repo|
7
+ assert Golem::Access.check(user, repo, 'unused'), "access check failed for #{user.to_s}, #{repo.to_s}"
8
+ end
9
+ end
10
+ end
11
+
12
+ def test_return_values
13
+ assert_kind_of Array, Golem::Access.users
14
+ assert_equal users, Golem::Access.users
15
+ assert_kind_of Array, Golem::Access.repositories
16
+ assert_equal repos.values.flatten, Golem::Access.repositories
17
+ assert_kind_of Hash, Golem::Access.ssh_keys
18
+ assert_equal keys.inject({}) {|m, (u, k)| m[u] = k.is_a?(Array) ? k : [k]; m}, Golem::Access.ssh_keys
19
+ end
20
+
21
+ def test_convenience_methods
22
+ assert Golem::Access.read?("receive-pack")
23
+ assert !Golem::Access.write?("receive-pack")
24
+ ["upload-pack", "upload-archive"].each do |w|
25
+ assert !Golem::Access.read?(w)
26
+ assert Golem::Access.write?(w)
27
+ end
28
+ assert !Golem::Access.read?("invalid")
29
+ assert !Golem::Access.write?("invalid")
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class TestConfig < Test::Unit::TestCase
4
+ def test_configure
5
+ assert_nothing_raised do
6
+ Golem.configure do |cfg|
7
+ Golem::Config::CFG_VARS.each do |var|
8
+ cfg.send((var.to_s + "=").to_sym, var)
9
+ end
10
+ end
11
+ Golem::Config::CFG_VARS.each do |var|
12
+ assert_equal var, Golem::Config.send(var)
13
+ end
14
+ end
15
+ end
16
+ end
data/test/test_db.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ class TestDb < WithTestDb
4
+ def test_static
5
+ assert_equal users.collect {|u| {:name => u}}, Golem::DB.users
6
+ assert_equal users, Golem::DB.users(:return => :array)
7
+ assert_equal repos.collect {|u, r| (r.is_a?(Array) ? r : [r]).collect {|r| {:user_name => u, :name => r}}}.flatten, Golem::DB.repositories
8
+ assert_equal repos.values.flatten, Golem::DB.repositories(:return => :array)
9
+ assert_equal keys.collect {|u, k| (k.is_a?(Array) ? k : [k]).collect {|k| {:user_name => u, :key => k}}}.flatten, Golem::DB.ssh_keys
10
+ assert_equal keys.collect {|u, k| (k.is_a?(Array) ? k : [k]).collect {|k| [u, k]}}.flatten(1), Golem::DB.ssh_keys(:return => :array)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitgolem
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - PoTa
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-10 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 7
27
+ segments:
28
+ - 0
29
+ - 6
30
+ - 0
31
+ version: 0.6.0
32
+ name: yard
33
+ prerelease: false
34
+ type: :development
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ name: bundler
49
+ prerelease: false
50
+ type: :development
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 1
61
+ - 5
62
+ - 2
63
+ version: 1.5.2
64
+ name: jeweler
65
+ prerelease: false
66
+ type: :development
67
+ requirement: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ name: rcov
79
+ prerelease: false
80
+ type: :development
81
+ requirement: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ name: bluecloth
93
+ prerelease: false
94
+ type: :development
95
+ requirement: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ hash: 1
103
+ segments:
104
+ - 1
105
+ version: "1"
106
+ name: test-unit
107
+ prerelease: false
108
+ type: :development
109
+ requirement: *id006
110
+ description: Golem provides an easy way to host and manage access to git repositories on a server under a single user.
111
+ email: pota@mosfet.hu
112
+ executables:
113
+ - golem
114
+ - golem-shell
115
+ extensions: []
116
+
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.md
120
+ - TODO
121
+ files:
122
+ - .document
123
+ - .yardopts
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/golem
129
+ - bin/golem-shell
130
+ - lib/gitgolem.rb
131
+ - lib/golem.rb
132
+ - lib/golem/access.rb
133
+ - lib/golem/command.rb
134
+ - lib/golem/command/auth.rb
135
+ - lib/golem/command/clear_repositories.rb
136
+ - lib/golem/command/create_repository.rb
137
+ - lib/golem/command/delete_repository.rb
138
+ - lib/golem/command/environment.rb
139
+ - lib/golem/command/save_config.rb
140
+ - lib/golem/command/setup_db.rb
141
+ - lib/golem/command/update_hooks.rb
142
+ - lib/golem/command/update_keys_file.rb
143
+ - lib/golem/config.rb
144
+ - lib/golem/db.rb
145
+ - lib/golem/db/pg.rb
146
+ - lib/golem/db/postgres.sql
147
+ - lib/golem/db/static.rb
148
+ - lib/golem/parser.rb
149
+ - lib/golem/version.rb
150
+ - test/helper.rb
151
+ - test/test_access.rb
152
+ - test/test_config.rb
153
+ - test/test_db.rb
154
+ - TODO
155
+ homepage: http://github.com/eLod/golem
156
+ licenses:
157
+ - MIT
158
+ post_install_message:
159
+ rdoc_options: []
160
+
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3
169
+ segments:
170
+ - 0
171
+ version: "0"
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ hash: 3
178
+ segments:
179
+ - 0
180
+ version: "0"
181
+ requirements: []
182
+
183
+ rubyforge_project:
184
+ rubygems_version: 1.7.2
185
+ signing_key:
186
+ specification_version: 3
187
+ summary: Gem to host git repositories.
188
+ test_files:
189
+ - test/helper.rb
190
+ - test/test_access.rb
191
+ - test/test_config.rb
192
+ - test/test_db.rb