idnio 2.3.2b

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.
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env ruby
2
+ require "json"
3
+ require "idnio/idnapi"
4
+ require "idnio/program"
5
+ require "idnio/markdown"
6
+
7
+ module EmailTemplates
8
+
9
+ @@email_template_cache = nil
10
+
11
+ @@exclude_email_templates = [
12
+ "Account Group Challenge Creation Notification",
13
+ "Account Selection Notification",
14
+ "Batch Approval",
15
+ "Certification Decision Challenged Notification",
16
+ "Certification Reminder",
17
+ "Certification Sign Off Approval",
18
+ "Challenge Accepted",
19
+ "Challenge Creation Notification",
20
+ "Challenge Decision Expiration",
21
+ "Challenge Expiration",
22
+ "Challenge Period End",
23
+ "Challenge Period Start",
24
+ "Challenge Rejected",
25
+ "Continuous Certification Escalation",
26
+ "Continuous Certification Reminder",
27
+ "Default Report Template",
28
+ "Delegation Finished",
29
+ "Delegation Revocation",
30
+ "Delegation",
31
+ "LCM Identity Update Approval",
32
+ "LCM Manager Notification",
33
+ "LCM Password Change Notification",
34
+ "LCM Registration Approval",
35
+ "LCM Registration Manager Notification",
36
+ "LCM Registration Security Officer Notification",
37
+ "LCM Registration User Notification",
38
+ "LCM Requester Notification",
39
+ "LCM User Notification",
40
+ "Mitigation Expiration",
41
+ "Native Account Change Manager Notification",
42
+ "Open Certifications",
43
+ "Pending Manual Changes",
44
+ "Policy Violation Delegation",
45
+ "Policy Violation",
46
+ "Provisioning Form Notification",
47
+ "Remediation Item Assignment Removal",
48
+ "Remediation Item Assignment",
49
+ "Remediation Notification",
50
+ "Remediation Work Item",
51
+ "Report Completion",
52
+ "Role Modeler - Approval",
53
+ "Role Modeler - Impact Analysis Review",
54
+ "Task Result Signoff",
55
+ "Task Status",
56
+ "Work Item Assignment Removal",
57
+ "Work Item Assignment",
58
+ "Work Item Comment",
59
+ "Work Item Escalation",
60
+ "Work Item Forward",
61
+ "Work Item Reminder"
62
+ ]
63
+
64
+ #
65
+ # Gets Email Template configuration by name.
66
+ #
67
+ def self.get_by_name( name )
68
+
69
+ if (@@email_template_cache == nil)
70
+ response = IDNAPI.get( "#{$url}/cc/api/emailTemplate/list", $token )
71
+ @@email_template_cache = JSON.parse( response.body )
72
+ end # if (@@email_template_cache == nil)
73
+
74
+ unless @@email_template_cache.nil?
75
+ @@email_template_cache['items'].each do |email_template|
76
+ if( email_template["name"] == name )
77
+ return email_template
78
+ end # if( email_template["name"] == name )
79
+ end # @@email_template_cache['items'].each do |email_template|
80
+ end # unless @@email_template_cache.nil?
81
+
82
+ return nil
83
+ end
84
+
85
+ #
86
+ # Exports Email Template configurations.
87
+ #
88
+ def self.export( directory )
89
+
90
+ response = IDNAPI.get( "#{$url}/cc/api/emailTemplate/list", $token )
91
+
92
+ case response
93
+ when Net::HTTPSuccess
94
+
95
+ email_templates = JSON.parse( response.body )
96
+
97
+ $log.info "\tDetected #{email_templates['count']} email templates."
98
+
99
+ email_templates['items'].each do |email_template|
100
+
101
+ if (!@@exclude_email_templates.include? email_template["name"])
102
+
103
+ $log.info "\tEmail Template: #{email_template["name"]}"
104
+ Program.write_file( "#{directory}/email-templates/", "Email Template - #{email_template["name"]}.json", JSON.pretty_generate( email_template ) )
105
+
106
+ else
107
+
108
+ $log.debug "\tSkipping Email Template: #{email_template["name"]}"
109
+
110
+ end # if (!@@default_email_templates.include? email_template["name"])...
111
+
112
+ end # email_templates['items'].each do |email_template|
113
+
114
+ else
115
+ $log.error "\tError: Unable to fetch email templates."
116
+ end # case response
117
+
118
+ end
119
+
120
+ #
121
+ # Imports Email Template configurations.
122
+ #
123
+ def self.import( directory )
124
+
125
+ # Read from the file system to determine how many identity profile configurations we have.
126
+ email_templates = Program.read_directory("#{directory}/email-templates")
127
+
128
+ $log.info "\tDetected #{email_templates.length} email templates."
129
+
130
+ # Iterate through each email template.
131
+ email_templates.each do |raw_email_template|
132
+
133
+ # Get the email template JSON.
134
+ email_template = JSON.parse( raw_email_template )
135
+
136
+ $log.info "\tEmail Template: #{email_template["name"]}"
137
+
138
+ # Get the existing email template.
139
+ existing_email_template = EmailTemplates.get_by_name( email_template["name"] )
140
+
141
+ # Make sure the email template referenced, actually exists.
142
+ unless existing_email_template.nil?
143
+
144
+ if (!@@exclude_email_templates.include? email_template["name"])
145
+
146
+ update_params = {
147
+ "id": existing_email_template["id"],
148
+ "name": email_template["name"],
149
+ "description": email_template["description"],
150
+ "subject": email_template["subject"],
151
+ "body": email_template["body"],
152
+ "state": email_template["state"],
153
+ "cc": email_template["cc"]
154
+ }
155
+
156
+ $log.debug "\t\tUpdating email template..."
157
+ response = IDNAPI.post_form( "#{$url}/cc/api/emailTemplate/update", $token, update_params )
158
+ $log.debug "\t\tEmail template updated."
159
+
160
+ else
161
+ $log.debug "\tSkipping Email Template: #{email_template["name"]}"
162
+ end # if (!@@default_transforms.include? transform["id"]...
163
+
164
+ else
165
+ $log.warn "\t\tSkipping unknown email template. \n"
166
+ end # unless existing_email_template.nil?
167
+
168
+ end # email_templates.each do |raw_email_template|
169
+
170
+ end
171
+
172
+ #
173
+ # Documents Email Template configurations.
174
+ #
175
+ def self.doc
176
+
177
+ response = IDNAPI.get( "#{$url}/cc/api/emailTemplate/list", $token )
178
+
179
+ case response
180
+ when Net::HTTPSuccess
181
+
182
+ email_templates = JSON.parse( response.body )
183
+
184
+ $log.info "\tDetected #{email_templates['count']} email templates."
185
+
186
+ # Give up if we don't have any email templates to doc
187
+ # if email_templates.nil? || email_templates.empty? || email_templates['count'] == 0 )
188
+ # break
189
+ # end
190
+
191
+ Markdown.h2( "Email Templates" )
192
+
193
+ email_templates['items'].each do |email_template|
194
+
195
+ if (!@@exclude_email_templates.include? email_template["name"])
196
+
197
+ $log.info "\tEmail Template: #{email_template["name"]}"
198
+
199
+ Markdown.h3( email_template["name"] )
200
+
201
+ unless email_template["subject"].nil?
202
+ Markdown.text( "Subject:\n")
203
+ Markdown.xml( email_template["subject"] )
204
+ end
205
+
206
+ unless email_template["body"].nil?
207
+ Markdown.text( "Body:\n")
208
+ Markdown.xml( email_template["body"] )
209
+ end
210
+
211
+ else
212
+
213
+ $log.debug "\tSkipping Email Template: #{email_template["name"]}"
214
+
215
+ end # if (!@@default_email_templates.include? email_template["name"])...
216
+
217
+ end # email_templates['items'].each do |email_template|
218
+
219
+ else
220
+ $log.error "\tError: Unable to fetch email templates."
221
+ end # case response
222
+
223
+ Markdown.write
224
+ end
225
+
226
+ end
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+ require "json"
3
+ require "idnio/idnapi"
4
+ require "idnio/program"
5
+ require "idnio/markdown"
6
+
7
+ module IdentityAttributes
8
+
9
+ @@disallowed_identity_attributes = [
10
+ "country",
11
+ "displayName",
12
+ "email",
13
+ "endDate",
14
+ "firstname",
15
+ "identificationNumber",
16
+ "lastname",
17
+ "licenseStatus",
18
+ "manager",
19
+ "personalEmail",
20
+ "phone",
21
+ "startDate",
22
+ "uid",
23
+ "workPhone",
24
+ "cloudLifecycleState",
25
+ "department",
26
+ "title"
27
+ ]
28
+
29
+ #
30
+ # Gets an identity attribute by name
31
+ #
32
+ def self.get_by_name( name )
33
+ response = IDNAPI.get( URI.escape("#{$url}/cc/api/identityAttribute/get?name=#{name}"), $token )
34
+ case response
35
+ when Net::HTTPSuccess
36
+ return JSON.parse( response.body )
37
+ else
38
+ return nil
39
+ end
40
+ end
41
+
42
+ #
43
+ # Creates an identity attribute
44
+ #
45
+ def self.create( identity_attribute )
46
+ create_json = {
47
+ 'displayName' => identity_attribute['displayName'],
48
+ 'name' => identity_attribute['name'],
49
+ 'multiValued' => identity_attribute['multiValued'],
50
+ 'namedColumn' => identity_attribute['namedColumn'],
51
+ 'searchable' => identity_attribute['searchable'],
52
+ 'standard' => identity_attribute['standard'],
53
+ 'system' => identity_attribute['system'],
54
+ 'type' => identity_attribute['type']
55
+ }
56
+ response = IDNAPI.post_json( "#{$url}/cc/api/identityAttribute/create", $token, create_json )
57
+ end
58
+
59
+ #
60
+ # Updates an identity attribute
61
+ #
62
+ def self.update( identity_attribute )
63
+ update_json = {
64
+ 'displayName' => identity_attribute['displayName'],
65
+ 'name' => identity_attribute['name'],
66
+ 'multiValued' => identity_attribute['multiValued'],
67
+ 'namedColumn' => identity_attribute['namedColumn'],
68
+ 'searchable' => identity_attribute['searchable'],
69
+ 'standard' => identity_attribute['standard'],
70
+ 'system' => identity_attribute['system'],
71
+ 'type' => identity_attribute['type']
72
+ }
73
+ response = IDNAPI.post_json( "#{$url}/cc/api/identityAttribute/update?name=#{identity_attribute['name']}", $token, update_json )
74
+ end
75
+
76
+ #
77
+ # Exports Identity Attribute configurations.
78
+ #
79
+ def self.export( directory )
80
+
81
+ response = IDNAPI.get( "#{$url}/cc/api/identityAttribute/list", $token )
82
+
83
+ case response
84
+ when Net::HTTPSuccess
85
+
86
+ identity_attributes = JSON.parse( response.body )
87
+
88
+ $log.info "\tRetreived identity attributes."
89
+
90
+ Program.write_file( File.join( directory, "identity-attributes"), "identity-attributes.json", JSON.pretty_generate( identity_attributes ) )
91
+
92
+ else
93
+ $log.error "\tError: Unable to fetch identity attributes."
94
+ end # case response
95
+
96
+ end
97
+
98
+ #
99
+ # Import Identity Attribute configurations.
100
+ #
101
+ def self.import( directory )
102
+
103
+ # Read configurations from the file system.
104
+ identity_attributes = Program.read_file( File.join( directory, "identity-attributes", "identity-attributes.json") )
105
+ $log.info "\tRetreived identity attributes."
106
+
107
+ unless identity_attributes.nil?
108
+
109
+ JSON.parse( identity_attributes ).each do |identity_attribute|
110
+
111
+ unless ( @@disallowed_identity_attributes.include? identity_attribute["name"] )
112
+
113
+ existing_identity_attribute = IdentityAttributes.get_by_name( identity_attribute["name"] )
114
+
115
+ if existing_identity_attribute.nil?
116
+ response = IdentityAttributes.create( identity_attribute )
117
+ else
118
+ response = IdentityAttributes.update( identity_attribute )
119
+ end
120
+
121
+ else
122
+ $log.warn "\t\tSkipping default identity attribute: #{identity_attribute["name"]}."
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+
129
+ #
130
+ # Documents Identity Attribute configurations.
131
+ #
132
+ def self.doc
133
+ $log.warn "\tDocumentation for object type identity-attributes is not supported at this time."
134
+ end
135
+
136
+ end
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env ruby
2
+ require "json"
3
+ require "idnio/idnapi"
4
+ require "idnio/program"
5
+ require "idnio/markdown"
6
+
7
+ module IdentityProfiles
8
+
9
+ #
10
+ # These are a list of attributes which are used to update.
11
+ #
12
+ @@update_attributes = [
13
+ "attributeConfig",
14
+ "authErrorText",
15
+ "autoInvitationOption",
16
+ "autoInvite",
17
+ "autoInviteLifeCycleState",
18
+ "blockOffNetwork",
19
+ "blockUntrustedGeographies",
20
+ "description",
21
+ "priority",
22
+ "pwdResetDuo",
23
+ "pwdResetKba",
24
+ "pwdResetMfaType",
25
+ "pwdResetPersonalEmailCode",
26
+ "pwdResetPersonalPhone",
27
+ "pwdResetRsa",
28
+ "pwdResetSafenet",
29
+ "pwdResetSymantecVip",
30
+ "pwdResetWorkEmailCode",
31
+ "pwdResetWorkPhone",
32
+ "strongAuthDuo",
33
+ "strongAuthKba",
34
+ "strongAuthLogin",
35
+ "strongAuthLoginOffNetwork",
36
+ "strongAuthLoginUntrustedGeographies",
37
+ "strongAuthPassword",
38
+ "strongAuthPersonalEmail",
39
+ "strongAuthPersonalPhone",
40
+ "strongAuthRsa",
41
+ "strongAuthSafenet",
42
+ "strongAuthSymantecVip",
43
+ "strongAuthWorkEmail",
44
+ "strongAuthWorkPhone"
45
+ ]
46
+
47
+ #
48
+ # Query an Identity Profile configuration.
49
+ #
50
+ def self.get_by_name( name )
51
+
52
+ response = IDNAPI.get( "#{$url}/cc/api/profile/list", $token )
53
+
54
+ case response
55
+ when Net::HTTPSuccess
56
+
57
+ identity_profiles = JSON.parse( response.body )
58
+
59
+ identity_profiles.each do |identity_profile|
60
+
61
+ if( identity_profile["name"] == name )
62
+ return identity_profile
63
+ end
64
+
65
+ end
66
+ end # case response
67
+
68
+ return nil
69
+ end
70
+
71
+ #
72
+ # Exports Identity Profile configurations.
73
+ #
74
+ def self.export( directory )
75
+
76
+ response = IDNAPI.get( "#{$url}/cc/api/profile/list", $token )
77
+
78
+ unless response.nil?
79
+
80
+ identityProfiles = JSON.parse( response.body )
81
+
82
+ $log.info "\tDetected #{identityProfiles.count} identity profiles."
83
+
84
+ identityProfiles.each do |identityProfile|
85
+
86
+ response = IDNAPI.get( "#{$url}/cc/api/profile/get/#{identityProfile["id"]}", $token )
87
+
88
+ identityProfileObject = JSON.parse( response.body )
89
+
90
+ $log.info "\tIdentity Profile: #{identityProfileObject["name"]}"
91
+
92
+ Program.write_file( "#{directory}/identity-profiles/", "Identity Profile - #{identityProfileObject["name"]}.json", JSON.pretty_generate( identityProfileObject ) )
93
+
94
+ end
95
+ end
96
+ end
97
+
98
+ #
99
+ # Imports Identity Profile configurations.
100
+ #
101
+ def self.import( directory )
102
+
103
+ # Read from the file system to determine how many identity profile configurations we have.
104
+ identity_profiles = Program.read_directory("#{directory}/identity-profiles")
105
+ $log.info "\tDetected #{identity_profiles.length} identity profiles."
106
+
107
+ #
108
+ # Iterate through each identity profile.
109
+ #
110
+ identity_profiles.each do |identity_profile|
111
+
112
+ # Get the identity profile JSON.
113
+ template_idp = JSON.parse( identity_profile )
114
+
115
+ $log.info "\tIdentity Profile: #{template_idp["name"]}"
116
+
117
+ # Get the existing identity profile.
118
+ existing_idp = IdentityProfiles.get_by_name( template_idp["name"] )
119
+
120
+ # If we don't have an existing IDP, lets create one.
121
+ if existing_idp.nil?
122
+
123
+ # Lets get our existing source.
124
+ existing_source_id = Sources.get_cc_id( template_idp['source']['name'] )
125
+
126
+ # We can't create an identity profile without an existing source, so make sure we have one.
127
+ unless existing_source_id.nil?
128
+
129
+ $log.debug "\t\tCreating identity profile..."
130
+
131
+ create_params = {
132
+ "name" => template_idp['name'],
133
+ "sourceId" => existing_source_id
134
+ }
135
+ response = IDNAPI.post_form( "#{$url}/cc/api/profile/create", $token, create_params )
136
+
137
+ unless response.nil?
138
+ existing_idp = IdentityProfiles.get_by_name( template_idp['name'] )
139
+ $log.debug "done.\n"
140
+ end
141
+ else
142
+ $log.warn "\t\tSkipping identity profile creation. Source [#{template_idp['source']['name']}] does not exist.\n"
143
+ end
144
+
145
+ end
146
+
147
+ # Now that we have an IDP, lets update it.
148
+ unless existing_idp.nil?
149
+
150
+ #
151
+ # Do some clean-up on attribute references... sigh.
152
+ #
153
+ template_idp["attributeConfig"]["attributeTransforms"].each do |attributeTransform|
154
+ unless attributeTransform.nil? || ["attributes"].nil?
155
+ attributeTransform["attributes"].delete( "applicationId" )
156
+ attributeTransform["attributes"].delete( "applicationName" )
157
+
158
+ unless attributeTransform["attributes"]["input"].nil?
159
+ attributeTransform["attributes"]["input"]["attributes"].delete( "applicationId" )
160
+ attributeTransform["attributes"]["input"]["attributes"].delete( "applicationName" )
161
+ end
162
+ end
163
+ end
164
+
165
+ #
166
+ # Copy over certain settings from the template.
167
+ #
168
+ @@update_attributes.each do |update_attribute|
169
+ existing_idp[update_attribute] = template_idp[update_attribute]
170
+ end
171
+
172
+ $log.debug "\t\tUpdating identity profile..."
173
+ IDNAPI.post_json( "#{$url}/cc/api/profile/update/#{existing_idp["id"]}", $token, existing_idp )
174
+ $log.debug "done.\n"
175
+
176
+ end
177
+
178
+ end
179
+ end
180
+
181
+ #
182
+ # Documents Identity Profile configurations.
183
+ #
184
+ def self.doc
185
+ Markdown.h2( "Identity Profiles" )
186
+
187
+ response = IDNAPI.get( "#{$url}/cc/api/profile/list", $token )
188
+ unless response.nil?
189
+ identityProfiles = JSON.parse( response.body )
190
+
191
+ $log.info "\tDetected #{identityProfiles.count} identity profiles."
192
+
193
+ identityProfiles.each do |identityProfile|
194
+
195
+ response = IDNAPI.get( "#{$url}/cc/api/profile/get/#{identityProfile["id"]}", $token )
196
+
197
+ identityProfile_object = JSON.parse( response.body )
198
+
199
+ $log.info "\tIdentity Profile: #{identityProfile_object["name"]}"
200
+
201
+ end
202
+ end
203
+
204
+ Markdown.write
205
+ end
206
+ end