opensecret 0.0.913 → 0.0.941

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -0
  3. data/README.md +129 -19
  4. data/Rakefile +0 -9
  5. data/bin/opensecret +1 -1
  6. data/lib/{opensecret/plugins.io/cipher/crypto.rb → crypto/amalgam.rb} +6 -8
  7. data/lib/crypto/collect.rb +139 -0
  8. data/lib/crypto/engineer.rb +201 -0
  9. data/lib/crypto/verify.rb +33 -0
  10. data/lib/extension/array.rb +133 -0
  11. data/lib/{opensecret/additions → extension}/dir.rb +0 -0
  12. data/lib/extension/file.rb +56 -0
  13. data/lib/extension/hash.rb +33 -0
  14. data/lib/extension/string.rb +349 -0
  15. data/lib/factbase/facts.opensecret.io.ini +28 -0
  16. data/lib/logging/gem.logging.rb +133 -0
  17. data/lib/opensecret.rb +102 -45
  18. data/lib/opensecret/executors/crypt.keys/crypt.keys.ini +0 -53
  19. data/lib/session/{session.rb → attributes.rb} +60 -5
  20. data/lib/session/exceptions.rb +53 -0
  21. data/lib/session/fact.finder.rb +684 -0
  22. data/lib/session/user.home.rb +49 -0
  23. data/lib/usecase/usecase.rb +245 -0
  24. data/lib/usecase/usecases/init.rb +190 -0
  25. data/lib/usecase/usecases/on.rb +33 -0
  26. data/lib/usecase/usecases/safe.rb +95 -0
  27. data/lib/version.rb +1 -1
  28. metadata +22 -17
  29. data/lib/opensecret/additions/array.rb +0 -117
  30. data/lib/opensecret/additions/string.rb +0 -312
  31. data/lib/opensecret/commons/eco.cmdline.rb +0 -446
  32. data/lib/opensecret/eco.do.rb +0 -46
  33. data/lib/opensecret/plugins.io/error/eco.exceptions.rb +0 -24
  34. data/lib/opensecret/plugins.io/facts/fact.chars.rb +0 -66
  35. data/lib/opensecret/plugins.io/facts/fact.factor.rb +0 -156
  36. data/lib/opensecret/plugins.io/facts/fact.locator.rb +0 -105
  37. data/lib/opensecret/plugins.io/facts/fact.reader.rb +0 -137
  38. data/lib/opensecret/plugins.io/facts/fact.tree.rb +0 -661
  39. data/lib/opensecret/plugins.io/logs/log.object.rb +0 -89
  40. data/lib/opensecret/plugins.io/logs/logging.rb +0 -203
