Dependency updates and rubocop fixes

This commit is contained in:
Norm MacLennan
2016-04-15 08:16:40 -04:00
parent fe6a319b43
commit 7433099409
14 changed files with 129 additions and 76 deletions

20
.codeclimate.yml Normal file
View File

@@ -0,0 +1,20 @@
---
engines:
bundler-audit:
enabled: true
duplication:
enabled: true
config:
languages:
- ruby
fixme:
enabled: true
rubocop:
enabled: true
ratings:
paths:
- Gemfile.lock
- "**.rb"
exclude_paths:
- spec/
- templates/

View File

@@ -3,3 +3,7 @@ Metrics/ClassLength:
Metrics/LineLength: Metrics/LineLength:
Max: 175 Max: 175
AllCops:
Exclude:
- 'spec/**/*'

20
CHANGELOG.md Normal file
View File

@@ -0,0 +1,20 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Changed
- Upgraded dependencies
- `rubyntlm`: ~>0.4.0 to ~>0.6.0
- `savon`: ~>2.10.0 to ~>2.11.0
- `rubocop`: ~>0.28.0 to ~>0.39.0
- Lots of rubocop-y code cleanup
- Converted from code climate classic to code climate platform
- Added rake task to run code climate platform locally
## [0.1.27] - 2016-04-15
### Added
- `zanzibar get` can fetch field values for fields other than password
- This ability has not been added to Zanzifiles yet.
[Unreleased]: https://github.com/Cimpress-MCP/Zanzibar/compare/v0.1.27...HEAD

View File

@@ -7,5 +7,15 @@ require 'rubocop/rake_task'
task default: [:test] task default: [:test]
RSpec::Core::RakeTask.new(:test) RSpec::Core::RakeTask.new(:test)
RuboCop::RakeTask.new RuboCop::RakeTask.new
task :cc_local do
command = 'docker run '
command << '--interactive --tty --rm '
command << '--env CODECLIMATE_CODE="$PWD" '
command << '--volume "$PWD":/code '
command << '--volume /var/run/docker.sock:/var/run/docker.sock '
command << '--volume /tmp/cc:/tmp/cc '
command << 'codeclimate/codeclimate analyze'
sh command
end

View File

