27 Commits

Author SHA1 Message Date
Norm MacLennan
a98319aebe version 2016-04-15 07:01:46 -04:00
Norm MacLennan
7c154f5bc8 Merge pull request #20 from Cimpress-MCP/get_fieldlabel_value
Get fieldlabel value
2016-04-14 13:46:32 -04:00
Calvin Leung Huang
9fc219d98a Remove extra newline 2016-04-14 13:37:38 -04:00
Calvin Leung Huang
561a523261 Set and use fieldlabel value in zanzibar_options instead 2016-04-14 13:29:43 -04:00
Calvin Leung Huang
ca55a4de57 Set fieldlabel default to Password 2016-04-14 11:30:55 -04:00
Calvin Leung Huang
0da43c9fd3 Uncomment spec test 2016-04-13 14:59:05 -04:00
Calvin Leung Huang
ddb2931f6c Fix case on download_secret_file 2016-04-13 14:55:43 -04:00
Calvin Leung Huang
7cec3f7461 Add spec test 2016-04-13 14:51:43 -04:00
Calvin Leung Huang
7f357ef60d Add get_fieldlabel_value 2016-04-13 14:38:21 -04:00
Norm MacLennan
64d2b7101a version bump 2015-12-02 08:49:05 -05:00
Norm MacLennan
01a1be8084 Merge pull request #18 from ballou88/bump-savon-for-rails-compat
Bumped savon gem version to fix depencency issue with rails 4.2+
2015-12-02 08:48:37 -05:00
Mike Ballou
378dd0e39d Bumped savon gem version to fix depencency issue with rails 4.2+ 2015-12-01 10:45:03 -08:00
Norm MacLennan
20c5d0e34d bump version 2015-11-20 08:55:43 -05:00
Norm MacLennan
b7558d64f5 Merge pull request #17 from ballou88/fix-for-broken-prompt-for-password
Fix for prompt_for_password
2015-11-20 08:54:56 -05:00
Mike Ballou
293abdacde this is a fix for commit 813b171d26 which
broke the prompt_for_password method and resulted a nil password.
2015-11-19 10:55:42 -08:00
Jason Davis-Cooke
804d044632 Merge pull request #16 from Cimpress-MCP/print-feedback
Print response to indicate when cli is no longer interactive
2015-10-12 08:48:30 -04:00
Theodore X. Pak
813b171d26 Print response to indicate when cli is no longer interactive 2015-10-07 16:04:56 -04:00
Norm MacLennan
7a0ce1c04d Build and test on more rubies
Build and test on 1.9.x, 2.0.x, 2.1.x, 2.2.x. I'd be comfortable-ish dropping 1.9.x and 2.0.x, but it's low effort/high value to just keep them there.

Also, build on containers for speed.
2015-09-18 12:42:39 -04:00
Norm MacLennan
49ea9ab9fa version bump 2015-07-28 10:22:00 -04:00
Norm MacLennan
60e0d52ab4 Merge pull request #12 from thedillonb/patch-1
Update get.rb to remove 'puts'
2015-07-28 10:21:34 -04:00
Dillon Buchanan
e3ec56210b Update get.rb to remove 'puts'
Remove the 'puts' dump of the options as it makes piping the output more difficult. Maybe better to add a verbosity flag and debug prints?
2015-07-28 08:55:54 -04:00
Jason Davis-Cooke
315d3d6499 don't write gitignore if one exists already 2015-06-29 08:50:13 -04:00
Calvin Leung Huang
0763265be1 Update README.md 2015-06-05 11:19:08 -04:00
Jason Davis-Cooke
8126deded5 Version bump 2015-06-05 10:00:37 -04:00
Jason Davis-Cooke
60545c5b7b Merge pull request #10 from Cimpress-MCP/feature/prefix_dir
Feature/prefix dir
2015-06-05 09:59:28 -04:00
Calvin Leung Huang
8b06192aa1 Update test 2015-06-04 14:55:00 -04:00
Calvin Leung Huang
244b9178b8 Add optional prefix option 2015-06-04 13:05:22 -04:00
11 changed files with 69 additions and 27 deletions

View File

@@ -1,7 +1,10 @@
sudo: false
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.7
- 2.2.3
addons:
code_climate:
repo_token:

View File

