Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a98319aebe | ||
|
|
7c154f5bc8 | ||
|
|
9fc219d98a | ||
|
|
561a523261 | ||
|
|
ca55a4de57 | ||
|
|
0da43c9fd3 | ||
|
|
ddb2931f6c | ||
|
|
7cec3f7461 | ||
|
|
7f357ef60d |
@@ -113,17 +113,25 @@ module Zanzibar
|
||||
raise "There was an error getting the secret with id #{scrt_id}: #{err}"
|
||||
end
|
||||
|
||||
## Retrieve a simple password from a secret
|
||||
## Retrieve the value from a field label of a secret
|
||||
# Will raise an error if there are any issues
|
||||
# @param [Integer] the secret id
|
||||
# @return [String] the password for the given secret
|
||||
|
||||
def get_password(scrt_id)
|
||||
# @param [String] the field label to get, defaults to Password
|
||||
# @return [String] the value for the given field label
|
||||
def get_fieldlabel_value(scrt_id, fieldlabel = 'Password')
|
||||
secret = get_secret(scrt_id)
|
||||
secret_items = secret[:secret][:items][:secret_item]
|
||||
return get_secret_item_by_field_name(secret_items, 'Password')[:value]
|
||||
return get_secret_item_by_field_name(secret_items, fieldlabel)[:value]
|
||||
rescue Savon::Error => err
|
||||
raise "There was an error getting the password for secret #{scrt_id}: #{err}"
|
||||
raise "There was an error getting '#{fieldlabel}' for secret #{scrt_id}: #{err}"
|
||||
end
|
||||
|
||||
## Retrieve a simple password from a secret
|
||||
# Calls get get_fieldlabel_value()
|
||||
# @param [Integer] the secret id
|
||||
# @return [String] the password for the given secret
|
||||
def get_password(scrt_id)
|
||||
return get_fieldlabel_value(scrt_id)
|
||||
end
|
||||
|
||||
## Get the password, save it to a file, and return the path to the file.
|
||||
|
||||
@@ -20,18 +20,19 @@ module Zanzibar
|
||||
construct_options
|
||||
ensure_options
|
||||
|
||||
fetch_secret(@scrt_id, options['filelabel'])
|
||||
fetch_secret(@scrt_id)
|
||||
end
|
||||
|
||||
def fetch_secret(scrt_id, label = nil)
|
||||
def fetch_secret(scrt_id)
|
||||
scrt = ::Zanzibar::Zanzibar.new(@zanzibar_options)
|
||||
|
||||
if label
|
||||
if @zanzibar_options[:filelabel]
|
||||
scrt.download_secret_file(scrt_id: scrt_id,
|
||||
type: label)
|
||||
type: @zanzibar_options[:filelabel])
|
||||
else
|
||||
scrt.get_password(scrt_id)
|
||||
scrt.get_fieldlabel_value(scrt_id, @zanzibar_options[:fieldlabel])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def construct_options
|
||||
@@ -40,6 +41,8 @@ module Zanzibar
|
||||
@zanzibar_options[:domain] = options['domain']
|
||||
@zanzibar_options[:username] = options['username'] unless options['username'].nil?
|
||||
@zanzibar_options[:domain] = options['domain'] ? options['domain'] : 'local'
|
||||
@zanzibar_options[:fieldlabel] = options['fieldlabel'] || 'Password'
|
||||
@zanzibar_options[:filelabel] = options['filelabel'] if options['filelabel']
|
||||
end
|
||||
|
||||
def construct_wsdl
|
||||
|
||||
@@ -76,6 +76,8 @@ module Zanzibar
|
||||
desc: 'Don\'t verify Secret Server\'s SSL certificate'
|
||||
option 'filelabel', type: :string, aliases: :f,
|
||||
desc: 'Specify a file (by label) to download'
|
||||
option 'fieldlabel', type: :string, aliases: :l,
|
||||
desc: 'Specify a field (by label) to get'
|
||||
option 'username', type: :string, aliases: :u
|
||||
option 'password', type: :string, aliases: :p
|
||||
def get(scrt_id)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# The version of the gem
|
||||
module Zanzibar
|
||||
VERSION = '0.1.24'
|
||||
VERSION = '0.1.27'
|
||||
end
|
||||
|
||||
@@ -47,6 +47,11 @@ describe Zanzibar::Cli do
|
||||
expect { subject.get(1234) }.to raise_error.with_message(/#{Zanzibar::NO_WSDL_ERROR}/)
|
||||
end
|
||||
|
||||
it 'should be able to get a field value' do
|
||||
subject.options = { 'domain' => 'zanzitest.net', 'wsdl' => 'scrt.wsdl', 'fieldlabel' => 'Username' }
|
||||
expect { subject.get(1234) }.to output(/ZanziUser/).to_stdout
|
||||
end
|
||||
|
||||
it 'should be able to download files' do
|
||||
WebMock.reset!
|
||||
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
|
||||
|
||||
Reference in New Issue
Block a user