opensecret 0.0.2 → 0.0.4

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/README.md +2 -2
  4. data/bin/opensecret +3 -6
  5. data/lib/opensecret-domain.ini +23 -0
  6. data/lib/opensecret.rb +30 -2
  7. data/lib/opensecret/additions/array.rb +117 -0
  8. data/lib/opensecret/additions/dir.rb +35 -0
  9. data/lib/opensecret/additions/string.rb +312 -0
  10. data/lib/opensecret/commons/eco.cmdline.rb +446 -0
  11. data/lib/opensecret/commons/eco.faculty.rb +364 -0
  12. data/lib/opensecret/commons/eco.system.rb +437 -0
  13. data/lib/opensecret/commons/eco.systems.rb +98 -0
  14. data/lib/opensecret/{safe.rb → delegate.rb} +4 -2
  15. data/lib/opensecret/eco.do.rb +46 -0
  16. data/lib/opensecret/executors/crypt.keys/crypt.keys.ini +79 -0
  17. data/lib/opensecret/executors/crypt.keys/crypt.keys.rb +68 -0
  18. data/lib/opensecret/executors/decrypt/decrypt.ini +64 -0
  19. data/lib/opensecret/executors/decrypt/decrypt.rb +49 -0
  20. data/lib/opensecret/executors/encrypt/encrypt.ini +55 -0
  21. data/lib/opensecret/executors/encrypt/encrypt.rb +82 -0
  22. data/lib/opensecret/factbase/hub-runtime.ini +123 -0
  23. data/lib/opensecret/factbase/known-hosts.ini +75 -0
  24. data/lib/opensecret/factbase/published.facts/blobbolicious-facts.ini +553 -0
  25. data/lib/opensecret/factbase/published.facts/credential-facts.ini +40 -0
  26. data/lib/opensecret/factbase/published.facts/infrastructure-facts.ini +63 -0
  27. data/lib/opensecret/factbase/readme.md +24 -0
  28. data/lib/opensecret/factbase/retired.facts/maven.database.ide.facts.ini +127 -0
  29. data/lib/opensecret/factbase/retired.facts/s3-upload-block-facts.ini +17 -0
  30. data/lib/opensecret/plugins.io/cipher/crypto.rb +174 -0
  31. data/lib/opensecret/plugins.io/error/eco.exceptions.rb +24 -0
  32. data/lib/opensecret/plugins.io/facts/fact.chars.rb +66 -0
  33. data/lib/opensecret/plugins.io/facts/fact.factor.rb +156 -0
  34. data/lib/opensecret/plugins.io/facts/fact.locator.rb +105 -0
  35. data/lib/opensecret/plugins.io/facts/fact.reader.rb +137 -0
  36. data/lib/opensecret/plugins.io/facts/fact.tree.rb +661 -0
  37. data/lib/opensecret/plugins.io/file/file.rb +483 -0
  38. data/lib/opensecret/plugins.io/git/git.flow.rb +388 -0
  39. data/lib/opensecret/plugins.io/logs/log.object.rb +89 -0
  40. data/lib/opensecret/plugins.io/logs/logging.rb +203 -0
  41. data/lib/opensecret/plugins.io/time/time.stamp.rb +425 -0
  42. data/lib/opensecret/version.rb +2 -2
  43. data/opensecret.gemspec +8 -13
  44. metadata +68 -18