@@ -1,446 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # -- --------------------------------------------------------------------------------- -- #
4
- # -- The [Command Interpreter] -- #
5
- # -- --------------------------------------------------------------------------------- -- #
6
- # -- -- #
7
- # -- From the command line we receive the below asset groups. -- #
8
- # -- -- #
9
- # -- [1] - major use case commands like "create", "register", "destroy" -- #
10
- # -- [2] - specifiers telling us "create what", "destroy which ones" -- #
11
- # -- [3] - boolean flags that dictate which way the hammer should fall -- #
12
- # -- [4] - option / arg config pairs (options can be long or short) -- #
13
- # -- -- #
14
- # -- Some flags and options are mandatory - others are optional. Argument types -- #
15
- # -- are usually => [ booleans, strings, lists, sets or numbers ]. -- #
16
- # -- -- #
17
- # -- --------------------------------------------------------------------------------- -- #
18
- # -- Art or Science -- #
19
- # -- --------------------------------------------------------------------------------- -- #
20
- # -- -- #
21
- # -- Parsing the command line and returning concise error messages is much more -- #
22
- # -- [ART] than it is [SCIENCE]. This is because the permutations and combinations -- #
23
- # -- are mind bogglingly vast. Hence this code is strictly ["best efforts"]. -- #
24
- # -- -- #
25
- # -- That said, the invoked commands should be belt and braces in processing the -- #
26
- # -- arguments and switches provided on the command line. -- #
27
- # -- -- #
28
- # -- This command interpreter in no way absolves the evoked software from the legwork -- #
29
- # -- of security, validation and semantic assessments. -- #
30
- # -- -- #
31
- # -- --------------------------------------------------------------------------------- -- #
32
- class CmdLine
33
- include Singleton
34
-
35
- attr_reader :create
36
- attr_reader :task
37
- attr_reader :do_read_db_names
38
- attr_reader :do_register_user
39
- attr_reader :do_destroy_app
40
-
41
- attr_reader :key_values
42
- attr_reader :args_cache
43
- attr_reader :args_after
44
-
45
-
46
- def initialize
47
-
48
- # -- ----------------------------------------------------------- --- #
49
- # -- If no commands to interpret - assume the caller needs help. --- #
50
- # -- ----------------------------------------------------------- --- #
51
- ARGV.push "--help" if ARGV.length == 0
52
-
53
- @key_values = {}
54
- @args_cache = [].replace ARGV
55
-
56
- # --- ------------------------------------------------------------- --- #
57
- # --- [--help] is a peripheral command with no [do] [what] pattern. --- #
58
- # --- ------------------------------------------------------------- --- #
59
- print_help_screen if ARGV.include? "--help"
60
- print_help_screen if ARGV.include? "-h"
61
-
62
- # --- -------------------------------------------------- --- #
63
- # --- Each line below pertains to a [do] [what] command. --- #
64
- # --- -------------------------------------------------- --- #
65
- read_eco_create_args if command_matches? "create", "what", "w"
66
- read_read_db_names_args if command_matches? "read", "s3", "s"
67
- read_aws_register_args if command_matches? "register", "aws-user", "a"
68
- read_destroy_app_args if command_matches? "destroy", "app", "a"
69
- read_task_args if command_matches? "task", "what", "w"
70
-
71
- # --- --------------------------------------------------------- --- #
72
- # --- Notify caller if [do] [what] portion could not be mapped. --- #
73
- # --- --------------------------------------------------------- --- #
74
- handle_cmd_match_fail if @options_parser == nil
75
-
76
- begin
77
-
78
- @options_parser.parse!
79
- @args_after = ARGV
80
-
81
- missing_args = @mandatory_options.select{ |param| @key_values[param].nil? }
82
- unless missing_args.empty?
83
- raise OptionParser::MissingArgument.new(missing_args.join(', '))
84
- end
85
-
86
- rescue OptionParser::InvalidOption => exception
87
-
88
- log.warn(ere) { "#--- ---------------------------------------------- --- #" }
89
- log.warn(ere) { "#--- eco did not recognize a command option. --- #" }
90
- log.warn(ere) { "#--- ---------------------------------------------- --- #" }
91
- log.warn(ere) { "#--- #{exception}" }
92
- log.warn(ere) { "#--- #{exception.inspect}" }
93
-
94
- #### Fix this if too spurious
95
- #### Fix this if too spurious
96
- #### Fix this if too spurious
97
- #### Fix this if too spurious
98
- ################ puts exception.backtrace if @@VERBOSE_MODE
99
-
100
- log.warn(ere) { "#{exception.backtrace}" } ##### may be add if ARGV.include? "--debug"
101
- log.warn(ere) { @options_parser.help }
102
- log.warn(ere) { "#--- ---------------------------------------------- --- #" }
103
-
104
- # @@
105
- # @@ No need to exit from this - this script does not need
106
- # @@ to be hard-coded with every command line option.
107
- # @@ (We need only know the [Mandatory] ones which is
108
- # @@ handled by the below rescue block.
109
- # @@
110
-
111
- ################## DELETE ME ASAP
112
- ############## exit
113
- ################## DELETE ME ASAP
114
-
115
-
116
- rescue OptionParser::MissingArgument => missing_arg
117
-
118
- log.fatal(ere) { $!.to_s }
119
- log.fatal(ere) { @options_parser }
120
- exit
121
-
122
- end
123
-
124
- end
125
-
126
-
127
- # --
128
- # -- Returns true if the option text was included on the command line.
129
- # --
130
- # -- This method does not look within a list of values. Only call this
131
- # -- method if the text is a free form switch WITHOUT an equal sign.
132
- # --
133
- def self.has? a_string
134
- return CmdLine.instance.args_cache.include? a_string
135
- end
136
-
137
-
138
- # --
139
- # -- Return true if symbol (switch) was included on the command line.
140
- # --
141
- # -- WARNING - Do not use externally as the line is cleared.
142
- # -- - Call has? like =] if CmdLine.has? --debug
143
- # --
144
- def self.include? a_symbol
145
- return CmdLine.instance.key_values.include? a_symbol
146
- end
147
-
148
-
149
- # -- ---------------------------------------------------------------------------- -- #
150
- # -- Does the command line contain a specific command and a flag in either of its -- #
151
- # -- forms - long and short. If yes then this method will return true. -- #
152
- # -- ---------------------------------------------------------------------------- -- #
153
- def command_matches? cmd_str, flag_long, flag_short
154
-
155
- return ( ARGV.include?( cmd_str ) && ARGV.include?("--#{flag_long}") ) ||
156
- ( ARGV.include?( cmd_str ) && ARGV.include?("-#{flag_short}") )
157
-
158
- end
159
-
160
-
161
- # -- ---------------------------------------------------------------------------- -- #
162
- # -- forms - long and short. If yes then this method will return true. -- #
163
- # -- ---------------------------------------------------------------------------- -- #
164
- def handle_cmd_match_fail
165
-
166
- log.fatal(ere) { " # - ------------------------------------------------------------ - #" }
167
- log.fatal(ere) { " # - eco command ==> could not match == [do] [what] [how] [where] - #" }
168
- log.fatal(ere) { " # - ------------------------------------------------------------ - #" }
169
- log.fatal(ere) { " eco [do] [what]" }
170
- log.fatal(ere) { " Could not match the [do what] branch of the command tree." }
171
- log.fatal(ere) { " [do] is CRUD based eg [create, register, read, update, destroy]." }
172
- log.fatal(ere) { " The [what] part tells the command interpreter what you want to do." }
173
- log.fatal(ere) { " eco optional arguments == [how] [where] [to]" }
174
- log.fatal(ere) { " [how] - do it how eg | --clean | --dry-run |" }
175
- log.fatal(ere) { " [where] - (on what) eg | --cloud | --local |" }
176
- log.fatal(ere) { " [to] - do it to eg | --eco-system | --service |" }
177
-
178
- exit
179
-
180
- end
181
-
182
-
183
- ## --- --------------------------------------------------------- --- ##
184
- ## --- How to use Declarative and Dynamic Command Interpretation --- ##
185
- ## --- --------------------------------------------------------- --- ##
186
- ## ---
187
- ## --- Once SREs are familiar with this command interpreter class
188
- ## --- the next refactor step is to generate the whole thing dynamically.
189
- ## --- I will probably write a ruby gem to do exactly this.
190
- ## ---
191
- ## --- The essence is to create a JSON or YAML configuration file that
192
- ## --- holds the command line interpretation variables. This is used to
193
- ## --- dynamically generate the optparse blocks.
194
- ## ---
195
- ## --- --------------------------------------------------------- --- ##
196
- ## --- How to use Dynamically Generate the Help Screen --- ##
197
- ## --- --------------------------------------------------------- --- ##
198
- ## ---
199
- ## --- To generate the help screen you can loop round calling each
200
- ## --- parser block (without any actual cmd line arguments)!
201
- ## ---
202
- ## --- Then you loop doing a to_string puts opt_parser for each
203
- ## --- parser and all the options will be ejected automatically!
204
- ## ---
205
- ## --- You are done when all read methods vanish (ruby magic)!
206
- ## ---
207
- ## --- --------------------------------------------------------- --- ##
208
-
209
-
210
- ## --- ---------------------- --- ##
211
- ## --- Create the application --- ##
212
- ## --- ---------------------- --- ##
213
- def read_eco_create_args
214
-
215
- ## ---------------------------------------------------------- #
216
- @create = true
217
- @mandatory_options = [:service_descriptors]
218
- ## ---------------------------------------------------------- #
219
- @options_parser = OptionParser.new do | the_options |
220
-
221
- the_options.banner = " eco create --what => create which eco systems\n\n"
222
-
223
- ## the_options.on( "-f", "--versions-file FILE_PATH", "Service versions file in JSON (mandatory)") do | versions_file |
224
-
225
- ## @key_values[:versions_file] = versions_file
226
-
227
- ## end
228
-
229
- the_options.on( "-w", "--what mongo,email,...", Array, "Comma separated service descriptors (mandatory)") do | service_descriptors_list |
230
-
231
- @key_values[:service_descriptors] = service_descriptors_list
232
-
233
- end
234
-
235
- end
236
-
237
- end
238
-
239
-
240
- ## --- -------------------- --- ##
241
- ## --- Register an AWS User --- ##
242
- ## --- -------------------- --- ##
243
- def read_aws_register_args
244
-
245
- ## ---------------------------------------------------------- #
246
- @do_register_user = true
247
- @mandatory_options = [:aws_user, :aws_user_id, :aws_password]
248
- ## ---------------------------------------------------------- #
249
- @options_parser = OptionParser.new do | the_options |
250
-
251
- the_options.banner = " eco register --aws-user => options to register [aws credentials]\n\n"
252
-
253
- the_options.on( "-a", "--aws-user", "Registering AWS Credentials") do
254
-
255
- @key_values[:aws_user] = true
256
-
257
- end
258
-
259
- the_options.on( "-u", "--aws-user-id AWS_USER_ID", "Your AWS User ID Key (mandatory)") do | aws_user_id |
260
-
261
- @key_values[:aws_user_id] = aws_user_id
262
-
263
- end
264
-
265
- the_options.on( "-p", "--aws-password AWS_PASSWORD", "Your AWS User Password (mandatory)") do | aws_password |
266
-
267
- @key_values[:aws_password] = aws_password
268
-
269
- end
270
-
271
- end
272
-
273
- end
274
-
275
-
276
- # --
277
- # -- Task does something (encrypts or decrypts) some text.
278
- # --
279
- # -- main command => encrypt
280
- # -- mandatory arg => --text=abc123 or -t
281
- # --
282
- # --
283
- def read_task_args
284
-
285
- ## ------------------------------------------------------------------ #
286
- @task = true
287
- @mandatory_options = [:service_descriptors]
288
- ## ------------------------------------------------------------------ #
289
- @options_parser = OptionParser.new do | the_options |
290
-
291
- the_options.banner = " eco encrypt --text => options to encrypt [some text]\n\n"
292
-
293
-
294
- the_options.on( "-w", "--what mongo,email,...", Array, "Comma separated descriptors (mandatory)") do | service_descriptors_list |
295
-
296
- @key_values[:service_descriptors] = service_descriptors_list
297
-
298
- end
299
-
300
-
301
- the_options.on( "-n", "--name NAME", "The name (reference) of the encryptee.") do | name |
302
-
303
- @key_values[:name] = name
304
-
305
- end
306
-
307
- the_options.on( "-f", "--file FILE", "The name of the file whose text is to be decrypted") do | file |
308
-
309
- @key_values[:file] = file
310
-
311
- end
312
-
313
- end
314
-
315
- end
316
-
317
-
318
- ## --- -------------------------- --- ##
319
- ## --- Read the DB Name Arguments --- ##
320
- ## --- -------------------------- --- ##
321
- def read_read_db_names_args
322
-
323
- ## ---------------------------------------------------------- #
324
- @do_read_db_names = true
325
- @mandatory_options = [:read_db_names]
326
- ## ---------------------------------------------------------- #
327
- @options_parser = OptionParser.new do | the_options |
328
-
329
- the_options.banner = " eco read --s3 => reading names of customer databases in S3\n\n"
330
-
331
- the_options.on( "-s", "--s3", "Available Customer DBs in S3") do
332
-
333
- @key_values[:read_db_names] = true
334
-
335
- end
336
-
337
- end
338
-
339
- end
340
-
341
-
342
- ## --- -------------------------------------------------------- --- ##
343
- ## --- Destroy and reclaim resources from created applications. --- ##
344
- ## --- -------------------------------------------------------- --- ##
345
- def read_destroy_app_args
346
-
347
- ## ---------------------------------------------------------- #
348
- @do_destroy_app = true
349
- @mandatory_options = [:destroy_app, :key]
350
- ## ---------------------------------------------------------- #
351
- @options_parser = OptionParser.new do | the_options |
352
-
353
- the_options.banner = " eco destroy --app => destroying an eco system\n\n"
354
-
355
- the_options.on( "-a", "--app", "Destroy enterprise application") do
356
-
357
- @key_values[:destroy_app] = true
358
-
359
- end
360
-
361
- the_options.on( "-k", "--key APP_KEY", "Key (ref) of app to delete (mandatory)") do | key_value |
362
-
363
- @key_values[:key] = key_value
364
-
365
- end
366
-
367
- end
368
-
369
- end
370
-
371
-
372
- ## --- --------------------------------------------------------- --- ##
373
- ## --- How to use Declarative and Dynamic Command Interpretation --- ##
374
- ## --- --------------------------------------------------------- --- ##
375
- ## ---
376
- ## --- Once SREs are familiar with this command interpreter class
377
- ## --- the next refactor step is to generate the whole thing dynamically.
378
- ## --- I will probably write a ruby gem to do exactly this.
379
- ## ---
380
- ## --- The essence is to create a JSON or YAML configuration file that
381
- ## --- holds the command line interpretation variables. This is used to
382
- ## --- dynamically generate the optparse blocks.
383
- ## ---
384
- ## --- --------------------------------------------------------- --- ##
385
- ## --- How to use Dynamically Generate the Help Screen --- ##
386
- ## --- --------------------------------------------------------- --- ##
387
- ## ---
388
- ## --- To generate the help screen you can loop round calling each
389
- ## --- parser block (without any actual cmd line arguments)!
390
- ## ---
391
- ## --- Then you loop doing a to_string puts opt_parser for each
392
- ## --- parser and all the options will be ejected automatically!
393
- ## ---
394
- ## --- --------------------------------------------------------- --- ##
395
-
396
- def print_help_screen
397
-
398
- read_eco_create_args
399
- args_documented = @options_parser.to_s
400
- read_aws_register_args
401
- args_documented = "#{args_documented}\n\n#{@options_parser.to_s}"
402
- read_read_db_names_args
403
- args_documented = "#{args_documented}\n\n#{@options_parser.to_s}"
404
- read_destroy_app_args
405
- args_documented = "#{args_documented}\n\n#{@options_parser.to_s}"
406
-
407
- if false then
408
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
409
- log.warn(ere) { " # --- create executable => => [only for DevOps and SRE personnel] --- #" }
410
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
411
-
412
- log.warn(ere) { " ruby eco-invoke.rb [do] [what]" }
413
- log.warn(ere) { " ruby eco-invoke.rb [create] [--exe]" }
414
- log.warn(ere) { " ruby eco-invoke.rb create --exe" }
415
- end
416
-
417
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
418
- log.warn(ere) { " # --- eco peripheral commands --- #" }
419
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
420
- log.warn(ere) { " eco --help" }
421
- log.warn(ere) { " eco -h" }
422
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
423
- log.warn(ere) { " # --- eco arguments documentation --- #" }
424
- log.warn(ere) { " # --- --------------------------------------------------------------------- --- #" }
425
- log.warn(ere) { args_documented }
426
-
427
- exit
428
-
429
- end
430
-
431
-
432
- # -- -------------------------------------------------------- #
433
- # -- [Cold Call Pattern] -- #
434
- # -- If class has no [internal] dependencies it can -- #
435
- # -- initialize itself ignoring any require order. -- #
436
- # -- -- #
437
- # -- [Advantage of Cold Call Pattern] -- #
438
- # -- The class [dependency] is not [hardcoded] into -- #
439
- # -- any other class. Others benefit from initialize -- #
440
- # -- activities without a create / handshake call. -- #
441
- # -- -- #
442
- # -- -------------------------------------------------------- #
443
- CmdLine.instance
444
-
445
-
446
- end
@@ -1,46 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'pp'
4
- require 'json'
5
- require 'inifile'
6
- require 'singleton'
7
- require 'filesize'
8
- require 'tmpdir'
9
- require 'base64'
10
- require 'date'
11
- require 'etc'
12
- require 'optparse'
13
- require 'securerandom'
14
- require 'digest'
15
- require 'net/http'
16
- require 'net/ssh'
17
- require 'net/scp'
18
- require 'aws-sdk'
19
- require 'aws-sdk-resources'
20
- require 'nokogiri'
21
- require 'openssl'
22
- require 'io/console'
23
-
24
- # --
25
- # -- Require modules that read config and require modules
26
- # --
27
- require_relative '../iaas.tool.collection/user.home'
28
- require_relative '../iaas.tool.collection/throw.error'
29
- require_relative '../iaas.tool.collection/ruby.require'
30
- require_relative '../reusable.classes/logs/logging'
31
-
32
-
33
- # --
34
- # -- Flush logs destined for STDOUT immediately.
35
- # -- Do not wait for a full cache or script end.
36
- # --
37
- $stdout.sync = true
38
-
39
- include Logging
40
-
41
- log.debug(ere) { "Require of ruby modules has been completed." }
42
-
43
- EcoSystems.create
44
-
45
- exit
46
-