conjur-cli 4.9.3 → 4.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,23 +18,22 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
- require 'conjur/authn'
22
- require 'conjur/command/dsl_command'
23
21
 
24
22
  class Conjur::Command::Script < Conjur::DSLCommand
25
- self.prefix = :script
23
+ desc "Execute Conjur DSL scripts"
24
+ command :script do |script|
25
+ script.desc "Run a Conjur DSL script"
26
+ script.arg_name "script"
27
+ script.command :execute do |c|
28
+ acting_as_option(c)
26
29
 
27
- desc "Run a Conjur DSL script"
28
- arg_name "script"
29
- command :execute do |c|
30
- acting_as_option(c)
31
-
32
- c.desc "Load context from this config file, and save it when finished. The file permissions will be 0600 by default."
33
- c.arg_name "context"
34
- c.flag [:c, :context]
35
-
36
- c.action do |global_options,options,args|
37
- run_script args, options
30
+ c.desc "Load context from this config file, and save it when finished. The file permissions will be 0600 by default."
31
+ c.arg_name "context"
32
+ c.flag [:c, :context]
33
+
34
+ c.action do |global_options,options,args|
35
+ run_script args, options
36
+ end
38
37
  end
39
38
  end
40
39
  end
@@ -18,32 +18,29 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
- require 'conjur/authn'
22
- require 'conjur/command'
23
21
 
24
22
  class Conjur::Command::Secrets < Conjur::Command
25
- self.prefix = :secret
26
-
27
- desc "Create and store a secret"
28
- arg_name "secret"
29
- command :create do |c|
30
- def c.nodoc; true end
23
+ desc "Manage secrets"
24
+ command :secret do |secret|
25
+ hide_docs(secret)
26
+ secret.desc "Create and store a secret"
27
+ secret.arg_name "secret"
28
+ secret.command :create do |c|
29
+ acting_as_option(c)
31
30
 
32
- acting_as_option(c)
33
-
34
- c.action do |global_options,options,args|
35
- secret = args.shift or raise "Missing parameter: secret"
36
- display api.create_secret(secret, options), options
31
+ c.action do |global_options,options,args|
32
+ secret = args.shift or raise "Missing parameter: secret"
33
+ display api.create_secret(secret, options), options
34
+ end
37
35
  end
38
- end
39
36
 
40
- desc "Retrieve a secret"
41
- arg_name "id"
42
- command :value do |c|
43
- def c.nodoc; true end
44
- c.action do |global_options,options,args|
45
- id = args.shift or raise "Missing parameter: id"
46
- puts api.secret(id).value
37
+ secret.desc "Retrieve a secret"
38
+ secret.arg_name "id"
39
+ secret.command :value do |c|
40
+ c.action do |global_options,options,args|
41
+ id = args.shift or raise "Missing parameter: id"
42
+ puts api.secret(id).value
43
+ end
47
44
  end
48
45
  end
49
46
  end
@@ -18,13 +18,9 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
- require 'conjur/api/authn'
22
- require 'conjur/authn'
23
- require 'conjur/command'
24
21
 
25
22
  class Conjur::Command::Users < Conjur::Command
26
- self.prefix = :user
27
-
23
+
28
24
  def self.prompt_for_password
29
25
  # use stderr to allow output redirection, e.g.
30
26
  # conjur user:create -p username > user.json
@@ -37,56 +33,61 @@ class Conjur::Command::Users < Conjur::Command
37
33
 
38
34
  password
39
35
  end
40
-
41
- desc "Create a new user"
42
- arg_name "login"
43
- command :create do |c|
44
- c.desc "Prompt for a password for the user (default: --no-password)"
45
- c.switch [:p,:password]
46
-
47
- acting_as_option(c)
48
-
49
- c.action do |global_options,options,args|
50
- login = require_arg(args, 'login')
51
-
52
- opts = options.slice(:ownerid)
53
36
 
