Save username and password to a Normariffic yaml file
This commit is contained in:
@@ -2,6 +2,7 @@ require 'zanzibar/version'
|
|||||||
require 'savon'
|
require 'savon'
|
||||||
require 'io/console'
|
require 'io/console'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
module Zanzibar
|
module Zanzibar
|
||||||
##
|
##
|
||||||
@@ -124,9 +125,11 @@ module Zanzibar
|
|||||||
end
|
end
|
||||||
|
|
||||||
## Get the password, save it to a file, and return the path to the file.
|
## Get the password, save it to a file, and return the path to the file.
|
||||||
def get_password_and_save(scrt_id, path, name)
|
def get_username_and_password_and_save(scrt_id, path, name)
|
||||||
password = get_password(scrt_id)
|
secret_items = get_secret(scrt_id)[:secret][:items][:secret_item]
|
||||||
save_password_to_file(password, path, name)
|
password = get_secret_item_by_field_name(secret_items, 'Password')[:value]
|
||||||
|
username = get_secret_item_by_field_name(secret_items, 'Username')[:value]
|
||||||
|
save_username_and_password_to_file(password, username, path, name)
|
||||||
return File.join(path, name)
|
return File.join(path, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -137,9 +140,10 @@ module Zanzibar
|
|||||||
end
|
end
|
||||||
|
|
||||||
## Write the password to a file. Intended for use with a Zanzifile
|
## Write the password to a file. Intended for use with a Zanzifile
|
||||||
def save_password_to_file(password, path, name)
|
def save_username_and_password_to_file(password, username, path, name)
|
||||||
|
user_pass = {'username' => username.to_s, 'password' => password.to_s}.to_yaml
|
||||||
File.open(File.join(path, name), 'wb') do |file|
|
File.open(File.join(path, name), 'wb') do |file|
|
||||||
file.print password
|
file.print user_pass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ module Zanzibar
|
|||||||
|
|
||||||
def download_one_secret(scrt_id, label, path, args, name = nil)
|
def download_one_secret(scrt_id, label, path, args, name = nil)
|
||||||
if label == 'Password'
|
if label == 'Password'
|
||||||
path = zanzibar(args).get_password_and_save(scrt_id, path, name)
|
path = zanzibar(args).get_username_and_password_and_save(scrt_id, path, name)
|
||||||
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
||||||
else
|
else
|
||||||
path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
|
path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
|
||||||
|
|||||||
@@ -104,15 +104,15 @@ describe 'Zanzibar Test' do
|
|||||||
File.delete('attachment.txt')
|
File.delete('attachment.txt')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save a password to a file' do
|
it 'should save credentials to a file' do
|
||||||
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
|
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
|
||||||
.to_return(body: AUTH_XML, status: 200).then
|
.to_return(body: AUTH_XML, status: 200).then
|
||||||
.to_return(body: SECRET_XML, status: 200)
|
.to_return(body: SECRET_XML, status: 200)
|
||||||
|
|
||||||
client.get_password_and_save(1234, '.', 'zanziTestPassword')
|
client.get_username_and_password_and_save(1234, '.', 'zanziTestCreds')
|
||||||
expect(File.exist? 'zanziTestPassword')
|
expect(File.exist? 'zanziTestCreds')
|
||||||
expect(File.read('zanziTestPassword')).to eq('zanziUserPassword')
|
expect(File.read('zanziTestCreds')).to eq({'username' => 'ZanziUser', 'password' => 'zanziUserPassword'}.to_yaml)
|
||||||
File.delete('zanziTestPassword')
|
File.delete('zanziTestCreds')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should use environment variables for credentials' do
|
it 'should use environment variables for credentials' do
|
||||||
|
|||||||
Reference in New Issue
Block a user