dtk-common 0.5.11 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTc5NTVkYjZlM2Y2MTRlYjE1YzY0YmQ4OTdlMmRlZDUwN2VmYmE3MQ==
4
+ ZGU3ZDY1NjdiMmQ2ZGY0ZGQ4NDIxMWJmZGUwNGRlODMxMTcwMzBmNw==
5
5
  data.tar.gz: !binary |-
6
- YjVjZGNmYWEwZWZhN2JhZjAyODA2MDU3Yjg3YWQyYWE3MzYxYTIwYw==
6
+ MTI5OTVkZDM5YWRlNTcxMjViODA0NzdiN2FhOWNlNTdmMTRmMmY3MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjM5ZjVhZDAzNjZjN2Q1YWY3NjY3ZmQ1Y2Q1ZTIyM2Q1NjE5YTdhODBiNTY2
10
- OTlkMmQ3MWM2MTZlNzRkMzQwYTFjNGVmZmRhNmYxYTEzZmUxZWY3MDU5NTk5
11
- N2ZiMTE3ZjcyMTAyYjkzNGM0OWUyZGRkYWU5MjQ3NGUxYTk5OWY=
9
+ ZTMyNzJmNjE5ZTUzMWFhY2IwMTQ2YzZhMDBhNGM4N2Q3NzU4NWY5MGUzMTRj
10
+ ZGYyM2E2Y2VkZTM4MDYyNjIyMmI5Y2QwZWM3MWRhOWQxOTQyMGEyYjU4ZjMy
11
+ MGFjZDQ0ZWEzNWEwMDQ0ZTJlYjdmNGVhODVhMzEzNWMzMDM5NGY=
12
12
  data.tar.gz: !binary |-
13
- YmQ4YTA3MzU4MDI0M2YyZjE2YTIwNjkxMzQzZGQ3ZDZhNjZhNjZkNWFmN2Jj
14
- YTQ1MmRkZGExZGIyZDk5ZjI1ZDJhM2I1MTZjZjVmNmM1NDdmMGRlM2I0NjQ0
15
- ZDNkMDNiNWVhODVjYTFiNDQ4MjFkMDVkZmIwODMyNzI3ODU5OWM=
13
+ OTJlNmY0Y2Q3YzFmOGE1Zjc0MTczMWQ2YTdkOTQxNTRkNDU3M2IzNDUzNzQ2
14
+ N2IwYmMxMGE2MmY2OTg4YzEwNzAyYjVhMzE0YzZiZjQ5ZGQyZjhmNmZjNGIy
15
+ NTEyNjI3ZjUzYWRiZWIwOTY5YzNhMjYzZmY1YjQzNzcxMTM5NzA=
@@ -1,3 +1,3 @@
1
1
  module DtkCommon
2
- VERSION = "0.5.11"
2
+ VERSION = "0.5.12"
3
3
  end
data/lib/gitolite/init.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  # use to require all needed files needed for running dtk-common gitolite lib
2
2
  require 'grit'; require 'erubis'
3
3
 
4
- Grit.debug = true
5
-
4
+ Grit.debug = false
6
5
 
7
6
  require File.expand_path('manager.rb', File.dirname(__FILE__))
8
7
  require File.expand_path('configuration.rb', File.dirname(__FILE__))
@@ -37,14 +37,16 @@ module Gitolite
37
37
  group_conf
38
38
  end
39
39
 
40
- def create_user(username, rsa_pub_key, opts={})
41
- key_path = @configuration.user_key_path(username)
40
+ # this should be depracated
41
+ def create_user(username, rsa_pub_key, rsa_pub_key_name)
42
+ key_name = "#{username}@#{rsa_pub_key_name}"
43
+ key_path = @configuration.user_key_path(key_name)
42
44
 
43
45
  if users_public_keys().include?(key_path)
44
- raise ::Gitolite::Duplicate, "Trying to create a user (#{username}) that exists already on gitolite server"
46
+ raise ::Gitolite::Duplicate, "Public key (#{rsa_pub_key_name}) already exists for user (#{username}) on gitolite server"
45
47
  end
46
48
 
47
- add_commit_file(key_path,rsa_pub_key, "Added RSA public key for user '#{username}'")
49
+ add_commit_file(key_path,rsa_pub_key, "Added public key (#{rsa_pub_key_name}) for user (#{username}) ")
48
50
 
49
51
  key_path
50
52
  end
@@ -52,15 +54,40 @@ module Gitolite
52
54
  def delete_user(username)
53
55
  key_path = @configuration.user_key_path(username)
54
56
 
55
- unless users_public_keys().include?(key_path)
57
+ has_there_been_deletion = remove_public_keys_for_user!(username)
58
+
59
+ unless has_there_been_deletion
56
60
  raise ::Gitolite::NotFound, "User (#{username}) not found on gitolite server"
57
61
  end
58
62
 
59
- remove_file(key_path, "Removing RSA public key for user '#{username}'")
60
63
  username
61
64
  end
62
65
 
