conjur-cli 4.12.0 → 4.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4340c1ab3fdec7c2cb49b4fa1ec442298df85a50
4
- data.tar.gz: 4acef5138095751da921eba71e2a13780fddd9d6
3
+ metadata.gz: 8e1f0f7628065a0ce442b2265afe5f31ead8eaca
4
+ data.tar.gz: 7779ade9cf9b10d8814e127d2e696a24fb5d6606
5
5
  SHA512:
6
- metadata.gz: 9d52290d6b3fb8a86df68d8bbc2faff5bd24e4b382f570096b74fe1d24b724592abb724df3e580448f52f93edf0376be8167e3b6fc4ff0b6c4daa45c90af959a
7
- data.tar.gz: 70fa8e0a22fe5cc93eb51b08b07b0e8ee875b8336c6e4e06fa9fa5d66e2bae27345c50005e947c814fe6d2139448f76467b93bbfc20547201b5f499c9988cc79
6
+ metadata.gz: 4caf67febf27ac99ccbb1183a5371f04c6c768b643172f78bef981917762da18d5cbc519b92675b54f1acb0af867e75fde053f4747d4a397a6f7730e4a47cbe8
7
+ data.tar.gz: 0efb81a0af8cdb3ec276a980507003a0785cdffc04b483f360f208dbb6971064fb53115d3b23a89b33368f979a29ceafad12d4764794145041612f2f5e69c826
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
 
19
19
  gem.add_dependency 'activesupport'
20
- gem.add_dependency 'conjur-api', '>=4.9.2'
20
+ gem.add_dependency 'conjur-api', '>=4.10.0'
21
21
  gem.add_dependency 'gli', '>=2.8.0'
22
22
  gem.add_dependency 'highline'
23
23
  gem.add_dependency 'netrc'
@@ -43,13 +43,20 @@ class Conjur::Command::Users < Conjur::Command
43
43
  c.desc "Prompt for a password for the user (default: --no-password)"
44
44
  c.switch [:p,:password]
45
45
 
46
+ c.desc "UID number to be associated with user (optional)"
47
+ c.flag [:uidnumber]
48
+
46
49
  acting_as_option(c)
47
50
 
48
51
  c.action do |global_options,options,args|
49
52
  login = require_arg(args, 'login')
50
53
 
51
- opts = options.slice(:ownerid)
52
-
54
+ opts = options.slice(:ownerid,:uidnumber)
55
+ if opts[:uidnumber]
56
+ raise "Uidnumber should be integer" unless /\d+/ =~ opts[:uidnumber]
57
+ opts[:uidnumber]=opts[:uidnumber].to_i
58
+ end
59
+
53
60
  if options[:p]
54
61
  opts[:password] = prompt_for_password
55
62
  end
@@ -88,6 +95,32 @@ class Conjur::Command::Users < Conjur::Command
88
95
  Conjur::API.update_password username, password, new_password
89
96
  end
90
97
  end
98
+
99
+ user.desc "Update user's attributes (only uidnumber supported now)"
100
+ user.arg_name "login"
101
+ user.command :update do |c|
102
+ c.desc "UID number to be associated with user"
103
+ c.flag [:uidnumber]
104
+ c.action do |global_options, options, args|
105
+ login=require_arg(args,'login')
106
+ raise "Uidnumber should be integer" unless /\d+/ =~ options[:uidnumber]
107
+ options[:uidnumber]=options[:uidnumber].to_i
108
+ api.user(login).update(options)
109
+ puts "UID set"
110
+ end
111
+ end
112
+
113
+ user.desc "Find the user by UID"
114
+ user.arg_name "uid"
115
+ user.command :uidsearch do |c|
116
+ c.action do |global_options, options, args|
117
+ uidnumber = require_arg(args,'uid')
118
+ raise "Uidnumber should be integer" unless /\d+/ =~ uidnumber
119
+ uidnumber=uidnumber.to_i
120
+ display api.find_users(uidnumber: uidnumber)
121
+ end
122
+ end
123
+
91
124
  end
92
125
 
93
126
  end
@@ -29,14 +29,25 @@ module Conjur
29
29
  def clear
30
30
  @@attributes = {}
31
31
  end
32
-
33
- def default_config_files
34
- [ File.join("/etc", "conjur.conf"), ( ENV['CONJURRC'] || [ File.expand_path("~/.conjurrc"), '.conjurrc'] ) ].flatten.tap do |f|
35
- if f.include?'.conjurrc' and File.file?('.conjurrc') and not ENV['CONJURRC']=='.conjurrc'
36
- $stderr.puts "WARNING: .conjurrc file from current directory is used. This behaviour is deprecated. Use ENV['CONJURRC'] to explicitly define custom configuration file if needed"
32
+
33
+ def user_config_files
34
+ if ENV['CONJURRC']
35
+ return ENV['CONJURRC']
36
+ else
37
+ homefile = File.expand_path "~/.conjurrc"
38
+ pwdfile = File.expand_path ".conjurrc"
39
+ if homefile != pwdfile && File.file?(pwdfile)
40
+ $stderr.puts "WARNING: .conjurrc file from current directory is " +
41
+ "used. This behaviour is deprecated. Use ENV['CONJURRC'] to " +
42
+ "explicitly define custom configuration file if needed"
37
43
  end