@@ -12,33 +12,33 @@ module Zanzibar
# @param args{:domain, :wsdl, :pwd, :username, :globals{}} # @param args{:domain, :wsdl, :pwd, :username, :globals{}}
def initialize(args = {}) def initialize(args = {})
if args[:username] @@username = if args[:username]
@@username = args[:username] args[:username]
elsif ENV['ZANZIBAR_USER'] elsif ENV['ZANZIBAR_USER']
@@username = ENV['ZANZIBAR_USER'] ENV['ZANZIBAR_USER']
else else
@@username = ENV['USER'] ENV['USER']
end end
if args[:wsdl] @@wsdl = if args[:wsdl]
@@wsdl = args[:wsdl] args[:wsdl]
else else
@@wsdl = get_wsdl_location get_wsdl_location
end end
if args[:pwd] @@password = if args[:pwd]
@@password = args[:pwd] args[:pwd]
elsif ENV['ZANZIBAR_PASSWORD'] elsif ENV['ZANZIBAR_PASSWORD']
@@password = ENV['ZANZIBAR_PASSWORD'] ENV['ZANZIBAR_PASSWORD']
else else
@@password = prompt_for_password prompt_for_password
end end
if args[:domain] @@domain = if args[:domain]
@@domain = args[:domain] args[:domain]
else else
@@domain = prompt_for_domain prompt_for_domain
end end
args[:globals] = {} unless args[:globals] args[:globals] = {} unless args[:globals]
init_client(args[:globals]) init_client(args[:globals])
end end
@@ -67,7 +67,7 @@ module Zanzibar
def prompt_for_password def prompt_for_password
puts "Please enter password for #{@@username}:" puts "Please enter password for #{@@username}:"
STDIN.noecho(&:gets).chomp.tap do STDIN.noecho(&:gets).chomp.tap do
puts "Using password to login..." puts 'Using password to login...'
end end
end end
@@ -93,8 +93,8 @@ module Zanzibar
def get_token def get_token
response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: '', domain: @@domain }) response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: '', domain: @@domain })
.hash[:envelope][:body][:authenticate_response][:authenticate_result] .hash[:envelope][:body][:authenticate_response][:authenticate_result]
fail "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors] raise "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
response[:token] response[:token]
rescue Savon::Error => err rescue Savon::Error => err
raise "There was an error generating the authentiaton token for user #{@@username}: #{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) 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] 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 return secret
rescue Savon::Error => err rescue Savon::Error => err
raise "There was an error getting the secret with id #{scrt_id}: #{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 # @param [Integer] the secret id
# @return [String] the password for the given secret # @return [String] the password for the given secret
def get_password(scrt_id) def get_password(scrt_id)
return get_fieldlabel_value(scrt_id) get_fieldlabel_value(scrt_id)
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.
@@ -140,7 +140,7 @@ module Zanzibar
password = get_secret_item_by_field_name(secret_items, 'Password')[:value] password = get_secret_item_by_field_name(secret_items, 'Password')[:value]
username = get_secret_item_by_field_name(secret_items, 'Username')[:value] username = get_secret_item_by_field_name(secret_items, 'Username')[:value]
save_username_and_password_to_file(password, username, path, name) save_username_and_password_to_file(password, username, path, name)
return File.join(path, name) File.join(path, name)
end end
def write_secret_to_file(path, secret_response) 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 ## Write the password to a file. Intended for use with a Zanzifile
def save_username_and_password_to_file(password, username, 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 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 user_pass file.print user_pass
end end
@@ -190,8 +190,8 @@ module Zanzibar
begin begin
response = @@client.call(:download_file_attachment_by_item_id, message: 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) }) { 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] .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] 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) write_secret_to_file(path, response)
return File.join(path, response[:file_name]) return File.join(path, response[:file_name])
rescue Savon::Error => err rescue Savon::Error => err

View File

@@ -39,7 +39,7 @@ module Zanzibar
end end
def ensure_zanzifile 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..." } debug { "#{ZANZIFILE_NAME} located..." }
end end
@@ -47,7 +47,7 @@ module Zanzibar
## Make sure the directory exists and that a .gitignore is there to ignore it ## Make sure the directory exists and that a .gitignore is there to ignore it
if @settings['secret_dir'] if @settings['secret_dir']
FileUtils.mkdir_p(@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.open("#{@settings['secret_dir']}/.gitignore", 'w') do |file|
file.puts '*' file.puts '*'
file.puts '!.gitignore' file.puts '!.gitignore'
@@ -69,7 +69,7 @@ module Zanzibar
def validate_environment def validate_environment
return unless @settings.empty? || @remote_secrets.empty? return unless @settings.empty? || @remote_secrets.empty?
fail Error, INVALID_ZANZIFILE_ERROR raise Error, INVALID_ZANZIFILE_ERROR
end end
def load_resolved_secrets def load_resolved_secrets
@@ -94,7 +94,7 @@ module Zanzibar
downloaded_secrets = {} downloaded_secrets = {}
remote_secrets.each do |key, secret| 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'], downloaded_secrets[key] = download_one_secret(secret['id'],
secret['label'], secret['label'],
full_path, full_path,
@@ -110,13 +110,13 @@ 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_username_and_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 }
else else
path = zanzibar(args).download_secret_file(scrt_id: scrt_id, path = zanzibar(args).download_secret_file(scrt_id: scrt_id,
type: label, type: label,
path: path) path: path)
{ path: path, hash: Digest::MD5.file(path).hexdigest }
end end
{ path: path, hash: Digest::MD5.file(path).hexdigest }
end end
def update_resolved_file(new_secrets) def update_resolved_file(new_secrets)

