rs_user_policy 0.1.11 → 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +5 -13
  2. data/bin/rs_user_policy +50 -10
  3. metadata +11 -11
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODAwMDdlOGM2NDMzMzljMDQwZjZiNTkyODFlZmVlYTBjOGViMTczYg==
5
- data.tar.gz: !binary |-
6
- OGI0YTE4NTQ2MzAzNzJiOTg1ODIyNWQ1NzliZTM5NGJmNjkyZjY0Mw==
2
+ SHA1:
3
+ metadata.gz: 4576f396772da4c965b1cbfdf34bc09ee5f9a6fd
4
+ data.tar.gz: 5216592d2b36de78aef33502ce652ff7da27bad1
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTM4Mjk0MjlkZTQ1N2NhMTM4ZDZmZGVjZGVhZjJmMDg5Njk1Yjc3YTMxZTMy
10
- ZTM4NTY2MTkwOWUyZjk2NjBmN2YwY2QyYmYwMDgzNWIzMTU1OGQ2OWZjNjRj
11
- NDRmNWVjNTU0OGE4NGE4ZTNkZTFlZDM5MTZjMDlhNDk3NWE2MGY=
12
- data.tar.gz: !binary |-
13
- NTgyNWU1YmE0ODQwN2UyNGZkMmY3YzUyMTMxZDdlNjQ2NTg0NGI0NTZiMTRk
14
- YmFlZjMxMDAwM2JkMmM3MmJiZTMwYWE4NmFiMGY3ZTkxNzYxZTE3ZTVhNmRl
15
- ZTY1NWE0NWViYzMxMTA5NTcyN2M2MTkxNTFmNWQ2Yjc0MTY3ZDI=
6
+ metadata.gz: d3e8afa8cd3950f14730d5a397805baa7555c21dea52c735b20be6dafa1be97827d4d6d6b1f698a24fde1b8ddc057cf3d805535f57bbea429576cfdaa37915d0
7
+ data.tar.gz: f7f73a20e3ee04b9115b09d19f2fac91a3e9a5f9686c255a00b58bb37296726ac2cfcd622fe6ad615996a47b4d6db38aad1bc4556342a61ed38e5619e06e9ea5
data/bin/rs_user_policy CHANGED
@@ -50,9 +50,15 @@ opts = Trollop::options do
50
50
  opt :audit_dir, "A directory where audit logs will be stored. By default this is the current working directory.", :type => :string
51
51
  opt :dry_run, "A flag indicating that no changes should be made, only the user_assignments.json should be evaluated (or created) and the audit_log.json produced"
52
52
  opt :authority, "A flag indicating that all users in the user_assignments file \"MUST\" exist, and will always be created. Effectively asserting that the user_assignments is your canonical authority for users."
53
+ opt :debug, "A flag which will cause very verbose logging to help torubleshoot problems."
53
54
  end
54
55
 
55
56
  log = Logger.new(STDOUT)
57
+ if opts[:debug]
58
+ log.level = Logger::DEBUG
59
+ else
60
+ log.level = Logger::INFO
61
+ end
56
62
  timestamp = Time::now.to_i
57
63
 
58
64
  if opts[:dry_run]
@@ -92,10 +98,25 @@ log.info("Invoked with account numbers (#{opts[:rs_acct_num].join(",")}).")
92
98
  # Iterate over all accounts once to discover users and their permissions
93
99
  multi_client.each do |account_id, account|
94
100
  child_client = account[:client]
95
- child_account = child_client.accounts(:id => account_id).show()
101
+ begin
102
+ child_account = child_client.accounts(:id => account_id).show()
103
+ rescue RightApi::ApiError => e
104
+ log.error("Failed to get account details for account id #{account_id}.\n Error: #{e}")
105
+ next
106
+ end
96
107
  account_href = child_account.href
97
- users = child_client.users.index
98
- permissions = child_client.permissions.index
108
+ begin
109
+ users = child_client.users.index
110
+ rescue RightApi::ApiError => e
111
+ log.error("Failed to list users for account #{child_account.name}:#{account_id} - #{child_account.href}.\n Error: #{e}")
112
+ next
113
+ end
114
+ begin
115
+ permissions = child_client.permissions.index
116
+ rescue RightApi::ApiError => e
117
+ log.error("Failed to create a user with the following properties.\n Properties: #{JSON.pretty_generate(user_create_params)}\n Error: #{e}")
118
+ next
119
+ end
99
120
  user_collection.add_users(users)