@@ -0,0 +1,24 @@
1
+ # --
2
+ # -- Exception when the AWS credentials are not found.
3
+ # --
4
+ class AwsCredentialsError < StandardError
5
+
6
+ ### attr_reader :action
7
+
8
+ # --
9
+ # -- Create this exception object
10
+ def initialize message, credential_name
11
+
12
+ # --
13
+ # -- Call the parent's constructor to set the message
14
+ # --
15
+ super( message + " Missing Credential => #{credential_name}" )
16
+
17
+ # --
18
+ # -- Store the action in an instance variable
19
+ # --
20
+ ### @action = action
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # --
4
+ # -- Dot the I's and Cross the T's
5
+ # --
6
+ class Do
7
+
8
+ # --
9
+ # -- p => period (full stop)
10
+ # -- Deliver a "." period character
11
+ # --
12
+ def self.t
13
+ return "."
14
+ end
15
+
16
+ # --
17
+ # -- Note you do not need this method for declaration
18
+ # -- of a fact that contains just a single forward slash.
19
+ # -- The below will do.
20
+ # --
21
+ # -- fact.name = /
22
+ # --
23
+ # -- / => forward slash
24
+ # -- Deliver a "/" fwd slash character
25
+ # --
26
+ def self.f
27
+ return "/"
28
+ end
29
+
30
+ # --
31
+ # -- dq => double quote
32
+ # -- Deliver a \" (backslash double quote).
33
+ # -- Can solve the \\\ triple backslash problem.
34
+ # -- Use in Ruby and .ini fact files.
35
+ # --
36
+ def self.dq
37
+ return "\""
38
+ end
39
+
40
+ end
41
+
42
+ # --
43
+ # -- Dot the I's and Cross the T's
44
+ # -- DEPRECATED - Use the [Do] class instead.
45
+ # --
46
+ class Ch
47
+
48
+ # --
49
+ # -- p => period (full stop)
50
+ # -- Deliver a "." period character
51
+ # --
52
+ def self.p
53
+ return "."
54
+ end
55
+
56
+ # --
57
+ # -- dq => double quote
58
+ # -- Deliver a \" (backslash double quote).
59
+ # -- Can solve the \\\ triple backslash problem.
60
+ # -- Use in Ruby and .ini fact files.
61
+ # --
62
+ def self.dq
63
+ return "\""
64
+ end
65
+
66
+ end
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/ruby
2
+
3
+ class Refactor
4
+
5
+ # --
6
+ # -- Convert the parameter 2D map to a 1D map that respects
7
+ # -- the placeholder convention.
8
+ # --
9
+ # -- ------------------
10
+ # -- Original INI File
11
+ # -- ------------------
12
+ # --
13
+ # -- [windows]
14
+ # -- maker = Microsoft
15
+ # -- version = Windows 10 SP2
16
+ # --
17
+ # -- [ubuntu]
18
+ # -- maker = Canonical
19
+ # -- version = Ubuntu 16.04
20
+ # --
21
+ # -- -----------------
22
+ # -- Fact 2D Database
23
+ # -- -----------------
24
+ # --
25
+ # -- @f[:windows][:maker] => Microsoft
26
+ # -- @f[:windows][:version] => Windows 10 SP2
27
+ # -- @f[:ubuntu][:maker] => Canonical
28
+ # -- @f[:version][:version] => Ubuntu 16.04
29
+ # --
30
+ # -- ------------------------------------
31
+ # -- Flattened 1D Placeholder Key Values
32
+ # -- ------------------------------------
33
+ # --
34
+ # -- @flat[ '@[windows|maker]' ] => Microsoft
35
+ # -- @flat[ '@[windows|version]' ] => Windows 10 SP2
36
+ # -- @flat[ '@[ubuntu|maker]' ] => Canonical
37
+ # -- @flat[ '@[ubuntu|version]' ] => Ubuntu 16.04
38
+ # --
39
+ def self.flatten fact_db
40
+
41
+ flat_db = {}
42
+
43
+ fact_db.each do |grp_name,list_db|
44
+ list_db.each do |key_name,key_value|
45
+ grp_str = grp_name.to_s.gsub("_", ".")
46
+ key_str = key_name.to_s.gsub("_", ".")
47
+
48
+ flat_db[ "@[#{grp_str}|#{key_str}]" ] = key_value
49
+ end
50
+
51
+ end
52
+
53
+ return flat_db
54
+
55
+ end
56
+
57
+
58
+ # --
59
+ # -- Produce a multiline [sandwiched] string with the
60
+ # -- prefix and postfix sandwiching the array element.
61
+ # -- Furthermore and the specified number of spaces by
62
+ # -- as an indent before the prefix of each line.
63
+ # --
64
+ # -- ---------
65
+ # -- Example
66
+ # -- ---------
67
+ # --
68
+ # -- x_array : mon, tue, wed, thu, fri
69
+ # -- prefix : <weekday>
70
+ # -- postfix : </weekday>
71
+ # -- indent_len : 8
72
+ # --
73
+ # -- x_to_y changes horizontal x to multi-line y
74
+ # --
75
+ # -- <weekday>mon</weekday>
76
+ # -- <weekday>tue</weekday>
77
+ # -- <weekday>wed</weekday>
78
+ # -- <weekday>thu</weekday>
79
+ # -- <weekday>fri</weekday>
80
+ # --
81
+ # -- ------------
82
+ # -- Parameters
83
+ # -- ------------
84
+ # --
85
+ # -- str_array : array of strings to enwrap
86
+ # -- prefix : the lead element of the sandwich
87
+ # -- postfix : the tail element of the sandwich
88
+ # -- indent_len : the length (spaces) of indent
89
+ # --
90
+ # -- Return
91
+ # -- the multiline enwrapped string
92
+ # --
93
+ def self.sandwich_lines in_array, prefix, postfix, indent_len
94
+
95
+ out_array = Array.new
96
+ indent_str = " " * indent_len
97
+ in_array.each do | str_to_wrap |
98
+ out_array.push( indent_str + prefix + str_to_wrap + postfix )
99
+ end
100
+
101
+ return out_array.join( "\n" )
102
+
103
+ end
104
+
105
+ # -- -------------------------------------------------- -- #
106
+ # -- Return an (out) array of [sandwiched] strings with -- #
107
+ # -- the [prefix] and [postfix] sandwiching each of the -- #
108
+ # -- (in) array elements. -- #
109
+ # -- -- #
110
+ # -- -------------------------------------------------- -- #
111
+ # -- Example -- #
112
+ # -- -------------------------------------------------- -- #
113
+ # -- -- #
114
+ # -- x_array : mon, tue, wed, thu, fri -- #
115
+ # -- prefix : <weekday> -- #
116
+ # -- postfix : </weekday> -- #
117
+ # -- -- #
118
+ # -- x_to_y changes horizontal x to multi-line y -- #
119
+ # -- -- #
120
+ # -- <weekday>mon</weekday> -- #
121
+ # -- <weekday>tue</weekday> -- #
122
+ # -- <weekday>wed</weekday> -- #
123
+ # -- <weekday>thu</weekday> -- #
124
+ # -- <weekday>fri</weekday> -- #
125
+ # -- -- #
126
+ # -- -------------------------------------------------- -- #
127
+ # -- Parameters -- #
128
+ # -- -------------------------------------------------- -- #
129
+ # -- in_array : array of strings to enwrap -- #
130
+ # -- prefix : the lead element of the sandwich -- #
131
+ # -- postfix : the tail element of the sandwich -- #
132
+ # -- -- #
133
+ # -- Return -- #
134
+ # -- an array of the sandwiched elements -- #
135
+ # -- -------------------------------------------------- -- #
136
+ def self.sandwich_array in_array, prefix, postfix
137
+
138
+ out_array = Array.new
139
+ in_array.each do | wrap_str |
140
+ out_array.push prefix + wrap_str + postfix
141
+ end
142
+
143
+ log.info(ere) {"sandwiching array strings with supplied prefix and postfix."}
144
+ log.info(ere) {"sandwich prefix => #{prefix}"}
145
+ log.info(ere) {"sandwich postfix => #{postfix}"}
146
+ log.info(ere) {"the incoming array (to sandwich) size => #{in_array.length}"}
147
+
148
+ log.debug(ere) { "IN ARRAY => #{pp in_array}" }
149
+ log.debug(ere) { "IN ARRAY => #{pp out_array}" }
150
+
151
+ return out_array
152
+
153
+ end
154
+
155
+
156
+ end
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # --
4
+ # -- Locate fact files using the stated convention when
5
+ # -- given the name and path of a module.
6
+ # --
7
+ class FactLocator
8
+
9
+ @@eco_factdir = "eco.system.facts"
10
+ @@fact_endtag = "factbase.ini"
11
+
12
+ # --
13
+ # -- Find path to class hierarchy fact file by convention.
14
+ # --
15
+ # -- -----------
16
+ # -- Convention
17
+ # -- -----------
18
+ # --
19
+ # -- Logic => read the module full file path
20
+ # -- => go down 2 directories (parent of parent)
21
+ # -- => go into folder eco.system.facts
22
+ # -- => add database.ini to extensionless module name
23
+ # --
24
+ # -- -----------
25
+ # -- Example
26
+ # -- -----------
27
+ # --
28
+ # -- module_path => /home/dir/prj/street/my_house.rb
29
+ # -- module_dir => /home/dir/prj
30
+ # -- fact folder => /home/dir/prj/eco.system.facts
31
+ # -- fact [file] => /home/dir/prj/eco.system.facts/my_house.factbase.ini
32
+ # --
33
+ # -- factdb_path => /home/dir/prj/street/eco.system.facts/my_house.factbase.ini
34
+ # --
35
+ def self.hierarchy_factdb_path module_path
36
+
37
+ module_name = File.basename module_path, File.extname(module_path)
38
+ factdb_name = "#{module_name}.#{@@fact_endtag}"
39
+ return File.join fact_base_dir(module_path), factdb_name
40
+ end
41
+
42
+
43
+ def self.keyfacts_factdb_path module_path
44
+
45
+ factdb_name = "facts.eco-instance.ini"
46
+ return File.join fact_base_dir(module_path), factdb_name
47
+
48
+ end
49
+
50
+
51
+ def self.workstation_factdb_path module_path
52
+
53
+ factdb_name = "facts.workstation.#{NetDns.instance.host_name}.ini"
54
+ return File.join fact_base_dir(module_path), factdb_name
55
+
56
+ end
57
+
58
+
59
+ # --
60
+ # -- Get the [fact databases] base directory given
61
+ # -- the full path to the requesting module.
62
+ # --
63
+ # -- ----------------------
64
+ # -- Acquire Base Dir Logic
65
+ # -- ----------------------
66
+ # --
67
+ # -- To acquire the base directory given the full
68
+ # -- path to the requesting module we
69
+ # --
70
+ # -- 1 => go down 2 directories (parent of parent)
71
+ # -- 2 => go into folder eco.system.facts
72
+ # --
73
+ def self.fact_base_dir module_path
74
+ fact_basedir = File.dirname( File.dirname( module_path ) )
75
+ return File.join fact_basedir, @@eco_factdir
76
+ end
77
+
78
+ # --
79
+ # -- --------------
80
+ # -- Use Case
81
+ # -- --------------
82
+ # -- Find path to method block scoped fact file by convention.
83
+ # --
84
+ # -- --------------
85
+ # -- Example
86
+ # -- --------------
87
+ # -- module_path => /home/dir/prj/street/my_flat.rb
88
+ # -- module_dir => /home/dir/prj/street
89
+ # -- module_name => my_flat
90
+ # -- method_name => to_rooms
91
+ # -- fact_folder = module_dir / eco.system.facts
92
+ # --
93
+ # -- factdb_path => /home/dir/prj/eco.system.facts/my_flat.to.rooms.ini
94
+ # --
95
+ def self.block_factdb_path module_path, method_symbol
96
+
97
+ module_name = File.basename module_path, File.extname(module_path)
98
+ method_name = method_symbol.to_s.gsub("_", ".")
99
+ factdb_name = module_name + "." + method_name + ".ini"
100
+ return File.join fact_base_dir(module_path), factdb_name
101
+
102
+ end
103
+
104
+
105
+ end
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/ruby
2
+
3
+ ## --- ---------------------------------------------------------------------- --- #
4
+ ## --- How to Use File to extract different parts of an [absolute] file path. --- #
5
+ ## --- ---------------------------------------------------------------------- --- #
6
+ ## ====] file = "/path/to/xyz.mp4"
7
+ ## --- ---------------------------------------------------------------------- --- #
8
+ ## ====] comp = File.basename file # => "xyz.mp4"
9
+ ## ====] extn = File.extname file # => ".mp4"
10
+ ## ====] name = File.basename file, extn # => "xyz"
11
+ ## ====] path = File.dirname file # => "/path/to"
12
+ ## --- ---------------------------------------------------------------------- --- #
13
+
14
+ # -- --------------------------------------------------------------------- -- #
15
+ # -- Global (dictionary) fact manager. -- #
16
+ # -- --------------------------------------------------------------------- -- #
17
+ class FactReader
18
+
19
+ attr_reader :f
20
+
21
+ # -
22
+ # -- Create a fact database given an INI file
23
+ # -- as well as an initial 2D database entry,
24
+ # -- and a parental fact database whose facts
25
+ # -- can be reused.
26
+ # -
27
+ # -- @f will be the referenciable object wide
28
+ # -- name for the created fact database.
29
+ # -
30
+ # -- Parameters
31
+ # -- fact_data : parental fact database
32
+ # -- ini_filepath : path to src INI factfile
33
+ # -- group_symbol : for first param entry
34
+ # -- key_symbol : for first param entry
35
+ # -- key_value : for first param entry
36
+ # -
37
+ # -- Dependencies and Assumptions
38
+ # -- the [inifile] gem is installed
39
+ # -- file exists at the ini_filepath
40
+ # -- factory_facts are instantiated
41
+ # -
42
+ def initialize fact_data, ini_filepath, group_symbol, key_symbol, key_value
43
+
44
+ # -- ---------------------------------------------------- -- #
45
+ # -- This time use param fact database for instantiation. -- #
46
+ # -- ---------------------------------------------------- -- #
47
+ @f = fact_data.nil? ? {} : fact_data
48
+
49
+ # -- ------------------------------------------------ -- #
50
+ # -- Add initializr (parameter) fact to the database. -- #
51
+ # -- ------------------------------------------------ -- #
52
+ add_fact group_symbol, key_symbol, key_value unless group_symbol.nil? && key_symbol.nil? && key_value.nil?
53
+
54
+ # -- ------------------------------------------ -- #
55
+ # -- Assimilate all the facts in this INI file. -- #
56
+ # -- ------------------------------------------ -- #
57
+ assimilate_ini_file ini_filepath
58
+
59
+ end
60
+
61
+
62
+ # -- ------------------------------------------- -- #
63
+ # -- Read the PROPERTY file key/value pairs -- #
64
+ # -- and store them in the fact database under -- #
65
+ # -- the group symbol specified. -- #
66
+ # -- -- #
67
+ # -- Can be used to assimilate files like the -- #
68
+ # -- ubiquitous application.properties into the -- #
69
+ # -- fact database. -- #
70
+ # -- -- #
71
+ # -- Subsequently, the incoming facts can then -- #
72
+ # -- be consumed, updated and deleted as per the -- #
73
+ # -- usual protocols. -- #
74
+ # -- ------------------------------------------- -- #
75
+ # -- property file facts are NOT evaluated they -- #
76
+ # -- are simply assumed to be strings. -- #
77
+ # -- ------------------------------------------- -- #
78
+ # -- Parameters -- #
79
+ # -- property_filepath : path to prop file -- #
80
+ # -- group_symbol : collection 4 facts -- #
81
+ # -- -- #
82
+ # -- Dependencies and Assumptions -- #
83
+ # -- properties file exists and formatted -- #
84
+ # -- group symbol not added if already exists -- #
85
+ # -- props are not eval'd - assumed 2b "strs" -- #
86
+ # -- ------------------------------------------- -- #
87
+ def assimilate_property_file property_filepath, group_symbol
88
+
89
+ return unless File.exists? property_filepath
90
+
91
+ then_count = @f[group_symbol].nil? ? 0 : @f[group_symbol].length
92
+
93
+ IO.foreach( property_filepath ) do |dirty_file_line|
94
+
95
+ file_line = dirty_file_line.strip
96
+ next if file_line.empty?
97
+ next if file_line.start_with? "#"
98
+
99
+ segments = file_line.split("=")
100
+ raise_properrty_error if segments.length < 2
101
+ property_value = file_line[(segments.first.length+1)..-1]
102
+
103
+ key_symbol = segments.first.strip.gsub(".","_").to_sym
104
+ add_fact group_symbol, key_symbol, property_value
105
+
106
+ end
107
+
108
+ now_count = @f[group_symbol].nil? ? 0 : @f[group_symbol].length
109
+
110
+ log.info(ere) { "[fact reader] -------------------------------------------------------- -- #" }
111
+ log.info(ere) { "[fact reader] THEN => [#{then_count}] properties existed (and)" }
112
+ log.info(ere) { "[fact reader] NOW => [#{now_count}] properties exist." }
113
+ log.info(ere) { "[fact reader] -------------------------------------------------------- -- #" }
114
+ LogObject.map @f[group_symbol]
115
+ log.info(ere) { "[fact reader] -------------------------------------------------------- -- #" }
116
+
117
+ end
118
+
119
+
120
+ # -- --------------------------------------------------------- -- #
121
+ # -- If a line in the property file contains less than two -- #
122
+ # -- segments (using equals = as the divider), raise error. -- #
123
+ # -- --------------------------------------------------------- -- #
124
+ def raise_properrty_error file_path, file_line, segments
125
+
126
+ error_desc = "Expected app properties file line to contain at least one equals."
127
+ error_vals = "Instead [#{segments.length}] parts were found in the array."
128
+ error_line = "file path => #{file_path}"
129
+ error_line = "file line => #{file_line}"
130
+ error_pair = "key value => #{segments.to_s}"
131
+ error_text = "\n\n#{error_desc}\n#{error_vals}\n\n#{error_line}\n\n#{error_pair}"
132
+ raise SyntaxError.new error_text
133
+
134
+ end
135
+
136
+
137
+ end