44
+ [ homefile, pwdfile ]
38
45
  end
39
46
  end
47
+
48
+ def default_config_files
49
+ ['/etc/conjur.conf', user_config_files].flatten
50
+ end
40
51
 
41
52
  def load(config_files = default_config_files)
42
53
  require 'yaml'
@@ -73,8 +84,12 @@ module Conjur
73
84
  end
74
85
 
75
86
  if Conjur.log
76
- require 'conjur/api'
77
- Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
87
+ begin
88
+ require 'conjur/api'
89
+ Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
90
+ rescue RuntimeError
91
+ raise $! unless $!.message == "Missing required option account"
92
+ end
78
93
  end
79
94
  if Config[:cert_file]
80
95
  OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file Config[:cert_file]
@@ -12,11 +12,14 @@ module Conjur
12
12
 
13
13
  def initialize(script, filename = nil)
14
14
  @context = {
15
- "env" => Conjur.env,
16
- "stack" => Conjur.stack,
17
15
  "account" => Conjur.account,
18
16
  "api_keys" => {}
19
17
  }
18
+
19
+ @context['env'] = Conjur.env unless Conjur.env == 'production'
20
+ @context['stack'] = Conjur.stack unless Conjur.stack == 'v4'
21
+ @context['appliance_url'] = Conjur.configuration.appliance_url unless Conjur.configuration.appliance_url.nil?
22
+
20
23
  @script = script
21
24
  @filename = filename
22
25
  @api = nil
@@ -19,6 +19,6 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module Conjur
22
- VERSION = "4.12.0"
22
+ VERSION = "4.13.1"
23
23
  ::Version=VERSION
24
24
  end
@@ -25,6 +25,33 @@ describe Conjur::Command::Users, logged_in: true do
25
25
  invoke
26
26
  end
27
27
  end
28
+ describe_command "#{cmd} --uidnumber 12345 the-user" do
29
+ it "Creates a user with specified uidnumber" do
30
+ Conjur::API.any_instance.should_receive(:create_user).with("the-user", { uidnumber: 12345 }).and_return new_user
31
+ invoke
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ context "updating UID number" do
38
+ describe_command "user update --uidnumber 12345 the-user" do
39
+ it "updates the uidnumber" do
40
+ stub_user = double()
41
+ Conjur::API.any_instance.should_receive(:user).with("the-user").and_return stub_user
42
+ stub_user.should_receive(:update).with(uidnumber: 12345).and_return ""
43
+ expect { invoke }.to write "UID set"
44
+ end
45
+ end
46
+ end
47
+
48
+ context "lookup per UID" do
49
+ let(:search_result) { {id: "the-user"} }
50
+ describe_command "user uidsearch 12345" do
51
+ it "finds user" do
52
+ Conjur::API.any_instance.should_receive(:find_users).with(uidnumber: 12345).and_return search_result
53
+ expect { invoke }.to write(JSON.pretty_generate(search_result))
54
+ end
28
55
  end
29
56
  end
30
57
 
@@ -54,4 +81,4 @@ describe Conjur::Command::Users, logged_in: true do
54
81
  end
55
82
  end
56
83
  end
57
- end
84
+ end
@@ -3,20 +3,26 @@ require 'conjur/config'
3
3
  require 'conjur/command/rspec/output_matchers'
4
4
 
5
5
  describe Conjur::Config do
6
- after {
7
- Conjur::Config.clear
8
- }
6
+ include_context "fresh config"
9
7
 
10
8
  describe ".default_config_files" do
11
9
  subject { Conjur::Config.default_config_files }
10
+ let(:homedir) { '/home/isfake' }
12
11
  around do |example|
13
12
  realhome = ENV.delete 'HOME'
14
- ENV['HOME'] = '/home/isfake'
13
+ ENV['HOME'] = homedir
15
14
  example.run
16
15
  ENV['HOME'] = realhome
17
16
  end
18
17
 
19
18
  let(:deprecation_warning) { "WARNING: .conjurrc file from current directory is used. This behaviour is deprecated. Use ENV['CONJURRC'] to explicitly define custom configuration file if needed" }
19
+
20
+ shared_examples "no deprecation warning" do
21
+ it "does not issue a deprecation warning" do
22
+ expect { subject }.to_not write(deprecation_warning).to(:stderr)
23
+ end
24
+ end
25
+
20
26
  context "when CONJURRC is not set" do
21
27
  around do |example|
22
28
  oldrc = ENV.delete 'CONJURRC'
@@ -25,19 +31,34 @@ describe Conjur::Config do
25
31
  end
26
32
 
27
33
  it { should include('/etc/conjur.conf') }
28
- it { should include('/home/isfake/.conjurrc') }
34
+ it { should include("#{homedir}/.conjurrc") }
29
35
  it { should include('.conjurrc') }
36
+
37
+ before do
38
+ File.stub(:expand_path).and_call_original
39
+ File.stub(:expand_path).with('.conjurrc').and_return '.conjurrc'
40
+ end
41
+
30
42
  context "When .conjurrc is present" do