63
- def remove_user_group(group_name)
66
+ def add_pub_key!(username, rsa_pub_key_name, rsa_pub_key)
67
+ file_name = "#{username}@#{rsa_pub_key_name}"
68
+ key_path = @configuration.user_key_path(file_name)
69
+
70
+ if users_public_keys().include?(key_path)
71
+ raise ::Gitolite::Duplicate, "Duplicate public key (#{rsa_pub_key_name}) for user (#{username})"
72
+ end
73
+
74
+ add_commit_file(key_path, rsa_pub_key, "Added RSA public key (#{file_name}) for user (#{username})")
75
+ file_name
76
+ end
77
+
78
+ def remove_pub_key!(username, rsa_pub_key_name)
79
+ file_name = "#{username}@#{rsa_pub_key_name}"
80
+ key_path = @configuration.user_key_path(file_name)
81
+
82
+ unless users_public_keys().include?(key_path)
83
+ raise ::Gitolite::NotFound, "Public key (#{rsa_pub_key_name}) for user (#{username}) not found"
84
+ end
85
+
86
+ remove_file(key_path, "Remove public key (#{rsa_pub_key_name}) for user (#{username})")
87
+ true
88
+ end
89
+
90
+ def delete_user_group!(group_name)
64
91
  group_path = @configuration.user_group_path(group_name)
65
92
 
66
93
  unless user_group_list.include?(group_path)
@@ -94,6 +121,31 @@ module Gitolite
94
121
  end
95
122
  end
96
123
 
124
+ # only to help with migration, to be deleted later TODO: Delete
125
+ def migrate_to_multiple_pub_keys()
126
+ all_pub_keys = users_public_keys()
127
+ base_path = @configuration.keydir_path
128
+
129
+ puts "Starting migration of PUB keys from old format to new! (This can take a while)"
130
+ all_pub_keys.each do |pub_key_path|
131
+ # skip git pub or already migrated key
132
+ unless pub_key_path.match(/.*git.pub$/) || pub_key_path.include?('@')
133
+ file_name = extract_file_name(pub_key_path,base_path,:pub)
134
+ pub_content = gitolite_admin_repo().file_content(pub_key_path)
135
+
136
+ # delete_user
137
+ remove_file(pub_key_path, "Migrating user ('#{file_name}') to new annotation, temporary removing user")
138
+
139
+ # create user
140
+ create_user(file_name, pub_content)
141
+ end
142
+ end
143
+ puts "End migration of pub keys"
144
+ require 'pp'
145
+ pp users_public_keys
146
+ puts "--------------- END ---------------"
147
+ end
148
+
97
149
  private
98
150
 
99
151
  def gitolite_admin_repo()
@@ -128,20 +180,8 @@ module Gitolite
128
180
  @commit_messages << commit_msg
129
181
  end
130
182
 
131
-
132
- class << self
133
-
134
- def repo_name_from_file_name(file_name, repo_file_path)
135
- if file_name =~ Regexp.new("^#{repo_file_path}/(.+)\.conf")
136
- $1
137
- else
138
- raise Error.new("File name not properly formed for repo config file name (#{file_name})")
139
- end
140
- end
141
- end
142
-
143
183
  def extract_file_name(full_path_name, file_path, file_extension)
144
- if file_name =~ Regexp.new("^#{full_path_name}/(.+)\.#{file_extension}")
184
+ if full_path_name =~ Regexp.new("^#{file_path}/(.+)\.#{file_extension}")
145
185
  $1
146
186
  else
147
187
  raise ::Gitolite::ParseError.new("File name not properly formed (#{full_path_name}), expected match based on '#{file_path}/*.#{file_extension}'")
@@ -154,5 +194,38 @@ module Gitolite
154
194
  paths.select{ |p| p =~ match_regexp }
155
195
  end
156
196
 
197
+ def remove_public_keys_for_user!(username)
198
+ all_pub_keys = users_public_keys()
199
+ base_path = @configuration.keydir_path
200
+ is_deleted = false
201
+
202
+ all_pub_keys.each do |pub_key_path|
203
+ file_name = extract_file_name(pub_key_path,base_path,:pub)
204
+
205
+ # looking only at pub keys will '@' in their names
206
+ if file_name.include?('@')
207
+ files_username, files_pub_name = file_name.split('@')
208
+
209
+ # e.g. for user 'haris' we remove haris@home.pub, haris@work.pub
210
+ if files_username && files_username.eql?(username)
211
+ remove_file(pub_key_path, "Remove public key (#{files_pub_name}) for user (#{username})")
212
+ is_deleted = true
213
+ end
214
+ end
215
+ end
216
+
217
+ is_deleted
218
+ end
219
+
220
+ def number_of_public_keys_for_user(username)
221
+ all_pub_keys = users_public_keys()
222
+ base_path = @configuration.keydir_path
223
+
224
+ return all_pub_keys.count do |pub_key_path|
225
+ file_name = extract_file_name(pub_key_path,base_path,:pub)
226
+ (file_name.eql?(username) || file_name.match(/^#{username}@/))
227
+ end
228
+ end
229
+
157
230
  end
158
231
  end
@@ -6,6 +6,7 @@ module DTK; module Common; class GritAdapter
6
6
  require File.expand_path('file_access/diff', File.dirname(__FILE__))
7
7
  include StatusMixin
8
8
  include DiffMixin
9
+
9
10
  def add_file(file_rel_path, content=nil)
10
11
  content ||= String.new
11
12
  file_path = qualified_path(file_rel_path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  version: '0'
199
199
  requirements: []
200
200
  rubyforge_project:
201
- rubygems_version: 2.1.9
201
+ rubygems_version: 2.2.2
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: Common libraries used for DTK CLI client.