admin_module 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +14 -0
  5. data/Guardfile +24 -0
  6. data/LICENSE +22 -0
  7. data/README.md +281 -0
  8. data/Rakefile +98 -0
  9. data/admin_module.gemspec +34 -0
  10. data/bin/admin_module +13 -0
  11. data/lib/admin_module.rb +260 -0
  12. data/lib/admin_module/cli.rb +54 -0
  13. data/lib/admin_module/cli/cli_guideline.rb +80 -0
  14. data/lib/admin_module/cli/cli_lock.rb +149 -0
  15. data/lib/admin_module/cli/cli_parameter.rb +66 -0
  16. data/lib/admin_module/cli/cli_task.rb +149 -0
  17. data/lib/admin_module/cli_old.rb +92 -0
  18. data/lib/admin_module/client.rb +146 -0
  19. data/lib/admin_module/command.rb +25 -0
  20. data/lib/admin_module/command/client_access.rb +43 -0
  21. data/lib/admin_module/command/config.rb +310 -0
  22. data/lib/admin_module/command/dc.rb +110 -0
  23. data/lib/admin_module/command/gdl.rb +71 -0
  24. data/lib/admin_module/command/lock.rb +110 -0
  25. data/lib/admin_module/command/ppm.rb +142 -0
  26. data/lib/admin_module/command/rule.rb +77 -0
  27. data/lib/admin_module/command/ruleset.rb +56 -0
  28. data/lib/admin_module/command/snapshot.rb +110 -0
  29. data/lib/admin_module/command/stage.rb +131 -0
  30. data/lib/admin_module/command/task.rb +110 -0
  31. data/lib/admin_module/config_helper.rb +33 -0
  32. data/lib/admin_module/dc.rb +133 -0
  33. data/lib/admin_module/guideline.rb +86 -0
  34. data/lib/admin_module/locks.rb +142 -0
  35. data/lib/admin_module/page_factory.rb +55 -0
  36. data/lib/admin_module/pages.rb +120 -0
  37. data/lib/admin_module/pages/dc_definitions_page.rb +73 -0
  38. data/lib/admin_module/pages/dc_detail_page.rb +187 -0
  39. data/lib/admin_module/pages/guideline_page.rb +35 -0
  40. data/lib/admin_module/pages/guideline_version_page.rb +140 -0
  41. data/lib/admin_module/pages/guidelines_page.rb +59 -0
  42. data/lib/admin_module/pages/guidelines_version_all_page.rb +116 -0
  43. data/lib/admin_module/pages/lock_definition_page.rb +178 -0
  44. data/lib/admin_module/pages/lock_definitions_page.rb +69 -0
  45. data/lib/admin_module/pages/login_page.rb +75 -0
  46. data/lib/admin_module/pages/parameter_page.rb +62 -0
  47. data/lib/admin_module/pages/parameters_page.rb +46 -0
  48. data/lib/admin_module/pages/ppms_page.rb +110 -0
  49. data/lib/admin_module/pages/rule_page.rb +68 -0
  50. data/lib/admin_module/pages/rules_page.rb +74 -0
  51. data/lib/admin_module/pages/ruleset_page.rb +64 -0
  52. data/lib/admin_module/pages/rulesets_page.rb +60 -0
  53. data/lib/admin_module/pages/select_list_syncable.rb +64 -0
  54. data/lib/admin_module/pages/snapshot_definitions_page.rb +73 -0
  55. data/lib/admin_module/pages/snapshot_detail_page.rb +246 -0
  56. data/lib/admin_module/pages/workflow_detail_page.rb +451 -0
  57. data/lib/admin_module/pages/workflow_detail_task_addl_detail_page.rb +172 -0
  58. data/lib/admin_module/pages/workflow_detail_task_mappings_page.rb +163 -0
  59. data/lib/admin_module/pages/workflow_detail_task_screens_page.rb +75 -0
  60. data/lib/admin_module/pages/workflow_details_page.rb +67 -0
  61. data/lib/admin_module/pages/workflow_task_page.rb +107 -0
  62. data/lib/admin_module/pages/workflow_tasks_page.rb +111 -0
  63. data/lib/admin_module/ppms.rb +78 -0
  64. data/lib/admin_module/rake.rb +22 -0
  65. data/lib/admin_module/rake/dc_tasks.rb +185 -0
  66. data/lib/admin_module/rake/deploy_task.rb +59 -0
  67. data/lib/admin_module/rake/gdl_tasks.rb +189 -0
  68. data/lib/admin_module/rake/lock_tasks.rb +189 -0
  69. data/lib/admin_module/rake/parameter_task.rb +86 -0
  70. data/lib/admin_module/rake/ppm_tasks.rb +248 -0
  71. data/lib/admin_module/rake/rule_tasks.rb +157 -0
  72. data/lib/admin_module/rake/snapshot_tasks.rb +223 -0
  73. data/lib/admin_module/rake/stage_tasks.rb +197 -0
  74. data/lib/admin_module/rake/stages_task.rb +197 -0
  75. data/lib/admin_module/rake/task_tasks.rb +189 -0
  76. data/lib/admin_module/rules.rb +50 -0
  77. data/lib/admin_module/rulesets.rb +42 -0
  78. data/lib/admin_module/snapshots.rb +133 -0
  79. data/lib/admin_module/stages.rb +171 -0
  80. data/lib/admin_module/tasks.rb +147 -0
  81. data/lib/admin_module/version.rb +3 -0
  82. data/old_spec/lib/admin_module/cli_configuration_spec.rb +126 -0
  83. data/old_spec/lib/admin_module/cli_create_stage_spec.rb +89 -0
  84. data/old_spec/lib/admin_module/cli_delete_rule_spec.rb +57 -0
  85. data/old_spec/lib/admin_module/cli_deploy_spec.rb +57 -0
  86. data/old_spec/lib/admin_module/cli_export_locks_spec.rb +62 -0
  87. data/old_spec/lib/admin_module/cli_export_stages_spec.rb +62 -0
  88. data/old_spec/lib/admin_module/cli_guidelines_version_all_spec.rb +58 -0
  89. data/old_spec/lib/admin_module/cli_import_locks_spec.rb +153 -0
  90. data/old_spec/lib/admin_module/cli_import_stages_spec.rb +173 -0
  91. data/old_spec/lib/admin_module/cli_modify_locks_spec.rb +128 -0
  92. data/old_spec/lib/admin_module/cli_modify_stages_spec.rb +88 -0
  93. data/old_spec/lib/admin_module/cli_rename_rule_spec.rb +53 -0
  94. data/old_spec/lib/admin_module/cli_rename_ruleset_spec.rb +53 -0
  95. data/old_spec/lib/admin_module/cli_var_spec.rb +41 -0
  96. data/old_spec/lib/admin_module/rake/deploy_task_spec.rb +85 -0
  97. data/old_spec/lib/admin_module/rake/parameter_task_spec.rb +58 -0
  98. data/old_spec/lib/admin_module/rake/rules_task_spec.rb +75 -0
  99. data/spec/data/build/test1.xml +0 -0
  100. data/spec/data/build/test2.xml +1 -0
  101. data/spec/data/import_dcs.yml +31 -0
  102. data/spec/data/import_locks.yml +4 -0
  103. data/spec/data/import_snapshots.yml +35 -0
  104. data/spec/data/import_stages.yml +4 -0
  105. data/spec/data/import_tasks.yml +25 -0
  106. data/spec/data/patch-test.xml +1 -0
  107. data/spec/data/remove_test_del_rule.xml +1 -0
  108. data/spec/data/stages.yml +518 -0
  109. data/spec/data/test_del_rule.xml +1 -0
  110. data/spec/lib/admin_module/admin_module_spec.rb +175 -0
  111. data/spec/lib/admin_module/cli_spec.rb +36 -0
  112. data/spec/lib/admin_module/client_spec.rb +158 -0
  113. data/spec/lib/admin_module/command/config_spec.rb +477 -0
  114. data/spec/lib/admin_module/command/dc_spec.rb +202 -0
  115. data/spec/lib/admin_module/command/gdl_spec.rb +139 -0
  116. data/spec/lib/admin_module/command/lock_spec.rb +207 -0
  117. data/spec/lib/admin_module/command/rule_spec.rb +163 -0
  118. data/spec/lib/admin_module/command/ruleset_spec.rb +124 -0
  119. data/spec/lib/admin_module/command/snapshot_spec.rb +202 -0
  120. data/spec/lib/admin_module/command/stage_spec.rb +259 -0
  121. data/spec/lib/admin_module/command/task_spec.rb +207 -0
  122. data/spec/lib/admin_module/dc_spec.rb +192 -0
  123. data/spec/lib/admin_module/guideline_spec.rb +177 -0
  124. data/spec/lib/admin_module/locks_spec.rb +188 -0
  125. data/spec/lib/admin_module/rules_spec.rb +110 -0
  126. data/spec/lib/admin_module/rulesets_spec.rb +85 -0
  127. data/spec/lib/admin_module/snapshot_spec.rb +192 -0
  128. data/spec/lib/admin_module/stages_spec.rb +179 -0
  129. data/spec/lib/admin_module/tasks_spec.rb +196 -0
  130. data/spec/spec_helper.rb +54 -0
  131. data/spec/support/asserts.rb +13 -0
  132. data/spec/support/data_clearing.rb +28 -0
  133. data/spec/support/dirs.rb +54 -0
  134. data/spec/support/helpers.rb +83 -0
  135. data/spec/support/lock.rb +23 -0
  136. data/spec/support/mocks.rb +213 -0
  137. data/spec/support/snapshot.rb +28 -0
  138. data/spec/support/stage.rb +22 -0
  139. data/spec/support/stage_factory.rb +138 -0
  140. data/spec/support/task.rb +23 -0
  141. metadata +381 -0