@@ -98,6 +98,8 @@ When it downloads a file, it gets added to `Zanzifile.resolved`. And next time
`resolved` file, it will not attempt to re-download. `zanzibar update` will attempt
to re-download all secrets.
Subdirectories under the root directory `secret_dir` can be created for individual keys by specifying a `prefix` path for that secret. Secrets will default to be downloaded to the root `secret_dir` directory otherwise.
Note: `zanzibar get` can fetch passwords or files, but `zanzibar bundle` can
only operate on secret files.
@@ -114,6 +116,7 @@ secrets:
ssh_key:
id: 249
label: Private Key
prefix: ssh/
encryption_key:
id: 483
label: Attachment

View File

@@ -66,7 +66,9 @@ module Zanzibar
def prompt_for_password
puts "Please enter password for #{@@username}:"
STDIN.noecho(&:gets).chomp
STDIN.noecho(&:gets).chomp.tap do
puts "Using password to login..."
end
end
## Gets the wsdl document location if none is provided in the constructor
@@ -111,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.

View File

@@ -47,9 +47,11 @@ 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'])
File.open("#{@settings['secret_dir']}/.gitignore", 'w') do |file|
file.puts '*'
file.puts '!.gitignore'
if !File.exist? "#{@settings['secret_dir']}/.gitignore"
File.open("#{@settings['secret_dir']}/.gitignore", 'w') do |file|
file.puts '*'
file.puts '!.gitignore'
end
end
end
end
@@ -92,9 +94,10 @@ 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']
downloaded_secrets[key] = download_one_secret(secret['id'],
secret['label'],
@settings['secret_dir'],
full_path,
args,
secret['name'] || "#{secret['id']}_password")

View File

@@ -20,20 +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)
puts @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
@@ -42,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

View File

@@ -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)

View File

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

View File

@@ -4,8 +4,11 @@ settings:
domain: zanzitest.net
secret_dir: secrets/
ignore_ssl: true
secrets:
secrets:
ssh_key:
id: 2345
label: Private Key
prefix_ssh_key:
id: 2345
label: Private Key
prefix: ssh/

View File

@@ -24,9 +24,12 @@ describe Zanzibar::Cli do
FakeFS::FileSystem.clone files
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return(body: AUTH_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: AUTH_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: AUTH_XML, status: 200}).then
.to_return({body: SECRET_WITH_KEY_XML, status: 200}).then
.to_return({body: PRIVATE_KEY_XML, status: 200})
Dir.chdir File.join(source_root, 'spec', 'files')
end
@@ -50,6 +53,12 @@ describe Zanzibar::Cli do
expect(FakeFS::FileTest.file? File.join('secrets', 'zanzi_key')).to be(true)
end
it 'should download a file to a prefix' do
expect(FakeFS::FileTest.file? File.join('secrets/ssh', 'zanzi_key')).to be(false)
expect { subject.bundle }.to output(/Finished downloading secrets/).to_stdout
expect(FakeFS::FileTest.file? File.join('secrets/ssh', 'zanzi_key')).to be(true)
end
it 'should create a .gitignore' do
expect(FakeFS::FileTest.file? File.join('secrets', '.gitignore')).to be(false)
expect { subject.bundle }.to output(/Finished downloading secrets/).to_stdout
@@ -64,7 +73,7 @@ describe Zanzibar::Cli do
it 'should not redownload files it already has' do
expect { subject.bundle }.to output(/Finished downloading secrets/).to_stdout
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(3)
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(6)
WebMock.reset!
@@ -74,16 +83,19 @@ describe Zanzibar::Cli do
it 'should redownload on update action' do
expect { subject.bundle }.to output(/Finished downloading secrets/).to_stdout
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(3)
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(6)
WebMock.reset!
stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
.to_return({body: AUTH_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: AUTH_XML, status: 200).then
.to_return(body: SECRET_WITH_KEY_XML, status: 200).then
.to_return(body: PRIVATE_KEY_XML, status: 200)
expect { subject.update }.to output(/Finished downloading secrets/).to_stdout
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(3)
expect(WebMock).to have_requested(:post, 'https://www.zanzitest.net/webservices/sswebservice.asmx').times(6)
end
it 'should reject a malformed Zanzifile' do

View File

@@ -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')

View File

@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'fakefs', '~> 0.6.4'
spec.add_development_dependency 'simplecov', '~> 0.9.1'
spec.add_runtime_dependency 'savon', '~> 2.8.0'
spec.add_runtime_dependency 'savon', '~> 2.10.0'
spec.add_runtime_dependency 'rubyntlm', '~> 0.4.0'
spec.add_runtime_dependency 'thor', '~> 0.19.0'
end