View File

@@ -32,7 +32,6 @@ module Zanzibar
else else
scrt.get_fieldlabel_value(scrt_id, @zanzibar_options[:fieldlabel]) scrt.get_fieldlabel_value(scrt_id, @zanzibar_options[:fieldlabel])
end end
end end
def construct_options def construct_options
@@ -55,7 +54,7 @@ module Zanzibar
def ensure_options def ensure_options
return if @zanzibar_options[:wsdl] return if @zanzibar_options[:wsdl]
fail Error, NO_WSDL_ERROR raise Error, NO_WSDL_ERROR
end end
end end
end end

View File

@@ -17,7 +17,7 @@ module Zanzibar
def check_for_zanzifile def check_for_zanzifile
return unless File.exist?(ZANZIFILE_NAME) && !options['force'] return unless File.exist?(ZANZIFILE_NAME) && !options['force']
fail Error, ALREADY_EXISTS_ERROR raise Error, ALREADY_EXISTS_ERROR
end end
def write_template def write_template

View File

@@ -52,12 +52,12 @@ module Zanzibar
run_action { bundle! } run_action { bundle! }
end 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 option 'verbose', type: :boolean, default: false, aliases: :v
alias_method :plunder, :bundle alias plunder bundle
desc 'install', "Alias to `#{APPLICATION_NAME} bundle`" desc 'install', "Alias to `#{APPLICATION_NAME} bundle`"
alias_method :install, :bundle alias install bundle
desc 'update', "Redownload all secrets in your #{ZANZIFILE_NAME}" desc 'update', "Redownload all secrets in your #{ZANZIFILE_NAME}"
option 'verbose', type: :boolean, default: false, aliases: :v option 'verbose', type: :boolean, default: false, aliases: :v

View File

@@ -3,14 +3,14 @@ require 'pathname'
# Definitions for various strings used throughout the gem # Definitions for various strings used throughout the gem
module Zanzibar module Zanzibar
APPLICATION_NAME = Pathname.new($PROGRAM_NAME).basename APPLICATION_NAME = Pathname.new($PROGRAM_NAME).basename
ZANZIFILE_NAME = 'Zanzifile' ZANZIFILE_NAME = 'Zanzifile'.freeze
RESOLVED_NAME = 'Zanzifile.resolved' RESOLVED_NAME = 'Zanzifile.resolved'.freeze
TEMPLATE_NAME = 'templates/Zanzifile.erb' TEMPLATE_NAME = 'templates/Zanzifile.erb'.freeze
DEFAULT_SERVER = 'secret.example.com' DEFAULT_SERVER = 'secret.example.com'.freeze
DEFAULT_WSDL = 'https://%s/webservices/sswebservice.asmx?wsdl' DEFAULT_WSDL = 'https://%s/webservices/sswebservice.asmx?wsdl'.freeze
ALREADY_EXISTS_ERROR = "#{ZANZIFILE_NAME} already exists! Aborting..." ALREADY_EXISTS_ERROR = "#{ZANZIFILE_NAME} already exists! Aborting...".freeze
NO_WSDL_ERROR = 'Could not construct WSDL URL. Please provide either --server or --wsdl' 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!" 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." INVALID_ZANZIFILE_ERROR = "Unable to load your #{ZANZIFILE_NAME}. Please ensure it is valid YAML.".freeze
end end

View File

@@ -1,4 +1,4 @@
# The version of the gem # The version of the gem
module Zanzibar module Zanzibar
VERSION = '0.1.27' VERSION = '0.2.0'.freeze
end end

View File