54
- if options[:p]
55
- opts[:password] = prompt_for_password
37
+ desc "Manage users"
38
+ command :user do |user|
39
+
40
+ user.desc "Create a new user"
41
+ user.arg_name "login"
42
+ user.command :create do |c|
43
+ c.desc "Prompt for a password for the user (default: --no-password)"
44
+ c.switch [:p,:password]
45
+
46
+ acting_as_option(c)
47
+
48
+ c.action do |global_options,options,args|
49
+ login = require_arg(args, 'login')
50
+
51
+ opts = options.slice(:ownerid)
52
+
53
+ if options[:p]
54
+ opts[:password] = prompt_for_password
55
+ end
56
+
57
+ display api.create_user(login, opts)
56
58
  end
57
-
58
- display api.create_user(login, opts)
59
59
  end
60
- end
61
60
 
62
- desc "Show a user"
63
- arg_name "id"
64
- command :show do |c|
65
- c.action do |global_options,options,args|
66
- id = require_arg(args, 'id')
67
- display(api.user(id), options)
61
+ user.desc "Show a user"
62
+ user.arg_name "id"
63
+ user.command :show do |c|
64
+ c.action do |global_options,options,args|
65
+ id = require_arg(args, 'id')
66
+ display(api.user(id), options)
67
+ end
68
68
  end
69
- end
70
69
 
71
- desc "List users"
72
- command :list do |c|
73
- command_options_for_list c
70
+ user.desc "List users"
71
+ user.command :list do |c|
72
+ command_options_for_list c
74
73
 
75
- c.action do |global_options, options, args|
76
- command_impl_for_list global_options, options.merge(kind: "user"), args
74
+ c.action do |global_options, options, args|
75
+ command_impl_for_list global_options, options.merge(kind: "user"), args
76
+ end
77
77
  end
78
- end
79
78
 
80
- desc "Update the password of the logged-in user"
81
- command :update_password do |c|
82
- c.desc "Password to use, otherwise you will be prompted"
83
- c.flag [:p,:password]
79
+ user.desc "Update the password of the logged-in user"
80
+ user.command :update_password do |c|
81
+ c.desc "Password to use, otherwise you will be prompted"
82
+ c.flag [:p,:password]
84
83
 
85
- c.action do |global_options,options,args|
86
- username, password = Conjur::Authn.read_credentials
87
- new_password = options[:password] || prompt_for_password
88
-
89
- Conjur::API.update_password username, password, new_password
84
+ c.action do |global_options,options,args|
85
+ username, password = Conjur::Authn.read_credentials
86
+ new_password = options[:password] || prompt_for_password
87
+
88
+ Conjur::API.update_password username, password, new_password
89
+ end
90
90
  end
91
91
  end
92
+
92
93
  end
@@ -17,102 +17,89 @@
17
17
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
- require 'conjur/authn'
22
- require 'conjur/command'
20
+
23
21
 
24
22
  class Conjur::Command::Variables < Conjur::Command
25
- self.prefix = :variable
26
-
27
- desc "Create and store a variable"
28
- arg_name "id"
29
- command :create do |c|
30
- c.arg_name "mime_type"
31
- c.flag [:m, :"mime-type"], default_value: "text/plain"
32
-
33
- c.arg_name "kind"
34
- c.flag [:k, :"kind"], default_value: "secret"
35
-
36
- c.arg_name "value"
37
- c.desc "Initial value"
38
- c.flag [:v, :"value"]
39
-
40
- acting_as_option(c)
41
-
42
- c.action do |global_options,options,args|
43
- id = args.shift
44
- options[:id] = id if id
45
-
46
- unless id
47
- ActiveSupport::Deprecation.warn "id argument will be required in future releases"
23
+ desc "Manage variables"
24
+ command :variable do |var|
25
+ var.desc "Create and store a variable"
26
+ var.arg_name "id"
27
+ var.command :create do |c|
28
+ c.arg_name "mime_type"
29
+ c.flag [:m, :"mime-type"], default_value: "text/plain"
30
+
31
+ c.arg_name "kind"
32
+ c.flag [:k, :"kind"], default_value: "secret"
33
+
34
+ c.arg_name "value"
35
+ c.desc "Initial value"
36
+ c.flag [:v, :"value"]
37
+
38
+ acting_as_option(c)
39
+
40
+ c.action do |global_options,options,args|
41
+ id = args.shift
42
+ options[:id] = id if id
43
+
44
+ unless id
45
+ ActiveSupport::Deprecation.warn "id argument will be required in future releases"
46
+ end
47
+
48
+ mime_type = options.delete(:m)
49
+ kind = options.delete(:k)
50
+
51
+ options.delete(:"mime-type")
52
+ options.delete(:"kind")
53
+
54
+ var = api.create_variable(mime_type, kind, options)
55
+ display(var, options)
48
56
  end
