zanzibar 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2NmMTgxMGFhODNjYWQ4MWNmNjY3MWFjZWZiMGYyZjIzMzgwYzc1Yw==
4
+ MjRjNDk1YTE4MDIxYWNlNDljZGYzN2YyYWNhMzQ1ZTgwZTE2YjkzNg==
5
5
  data.tar.gz: !binary |-
6
- ZDZhYThhNTk3MTk4MTc1MzJjYjlhMDQzMzI1YmI1Yjc3MTZlNDJkZg==
6
+ ZTI3YjhhNzNiMmZiZTkzMTI3MmRlZTYxYjBlZTVkZDVjODZmZmQwZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2Y3NDM5M2E3MDM3NTZkOGE4OWQ0YTZkZThhNmMxNjcxNzU3MjcwNTEzYzAw
10
- MWNlNGY3MTdmODdjZGIxY2VjMzliM2JlYzJlYTZjMzQ1YTBmYTkxYzZjYmNi
11
- ZDIzNzIzZGEwNWQwMDczMjVjY2JkOTE1Nzk5N2RmM2MzODIxNDE=
9
+ YjZmMWMwNTgyMGI0NzllNGY3MzhmMTA5YzllOTU4NTliMDFhNWVlYTk5Nzlm
10
+ MjViYWI2MDY5YTMzNzA5OTEzZGZlNDI1MmRkZjE3MDY1M2I4NGFkMjU1YmZm
11
+ MjdiMzBhYzJjZTE0YzYxZDQwYmRmNjI5ZjcwMzIzYTM3MzViYzc=
12
12
  data.tar.gz: !binary |-
13
- ZGFkNDI2NDNlMjBiZDI4ZjYzNDdlMzZkMmE4ZGI1NDc4MTk0ZjRmODMyZWU5
14
- NDdhOTg4NjA3YTNiMDg1MDhlYjRhMWVkODI3NzM1NTc4MmQ0MGMyNDM4OGJk
15
- YjA3YzVmODI5YzkxZDU0NzMyYzM5MDQ2NTcxNTg1YmVlY2FlZTk=
13
+ Y2RkYTQ4NjQ3ZTBlZjEzZTY4NjU1ZDNkNTJjZjMyYTQzNDFlZDBlNmNmZjlm
14
+ MDA3ZjVmOWE5Njg0MjIzZDdjNWI1OTc0NzNiMjllNTNkZDg1ZGUzNGI5MDE0
15
+ NTdhNTJmMDIyYTUwOGJiODU0NGI3ZjM1NjZiNWFkYTFmYjc1NmU=
data/Gemfile CHANGED
@@ -7,8 +7,9 @@ group :test do
7
7
  gem 'savon_spec'
8
8
  gem 'rspec'
9
9
  gem 'webmock'
10
- gem "codeclimate-test-reporter"
10
+ gem 'codeclimate-test-reporter'
11
11
  gem 'zanzibar', path: '.'
12
+ gem 'rubocop'
12
13
  end
13
14
 
14
15
  # Specify your gem's dependencies in zanzibar.gemspec