@@ -24,12 +24,12 @@ describe Zanzibar::Cli do
FakeFS::FileSystem.clone files FakeFS::FileSystem.clone files
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_WITH_KEY_XML, status: 200}).then .to_return(body: SECRET_WITH_KEY_XML, status: 200).then
.to_return({body: PRIVATE_KEY_XML, status: 200}).then .to_return(body: PRIVATE_KEY_XML, status: 200).then
.to_return({body: AUTH_XML, status: 200}).then .to_return(body: AUTH_XML, status: 200).then
.to_return({body: SECRET_WITH_KEY_XML, status: 200}).then .to_return(body: SECRET_WITH_KEY_XML, status: 200).then
.to_return({body: PRIVATE_KEY_XML, status: 200}) .to_return(body: PRIVATE_KEY_XML, status: 200)
Dir.chdir File.join(source_root, 'spec', 'files') Dir.chdir File.join(source_root, 'spec', 'files')
end end
@@ -87,9 +87,9 @@ describe Zanzibar::Cli do
WebMock.reset! WebMock.reset!
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_WITH_KEY_XML, status: 200}).then .to_return(body: SECRET_WITH_KEY_XML, status: 200).then
.to_return({body: PRIVATE_KEY_XML, status: 200}).then .to_return(body: PRIVATE_KEY_XML, status: 200).then
.to_return(body: AUTH_XML, status: 200).then .to_return(body: AUTH_XML, status: 200).then
.to_return(body: SECRET_WITH_KEY_XML, status: 200).then .to_return(body: SECRET_WITH_KEY_XML, status: 200).then
.to_return(body: PRIVATE_KEY_XML, status: 200) .to_return(body: PRIVATE_KEY_XML, status: 200)

View File

@@ -109,10 +109,10 @@ describe 'Zanzibar Test' do
.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_username_and_password_and_save(1234, '.', 'zanziTestCreds') client.get_username_and_password_and_save(1234, '.', 'zanziTestCreds')
expect(File.exist? 'zanziTestCreds') expect(File.exist? 'zanziTestCreds')
expect(File.read('zanziTestCreds')).to eq({'username' => 'ZanziUser', 'password' => 'zanziUserPassword'}.to_yaml) expect(File.read('zanziTestCreds')).to eq({ 'username' => 'ZanziUser', 'password' => 'zanziUserPassword' }.to_yaml)
File.delete('zanziTestCreds') File.delete('zanziTestCreds')
end end
it 'should use environment variables for credentials' do it 'should use environment variables for credentials' do

View File

@@ -14,13 +14,13 @@ Gem::Specification.new do |spec|
spec.license = 'Apache 2.0' spec.license = 'Apache 2.0'
spec.files = `git ls-files -z`.split("\x0") spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)\//) spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
spec.require_paths = ['lib'] spec.require_paths = ['lib']
spec.add_development_dependency 'bundler', '~> 1.7' spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop', '~> 0.28.0' spec.add_development_dependency 'rubocop', '~> 0.39.0'
spec.add_development_dependency 'savon_spec', '~> 0.1.6' spec.add_development_dependency 'savon_spec', '~> 0.1.6'
spec.add_development_dependency 'rspec', '~> 3.1.0' spec.add_development_dependency 'rspec', '~> 3.1.0'
spec.add_development_dependency 'webmock', '~> 1.20.4' spec.add_development_dependency 'webmock', '~> 1.20.4'
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'fakefs', '~> 0.6.4' spec.add_development_dependency 'fakefs', '~> 0.6.4'
spec.add_development_dependency 'simplecov', '~> 0.9.1' spec.add_development_dependency 'simplecov', '~> 0.9.1'
spec.add_runtime_dependency 'savon', '~> 2.10.0' spec.add_runtime_dependency 'savon', '~> 2.11.0'
spec.add_runtime_dependency 'rubyntlm', '~> 0.4.0' spec.add_runtime_dependency 'rubyntlm', '~> 0.6.0'
spec.add_runtime_dependency 'thor', '~> 0.19.0' spec.add_runtime_dependency 'thor', '~> 0.19.0'
end end