Add get_fieldlabel_value
This commit is contained in:
@@ -113,17 +113,26 @@ 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
|
||||
# @param [String] the field label to get
|
||||
# @return [String] the value for the given field label
|
||||
def get_fieldlabel_value(scrt_id, fieldlabel)
|
||||
secret = get_secret(scrt_id)
|
||||
secret_items = secret[:secret][:items][:secret_item]
|
||||
return get_secret_item_by_field_name(secret_items, fieldlabel)[:value]
|
||||
rescue Savon::Error => 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(), passing in 'Password' as the fieldlabel
|
||||
# @param [Integer] the secret id
|
||||
# @return [String] the password for the given secret
|
||||
|
||||
def get_password(scrt_id)
|
||||
secret = get_secret(scrt_id)
|
||||
secret_items = secret[:secret][:items][:secret_item]
|
||||
return get_secret_item_by_field_name(secret_items, 'Password')[:value]
|
||||
rescue Savon::Error => err
|
||||
raise "There was an error getting the password for secret #{scrt_id}: #{err}"
|
||||
return get_fieldlabel_value(scrt_id, 'Password')
|
||||
end
|
||||
|
||||
## Get the password, save it to a file, and return the path to the file.
|
||||
|
||||
@@ -20,15 +20,17 @@ module Zanzibar
|
||||
construct_options
|
||||
ensure_options
|
||||
|
||||
fetch_secret(@scrt_id, options['filelabel'])
|
||||
fetch_secret(@scrt_id, options)
|
||||
end
|
||||
|
||||
def fetch_secret(scrt_id, label = nil)
|
||||
def fetch_secret(scrt_id, opts = nil)
|
||||
scrt = ::Zanzibar::Zanzibar.new(@zanzibar_options)
|
||||
|
||||
if label
|
||||
if opts['filelabel']
|
||||
scrt.download_secret_file(scrt_id: scrt_id,
|
||||
type: label)
|
||||
elsif opts['fieldlabel']
|
||||
scrt.get_fieldlabel_value(scrt_id, opts['fieldlabel'])
|
||||
else
|
||||
scrt.get_password(scrt_id)
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user