zanzibar 0.1.16 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/zanzibar.rb +18 -0
- data/lib/zanzibar/actions/bundle.rb +16 -6
- data/lib/zanzibar/cli.rb +1 -0
- data/lib/zanzibar/version.rb +1 -1
- data/spec/lib/zanzibar_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDUyMjI4YjkzMGY3ZTRjMDVhNGQ2Nzg0MjU0MTQ3YmYyOTlmOGRhYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2NkNzBmN2M0Y2Q2OThjOGI4YmM4OTQwMzlmMjJiNjhhNmE5ZGNmZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OThjNTE0YjFiYjdiMDI2NTI1N2Q3NDNlNzc4N2ZmYzM0MzE3ZGIyYTEyMDZm
|
10
|
+
YmQ5MzgwNGEwODBkNzBkOTliMDBjNzQzMDgwOGQxMDA0Mzk4YjZjYjMzODg1
|
11
|
+
MDM0MGZiOWE0ZjYyZDY5NjE2MjRmOTM3YmIzYzMyNThjYWJkZTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjBkMjA0MWJlMDM0MzBjYWM1ZGY5OGM2NWE3NGU5NDYyNzkwN2Y1YzYzMzZj
|
14
|
+
NzI0NWZiY2UxNDI4YjcyYzM0MDVlYzc4MjVkNjM5ODFhYTA4YjYxMjE1OTFm
|
15
|
+
NmIzNjJhY2VjZTEwNTI4NTVhN2I1OTk5MTIyNjZjYjhmZjNmYzk=
|
data/lib/zanzibar.rb
CHANGED
@@ -2,6 +2,7 @@ require 'zanzibar/version'
|
|
2
2
|
require 'savon'
|
3
3
|
require 'io/console'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
module Zanzibar
|
7
8
|
##
|
@@ -123,12 +124,29 @@ module Zanzibar
|
|
123
124
|
raise "There was an error getting the password for secret #{scrt_id}: #{err}"
|
124
125
|
end
|
125
126
|
|
127
|
+
## Get the password, save it to a file, and return the path to the file.
|
128
|
+
def get_username_and_password_and_save(scrt_id, path, name)
|
129
|
+
secret_items = get_secret(scrt_id)[:secret][:items][:secret_item]
|
130
|
+
password = get_secret_item_by_field_name(secret_items, 'Password')[:value]
|
131
|
+
username = get_secret_item_by_field_name(secret_items, 'Username')[:value]
|
132
|
+
save_username_and_password_to_file(password, username, path, name)
|
133
|
+
return File.join(path, name)
|
134
|
+
end
|
135
|
+
|
126
136
|
def write_secret_to_file(path, secret_response)
|
127
137
|
File.open(File.join(path, secret_response[:file_name]), 'wb') do |file|
|
128
138
|
file.puts Base64.decode64(secret_response[:file_attachment])
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
142
|
+
## Write the password to a file. Intended for use with a Zanzifile
|
143
|
+
def save_username_and_password_to_file(password, username, path, name)
|
144
|
+
user_pass = {'username' => username.to_s, 'password' => password.to_s}.to_yaml
|
145
|
+
File.open(File.join(path, name), 'wb') do |file|
|
146
|
+
file.print user_pass
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
132
150
|
def get_secret_item_by_field_name(secret_items, field_name)
|
133
151
|
secret_items.each do |item|
|
134
152
|
return item if item[:field_name] == field_name
|
@@ -20,6 +20,7 @@ module Zanzibar
|
|
20
20
|
def run
|
21
21
|
ensure_zanzifile
|
22
22
|
load_required_secrets
|
23
|
+
ensure_secrets_path
|
23
24
|
validate_environment
|
24
25
|
load_resolved_secrets if resolved_file?
|
25
26
|
validate_local_secrets unless @update
|
@@ -42,6 +43,10 @@ module Zanzibar
|
|
42
43
|
debug { "#{ZANZIFILE_NAME} located..." }
|
43
44
|
end
|
44
45
|
|
46
|
+
def ensure_secrets_path
|
47
|
+
FileUtils.mkdir_p(@settings['secret_dir']) unless @settings['secret_dir'] == nil
|
48
|
+
end
|
49
|
+
|
45
50
|
def resolved_file?
|
46
51
|
File.exist? RESOLVED_NAME
|
47
52
|
end
|
@@ -83,20 +88,25 @@ module Zanzibar
|
|
83
88
|
downloaded_secrets[key] = download_one_secret(secret['id'],
|
84
89
|
secret['label'],
|
85
90
|
@settings['secret_dir'],
|
86
|
-
args
|
91
|
+
args,
|
92
|
+
secret['name'] || "#{secret['id']}_password")
|
87
93
|
|
88
|
-
debug { "Downloaded secret: #{key} to #{
|
94
|
+
debug { "Downloaded secret: #{key} to #{@settings['secret_dir']}..." }
|
89
95
|
end
|
90
96
|
|
91
97
|
downloaded_secrets
|
92
98
|
end
|
93
99
|
|
94
|
-
def download_one_secret(scrt_id, label, path, args)
|
95
|
-
|
100
|
+
def download_one_secret(scrt_id, label, path, args, name = nil)
|
101
|
+
if label == 'Password'
|
102
|
+
path = zanzibar(args).get_username_and_password_and_save(scrt_id, path, name)
|
103
|
+
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
104
|
+
else
|
105
|
+
path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
|
96
106
|
type: label,
|
97
107
|
path: path)
|
98
|
-
|
99
|
-
|
108
|
+
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
109
|
+
end
|
100
110
|
end
|
101
111
|
|
102
112
|
def update_resolved_file(new_secrets)
|
data/lib/zanzibar/cli.rb
CHANGED
data/lib/zanzibar/version.rb
CHANGED
data/spec/lib/zanzibar_spec.rb
CHANGED
@@ -104,6 +104,17 @@ describe 'Zanzibar Test' do
|
|
104
104
|
File.delete('attachment.txt')
|
105
105
|
end
|
106
106
|
|
107
|
+
it 'should save credentials to a file' do
|
108
|
+
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
|
109
|
+
.to_return(body: AUTH_XML, status: 200).then
|
110
|
+
.to_return(body: SECRET_XML, status: 200)
|
111
|
+
|
112
|
+
client.get_username_and_password_and_save(1234, '.', 'zanziTestCreds')
|
113
|
+
expect(File.exist? 'zanziTestCreds')
|
114
|
+
expect(File.read('zanziTestCreds')).to eq({'username' => 'ZanziUser', 'password' => 'zanziUserPassword'}.to_yaml)
|
115
|
+
File.delete('zanziTestCreds')
|
116
|
+
end
|
117
|
+
|
107
118
|
it 'should use environment variables for credentials' do
|
108
119
|
ENV['ZANZIBAR_USER'] = 'environment_user'
|
109
120
|
ENV['ZANZIBAR_PASSWORD'] = 'environment_password'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zanzibar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Davis-Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|