@@ -0,0 +1,189 @@
1
+ ##############################################################################
2
+ # File:: lock_tasks.rb
3
+ # Purpose:: LockTasks definition
4
+ #
5
+ # Author:: Jeff McAffee 2015-03-12
6
+ #
7
+ ##############################################################################
8
+
9
+ require 'admin_module'
10
+ require 'rake/dsl_definition'
11
+ require 'rake'
12
+
13
+ module AdminModule::Rake
14
+
15
+ class LockTasks
16
+ include ::Rake::DSL if defined?(::Rake::DSL)
17
+
18
+ attr_accessor :env
19
+ attr_accessor :name
20
+ attr_accessor :to
21
+ attr_accessor :path
22
+ attr_accessor :allow_create
23
+ attr_reader :action
24
+ attr_reader :valid_actions
25
+ attr_reader :stop_on_exception
26
+
27
+ def initialize(task_name = 'locks_task', desc = "Modify a lock or locks")
28
+ @valid_actions = ['import', 'export', 'read', 'list', 'rename']
29
+ @task_name, @desc = task_name, desc
30
+
31
+ @stop_on_exception = true
32
+ @allow_create = false
33
+
34
+ yield self if block_given?
35
+
36
+ define_task
37
+ end
38
+
39
+ def define_task #:nodoc:
40
+ desc @desc
41
+ task(@task_name, required_args_for_action) do |t,args|
42
+ set_vars args
43
+ commit # Call method to perform when invoked.
44
+ end
45
+ end
46
+
47
+ def set_vars args
48
+ args.each do |arg,val|
49
+ instance_variable_set "@#{arg}", val
50
+ end
51
+
52
+ args
53
+ end
54
+
55
+ def action=(task_action)
56
+ raise "action must be one of #{valid_types.join(', ')}" unless valid_actions.include?(task_action.downcase)
57
+ @action = task_action
58
+ end
59
+
60
+ def stop_on_exception=(do_stop)
61
+ raise ArgumentError, 'Expecting true or false' unless do_stop === true || do_stop === false
62
+ @stop_on_exception = do_stop
63
+ end
64
+
65
+ def commit
66
+ validate_params
67
+
68
+ client = AdminModule::Client.new
69
+ client.env = env
70
+
71
+ if self.respond_to? action
72
+ self.send(action, client)
73
+ return
74
+ else
75
+ raise "Unknown action - #{action}"
76
+ end
77
+
78
+ rescue Exception => e
79
+ raise e if stop_on_exception == true
80
+ ensure
81
+ client.quit
82
+ end
83
+
84
+ def list client
85
+ $stdout << client.locks.list.join("\n")
86
+ $stdout << "\n"
87
+ end
88
+
89
+ def read client
90
+ result = {}
91
+ result[name] = client.locks.read(name)
92
+ $stdout << result.to_yaml
93
+ end
94
+
95
+ def import client
96
+ $stdout << client.locks.import(path, allow_create)
97
+ end
98
+
99
+ def export client
100
+ $stdout << client.locks.export(path)
101
+ end
102
+
103
+ def rename client
104
+ $stdout << client.locks.rename(name, to)
105
+ end
106
+
107
+ def validate_params
108
+ assert_provided env, 'Missing "env"'
109
+ assert_provided action, 'Missing "action"'
110
+
111
+ case action
112
+ when 'import'
113
+ assert_provided path, 'Missing "path"'
114
+
115
+ when 'export'
116
+ assert_provided path, 'Missing "path"'
117
+
118
+ when 'read'
119
+ assert_provided name, 'Missing "name"'
120
+
121
+ when 'rename'
122
+ assert_provided name, 'Missing "name"'
123
+ assert_provided to, 'Missing "to"'
124
+
125
+ end
126
+
127
+ assert_env_is_configured env
128
+ end
129
+
130
+ def assert_provided value, msg
131
+ if value.nil? || value.empty?
132
+ raise msg
133
+ end
134
+ end
135
+
136
+ def assert_env_is_configured arg
137
+ unless AdminModule.configuration.credentials.key? arg
138
+ init_msg = "Have you initialized your config file?\n Try: admin_module config init <filedir>"
139
+ env_msg = "Have you configured your environments?\n Try: admin_module config add env <envname> <url>"
140
+ raise "Unknown environment: #{arg}\n#{init_msg}\n\n#{env_msg}"
141
+ end
142
+ end
143
+
144
+ def required_args_for_action
145
+ args = []
146
+
147
+ case action
148
+ when 'read'
149
+ args << :name
150
+
151
+ when 'rename'
152
+ args << :name
153
+ args << :to
154
+
155
+ when 'import'
156
+ args << :path
157
+ args << :allow_create
158
+
159
+ when 'export'
160
+ args << :path
161
+
162
+ else
163
+ # Noop
164
+ end
165
+
166
+ args
167
+ end
168
+
169
+ class << self
170
+ def install
171
+ new.install
172
+ end
173
+ end
174
+
175
+ def install
176
+ AdminModule.configuration.credentials.keys.each do |e|
177
+ valid_actions.each do |action|
178
+ AdminModule::Rake::LockTasks.new("am:#{e}:lock:#{action}", "#{action} #{e} lock(s)") do |t|
179
+ t.env = e
180
+ t.action = action
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end # class
186
+ end # module
187
+
188
+ AdminModule::Rake::LockTasks.install
189
+
@@ -0,0 +1,86 @@
1
+ ##############################################################################
2
+ # File:: parameter_task.rb
3
+ # Purpose:: ParameterTask definition
4
+ #
5
+ # Author:: Jeff McAffee 03/19/2014
6
+ # Copyright:: Copyright (c) 2014, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'admin_module'
11
+ require 'rake/dsl_definition'
12
+ require 'rake'
13
+
14
+ module AdminModule::Rake
15
+
16
+ class ParameterTask
17
+ include ::Rake::DSL if defined?(::Rake::DSL)
18
+
19
+ attr_accessor :env
20
+ attr_accessor :name
21
+ attr_reader :type
22
+ attr_reader :decision
23
+ attr_reader :order
24
+ attr_reader :precision
25
+ attr_reader :include
26
+
27
+ def initialize(task_name = 'save_in_xml', desc = "Set or clear a variable's Save in XML flag")
28
+ @task_name, @desc = task_name, desc
29
+
30
+ yield self if block_given?
31
+
32
+ define_task
33
+ end
34
+
35
+ def define_task #:nodoc:
36
+ desc @desc
37
+ task @task_name do
38
+ update
39
+ end
40
+ end
41
+
42
+ def type=(new_type)
43
+ valid_types = ['Boolean', 'Date', 'DateTime', 'Money', 'Numeric', 'Percentage', 'Text']
44
+ raise "type must be one of #{valid_types.join(', ')}" unless valid_types.include?(new_type)
45
+ @type = new_type
46
+ end
47
+
48
+ def decision=(new_decision)
49
+ raise "decision must be true or false" unless (new_decision === true || new_decision === false)
50
+ @decision = new_decision ? 'Yes' : 'No'
51
+ end
52
+
53
+ def order=(new_order)
54
+ @order = new_order.to_i
55
+ end
56
+
57
+ def precision=(new_precision)
58
+ @precision = new_precision.to_i
59
+ end
60
+
61
+ def include=(new_state)
62
+ raise "include must be true or false" unless (new_state === true || new_state === false)
63
+ @include = new_state
64
+ end
65
+
66
+ def update(current_name = nil)
67
+ current_name = name if current_name.nil?
68
+ current_name = '' if current_name.nil?
69
+
70
+ cli = AdminModule::CLI.new
71
+ cli.environment = env
72
+ params = { :name => @name,
73
+ :type => @type,
74
+ :decision => @decision,
75
+ :order => @order,
76
+ :precision => @precision,
77
+ :include => @include }
78
+ params.delete_if { |k,v| v.nil? }
79
+
80
+ cli.update_parameter(current_name, params)
81
+ ensure
82
+ cli.quit
83
+ end
84
+ end # class ParameterTask
85
+ end # module AdminModule::Task
86
+
@@ -0,0 +1,248 @@
1
+ ##############################################################################
2
+ # File:: ppm_tasks.rb
3
+ # Purpose:: PpmTasks definition
4
+ #
5
+ # Author:: Jeff McAffee 2015-06-23
6
+ #
7
+ ##############################################################################
8
+
9
+ require 'admin_module'
10
+ require 'rake/dsl_definition'
11
+ require 'rake'
12
+
13
+ module AdminModule::Rake
14
+ class PpmTasks
15
+ include ::Rake::DSL if defined?(::Rake::DSL)
16
+
17
+ attr_accessor :env
18
+ attr_accessor :name
19
+ attr_accessor :to
20
+ attr_accessor :path
21
+ attr_reader :action
22
+ attr_reader :valid_actions
23
+ attr_reader :stop_on_exception
24
+ attr_reader :format
25
+
26
+ def initialize(task_name = '', desc = "")
27
+ @valid_actions = ['import', 'export', 'dups', 'list']
28
+ @task_name, @desc = task_name, desc
29
+
30
+ @stop_on_exception = true
31
+
32
+ yield self if block_given?
33
+
34
+ define_task
35
+ end
36
+
37
+ def define_task #:nodoc:
38
+ desc @desc
39
+ task(@task_name, required_args_for_action) do |t,args|
40
+ set_vars args
41
+ commit # Call method to perform when invoked.
42
+ end
43
+ end
44
+
45
+ #
46
+ # Add each arg passed to the task, as an instance variable of the task
47
+ #
48
+
49
+ def set_vars args
50
+ args.each do |arg,val|
51
+ instance_variable_set "@#{arg}", val
52
+ end
53
+
54
+ args
55
+ end
56
+
57
+ def action=(task_action)
58
+ raise "action must be one of #{valid_types.join(', ')}" unless valid_actions.include?(task_action.downcase)
59
+ @action = task_action
60
+ end
61
+
62
+ def stop_on_exception=(do_stop)
63
+ raise ArgumentError, 'Expecting true or false' unless do_stop === true || do_stop === false
64
+ @stop_on_exception = do_stop
65
+ end
66
+
67
+ def format=(output_format)
68
+ output_format = 'txt' if output_format.nil?
69
+ valid_formats = %w(txt csv)
70
+ raise "format must be one of #{valid_formats.join(', ')}" unless valid_formats.include?(output_format.downcase)
71
+ @format = output_format
72
+ end
73
+
74
+ #
75
+ # Execute the task (action)
76
+ #
77
+
78
+ def commit
79
+ validate_params
80
+
81
+ client = AdminModule::Client.new
82
+ client.env = env
83
+
84
+ if self.respond_to? action
85
+ self.send(action, client)
86
+ return
87
+ else
88
+ raise "Unknown action - #{action}"
89
+ end
90
+
91
+ rescue Exception => e
92
+ raise e if stop_on_exception == true
93
+ ensure
94
+ client.quit
95
+ end
96
+
97
+ #
98
+ # Actions
99
+ #
100
+
101
+ def list client
102
+ $stdout << client.ppms.list.join("\n")
103
+ $stdout << "\n"
104
+ end
105
+
106
+ def dups client
107
+ result = Array.new
108
+ result = client.ppms.dups
109
+ output_method = "output_as_#{@format}"
110
+
111
+ if self.respond_to? output_method
112
+ self.send(output_method, result)
113
+ else
114
+ $stderr << "Invalid format: #{@format}"
115
+ end
116
+ end
117
+
118
+ def import client
119
+ $stdout << client.ppms.import(path)
120
+ end
121
+
122
+ def export client
123
+ $stdout << client.ppms.export(path)
124
+ end
125
+
126
+ #
127
+ # Verify we have the needed parameters (arguments) to perform
128
+ # the task action.
129
+ #
130
+
131
+ def validate_params
132
+ assert_provided env, 'Missing "env"'
133
+ assert_provided action, 'Missing "action"'
134
+
135
+ case action
136
+ when 'import'
137
+ assert_provided path, 'Missing "path"'
138
+
139
+ when 'export'
140
+ assert_provided path, 'Missing "path"'
141
+
142
+ end
143
+
144
+ assert_env_is_configured env
145
+ end
146
+
147
+ def assert_provided value, msg
148
+ if value.nil? || value.empty?
149
+ raise msg
150
+ end
151
+ end
152
+
153
+ def assert_env_is_configured arg
154
+ unless AdminModule.configuration.credentials.key? arg
155
+ init_msg = "Have you initialized your config file?\n Try: admin_module config init <filedir>"
156
+ env_msg = "Have you configured your environments?\n Try: admin_module config add env <envname> <url>"
157
+ raise "Unknown environment: #{arg}\n#{init_msg}\n\n#{env_msg}"
158
+ end
159
+ end
160
+
161
+ #
162
+ # Define the task args, based on the action.
163
+ # Used when programatically generating the tasks.
164
+ #
165
+
166
+ def required_args_for_action
167
+ args = []
168
+
169
+ case action
170
+ when 'import'
171
+ args << :path
172
+
173
+ when 'export'
174
+ args << :path
175
+
176
+ when 'dups'
177
+ args << :format
178
+
179
+ else
180
+ # Noop
181
+ end
182
+
183
+ args
184
+ end
185
+
186
+
187
+ def output_as_txt data
188
+ if data.count > 0
189
+ $stdout << " Name ID\n"
190
+ $stdout << '-'*79 << "\n"
191
+ else
192
+ return
193
+ end
194
+
195
+ data.each do |dp|
196
+ $stdout << "#{dp[:name]}\t#{dp[:id]}\n"
197
+ end
198
+ end
199
+
200
+ def output_as_csv data
201
+ if data.count > 0
202
+ $stdout << "Name,ID\n"
203
+ else
204
+ return
205
+ end
206
+
207
+ data.each do |dp|
208
+ $stdout << "#{dp[:name]},#{dp[:id]}\n"
209
+ end
210
+ end
211
+
212
+ #
213
+ # Class method to create an instance of the task generator,
214
+ # and call the instance's install method.
215
+ #
216
+
217
+ class << self
218
+ def install
219
+ new.install
220
+ end
221
+ end
222
+
223
+ #
224
+ # Instance method to generate the tasks;
225
+ # For each environment where we have configured credentials,
226
+ # generate a task for each available action.
227
+ #
228
+
229
+ def install
230
+ AdminModule.configuration.credentials.keys.each do |e|
231
+ valid_actions.each do |action|
232
+ AdminModule::Rake::PpmTasks.new("am:#{e}:ppm:#{action}", "#{action} #{e} ppms") do |t|
233
+ t.env = e
234
+ t.action = action
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end # class
240
+ end # module
241
+
242
+
243
+ #
244
+ # Install (generate) the tasks
245
+ #
246
+
247
+ AdminModule::Rake::PpmTasks.install
248
+