49
-
50
- mime_type = options.delete(:m)
51
- kind = options.delete(:k)
52
-
53
- options.delete(:"mime-type")
54
- options.delete(:"kind")
55
-
56
- var = api.create_variable(mime_type, kind, options)
57
- display(var, options)
58
57
  end
59
- end
60
58
 
61
- desc "Show a variable"
62
- arg_name "id"
63
- command :show do |c|
64
- c.action do |global_options,options,args|
65
- id = require_arg(args, 'id')
66
- display(api.variable(id), options)
59
+ var.desc "Show a variable"
60
+ var.arg_name "id"
61
+ var.command :show do |c|
62
+ c.action do |global_options,options,args|
63
+ id = require_arg(args, 'id')
64
+ display(api.variable(id), options)
65
+ end
67
66
  end
68
- end
69
67
 
70
- desc "List variables"
71
- command :list do |c|
72
- command_options_for_list c
68
+ var.desc "List variables"
69
+ var.command :list do |c|
70
+ command_options_for_list c
73
71
 
74
- c.action do |global_options, options, args|
75
- command_impl_for_list global_options, options.merge(kind: "variable"), args
76
- end
77
- end
78
-
79
- desc "Add a value"
80
- arg_name "variable ( value | STDIN )"
81
- command :"values:add" do |c|
82
- c.action do |global_options,options,args|
83
- id = require_arg(args, 'variable')
84
- value = args.shift || STDIN.read
85
-
86
- api.variable(id).add_value(value)
87
- puts "Value added"
72
+ c.action do |global_options, options, args|
73
+ command_impl_for_list global_options, options.merge(kind: "variable"), args
74
+ end
88
75
  end
89
- end
90
-
91
-
92
- desc "Get a value"
93
- arg_name "variable"
94
- command :value do |c|
95
- c.desc "Version number"
96
- c.flag [:v, :version]
97
-
98
- c.action do |global_options,options,args|
99
- id = require_arg(args, 'variable')
100
- $stdout.write api.variable(id).value(options[:version])
76
+
77
+ var.desc "Access varialbe values"
78
+ var.command :values do |values|
79
+ values.desc "Add a value"
80
+ values.arg_name "variable ( value | STDIN )"
81
+ values.command :add do |c|
82
+ c.action do |global_options,options,args|
83
+ id = require_arg(args, 'variable')
84
+ value = args.shift || STDIN.read
85
+
86
+ api.variable(id).add_value(value)
87
+ puts "Value added"
88
+ end
89
+ end
101
90
  end
102
- end
103
91
 
104
- desc "Store value into temporary file and print out it's name"
105
- arg_name "variable"
106
- command :"to_file" do |c|
107
- c.desc "Version number"
108
- c.flag [:v, :version]
109
- c.action do |global_options,options,args|
110
- id = require_arg(args, 'variable')
111
- value = api.variable(id).value(options[:version])
112
- tempfile = `mktemp /dev/shm/conjur.XXXXXX`.strip
113
- File.open(tempfile,'w') { |f| f.write(value) }
114
- puts tempfile
92
+ var.desc "Get a value"
93
+ var.arg_name "variable"
94
+ var.command :value do |c|
95
+ c.desc "Version number"
96
+ c.flag [:v, :version]
97
+
98
+ c.action do |global_options,options,args|
99
+ id = require_arg(args, 'variable')
100
+ $stdout.write api.variable(id).value(options[:version])
101
+ end
115
102
  end
