rs_user_policy 0.0.1 → 0.0.2
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.
- data/lib/audit_log.rb +59 -0
- data/lib/utilities.rb +54 -0
- metadata +7 -5
data/lib/audit_log.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright (c) 2012 Ryan J. Geyer
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
class AuditLog
|
23
|
+
|
24
|
+
attr_accessor :filename, :audit_log
|
25
|
+
|
26
|
+
# Initializes a new AuditLog
|
27
|
+
#
|
28
|
+
# === Parameters
|
29
|
+
# options(Hash):: A hash of options that impact the audit log filename. Possible options are;
|
30
|
+
# :timestamp(String):: The timestamp to append to the filename
|
31
|
+
# :dry_run(Bool):: A boolean indicating if this is a dry run
|
32
|
+
def initialize(options={})
|
33
|
+
timestamp = options[:timestamp] || Time.now.to_i
|
34
|
+
@audit_log = {}
|
35
|
+
@filename = "audit_log#{options[:dry_run] ? '_dryrun' : ''}-#{timestamp}.json"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Adds a new entry to the audit log
|
39
|
+
#
|
40
|
+
# === Parameters
|
41
|
+
# email(String):: The email address of the user impacted by the change
|
42
|
+
# account(String):: The account name impacted by the change
|
43
|
+
# action(String):: The action performed. Expected options are ['update_permissions', 'deleted']
|
44
|
+
# changes(String):: A free form description of the changes
|
45
|
+
def add_entry(email, account, action, changes)
|
46
|
+
@audit_log[email] = [] unless audit_log[email]
|
47
|
+
@audit_log[email] << {
|
48
|
+
:account => account,
|
49
|
+
:action => action,
|
50
|
+
:changes => changes
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Writes the audit log to a file
|
55
|
+
#
|
56
|
+
def write_file
|
57
|
+
File.open(@filename, 'w') {|f| f.write(JSON.pretty_generate(@audit_log))}
|
58
|
+
end
|
59
|
+
end
|
data/lib/utilities.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2012 Ryan J. Geyer
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
class Utilities
|
23
|
+
|
24
|
+
# Uses a regex to parse a RightScale API resource id from it's relative href
|
25
|
+
#
|
26
|
+
# === Parameters
|
27
|
+
# href(String):: The relative href of the RightScale API resource
|
28
|
+
#
|
29
|
+
# === Return
|
30
|
+
# The resources ID
|
31
|
+
def self.id_from_href(href)
|
32
|
+
matches = /.*\/([0-9]*)/.match(href)
|
33
|
+
matches[1] || nil
|
34
|
+
end
|
35
|
+
|
36
|
+
# Operates on the key/value pairs in a hash in the order specified in 'order'
|
37
|
+
# followed by any key/value pairs not specified in the order
|
38
|
+
#
|
39
|
+
# === Parameters
|
40
|
+
# order(Array):: An array containing keys in the order they should be yielded to the block
|
41
|
+
# hash(Hash):: The hash to operate on in the specified order
|
42
|
+
# block(Closure):: A closure to yield to
|
43
|
+
def self.yield_on_keys_in_order(order, hash, &block)
|
44
|
+
order.each do |key|
|
45
|
+
if hash.key?(key)
|
46
|
+
yield key, hash.delete(key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
hash.each do |key,val|
|
50
|
+
yield key, val
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rs_user_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: right_api_client
|
@@ -51,10 +51,12 @@ executables:
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
+
- lib/audit_log.rb
|
55
|
+
- lib/utilities.rb
|
54
56
|
- bin/rs_user_policy
|
55
57
|
- LICENSE.txt
|
56
58
|
- README.rdoc
|
57
|
-
homepage:
|
59
|
+
homepage: https://github.com/rgeyer/rs_user_policy
|
58
60
|
licenses:
|
59
61
|
- MIT
|
60
62
|
post_install_message:
|
@@ -69,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
71
|
version: '0'
|
70
72
|
segments:
|
71
73
|
- 0
|
72
|
-
hash: -
|
74
|
+
hash: -1930275068111788648
|
73
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
76
|
none: false
|
75
77
|
requirements:
|
@@ -78,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
80
|
version: '0'
|
79
81
|
segments:
|
80
82
|
- 0
|
81
|
-
hash: -
|
83
|
+
hash: -1930275068111788648
|
82
84
|
requirements: []
|
83
85
|
rubyforge_project:
|
84
86
|
rubygems_version: 1.8.23
|