Dependency updates and rubocop fixes
This commit is contained in:
@@ -12,33 +12,33 @@ module Zanzibar
|
||||
# @param args{:domain, :wsdl, :pwd, :username, :globals{}}
|
||||
|
||||
def initialize(args = {})
|
||||
if args[:username]
|
||||
@@username = args[:username]
|
||||
elsif ENV['ZANZIBAR_USER']
|
||||
@@username = ENV['ZANZIBAR_USER']
|
||||
else
|
||||
@@username = ENV['USER']
|
||||
end
|
||||
@@username = if args[:username]
|
||||
args[:username]
|
||||
elsif ENV['ZANZIBAR_USER']
|
||||
ENV['ZANZIBAR_USER']
|
||||
else
|
||||
ENV['USER']
|
||||
end
|
||||
|
||||
if args[:wsdl]
|
||||
@@wsdl = args[:wsdl]
|
||||
else
|
||||
@@wsdl = get_wsdl_location
|
||||
end
|
||||
@@wsdl = if args[:wsdl]
|
||||
args[:wsdl]
|
||||
else
|
||||
get_wsdl_location
|
||||
end
|
||||
|
||||
if args[:pwd]
|
||||
@@password = args[:pwd]
|
||||
elsif ENV['ZANZIBAR_PASSWORD']
|
||||
@@password = ENV['ZANZIBAR_PASSWORD']
|
||||
else
|
||||
@@password = prompt_for_password
|
||||
end
|
||||
@@password = if args[:pwd]
|
||||
args[:pwd]
|
||||
elsif ENV['ZANZIBAR_PASSWORD']
|
||||
ENV['ZANZIBAR_PASSWORD']
|
||||
else
|
||||
prompt_for_password
|
||||
end
|
||||
|
||||
if args[:domain]
|
||||
@@domain = args[:domain]
|
||||
else
|
||||
@@domain = prompt_for_domain
|
||||
end
|
||||
@@domain = if args[:domain]
|
||||
args[:domain]
|
||||
else
|
||||
prompt_for_domain
|
||||
end
|
||||
args[:globals] = {} unless args[:globals]
|
||||
init_client(args[:globals])
|
||||
end
|
||||
@@ -67,7 +67,7 @@ module Zanzibar
|
||||
def prompt_for_password
|
||||
puts "Please enter password for #{@@username}:"
|
||||
STDIN.noecho(&:gets).chomp.tap do
|
||||
puts "Using password to login..."
|
||||
puts 'Using password to login...'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,8 +93,8 @@ module Zanzibar
|
||||
|
||||
def get_token
|
||||
response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: '', domain: @@domain })
|
||||
.hash[:envelope][:body][:authenticate_response][:authenticate_result]
|
||||
fail "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
|
||||
.hash[:envelope][:body][:authenticate_response][:authenticate_result]
|
||||
raise "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
|
||||
response[:token]
|
||||
rescue Savon::Error => err
|
||||
raise "There was an error generating the authentiaton token for user #{@@username}: #{err}"
|
||||
@@ -107,7 +107,7 @@ module Zanzibar
|
||||
|
||||
def get_secret(scrt_id, token = nil)
|
||||
secret = @@client.call(:get_secret, message: { token: token || get_token, secretId: scrt_id }).hash[:envelope][:body][:get_secret_response][:get_secret_result]
|
||||
fail "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors]
|
||||
raise "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors]
|
||||
return secret
|
||||
rescue Savon::Error => err
|
||||
raise "There was an error getting the secret with id #{scrt_id}: #{err}"
|
||||
@@ -131,7 +131,7 @@ module Zanzibar
|
||||
# @param [Integer] the secret id
|
||||
# @return [String] the password for the given secret
|
||||
def get_password(scrt_id)
|
||||
return get_fieldlabel_value(scrt_id)
|
||||
get_fieldlabel_value(scrt_id)
|
||||
end
|
||||
|
||||
## Get the password, save it to a file, and return the path to the file.
|
||||
@@ -140,7 +140,7 @@ module Zanzibar
|
||||
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)
|
||||
File.join(path, name)
|
||||
end
|
||||
|
||||
def write_secret_to_file(path, secret_response)
|
||||
@@ -151,7 +151,7 @@ module Zanzibar
|
||||
|
||||
## Write the password to a file. Intended for use with a Zanzifile
|
||||
def save_username_and_password_to_file(password, username, path, name)
|
||||
user_pass = {'username' => username.to_s, 'password' => password.to_s}.to_yaml
|
||||
user_pass = { 'username' => username.to_s, 'password' => password.to_s }.to_yaml
|
||||
File.open(File.join(path, name), 'wb') do |file|
|
||||
file.print user_pass
|
||||
end
|
||||
@@ -190,8 +190,8 @@ module Zanzibar
|
||||
begin
|
||||
response = @@client.call(:download_file_attachment_by_item_id, message:
|
||||
{ token: token, secretId: args[:scrt_id], secretItemId: args[:scrt_item_id] || get_scrt_item_id(args[:scrt_id], args[:type], token) })
|
||||
.hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result]
|
||||
fail "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors]
|
||||
.hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result]
|
||||
raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors]
|
||||
write_secret_to_file(path, response)
|
||||
return File.join(path, response[:file_name])
|
||||
rescue Savon::Error => err
|
||||
|
||||
@@ -39,7 +39,7 @@ module Zanzibar
|
||||
end
|
||||
|
||||
def ensure_zanzifile
|
||||
fail Error, NO_ZANZIFILE_ERROR unless File.exist? ZANZIFILE_NAME
|
||||
raise Error, NO_ZANZIFILE_ERROR unless File.exist? ZANZIFILE_NAME
|
||||
debug { "#{ZANZIFILE_NAME} located..." }
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ module Zanzibar
|
||||
## Make sure the directory exists and that a .gitignore is there to ignore it
|
||||
if @settings['secret_dir']
|
||||
FileUtils.mkdir_p(@settings['secret_dir'])
|
||||
if !File.exist? "#{@settings['secret_dir']}/.gitignore"
|
||||
unless File.exist? "#{@settings['secret_dir']}/.gitignore"
|
||||
File.open("#{@settings['secret_dir']}/.gitignore", 'w') do |file|
|
||||
file.puts '*'
|
||||
file.puts '!.gitignore'
|
||||
@@ -69,7 +69,7 @@ module Zanzibar
|
||||
|
||||
def validate_environment
|
||||
return unless @settings.empty? || @remote_secrets.empty?
|
||||
fail Error, INVALID_ZANZIFILE_ERROR
|
||||
raise Error, INVALID_ZANZIFILE_ERROR
|
||||
end
|
||||
|
||||
def load_resolved_secrets
|
||||
@@ -94,7 +94,7 @@ module Zanzibar
|
||||
|
||||
downloaded_secrets = {}
|
||||
remote_secrets.each do |key, secret|
|
||||
full_path = secret.has_key?('prefix') ? File.join(@settings['secret_dir'], secret['prefix']) : @settings['secret_dir']
|
||||
full_path = secret.key?('prefix') ? File.join(@settings['secret_dir'], secret['prefix']) : @settings['secret_dir']
|
||||
downloaded_secrets[key] = download_one_secret(secret['id'],
|
||||
secret['label'],
|
||||
full_path,
|
||||
@@ -110,13 +110,13 @@ module Zanzibar
|
||||
def download_one_secret(scrt_id, label, path, args, name = nil)
|
||||
if label == 'Password'
|
||||
path = zanzibar(args).get_username_and_password_and_save(scrt_id, path, name)
|
||||
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
||||
else
|
||||
path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
|
||||
type: label,
|
||||
path: path)
|
||||
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
||||
type: label,
|
||||
path: path)
|
||||
end
|
||||
|
||||
{ path: path, hash: Digest::MD5.file(path).hexdigest }
|
||||
end
|
||||
|
||||
def update_resolved_file(new_secrets)
|
||||
|
||||
@@ -32,7 +32,6 @@ module Zanzibar
|
||||
else
|
||||
scrt.get_fieldlabel_value(scrt_id, @zanzibar_options[:fieldlabel])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def construct_options
|
||||
@@ -55,7 +54,7 @@ module Zanzibar
|
||||
|
||||
def ensure_options
|
||||
return if @zanzibar_options[:wsdl]
|
||||
fail Error, NO_WSDL_ERROR
|
||||
raise Error, NO_WSDL_ERROR
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Zanzibar
|
||||
|
||||
def check_for_zanzifile
|
||||
return unless File.exist?(ZANZIFILE_NAME) && !options['force']
|
||||
fail Error, ALREADY_EXISTS_ERROR
|
||||
raise Error, ALREADY_EXISTS_ERROR
|
||||
end
|
||||
|
||||
def write_template
|
||||
|
||||
@@ -52,12 +52,12 @@ module Zanzibar
|
||||
run_action { bundle! }
|
||||
end
|
||||
|
||||
desc 'plunder', "Alias to `#{APPLICATION_NAME} bundle`", :hide => true
|
||||
desc 'plunder', "Alias to `#{APPLICATION_NAME} bundle`", hide: true
|
||||
option 'verbose', type: :boolean, default: false, aliases: :v
|
||||
alias_method :plunder, :bundle
|
||||
alias plunder bundle
|
||||
|
||||
desc 'install', "Alias to `#{APPLICATION_NAME} bundle`"
|
||||
alias_method :install, :bundle
|
||||
alias install bundle
|
||||
|
||||
desc 'update', "Redownload all secrets in your #{ZANZIFILE_NAME}"
|
||||
option 'verbose', type: :boolean, default: false, aliases: :v
|
||||
|
||||
@@ -3,14 +3,14 @@ require 'pathname'
|
||||
# Definitions for various strings used throughout the gem
|
||||
module Zanzibar
|
||||
APPLICATION_NAME = Pathname.new($PROGRAM_NAME).basename
|
||||
ZANZIFILE_NAME = 'Zanzifile'
|
||||
RESOLVED_NAME = 'Zanzifile.resolved'
|
||||
TEMPLATE_NAME = 'templates/Zanzifile.erb'
|
||||
DEFAULT_SERVER = 'secret.example.com'
|
||||
DEFAULT_WSDL = 'https://%s/webservices/sswebservice.asmx?wsdl'
|
||||
ZANZIFILE_NAME = 'Zanzifile'.freeze
|
||||
RESOLVED_NAME = 'Zanzifile.resolved'.freeze
|
||||
TEMPLATE_NAME = 'templates/Zanzifile.erb'.freeze
|
||||
DEFAULT_SERVER = 'secret.example.com'.freeze
|
||||
DEFAULT_WSDL = 'https://%s/webservices/sswebservice.asmx?wsdl'.freeze
|
||||
|
||||
ALREADY_EXISTS_ERROR = "#{ZANZIFILE_NAME} already exists! Aborting..."
|
||||
NO_WSDL_ERROR = 'Could not construct WSDL URL. Please provide either --server or --wsdl'
|
||||
NO_ZANZIFILE_ERROR = "You don't have a #{ZANZIFILE_NAME}! Run `#{APPLICATION_NAME} init` first!"
|
||||
INVALID_ZANZIFILE_ERROR = "Unable to load your #{ZANZIFILE_NAME}. Please ensure it is valid YAML."
|
||||
ALREADY_EXISTS_ERROR = "#{ZANZIFILE_NAME} already exists! Aborting...".freeze
|
||||
NO_WSDL_ERROR = 'Could not construct WSDL URL. Please provide either --server or --wsdl'.freeze
|
||||
NO_ZANZIFILE_ERROR = "You don't have a #{ZANZIFILE_NAME}! Run `#{APPLICATION_NAME} init` first!".freeze
|
||||
INVALID_ZANZIFILE_ERROR = "Unable to load your #{ZANZIFILE_NAME}. Please ensure it is valid YAML.".freeze
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# The version of the gem
|
||||
module Zanzibar
|
||||
VERSION = '0.1.27'
|
||||
VERSION = '0.2.0'.freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user