31
43
  before { File.stub(:file?).with('.conjurrc').and_return true }
32
44
  it "Issues a deprecation warning" do
33
45
  expect { subject }.to write(deprecation_warning).to(:stderr)
34
46
  end
35
- end
47
+
48
+ context "but the current directory is home" do
49
+ before do
50
+ File.unstub(:expand_path)
51
+ File.stub(:expand_path).and_call_original
52
+ File.stub(:expand_path).with('.conjurrc').and_return("#{homedir}/.conjurrc")
53
+ end
54
+
55
+ include_examples "no deprecation warning"
56
+ end
57
+ end
58
+
36
59
  context "When .conjurrc is missing" do
37
60
  before { File.stub(:file?).with('.conjurrc').and_return false }
38
- it "Does not issue a deprecation warning" do
39
- expect { subject }.to_not write(deprecation_warning).to(:stderr)
40
- end
61
+ include_examples "no deprecation warning"
41
62
  end
42
63
  end
43
64
 
@@ -50,11 +71,10 @@ describe Conjur::Config do
50
71
  end
51
72
  it { should include('/etc/conjur.conf') }
52
73
  it { should include('stub_conjurrc') }
53
- it { should_not include('/home/isfake/.conjurrc') }
74
+ it { should_not include("#{homedir}/.conjurrc") }
54
75
  it { should_not include('.conjurrc') }
55
- it "Does not issue a deprecation warning" do
56
- expect { subject }.to_not write(deprecation_warning).to(:stderr)
57
- end
76
+
77
+ include_examples "no deprecation warning"
58
78
  end
59
79
 
60
80
  context "when CONJURRC is set to .conjurrc" do
@@ -67,10 +87,9 @@ describe Conjur::Config do
67
87
  before { File.stub(:file?).with('.conjurrc').and_return true }
68
88
  it { should include('/etc/conjur.conf') }
69
89
  it { should include('.conjurrc') }
70
- it { should_not include('/home/isfake/.conjurrc') }
71
- it "Does not issue a deprecation warning" do
72
- expect { subject }.to_not write(deprecation_warning).to(:stderr)
73
- end
90
+ it { should_not include("#{homedir}/.conjurrc") }
91
+
92
+ include_examples "no deprecation warning"
74
93
  end
75
94
  end
76
95
 
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
  require 'conjur/dsl/runner'
3
3
 
4
4
  describe Conjur::DSL::Runner, logged_in: true do
5
+ include_context "fresh config"
6
+
5
7
  let(:filename) { nil }
6
8
  let(:runner) { Conjur::DSL::Runner.new script, filename }
7
9
  let(:script) { "user 'alice'" }
@@ -31,4 +33,36 @@ describe Conjur::DSL::Runner, logged_in: true do
31
33
  "the-account:user:alice" => "the-api-key"
32
34
  }
33
35
  end
34
- end
36
+
37
+ it "doesn't store default env and stack in context" do
38
+ expect(runner.context).to_not have_key 'env'
39
+ expect(runner.context).to_not have_key 'stack'
40
+ end
41
+
42
+ context "with non-default stack and env" do
43
+ let(:runner) do
44
+ Conjur::Config.merge env: 'baz', stack: 'bar'
45
+ Conjur::Config.apply
46
+ Conjur::DSL::Runner.new '', nil
47
+ end
48
+
49
+ it "stores them in context" do
50
+ expect(runner.context['env']).to eq 'baz'
51
+ expect(runner.context['stack']).to eq 'bar'
52
+ end
53
+ end
54
+
55
+ context "with appliance url" do
56
+ let(:appliance_url) { "https://conjur.example.com/api" }
57
+ let(:runner) do
58
+ Conjur::Config.merge appliance_url: appliance_url
59
+ Conjur::Config.apply
60
+
61
+ Conjur::DSL::Runner.new '', nil
62
+ end
63
+
64
+ it "stores appliance url in the context" do
65
+ expect(runner.context['appliance_url']).to eq appliance_url
66
+ end
67
+ end
68
+ end
@@ -29,3 +29,18 @@ require 'conjur/command/rspec/helpers'
29
29
  ENV['CONJURRC'] = '/dev/null'
30
30
 
31
31
  require 'conjur/cli'
32
+
33
+ shared_context "fresh config" do
34
+ before {
35
+ ENV.delete_if do |k,v|
36
+ k =~ /^CONJUR_/
37
+ end
38
+
39
+ @configuration = Conjur.configuration
40
+ Conjur.configuration = Conjur::Configuration.new
41
+ }
42
+ after {
43
+ Conjur::Config.clear
44
+ Conjur.configuration = @configuration
45
+ }
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.0
4
+ version: 4.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Rzepecki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-05 00:00:00.000000000 Z
12
+ date: 2014-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - '>='
33
33
  - !ruby/object:Gem::Version
34
- version: 4.9.2
34
+ version: 4.10.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '>='
40
40
  - !ruby/object:Gem::Version
41
- version: 4.9.2
41
+ version: 4.10.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: gli
44
44
  requirement: !ruby/object:Gem::Requirement