opensecret 0.0.9925 → 0.0.9949
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.
- checksums.yaml +4 -4
- data/README.md +656 -40
- data/lib/configs/README.md +58 -0
- data/lib/extension/file.rb +67 -0
- data/lib/extension/string.rb +10 -0
- data/lib/factbase/facts.opensecret.io.ini +1 -0
- data/lib/interprete.rb +334 -61
- data/lib/keytools/PRODUCE_RAND_SEQ_USING_DEV_URANDOM.txt +0 -0
- data/lib/keytools/kdf.api.rb +9 -15
- data/lib/keytools/kdf.bcrypt.rb +69 -19
- data/lib/keytools/kdf.pbkdf2.rb +112 -23
- data/lib/keytools/key.api.rb +146 -36
- data/lib/keytools/key.db.rb +94 -29
- data/lib/keytools/key.id.rb +1 -1
- data/lib/keytools/key.ident.rb +243 -0
- data/lib/keytools/key.local.rb +62 -68
- data/lib/keytools/key.pass.rb +2 -2
- data/lib/keytools/key.rb +2 -28
- data/lib/modules/{cryptology.md → README.md} +0 -0
- data/lib/session/fact.finder.rb +65 -428
- data/lib/session/time.stamp.rb +1 -28
- data/lib/usecase/cmd.rb +127 -54
- data/lib/usecase/config/README.md +57 -0
- data/lib/usecase/docker/README.md +146 -0
- data/lib/usecase/docker/docker.rb +49 -0
- data/lib/usecase/edit/README.md +43 -0
- data/lib/usecase/edit/delete.rb +46 -0
- data/lib/usecase/export.rb +40 -0
- data/lib/usecase/files/README.md +37 -0
- data/lib/usecase/files/eject.rb +56 -0
- data/lib/usecase/files/file_me.rb +78 -0
- data/lib/usecase/files/read.rb +169 -0
- data/lib/usecase/files/write.rb +89 -0
- data/lib/usecase/goto.rb +57 -0
- data/lib/usecase/id.rb +1 -1
- data/lib/usecase/import.rb +13 -30
- data/lib/usecase/init.rb +2 -17
- data/lib/usecase/jenkins/README.md +146 -0
- data/lib/usecase/jenkins/crazy_ruby_post_attempt.OLD +234 -0
- data/lib/usecase/jenkins/jenkins.rb +208 -0
- data/lib/usecase/login.rb +6 -5
- data/lib/usecase/logout.rb +1 -3
- data/lib/usecase/open.rb +11 -66
- data/lib/usecase/print.rb +40 -0
- data/lib/usecase/put.rb +34 -156
- data/lib/usecase/set.rb +2 -4
- data/lib/usecase/show.rb +138 -0
- data/lib/usecase/terraform/README.md +91 -0
- data/lib/usecase/terraform/terraform.rb +121 -0
- data/lib/usecase/token.rb +4 -80
- data/lib/usecase/update/README.md +55 -0
- data/lib/usecase/update/rename.rb +180 -0
- data/lib/usecase/use.rb +1 -3
- data/lib/usecase/verse.rb +20 -0
- data/lib/usecase/view.rb +71 -0
- data/lib/usecase/vpn/README.md +150 -0
- data/lib/usecase/vpn/vpn.ini +31 -0
- data/lib/usecase/vpn/vpn.rb +54 -0
- data/lib/version.rb +1 -1
- data/opensecret.gemspec +3 -4
- metadata +34 -35
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/LICENSE.txt +0 -21
- data/bin/ops +0 -20
- data/lib/keytools/binary.map.rb +0 -294
- data/lib/keytools/doc.conversion.to.ones.and.zeroes.ruby +0 -179
- data/lib/keytools/doc.rsa.radix.binary-mapping.ruby +0 -190
- data/lib/keytools/doc.star.schema.strategy.txt +0 -77
- data/lib/keytools/doc.using.pbkdf2.kdf.ruby +0 -95
- data/lib/keytools/doc.using.pbkdf2.pkcs.ruby +0 -266
- data/lib/keytools/key.mach.rb +0 -248
- data/lib/keytools/keydebug.txt +0 -295
- data/lib/modules/cryptology/open.bcrypt.rb +0 -170
- data/lib/usecase/read.rb +0 -89
- data/lib/usecase/safe.rb +0 -92
data/lib/usecase/login.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module OpenSecret
|
4
4
|
|
5
|
-
require 'openssl'
|
6
|
-
|
7
5
|
# The <b>login use case</b> is given the domain name and if needs be
|
8
6
|
# it collects the password then (if correct) logs the user in.
|
9
7
|
#
|
@@ -12,11 +10,12 @@ module OpenSecret
|
|
12
10
|
# - its domain name parameter is mandatory
|
13
11
|
# - it is called at the start of every session
|
14
12
|
# - it is undone by the logout command
|
15
|
-
# - it requires the
|
13
|
+
# - it requires the shell token environment variable to be set
|
16
14
|
# - you can nest login commands thus using multiple domains
|
17
15
|
# - you can call it with a --with=password switch
|
16
|
+
# - a space before the command prevents it being logged in .bash_history
|
18
17
|
# - you can deliver the password in multiple ways
|
19
|
-
class Login <
|
18
|
+
class Login < UseCase
|
20
19
|
|
21
20
|
attr_writer :master_p4ss, :domain_name
|
22
21
|
|
@@ -46,7 +45,9 @@ module OpenSecret
|
|
46
45
|
############## Use [[ KeyApi.valid_password? ]] and give error if not valid
|
47
46
|
|
48
47
|
OpenKey::KeyApi.do_login( @domain_name, domain_secret, create_header() )
|
49
|
-
|
48
|
+
|
49
|
+
view_uc = View.new
|
50
|
+
view_uc.flow_of_events
|
50
51
|
|
51
52
|
end
|
52
53
|
|
data/lib/usecase/logout.rb
CHANGED
data/lib/usecase/open.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module OpenSecret
|
4
4
|
|
5
|
-
require 'openssl'
|
6
|
-
|
7
5
|
# The <tt>open use case</tt> allows us to add (put), subtract (del)ete, change
|
8
6
|
# (update) and list the secrets within an envelope (outer path) at a given
|
9
7
|
# position (inner path), whether that envelope exists or not.
|
@@ -18,16 +16,6 @@ module OpenSecret
|
|
18
16
|
# single colon separating the outer (path to envelope) from the inner (path
|
19
17
|
# within envelope).
|
20
18
|
#
|
21
|
-
# ops open aws.credentials:s3reader
|
22
|
-
#
|
23
|
-
# The outer and inner paths can contain forward slashes that segment the path.
|
24
|
-
#
|
25
|
-
# ops open production/aws.credentials:s3/s3reader
|
26
|
-
# ops put access_key ABCD1234
|
27
|
-
# ops put secret_key FGHIJ56789
|
28
|
-
# ops put region_key eu-central-1
|
29
|
-
# ops seal
|
30
|
-
#
|
31
19
|
# == Open (Path) Pre-Conditions
|
32
20
|
#
|
33
21
|
# The domain must have been initialized on this machine stating the path to
|
@@ -36,13 +24,11 @@ module OpenSecret
|
|
36
24
|
# To open a path these conditions must be true.
|
37
25
|
#
|
38
26
|
# - the shell session token must have been set at the session beginning
|
39
|
-
# - a successful <tt>
|
27
|
+
# - a successful <tt>login</tt> command must have been issued
|
40
28
|
# - the external drive (eg usb key) must be configured and accessible
|
41
29
|
#
|
42
30
|
# == Observable Value
|
43
31
|
#
|
44
|
-
# $ ops open home/wifi
|
45
|
-
#
|
46
32
|
# The observable value delivered by +[open]+ boils down to
|
47
33
|
#
|
48
34
|
# - an openkey (eg asdfx1234) and corresponding open encryption key
|
@@ -53,7 +39,7 @@ module OpenSecret
|
|
53
39
|
# [session]
|
54
40
|
# base.path = home/wifi
|
55
41
|
#
|
56
|
-
class Open <
|
42
|
+
class Open < UseCase
|
57
43
|
|
58
44
|
# The two paths that have been posted to the open command.
|
59
45
|
# First is a relative path to the obfuscated envelope and then
|
@@ -63,59 +49,18 @@ module OpenSecret
|
|
63
49
|
def execute
|
64
50
|
|
65
51
|
return unless ops_key_exists?
|
66
|
-
|
67
|
-
|
68
|
-
puts "---\n"
|
69
|
-
puts "--- The Master Database (Before)\n"
|
70
|
-
puts "---\n"
|
71
|
-
puts JSON.pretty_generate( appdb_content )
|
72
|
-
puts "---\n"
|
73
|
-
|
74
|
-
appdb_content[ ENV_PATH ] = @env_path
|
75
|
-
appdb_content[ KEY_PATH ] = @key_path
|
76
|
-
|
77
|
-
puts "---\n"
|
78
|
-
puts "--- The Master Database (After)\n"
|
79
|
-
puts "---\n"
|
80
|
-
puts JSON.pretty_generate( appdb_content )
|
81
|
-
puts "---\n"
|
82
|
-
|
83
|
-
OpenKey::KeyApi.write_app_content( create_header(), appdb_content )
|
84
|
-
print_open_success
|
85
|
-
|
86
|
-
return
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
|
94
|
-
def print_open_success
|
95
|
-
|
96
|
-
puts ""
|
97
|
-
puts "Success opening a path to a data bucket."
|
98
|
-
puts "You can now put data into a dictionary or"
|
99
|
-
puts "add it to a list or set a scalar value."
|
100
|
-
puts ""
|
101
|
-
puts " ops put aws.iam.usr joebloggs"
|
102
|
-
puts " ops put access.key ABCD1234"
|
103
|
-
puts " ops put secret.key FGHIJ56789"
|
104
|
-
puts " ops put region.key eu-central-1"
|
105
|
-
puts " ops close"
|
106
|
-
puts ""
|
107
|
-
|
108
|
-
end
|
52
|
+
master_db = OpenKey::KeyApi.read_master_db()
|
109
53
|
|
54
|
+
master_db[ ENV_PATH ] = @env_path
|
55
|
+
master_db[ KEY_PATH ] = @key_path
|
110
56
|
|
111
|
-
|
112
|
-
# of events for this use case. This method may throw the below exceptions.
|
113
|
-
#
|
114
|
-
# @raise [SafeDirNotConfigured] if the safe's url has not been configured
|
115
|
-
# @raise [EmailAddrNotConfigured] if the email address has not been configured
|
116
|
-
# @raise [StoreUrlNotConfigured] if the crypt store url is not configured
|
117
|
-
def pre_validation
|
57
|
+
OpenKey::KeyApi.write_master_db( create_header(), master_db )
|
118
58
|
|
59
|
+
# Show the mini dictionary at the opened chapter and verse location
|
60
|
+
# More work is needed when for when only the chapter is opened in
|
61
|
+
# which case we should show the list of verses and perhaps the count
|
62
|
+
# of key value pairs each verse contains.
|
63
|
+
Show.new.flow_of_events
|
119
64
|
|
120
65
|
end
|
121
66
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module OpenSecret
|
4
|
+
|
5
|
+
class Print < UseCase
|
6
|
+
|
7
|
+
attr_writer :key_name
|
8
|
+
|
9
|
+
def get_chapter_data( chapter_key )
|
10
|
+
return OpenKey::KeyDb.from_json( OpenKey::KeyApi.content_unlock( chapter_key ) )
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
|
15
|
+
return unless ops_key_exists?
|
16
|
+
|
17
|
+
master_db = get_master_database()
|
18
|
+
|
19
|
+
return if unopened_envelope?( master_db )
|
20
|
+
|
21
|
+
chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
|
22
|
+
has_chapter = OpenKey::KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
|
23
|
+
|
24
|
+
chapter_data = get_chapter_data( master_db[ chapter_id ] ) if has_chapter
|
25
|
+
has_verse = has_chapter && chapter_data.has_key?( master_db[ KEY_PATH ] )
|
26
|
+
|
27
|
+
chapter_err_msg = "Nothing was found at chapter " + master_db[ ENV_PATH ]
|
28
|
+
raise ArgumentError, chapter_err_msg unless has_chapter
|
29
|
+
verse_err_msg = "Nothing was found at chapter " + master_db[ ENV_PATH ] + " verse " + master_db[ KEY_PATH ]
|
30
|
+
raise ArgumentError, verse_err_msg unless has_verse
|
31
|
+
|
32
|
+
print chapter_data[ master_db[ KEY_PATH ] ][ @key_name ]
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
data/lib/usecase/put.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module OpenSecret
|
4
4
|
|
5
|
-
require 'openssl'
|
6
|
-
|
7
5
|
# The <b>put use case</b> follows <b>open</b> and it adds secrets into an
|
8
6
|
# <em>(encrypted at rest)</em> <b>envelope</b>. Put can be called many times
|
9
7
|
# and when done, the <b>lock use case</b> can be called to commit all opened
|
@@ -27,172 +25,52 @@ module OpenSecret
|
|
27
25
|
# - a new group_name/key_name (like monica/surname) entry is added if required
|
28
26
|
# - a secret value is added against the key or updated if it already exists
|
29
27
|
# - a new session id and encryption key is generated and used to re-encrypt
|
30
|
-
|
31
|
-
# == Example | Bill Clinton's Secrets
|
32
|
-
#
|
33
|
-
# In our fictitious example Bill Clinton uses opensecret to lock away the
|
34
|
-
# names and dates of his lady friends.
|
35
|
-
#
|
36
|
-
# $ opensecret init bill.clinton@example.com
|
37
|
-
# $ opensecret open my/friends
|
38
|
-
#
|
39
|
-
# $ opensecret put monica/surname lewinsky
|
40
|
-
# $ opensecret put monica/from "April 1989"
|
41
|
-
# $ opensecret put monica/to "September 1994"
|
42
|
-
#
|
43
|
-
# $ opensecret put hilary/surname clinton
|
44
|
-
# $ opensecret put hilary/from "January 1988"
|
45
|
-
# $ opensecret put hilary/to "Present Day"
|
46
|
-
#
|
47
|
-
# $ opensecret lock
|
48
|
-
#
|
49
|
-
# Soon follow up use cases will be unveiled, enabling us to
|
50
|
-
#
|
51
|
-
# - <b>get</b>
|
52
|
-
# - <b>read</b>
|
53
|
-
# - <b>list</b>
|
54
|
-
# - <b>look</b>
|
55
|
-
# - <b>peep</b> and
|
56
|
-
# - <b>peek</b>
|
57
|
-
class Put < Command
|
58
|
-
|
28
|
+
class Put < UseCase
|
59
29
|
|
60
30
|
attr_writer :secret_id, :secret_value
|
61
31
|
|
62
|
-
|
63
|
-
#
|
64
|
-
# <em>(encrypted at rest)</em> envelope. Put can be called many times to
|
65
|
-
# add secrets. Finally the <b>lock use case</b> commits all opened secrets
|
66
|
-
# into the configured storage engines.
|
67
|
-
#
|
68
|
-
# Calling <em>put</em> <b>before</b> calling open or <b>after</b> calling lock
|
69
|
-
# is not allowed and will result in an error.
|
70
|
-
#
|
71
|
-
# == Put Pre-Conditions
|
72
|
-
#
|
73
|
-
# When the put use case is called - the below conditions ring true.
|
74
|
-
#
|
75
|
-
# - the <b>folder path</b> ending in ../../my must exist
|
76
|
-
# - a session id, filename and encryption key ( in workstation config )
|
77
|
-
#
|
78
|
-
# == Observable Value
|
79
|
-
#
|
80
|
-
# The observable value delivered by +put+ boils down to
|
81
|
-
#
|
82
|
-
# - a new <b>friends.xyz123abc.os.txt</b> file if this is the first put.
|
83
|
-
# - a new group_name/key_name (like monica/surname) entry is added if required
|
84
|
-
# - a secret value is added against the key or updated if it already exists
|
85
|
-
# - a new session id and encryption key is generated and used to re-encrypt
|
32
|
+
# Execute the act of putting a string key and string value pair into a
|
33
|
+
# map at the chapter and verse location, overwriting if need be.
|
86
34
|
def execute
|
87
35
|
|
88
|
-
## @todo - rename appdb_content as master_db
|
89
|
-
## @todo - rename appdb_content as master_db
|
90
|
-
## @todo - rename appdb_content as master_db
|
91
|
-
## @todo - rename appdb_content as master_db
|
92
|
-
## @todo - rename appdb_content as master_db
|
93
|
-
## @todo - rename appdb_content as master_db
|
94
|
-
## @todo - rename appdb_content as master_db
|
95
|
-
## @todo - rename appdb_content as master_db
|
96
|
-
## @todo - rename appdb_content as master_db
|
97
|
-
## @todo - rename appdb_content as master_db
|
98
|
-
## @todo - rename appdb_content as master_db
|
99
|
-
## @todo - rename appdb_content as master_db
|
100
|
-
## @todo - rename appdb_content as master_db
|
101
|
-
## @todo - rename appdb_content as master_db
|
102
|
-
|
103
36
|
return unless ops_key_exists?
|
104
|
-
|
105
|
-
|
106
|
-
puts "---\n"
|
107
|
-
puts "--- The Master Database (Before)\n"
|
108
|
-
puts "---\n"
|
109
|
-
puts JSON.pretty_generate( appdb_content )
|
110
|
-
puts "---\n"
|
111
|
-
|
112
|
-
return if unopened_envelope?( appdb_content )
|
113
|
-
|
114
|
-
envelope_id = ENVELOPE_KEY_PREFIX + appdb_content[ ENV_PATH ]
|
115
|
-
has_content = OpenKey::KeyApi.content_exists?( appdb_content[ envelope_id ] )
|
116
|
-
|
117
|
-
# --
|
118
|
-
# -- To get hold of the content we must either
|
119
|
-
# --
|
120
|
-
# -- a) unlock it using the breadcrumbs or
|
121
|
-
# -- b) start afresh with a new content db
|
122
|
-
# --
|
123
|
-
content_box = OpenKey::KeyApi.content_unlock( appdb_content[ envelope_id ] ) if has_content
|
124
|
-
content_box = OpenKey::KeyDb.new() unless has_content
|
125
|
-
content_hdr = create_header()
|
126
|
-
|
127
|
-
# --
|
128
|
-
# -- If no content envelope exists we need to place
|
129
|
-
# -- an empty one inside the appdb content database.
|
130
|
-
# --
|
131
|
-
appdb_content[ envelope_id ] = {} unless has_content
|
132
|
-
|
133
|
-
# --
|
134
|
-
# -- This is the PUT use case so we append a
|
135
|
-
# --
|
136
|
-
# -- a) key for the new dictionary entry
|
137
|
-
# -- b) value for the new dictionary entry
|
138
|
-
# --
|
139
|
-
# -- into the current content envelope and write
|
140
|
-
# -- the envelope to the content filepath.
|
141
|
-
# --
|
142
|
-
crumbs_dict = appdb_content[ envelope_id ]
|
143
|
-
content_box.create_entry( appdb_content[ KEY_PATH ], @secret_id, @secret_value )
|
144
|
-
OpenKey::KeyApi.content_lock( crumbs_dict, content_box.to_json, content_hdr )
|
145
|
-
|
146
|
-
puts "---\n"
|
147
|
-
puts "--- The Master Database (After)\n"
|
148
|
-
puts "---\n"
|
149
|
-
puts JSON.pretty_generate( appdb_content )
|
150
|
-
puts "---\n"
|
151
|
-
|
152
|
-
# --
|
153
|
-
# -- Three envelope crumbs namely the external ID, the
|
154
|
-
# -- random iv and the crypt key are written afreshinto
|
155
|
-
# -- the master database.
|
156
|
-
# --
|
157
|
-
OpenKey::KeyApi.write_app_content( content_hdr, appdb_content )
|
158
|
-
print_put_success
|
159
|
-
|
160
|
-
return
|
161
|
-
|
162
|
-
|
163
|
-
# ---> secret_ids = @secret_id.split("/")
|
164
|
-
# ---> if ( envelope.has_key? secret_ids.first )
|
165
|
-
# ---> envelope[secret_ids.first][secret_ids.last] = @secret_value
|
166
|
-
# ---> else
|
167
|
-
# ---> envelope[secret_ids.first] = { secret_ids.last => @secret_value }
|
168
|
-
# ---> end
|
169
|
-
|
170
|
-
end
|
37
|
+
master_db = OpenKey::KeyApi.read_master_db()
|
171
38
|
|
39
|
+
return if unopened_envelope?( master_db )
|
172
40
|
|
173
|
-
|
41
|
+
envelope_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
|
42
|
+
has_content = OpenKey::KeyApi.db_envelope_exists?( master_db[ envelope_id ] )
|
174
43
|
|
44
|
+
# To get hold of the content we must either
|
45
|
+
#
|
46
|
+
# a) unlock it using the breadcrumbs or
|
47
|
+
# b) start afresh with a new content db
|
48
|
+
content_box = OpenKey::KeyDb.from_json( OpenKey::KeyApi.content_unlock( master_db[ envelope_id ] ) ) if has_content
|
49
|
+
content_box = OpenKey::KeyDb.new() unless has_content
|
50
|
+
content_hdr = create_header()
|
175
51
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
52
|
+
# If no content envelope exists we need to place
|
53
|
+
# an empty one inside the appdb content database.
|
54
|
+
master_db[ envelope_id ] = {} unless has_content
|
55
|
+
|
56
|
+
# This is the PUT use case so we append a
|
57
|
+
#
|
58
|
+
# a) key for the new dictionary entry
|
59
|
+
# b) value for the new dictionary entry
|
60
|
+
#
|
61
|
+
# into the current content envelope and write
|
62
|
+
# the envelope to the content filepath.
|
63
|
+
crumbs_dict = master_db[ envelope_id ]
|
64
|
+
content_box.create_entry( master_db[ KEY_PATH ], @secret_id, @secret_value )
|
65
|
+
OpenKey::KeyApi.content_lock( crumbs_dict, content_box.to_json, content_hdr )
|
187
66
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
# @raise [EmailAddrNotConfigured] if the email address has not been configured
|
193
|
-
# @raise [StoreUrlNotConfigured] if the crypt store url is not configured
|
194
|
-
def pre_validation
|
67
|
+
# Three envelope crumbs namely the external ID, the
|
68
|
+
# random iv and the crypt key are written afresh into
|
69
|
+
# the master database.
|
70
|
+
OpenKey::KeyApi.write_master_db( content_hdr, master_db )
|
195
71
|
|
72
|
+
# Show the mini dictionary at the opened chapter and verse location
|
73
|
+
Show.new.flow_of_events
|
196
74
|
|
197
75
|
end
|
198
76
|
|
data/lib/usecase/set.rb
CHANGED
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
module OpenSecret
|
4
4
|
|
5
|
-
require 'openssl'
|
6
|
-
|
7
5
|
# The <b>set <em>use case</em></b> is the generic tool for setting configuration
|
8
|
-
# directives inside the
|
6
|
+
# directives inside the opensecret workstation INI formatted file.
|
9
7
|
#
|
10
8
|
# The mirror of this use case is <b><em>unset</em></b>.
|
11
9
|
#
|
@@ -21,7 +19,7 @@ module OpenSecret
|
|
21
19
|
# Error - if the directive path is not composed of two (fwd slash separated) parts
|
22
20
|
# Error - if the directive path and/or value contains (or not) unacceptable characters
|
23
21
|
#
|
24
|
-
class Set <
|
22
|
+
class Set < UseCase
|
25
23
|
|
26
24
|
attr_writer :domain_name
|
27
25
|
|
data/lib/usecase/show.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module OpenSecret
|
4
|
+
|
5
|
+
# Show the mini dictionary of key-value pairs within the logged in book
|
6
|
+
# at the opened chapter and verse.
|
7
|
+
#
|
8
|
+
# If no dictionary exists at the opened chapter and verse a suitable
|
9
|
+
# message is pushed out to the console.
|
10
|
+
class Show < UseCase
|
11
|
+
|
12
|
+
def get_chapter_data( chapter_key )
|
13
|
+
return OpenKey::KeyDb.from_json( OpenKey::KeyApi.content_unlock( chapter_key ) )
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
|
18
|
+
return unless ops_key_exists?
|
19
|
+
master_db = OpenKey::KeyApi.read_master_db()
|
20
|
+
|
21
|
+
return if unopened_envelope?( master_db )
|
22
|
+
|
23
|
+
chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ]
|
24
|
+
has_chapter = OpenKey::KeyApi.db_envelope_exists?( master_db[ chapter_id ] )
|
25
|
+
chapter_data = get_chapter_data( master_db[ chapter_id ] ) if has_chapter
|
26
|
+
has_verse = has_chapter && chapter_data.has_key?( master_db[ KEY_PATH ] )
|
27
|
+
|
28
|
+
|
29
|
+
##global_variables - DONE
|
30
|
+
##local_variables - DONE
|
31
|
+
##instance_variables - DONE
|
32
|
+
##class_variables - tough nut to crack with very little benefit (method class_variables not defined)
|
33
|
+
|
34
|
+
=begin
|
35
|
+
puts ""
|
36
|
+
puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
37
|
+
puts "QQQ ~~~~~~~~~~~~~ Global Variable Array List ~~~~~~~~~~~~~~~~ QQQQQ"
|
38
|
+
puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
39
|
+
|
40
|
+
puts global_variables.inspect
|
41
|
+
|
42
|
+
puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
43
|
+
puts "QQQ ~~~~~~~~~~~~~ Global Variable Values Printed ~~~~~~~~~~~~~~~~ QQQQQ"
|
44
|
+
puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
45
|
+
|
46
|
+
global_variables.sort.each do |name|
|
47
|
+
|
48
|
+
puts "<<< ------------------------------------------------------------------->>>"
|
49
|
+
puts "<<< #{name.to_s} >>>"
|
50
|
+
puts "<<< ------------------------------------------------------------------->>>"
|
51
|
+
next if name.to_s.eql?( "$FILENAME" )
|
52
|
+
global_variable_value = eval "#{name}.inspect"
|
53
|
+
puts "<<< #{global_variable_value}"
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
puts ""
|
58
|
+
puts "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
59
|
+
puts "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
60
|
+
puts ""
|
61
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
62
|
+
puts "QQQQQQQQQQQ Bug Finder QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
63
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
64
|
+
puts ""
|
65
|
+
self.instance_variables.map do |attribute|
|
66
|
+
puts "=============================================="
|
67
|
+
puts "----------------------------------------------"
|
68
|
+
puts attribute
|
69
|
+
pp self.instance_variable_get(attribute)
|
70
|
+
end
|
71
|
+
puts "=============================================="
|
72
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
73
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
74
|
+
puts ""
|
75
|
+
puts "### ------------------------------------"
|
76
|
+
puts "### Inspect View"
|
77
|
+
puts "### ------------------------------------"
|
78
|
+
pp self.inspect
|
79
|
+
puts "### ------------------------------------"
|
80
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
81
|
+
puts "QQQQQQQQQQQ Local Variables QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
82
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
83
|
+
|
84
|
+
local_variables.map do |attribute|
|
85
|
+
puts "=============================================="
|
86
|
+
puts "----------------------------------------------"
|
87
|
+
puts attribute
|
88
|
+
pp binding.local_variable_get(attribute.to_sym)
|
89
|
+
end
|
90
|
+
puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
|
91
|
+
|
92
|
+
puts ""
|
93
|
+
=end
|
94
|
+
|
95
|
+
|
96
|
+
return unless has_verse
|
97
|
+
|
98
|
+
line_dictionary = chapter_data[ master_db[ KEY_PATH ] ]
|
99
|
+
|
100
|
+
puts ""
|
101
|
+
puts "### ##################################\n"
|
102
|
+
puts "### chapter =>> #{master_db[ ENV_PATH ]}\n"
|
103
|
+
puts "### & verse =>> #{master_db[ KEY_PATH ]}\n"
|
104
|
+
puts "### # lines =>> #{line_dictionary.length}\n"
|
105
|
+
puts "### ##################################\n"
|
106
|
+
puts "--- ----------------------------------\n"
|
107
|
+
puts ""
|
108
|
+
|
109
|
+
showable_content = {}
|
110
|
+
line_dictionary.each do | key_str, value_object |
|
111
|
+
|
112
|
+
is_file = key_str.start_with? FILE_KEY_PREFIX
|
113
|
+
value_object.store( FILE_CONTENT_KEY, SECRET_MASK_STRING ) if is_file
|
114
|
+
showable_content.store( key_str[ FILE_KEY_PREFIX.length .. -1 ], value_object ) if is_file
|
115
|
+
next if is_file
|
116
|
+
|
117
|
+
is_secret = key_str.start_with? "@"
|
118
|
+
showable_val = SECRET_MASK_STRING if is_secret
|
119
|
+
showable_val = value_object unless is_secret
|
120
|
+
showable_content.store( key_str, showable_val )
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
puts JSON.pretty_generate( showable_content )
|
125
|
+
puts "--- ----------------------------------\n"
|
126
|
+
puts "### ##################################\n"
|
127
|
+
puts ""
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
SECRET_MASK_STRING = "***********************"
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
end
|