100
121
  user_collection.add_permissions(account_href, permissions)
101
122
 
@@ -154,9 +175,15 @@ end
154
175
  begin
155
176
  multi_client.each do |account_id,account|
156
177
  child_client = account[:client]
157
- child_account = child_client.accounts(:id => account_id).show()
178
+ begin
179
+ child_account = child_client.accounts(:id => account_id).show()
180
+ rescue RightApi::ApiError => e
181
+ log.error("Failed to get account details for account id #{account_id}.\n Error: #{e}")
182
+ next
183
+ end
158
184
  account_name = child_account.name
159
185
  account_href = child_account.href
186
+ log.info("Making user permission changes in account #{account_name}:#{account_href}")
160
187
 
161
188
  user_collection.users.each do |user|
162
189
  email = user.email
@@ -169,15 +196,28 @@ begin
169
196
  # a user can also be effectively deleted if they have an empty list of
170
197
  # permissions for a particular account
171
198
  unless opts[:dry_run]
172
- log.debug("Deleting #{user.email} from #{account_name} by removing these permissions #{JSON.pretty_generate(existing_permissions)}")
173
- user.clear_permissions(account_href, child_client)
199
+ log.debug(" Deleting #{user.email} from #{account_name} by removing these permissions #{JSON.pretty_generate(existing_permissions)}")
200
+ begin
201
+ user.clear_permissions(account_href, child_client)
202
+ rescue RightApi::ApiError => e
203
+ log.error(" Failed to delete user #{user.email}:#{user.href} from #{account_name}.\n Error: #{e}")
204
+ next
205
+ end
174
206
  end
175
207
  audit_log.add_entry(email, account_name, 'deleted', 'deleted')
176
208
  elsif !user_role.include?("immutable")
177
- user_policy = policy.get_permissions(user_role, account_href)
178
- removed,added = user.set_api_permissions(user_policy, account_href, child_client, :dry_run => opts[:dry_run])
179
- changes = "-#{removed.values} +#{added.values}"
180
- audit_log.add_entry(email, account_name, 'update_permissions', changes) unless removed.length + added.length == 0
209
+ begin
210
+ user_policy = policy.get_permissions(user_role, account_href)
211
+ role_titles = existing_permissions.map{|p| p.role_title }
212
+ log.debug(" Updating user #{user.email}:#{user.href}.\n Existing Permissions: #{role_titles.sort}\n Desired Permissions: #{user_policy.sort}")
213
+
214
+ removed,added = user.set_api_permissions(user_policy, account_href, child_client, :dry_run => opts[:dry_run])
215
+ changes = "-#{removed.values} +#{added.values}"
216
+ audit_log.add_entry(email, account_name, 'update_permissions', changes) unless removed.length + added.length == 0
217
+ rescue RightApi::ApiError => e
218
+ log.error("Failed to update permissions for user #{user.email}:#{user.href} in account #{account_name}:#{account_href}.\n Error: #{e}")
219
+ next
220
+ end
181
221
  end
182
222
  end
183
223
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs_user_policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan J. Geyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: right_api_client
@@ -28,7 +28,7 @@ dependencies:
28
28
  name: trollop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.16'
34
34
  - - <
@@ -38,7 +38,7 @@ dependencies:
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ! '>='
41
+ - - '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '1.16'
44
44
  - - <
@@ -52,10 +52,6 @@ executables:
52
52
  extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
- - LICENSE.txt
56
- - README.rdoc
57
- - bin/rs_user_policy
58
- - lib/rs_user_policy.rb
59
55
  - lib/rs_user_policy/audit_log.rb
60
56
  - lib/rs_user_policy/policy/json_policy.rb
61
57
  - lib/rs_user_policy/policy/policy.rb
@@ -66,6 +62,10 @@ files:
66
62
  - lib/rs_user_policy/user_assignments/user_assignments.rb
67
63
  - lib/rs_user_policy/user_collection.rb
68
64
  - lib/rs_user_policy/utilities.rb
65
+ - lib/rs_user_policy.rb
66
+ - bin/rs_user_policy
67
+ - LICENSE.txt
68
+ - README.rdoc
69
69
  homepage: https://github.com/rgeyer/rs_user_policy
70
70
  licenses:
71
71
  - MIT
@@ -76,17 +76,17 @@ require_paths:
76
76
  - lib
77
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ! '>='
79
+ - - '>='
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ! '>='
84
+ - - '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.2.2
89
+ rubygems_version: 2.0.14
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Manages users across many different child accounts of a RightScale Enterprise