data/README.md CHANGED
@@ -38,29 +38,29 @@ secrets = Zanzibar::Zanzibar.new(:domain => 'mydomain.net', :wsdl => "https://my
38
38
  # Zanzibar::Zanzibar.new(:domain => 'mydomain.net', :wsdl => "https://my.scrt.server/webservices/sswebservice.asmx?wsdl", :globals => {:ssl_verify_mode => :none})
39
39
 
40
40
  ## Simple password -> takes secret id as argument
41
- secrets.get_secret(1234)
41
+ secrets.get_password(1234)
42
42
 
43
- ## Private Key -> takes hash as argument, requires :scrt_id, optional :scrt_item_id, :path
44
- secrets.download_private_key(:scrt_id => 2345, :path => 'secrets/')
43
+ ## Private Key -> takes hash as argument, requires :scrt_id, :type, optional :scrt_item_id, :path
44
+ secrets.download_secret_file(:scrt_id => 2345, :path => 'secrets/', :type => "Private Key")
45
45
 
46
- ## Public Key -> takes hash as argument, requires :scrt_id, optional :scrt_item_id, :path
47
- secrets.download_public_key(:scrt_id => 2345, :path => 'secrets/')
46
+ ## Public Key -> takes hash as argument, requires :scrt_id, :type, optional :scrt_item_id, :path
47
+ secrets.download_secret_file(:scrt_id => 2345, :path => 'secrets/', :type => "Public Key")
48
48
 
49
- ## Attachment; only supports secrets with single attachment -> takes hash as argument, requires :scrt_id, optional :scrt_item_id, :path
50
- secrets.download_attachment(:scrt_id => 3456, :path => 'secrets/')
49
+ ## Attachment; only supports secrets with single attachment -> takes hash as argument, requires :scrt_id, :path, optional :scrt_item_id, :path
50
+ secrets.download_secret_file(:scrt_id => 2345, :path => 'secrets/', :type => "Attachment")
51
51
 
52
52
  ```
53
53
 
54
54
  ### Command Line
55
55
 
56
- Zanzibar comes bundled with the [`zamioculcas`](http://en.wikipedia.org/wiki/Zamioculcas) command-line utility that can be used for fetching passwords and downloading keys from outside of Ruby.
56
+ Zanzibar comes bundled with the `zanzibar` command-line utility that can be used for fetching passwords and downloading keys from outside of Ruby.
57
57
 
58
- `Zamioculcas` supports most actions provided by Zanzibar itself. Because it operates on the command-line, it can be used as part of a pipeline or within a bash script.
58
+ `zanzibar` supports most actions provided by Zanzibar itself. Because it operates on the command-line, it can be used as part of a pipeline or within a bash script.
59
59
 
60
60
  ```bash
61
61
  # if you don't pipe in a password, you will be prompted to enter one.
62
62
  # this will download the private key from secret 1984 to the current directory
63
- cat ./local-password | zamioculcas 1984 -s server.example.com -d example.com -t privatekey
63
+ cat ./local-password | zanzibar 1984 -s server.example.com -d example.com -t privatekey
64
64
 
65
65
  ssh user@someremote -i ./private_key
66
66
  ```
data/Rakefile CHANGED
@@ -1,8 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "bundler/setup" # load up our gem environment (incl. local zanzibar)
3
- require 'rspec/core/rake_task'
4
- require 'zanzibar/version'
5
-
6
- task :default => [:test]
7
-
8
- RSpec::Core::RakeTask.new(:test)
1
+ require 'bundler/gem_tasks'
2
+ require 'bundler/setup' # load up our gem environment (incl. local zanzibar)
3
+ require 'rspec/core/rake_task'
4
+ require 'zanzibar/version'
5
+ require 'rubocop/rake_task'
6
+
7
+ task default: [:test]
8
+
9
+ RSpec::Core::RakeTask.new(:test)
10
+
11
+ RuboCop::RakeTask.new
data/bin/zamioculcas CHANGED
@@ -1,70 +1,2 @@
1
1
  #! ruby
2
-
3
- require 'zanzibar'
4
- require 'optparse'
5
-
6
- options = {
7
- :domain => 'local'
8
- }
9
-
10
- OptionParser.new do |opts|
11
- opts.banner = "Usage: zamioculcas -d domain [-w wsdl] [-k] [-p] [secret_id]"
12
-
13
- opts.on("-d", "--domain DOMAIN", "Specify domain") do |v|
14
- options[:domain] = v
15
- end
16
-
17
- opts.on("-w", "--wsdl WSDL", "Specify WSDL location") do |v|
18
- options[:wsdl] = v
19
- end
20
-
21
- opts.on("-s", "--server SERVER", "Secret server hostname or IP") do |v|
22
- options[:server] = v
23
- end
24
-
25
- opts.on("-k", "--no-check-certificate", "Don't run SSL certificate checks") do |v|
26
- options[:globals] = {:ssl_verify_mode => :none}
27
- end
28
-
29
- opts.on("-p", "--password PASSWORD", "Specify password") do |v|
30
- options[:pwd] = v
31
- end
32
-
33
- opts.on("-t", "--type TYPE", "Specify the type of secret") do |v|
34
- options[:type] = v
35
- end
36
-
37
- opts.on("-u", "--user USER", "Specify the username") do |v|
38
- options[:username] = v
39
- end
40
-
41
- end.parse!
42
-
43
- raise OptionParser::MissingArgument if options[:server].nil?
44
- options[:type] = "password" if options[:type].nil?
45
-
46
- unless STDIN.tty? || options[:pwd]
47
- options[:pwd] = $stdin.read.strip
48
- end
49
-
50
- secret_id = Integer(ARGV.pop)
51
- if(!secret_id)
52
- fail "no secret!"
53
- end
54
-
55
- unless options[:wsdl] || options[:server].nil?
56
- options[:wsdl] = "https://#{options[:server]}/webservices/sswebservice.asmx?wsdl"
57
- end
58
-
59
- scrt = Zanzibar::Zanzibar.new(options)
60
-
61
- case options[:type]
62
- when "password"
63
- $stdout.write "#{scrt.get_password(secret_id)}\n"
64
- when "privatekey"
65
- scrt.download_private_key(:scrt_id=>secret_id)
66
- when "publickey"
67
- scrt.download_public_key(:scrt_id=>secret_id)
68
- else
69
- $stderr.write "#{options[:type]} is not a known type."
70
- end
2
+ system("zanzibar #{ARGV.join(" ")}")
data/bin/zanzibar ADDED
@@ -0,0 +1,70 @@
1
+ #! ruby
2
+
3
+ require 'zanzibar'
4
+ require 'optparse'
5
+
6
+ options = {
7
+ :domain => 'local'
8
+ }
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: zamioculcas -d domain [-w wsdl] [-k] [-p] [secret_id]"
12
+
13
+ opts.on("-d", "--domain DOMAIN", "Specify domain") do |v|
14
+ options[:domain] = v
15
+ end
16
+
17
+ opts.on("-w", "--wsdl WSDL", "Specify WSDL location") do |v|
18
+ options[:wsdl] = v
19
+ end
20
+
21
+ opts.on("-s", "--server SERVER", "Secret server hostname or IP") do |v|
22
+ options[:server] = v
23
+ end
24
+
25
+ opts.on("-k", "--no-check-certificate", "Don't run SSL certificate checks") do |v|
26
+ options[:globals] = {:ssl_verify_mode => :none}
27
+ end
28
+
29
+ opts.on("-p", "--password PASSWORD", "Specify password") do |v|
30
+ options[:pwd] = v
31
+ end
32
+
33
+ opts.on("-t", "--type TYPE", "Specify the type of secret") do |v|
34
+ options[:type] = v
35
+ end
36
+
37
+ opts.on("-u", "--user USER", "Specify the username") do |v|
38
+ options[:username] = v
39
+ end
40
+
41
+ end.parse!
42
+
43
+ raise OptionParser::MissingArgument if options[:server].nil?
44
+ options[:type] = "password" if options[:type].nil?
45
+
46
+ unless STDIN.tty? || options[:pwd]
47
+ options[:pwd] = $stdin.read.strip
48
+ end
49
+
50
+ secret_id = Integer(ARGV.pop)
51
+ if(!secret_id)
52
+ fail "no secret!"
53
+ end
54
+
55
+ unless options[:wsdl] || options[:server].nil?
56
+ options[:wsdl] = "https://#{options[:server]}/webservices/sswebservice.asmx?wsdl"
57
+ end
58
+
59
+ scrt = Zanzibar::Zanzibar.new(options)
60
+
61
+ case options[:type]
62
+ when "password"
63
+ $stdout.write "#{scrt.get_password(secret_id)}\n"
64
+ when "privatekey"
65
+ scrt.download_private_key(:scrt_id=>secret_id)
66
+ when "publickey"
67
+ scrt.download_public_key(:scrt_id=>secret_id)
68
+ else
69
+ $stderr.write "#{options[:type]} is not a known type."
70
+ end
data/lib/zanzibar.rb CHANGED
@@ -1,19 +1,16 @@
1
- require "zanzibar/version"
1
+ require 'zanzibar/version'
2
2
  require 'savon'
3
3
  require 'io/console'
4
4
  require 'fileutils'
5
5
 
6
6
  module Zanzibar
7
-
8
7
  ##
9
8
  # Class for interacting with Secret Server
10
9
  class Zanzibar
11
-
12
10
  ##
13
11
  # @param args{:domain, :wsdl, :pwd, :username, :globals{}}
14
12
 
15
13
  def initialize(args = {})
16
-
17
14
  if args[:username]
18
15
  @@username = args[:username]
19
16
  else
@@ -26,7 +23,7 @@ module Zanzibar
26
23
  @@wsdl = get_wsdl_location
27
24
  end
28
25
  if args[:pwd]
29
- @@password = args[:pwd]
26
+ @@password = args[:pwd]
30
27
  else
31
28
  @@password = prompt_for_password
32
29
  end
@@ -43,7 +40,7 @@ module Zanzibar
43
40
  # @param globals{}, optional
44
41
 
45
42
  def init_client(globals = {})
46
- globals = {} if globals == nil
43
+ globals = {} if globals.nil?
47
44
  @@client = Savon.client(globals) do
48
45
  wsdl @@wsdl
49
46
  end
@@ -54,39 +51,36 @@ module Zanzibar
54
51
 
55
52
  def prompt_for_password
56
53
  puts "Please enter password for #{@@username}:"
57
- return STDIN.noecho(&:gets).chomp
54
+ STDIN.noecho(&:gets).chomp
58
55
  end
59
56
 
60
57
  ## Gets the wsdl document location if none is provided in the constructor
61
58
  # @return [String] the location of the WDSL document
62
59
 
63
60
  def prompt_for_wsdl_location
64
- puts "Enter the URL of the Secret Server WSDL:"
65
- return STDIN.gets.chomp
61
+ puts 'Enter the URL of the Secret Server WSDL:'
62
+ STDIN.gets.chomp
66
63
  end
67
64
 
68
65
  ## Gets the domain of the Secret Server installation if none is provided in the constructor
69
66
  # @return [String] the domain of the secret server installation
70
67
 
71
68
  def prompt_for_domain
72
- puts "Enter the domain of your Secret Server:"
73
- return STDIN.gets.chomp
69
+ puts 'Enter the domain of your Secret Server:'
70
+ STDIN.gets.chomp
74
71
  end
75
72
 
76
-
77
73
  ## Get an authentication token for interacting with Secret Server. These are only good for about 10 minutes so just get a new one each time.
78
74
  # Will raise an error if there is an issue with the authentication.
79
75
  # @return the authentication token for the current user.
80
76
 
81
77
  def get_token
82
- begin
83
- response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: "", domain: @@domain })
84
- .hash[:envelope][:body][:authenticate_response][:authenticate_result]
85
- raise "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
86
- response[:token]
87
- rescue Savon::Error => err
88
- raise "There was an error generating the authentiaton token for user #{@@username}: #{err}"
89
- end
78
+ response = @@client.call(:authenticate, message: { username: @@username, password: @@password, organization: '', domain: @@domain })
79
+ .hash[:envelope][:body][:authenticate_response][:authenticate_result]
80
+ fail "Error generating the authentication token for user #{@@username}: #{response[:errors][:string]}" if response[:errors]
81
+ response[:token]
82
+ rescue Savon::Error => err
83
+ raise "There was an error generating the authentiaton token for user #{@@username}: #{err}"
90
84
  end
91
85
 
92
86
  ## Get a secret returned as a hash
@@ -95,13 +89,11 @@ module Zanzibar
95
89
  # @return [Hash] the secret hash retrieved from the wsdl
96
90
 
97
91
  def get_secret(scrt_id, token = nil)
98
- begin
99
- secret = @@client.call(:get_secret, message: { token: token || get_token, secretId: scrt_id}).hash[:envelope][:body][:get_secret_response][:get_secret_result]
100
- raise "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors]
101
- return secret
102
- rescue Savon::Error => err
103
- raise "There was an error getting the secret with id #{scrt_id}: #{err}"
104
- end
92
+ secret = @@client.call(:get_secret, message: { token: token || get_token, secretId: scrt_id }).hash[:envelope][:body][:get_secret_response][:get_secret_result]
93
+ fail "There was an error getting secret #{scrt_id}: #{secret[:errors][:string]}" if secret[:errors]
94
+ return secret
95
+ rescue Savon::Error => err
96
+ raise "There was an error getting the secret with id #{scrt_id}: #{err}"
105
97
  end
106
98
 
107
99
  ## Retrieve a simple password from a secret
@@ -110,13 +102,11 @@ module Zanzibar
110
102
  # @return [String] the password for the given secret
111
103
 
112
104
  def get_password(scrt_id)
113
- begin
114
- secret = get_secret(scrt_id)
115
- secret_items = secret[:secret][:items][:secret_item]
116
- return get_secret_item_by_field_name(secret_items,"Password")[:value]
117
- rescue Savon::Error => err
118
- raise "There was an error getting the password for secret #{scrt_id}: #{err}"
119
- end
105
+ secret = get_secret(scrt_id)
106
+ secret_items = secret[:secret][:items][:secret_item]
107
+ return get_secret_item_by_field_name(secret_items, 'Password')[:value]
108
+ rescue Savon::Error => err
109
+ raise "There was an error getting the password for secret #{scrt_id}: #{err}"
120
110
  end
121
111
 
122
112
  def write_secret_to_file(path, secret_response)
@@ -151,23 +141,21 @@ module Zanzibar
151
141
  # Raise on error
152
142
  # @param [Hash] args, :scrt_id, :type (one of "Private Key", "Public Key", "Attachment"), :scrt_item_id - optional, :path - optional
153
143
 
154
-
155
144
  def download_secret_file(args = {})
156
145
  token = get_token
157
146
  FileUtils.mkdir_p(args[:path]) if args[:path]
158
147
  path = args[:path] ? args[:path] : '.' ## The File.join below doesn't handle nils well, so let's take that possibility away.
159
148
  begin
160
149
  response = @@client.call(:download_file_attachment_by_item_id, message:
161
- { token: token, secretId: args[:scrt_id], secretItemId: args[:scrt_item_id] || get_scrt_item_id(args[:scrt_id], args[:type], token)})
162
- .hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result]
163
- raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors]
150
+ { token: token, secretId: args[:scrt_id], secretItemId: args[:scrt_item_id] || get_scrt_item_id(args[:scrt_id], args[:type], token) })
151
+ .hash[:envelope][:body][:download_file_attachment_by_item_id_response][:download_file_attachment_by_item_id_result]
152
+ fail "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{response[:errors][:string]}" if response[:errors]
164
153
  write_secret_to_file(path, response)
165
154
  rescue Savon::Error => err
166
155
  raise "There was an error getting the #{args[:type]} for secret #{args[:scrt_id]}: #{err}"
167
156
  end
168
157
  end
169
158
 
170
-
171
159
  ## Methods to maintain backwards compatibility
172
160
  def download_private_key(args = {})
173
161
  args[:type] = 'Private Key'
@@ -183,6 +171,5 @@ module Zanzibar
183
171
  args[:type] = 'Attachment'
184
172
  download_secret_file(args)
185
173
  end
186
-
187
174
  end
188
175
  end
@@ -1,3 +1,3 @@
1
1
  module Zanzibar
2
- VERSION = "0.1.10"
2
+ VERSION = '0.1.11'
3
3
  end
@@ -1,97 +1,95 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
5
- #
6
- # Given that it is always loaded, you are encouraged to keep this file as
7
- # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test suite on EVERY test run, even for an
9
- # individual file that may not need all of that loaded. Instead, consider making
10
- # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
- #
13
- # The `.rspec` file also contains a few flags that are not defaults but that
14
- # users commonly want.
15
- #
16
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- require 'webmock/rspec'
18
- require "codeclimate-test-reporter"
19
- CodeClimate::TestReporter.start
20
-
21
- RSpec.configure do |config|
22
- # rspec-expectations config goes here. You can use an alternate
23
- # assertion/expectation library such as wrong or the stdlib/minitest
24
- # assertions if you prefer.
25
- config.expect_with :rspec do |expectations|
26
- # This option will default to `true` in RSpec 4. It makes the `description`
27
- # and `failure_message` of custom matchers include text for helper methods
28
- # defined using `chain`, e.g.:
29
- # be_bigger_than(2).and_smaller_than(4).description
30
- # # => "be bigger than 2 and smaller than 4"
31
- # ...rather than:
32
- # # => "be bigger than 2"
33
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
- end
35
-
36
- # rspec-mocks config goes here. You can use an alternate test double
37
- # library (such as bogus or mocha) by changing the `mock_with` option here.
38
- config.mock_with :rspec do |mocks|
39
- # Prevents you from mocking or stubbing a method that does not exist on
40
- # a real object. This is generally recommended, and will default to
41
- # `true` in RSpec 4.
42
- mocks.verify_partial_doubles = true
43
- end
44
-
45
- config.after(:suite) do
46
- WebMock.disable_net_connect!(:allow => 'codeclimate.com')
47
- end
48
-
49
- # The settings below are suggested to provide a good initial experience
50
- # with RSpec, but feel free to customize to your heart's content.
51
- =begin
52
- # These two settings work together to allow you to limit a spec run
53
- # to individual examples or groups you care about by tagging them with
54
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
55
- # get run.
56
- config.filter_run :focus
57
- config.run_all_when_everything_filtered = true
58
-
59
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
60
- # For more details, see:
61
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
64
- config.disable_monkey_patching!
65
-
66
- # This setting enables warnings. It's recommended, but in some cases may
67
- # be too noisy due to issues in dependencies.
68
- config.warnings = true
69
-
70
- # Many RSpec users commonly either run the entire suite or an individual
71
- # file, and it's useful to allow more verbose output when running an
72
- # individual spec file.
73
- if config.files_to_run.one?
74
- # Use the documentation formatter for detailed output,
75
- # unless a formatter has already been configured
76
- # (e.g. via a command-line flag).
77
- config.default_formatter = 'doc'
78
- end
79
-
80
- # Print the 10 slowest examples and example groups at the
81
- # end of the spec run, to help surface which specs are running
82
- # particularly slow.
83
- config.profile_examples = 10
84
-
85
- # Run specs in random order to surface order dependencies. If you find an
86
- # order dependency and want to debug it, you can fix the order by providing
87
- # the seed, which is printed after each run.
88
- # --seed 1234
89
- config.order = :random
90
-
91
- # Seed global randomization in this process using the `--seed` CLI option.
92
- # Setting this allows you to use `--seed` to deterministically reproduce
93
- # test failures related to randomization by passing the same `--seed` value
94
- # as the one that triggered the failure.
95
- Kernel.srand config.seed
96
- =end
97
- end
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'webmock/rspec'
18
+ require 'codeclimate-test-reporter'
19
+ CodeClimate::TestReporter.start
20
+
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ config.after(:suite) do
46
+ WebMock.disable_net_connect!(allow: 'codeclimate.com')
47
+ end
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # These two settings work together to allow you to limit a spec run
52
+ # # to individual examples or groups you care about by tagging them with
53
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
54
+ # # get run.
55
+ # config.filter_run :focus
56
+ # config.run_all_when_everything_filtered = true
57
+ #
58
+ # # Limits the available syntax to the non-monkey patched syntax that is recommended.
59
+ # # For more details, see:
60
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ # config.disable_monkey_patching!
64
+ #
65
+ # # This setting enables warnings. It's recommended, but in some cases may
66
+ # # be too noisy due to issues in dependencies.
67
+ # config.warnings = true
68
+ #
69
+ # # Many RSpec users commonly either run the entire suite or an individual
70
+ # # file, and it's useful to allow more verbose output when running an
71
+ # # individual spec file.
72
+ # if config.files_to_run.one?
73
+ # # Use the documentation formatter for detailed output,
74
+ # # unless a formatter has already been configured
75
+ # # (e.g. via a command-line flag).
76
+ # config.default_formatter = 'doc'
77
+ # end
78
+ #
79
+ # # Print the 10 slowest examples and example groups at the
80
+ # # end of the spec run, to help surface which specs are running
81
+ # # particularly slow.
82
+ # config.profile_examples = 10
83
+ #
84
+ # # Run specs in random order to surface order dependencies. If you find an
85
+ # # order dependency and want to debug it, you can fix the order by providing
86
+ # # the seed, which is printed after each run.
87
+ # # --seed 1234
88
+ # config.order = :random
89
+ #
90
+ # # Seed global randomization in this process using the `--seed` CLI option.
91
+ # # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # # test failures related to randomization by passing the same `--seed` value
93
+ # # as the one that triggered the failure.
94
+ # Kernel.srand config.seed
95
+ end
@@ -1,116 +1,113 @@
1
- require 'zanzibar'
2
- require 'savon'
3
- require 'webmock'
4
- require 'rspec'
5
- require 'webmock/rspec'
6
-
7
- include WebMock::API
8
-
9
- describe "Zanzibar Test" do
10
-
11
- client = Zanzibar::Zanzibar.new(:domain => "zanzitest.net", :pwd=>'password', :wsdl => "spec/scrt.wsdl")
12
- auth_xml = File.read('spec/responses/authenticate_response.xml')
13
- secret_xml = File.read('spec/responses/get_secret_response.xml')
14
- secret_with_key_xml = File.read('spec/responses/get_secret_with_keys_response.xml')
15
- secret_with_attachment_xml = File.read('spec/responses/get_secret_with_attachment_response.xml')
16
- private_key_xml = File.read('spec/responses/download_private_key_response.xml')
17
- public_key_xml = File.read('spec/responses/download_public_key_response.xml')
18
- attachment_xml = File.read('spec/responses/attachment_response.xml')
19
-
20
-
21
- it 'should return an auth token' do
22
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
23
- to_return(:body => auth_xml, :status => 200)
24
-
25
- expect(client.get_token).to eq("imatoken")
26
- end
27
-
28
- it 'should get a secret' do
29
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
30
- to_return(:body => auth_xml, :status => 200).then.
31
- to_return(:body => secret_xml, :status => 200)
32
-
33
- expect(client.get_secret(1234)[:secret][:name]).to eq("Zanzi Test Secret")
34
- end
35
-
36
- it 'should get a password' do
37
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
38
- to_return(:body => auth_xml, :status => 200).then.
39
- to_return(:body => secret_xml, :status => 200)
40
-
41
- expect(client.get_password(1234)).to eq("zanziUserPassword")
42
- end
43
-
44
- it 'should download a private key' do
45
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
46
- to_return(:body => auth_xml, :status => 200).then.
47
- to_return(:body => secret_with_key_xml, :status => 200).then.
48
- to_return(:body => private_key_xml, :status => 200)
49
-
50
- client.download_secret_file(:scrt_id => 2345, :type => 'Private Key')
51
- expect(File.exist? 'zanzi_key')
52
- expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
53
- File.delete('zanzi_key')
54
- end
55
-
56
- it 'should download a private key legacy' do
57
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
58
- to_return(:body => auth_xml, :status => 200).then.
59
- to_return(:body => secret_with_key_xml, :status => 200).then.
60
- to_return(:body => private_key_xml, :status => 200)
61
-
62
- client.download_private_key(:scrt_id => 2345)
63
- expect(File.exist? 'zanzi_key')
64
- expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
65
- File.delete('zanzi_key')
66
- end
67
-
68
-
69
- it 'should download a public key' do
70
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
71
- to_return(:body => auth_xml, :status => 200).then.
72
- to_return(:body => secret_with_key_xml, :status => 200).then.
73
- to_return(:body => public_key_xml, :status => 200)
74
-
75
- client.download_secret_file(:scrt_id => 2345, :type => 'Public Key')
76
- expect(File.exist? 'zanzi_key.pub')
77
- expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
78
- File.delete('zanzi_key.pub')
79
- end
80
-
81
- it 'should download a public key legacy' do
82
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
83
- to_return(:body => auth_xml, :status => 200).then.
84
- to_return(:body => secret_with_key_xml, :status => 200).then.
85
- to_return(:body => public_key_xml, :status => 200)
86
-
87
- client.download_public_key(:scrt_id => 2345)
88
- expect(File.exist? 'zanzi_key.pub')
89
- expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
90
- File.delete('zanzi_key.pub')
91
- end
92
-
93
- it 'should download an attachment' do
94
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
95
- to_return(:body => auth_xml, :status => 200).then.
96
- to_return(:body => secret_with_attachment_xml, :status => 200).then.
97
- to_return(:body => attachment_xml, :status => 200)
98
-
99
- client.download_secret_file(:scrt_id => 3456, :type => 'Attachment')
100
- expect(File.exist? 'attachment.txt')
101
- expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
102
- File.delete('attachment.txt')
103
- end
104
-
105
- it 'should download an attachment legacy' do
106
- stub_request(:any, "https://www.zanzitest.net/webservices/sswebservice.asmx").
107
- to_return(:body => auth_xml, :status => 200).then.
108
- to_return(:body => secret_with_attachment_xml, :status => 200).then.
109
- to_return(:body => attachment_xml, :status => 200)
110
-
111
- client.download_attachment(:scrt_id => 3456)
112
- expect(File.exist? 'attachment.txt')
113
- expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
114
- File.delete('attachment.txt')
115
- end
116
- end
1
+ require 'zanzibar'
2
+ require 'savon'
3
+ require 'webmock'
4
+ require 'rspec'
5
+ require 'webmock/rspec'
6
+
7
+ include WebMock::API
8
+
9
+ describe 'Zanzibar Test' do
10
+ client = Zanzibar::Zanzibar.new(domain: 'zanzitest.net', pwd: 'password', wsdl: 'spec/scrt.wsdl')
11
+ auth_xml = File.read('spec/responses/authenticate_response.xml')
12
+ secret_xml = File.read('spec/responses/get_secret_response.xml')
13
+ secret_with_key_xml = File.read('spec/responses/get_secret_with_keys_response.xml')
14
+ secret_with_attachment_xml = File.read('spec/responses/get_secret_with_attachment_response.xml')
15
+ private_key_xml = File.read('spec/responses/download_private_key_response.xml')
16
+ public_key_xml = File.read('spec/responses/download_public_key_response.xml')
17
+ attachment_xml = File.read('spec/responses/attachment_response.xml')
18
+
19
+ it 'should return an auth token' do
20
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
21
+ .to_return(body: auth_xml, status: 200)
22
+
23
+ expect(client.get_token).to eq('imatoken')
24
+ end
25
+
26
+ it 'should get a secret' do
27
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
28
+ .to_return(body: auth_xml, status: 200).then
29
+ .to_return(body: secret_xml, status: 200)
30
+
31
+ expect(client.get_secret(1234)[:secret][:name]).to eq('Zanzi Test Secret')
32
+ end
33
+
34
+ it 'should get a password' do
35
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
36
+ .to_return(body: auth_xml, status: 200).then
37
+ .to_return(body: secret_xml, status: 200)
38
+
39
+ expect(client.get_password(1234)).to eq('zanziUserPassword')
40
+ end
41
+
42
+ it 'should download a private key' do
43
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
44
+ .to_return(body: auth_xml, status: 200).then
45
+ .to_return(body: secret_with_key_xml, status: 200).then
46
+ .to_return(body: private_key_xml, status: 200)
47
+
48
+ client.download_secret_file(scrt_id: 2345, type: 'Private Key')
49
+ expect(File.exist? 'zanzi_key')
50
+ expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
51
+ File.delete('zanzi_key')
52
+ end
53
+
54
+ it 'should download a private key legacy' do
55
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
56
+ .to_return(body: auth_xml, status: 200).then
57
+ .to_return(body: secret_with_key_xml, status: 200).then
58
+ .to_return(body: private_key_xml, status: 200)
59
+
60
+ client.download_private_key(scrt_id: 2345)
61
+ expect(File.exist? 'zanzi_key')
62
+ expect(File.read('zanzi_key')).to eq("-----BEGIN RSA PRIVATE KEY -----\nzanzibarTestPassword\n-----END RSA PRIVATE KEY-----\n")
63
+ File.delete('zanzi_key')
64
+ end
65
+
66
+ it 'should download a public key' do
67
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
68
+ .to_return(body: auth_xml, status: 200).then
69
+ .to_return(body: secret_with_key_xml, status: 200).then
70
+ .to_return(body: public_key_xml, status: 200)
71
+
72
+ client.download_secret_file(scrt_id: 2345, type: 'Public Key')
73
+ expect(File.exist? 'zanzi_key.pub')
74
+ expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
75
+ File.delete('zanzi_key.pub')
76
+ end
77
+
78
+ it 'should download a public key legacy' do
79
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
80
+ .to_return(body: auth_xml, status: 200).then
81
+ .to_return(body: secret_with_key_xml, status: 200).then
82
+ .to_return(body: public_key_xml, status: 200)
83
+
84
+ client.download_public_key(scrt_id: 2345)
85
+ expect(File.exist? 'zanzi_key.pub')
86
+ expect(File.read('zanzi_key.pub')).to eq("1234PublicKey5678==\n")
87
+ File.delete('zanzi_key.pub')
88
+ end
89
+
90
+ it 'should download an attachment' do
91
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
92
+ .to_return(body: auth_xml, status: 200).then
93
+ .to_return(body: secret_with_attachment_xml, status: 200).then
94
+ .to_return(body: attachment_xml, status: 200)
95
+
96
+ client.download_secret_file(scrt_id: 3456, type: 'Attachment')
97
+ expect(File.exist? 'attachment.txt')
98
+ expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
99
+ File.delete('attachment.txt')
100
+ end
101
+
102
+ it 'should download an attachment legacy' do
103
+ stub_request(:any, 'https://www.zanzitest.net/webservices/sswebservice.asmx')
104
+ .to_return(body: auth_xml, status: 200).then
105
+ .to_return(body: secret_with_attachment_xml, status: 200).then
106
+ .to_return(body: attachment_xml, status: 200)
107
+
108
+ client.download_attachment(scrt_id: 3456)
109
+ expect(File.exist? 'attachment.txt')
110
+ expect(File.read('attachment.txt')).to eq("I am a secret attachment\n")
111
+ File.delete('attachment.txt')
112
+ end
113
+ end
data/zanzibar.gemspec CHANGED
@@ -4,22 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'zanzibar/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "zanzibar"
7
+ spec.name = 'zanzibar'
8
8
  spec.version = Zanzibar::VERSION
9
- spec.authors = ["Jason Davis-Cooke"]
10
- spec.email = ["jdaviscooke@cimpress.com"]
11
- spec.summary = "Retrieve secrets from Secret Server"
12
- spec.description = "Programatically get secrets from Secret Server via the Web Service API"
13
- spec.homepage = "https://github.com/Cimpress-MCP/zanzibar"
14
- spec.license = "Apache 2.0"
9
+ spec.authors = ['Jason Davis-Cooke']
10
+ spec.email = ['jdaviscooke@cimpress.com']
11
+ spec.summary = 'Retrieve secrets from Secret Server'
12
+ spec.description = 'Programatically get secrets from Secret Server via the Web Service API'
13
+ spec.homepage = 'https://github.com/Cimpress-MCP/zanzibar'
14
+ spec.license = 'Apache 2.0'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "rubyntlm", "~> 0.4.0"
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_runtime_dependency "savon", "~> 2.8.0"
21
+ spec.add_dependency 'rubyntlm', '~> 0.4.0'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rubocop', '~>0.18.1'
25
+ spec.add_runtime_dependency 'savon', '~> 2.8.0'
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zanzibar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Davis-Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyntlm
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.18.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.18.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: savon
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -71,6 +85,7 @@ email:
71
85
  - jdaviscooke@cimpress.com
72
86
  executables:
73
87
  - zamioculcas
88
+ - zanzibar
74
89
  extensions: []
75
90
  extra_rdoc_files: []
76
91
  files:
@@ -82,6 +97,7 @@ files:
82
97
  - README.md
83
98
  - Rakefile
84
99
  - bin/zamioculcas
100
+ - bin/zanzibar
85
101
  - lib/zanzibar.rb
86
102
  - lib/zanzibar/version.rb
87
103
  - spec/responses/attachment_response.xml