116
-
103
+
117
104
  end
118
105
  end
data/lib/conjur/config.rb CHANGED
@@ -36,6 +36,7 @@ module Conjur
36
36
 
37
37
  def load(config_files = default_config_files)
38
38
  require 'yaml'
39
+ require 'conjur/log'
39
40
  config_files.each do |f|
40
41
  if File.file?(f)
41
42
  if Conjur.log
@@ -51,6 +52,7 @@ module Conjur
51
52
  end
52
53
 
53
54
  def apply
55
+ require 'conjur/configuration'
54
56
  keys = Config.keys.dup
55
57
  keys.delete(:plugins)
56
58
  keys.each do |k|
@@ -59,6 +61,7 @@ module Conjur
59
61
  end
60
62
 
61
63
  if Conjur.log
64
+ require 'conjur/api'
62
65
  Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
63
66
  end
64
67
  if Config[:cert_file]
@@ -1,4 +1,3 @@
1
- require 'conjur/identifier_manipulation'
2
1
 
3
2
  module Conjur
4
3
  module DSL
@@ -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.9.3"
22
+ VERSION = "4.10.1"
23
23
  ::Version=VERSION
24
24
  end
data/profile.rb ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ruby-prof'
3
+
4
+ result = RubyProf.profile do
5
+ require 'conjur/cli'
6
+ Conjur::CLI.run(ARGV)
7
+ end
8
+
9
+
10
+ `mkdir -p #{File.dirname(__FILE__)}/profile`
11
+ File.open("profile/graph.html", "w") do |io|
12
+ grapher = RubyProf::GraphHtmlPrinter.new(result)
13
+ grapher.print(io)
14
+ end
15
+ File.open("profile/stack.html", "w") do |io|
16
+ printer = RubyProf::CallStackPrinter.new(result)
17
+ printer.print(io)
18
+ end
19
+
@@ -2,6 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  describe Conjur::Command::Authn do
4
4
  context logged_in: false do
5
+ context "logging in" do
6
+ [ "authn:login", "authn login" ].each do |cmd|
7
+ before do
8
+ Conjur::Authn.stub(:write_credentials)
9
+ end
10
+ describe_command "#{cmd}" do
11
+ it "prompts for username and password and logs in the user" do
12
+ Conjur::Authn.should_receive(:ask_for_credentials).with({}).and_return [ "the-user", "the-api-key" ]
13
+
14
+ expect { invoke }.to write("Logged in")
15
+ end
16
+ end
17
+ describe_command "#{cmd} -u the-user" do
18
+ it "prompts for password and logs in the user" do
19
+ Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user'}).and_return [ "the-user", "the-api-key" ]
20
+
21
+ expect { invoke }.to write("Logged in")
22
+ end
23
+ end
24
+ describe_command "#{cmd} -u the-user -p the-password" do
25
+ it "logs in the user" do
26
+ Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user', password: 'the-password'}).and_return [ "the-user", "the-api-key" ]
27
+
28
+ expect { invoke }.to write("Logged in")
29
+ end
30
+ end
31
+ describe_command "#{cmd} -p the-password the-user" do
32
+ it "logs in the user" do
33
+ Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user', password: 'the-password'}).and_return [ "the-user", "the-api-key" ]
34
+
35
+ expect { invoke }.to write("Logged in")
36
+ end
37
+ end
38
+ end
39
+ end
40
+
5
41
  describe_command 'authn:whoami' do
6
42
  it "errors out" do
7
43
  expect { invoke }.to raise_error(GLI::CustomExit, /not logged in/i)
@@ -12,7 +48,7 @@ describe Conjur::Command::Authn do
12
48
  context logged_in: true do
13
49
  describe_command 'authn:logout' do
14
50
  it "deletes credentials" do
15
- invoke
51
+ expect { invoke }.to write("Logged out")
16
52
  netrc[authn_host].should_not be
17
53
  end
18
54
  end