conjur-cli 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>conjur-cli</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ <nature>com.aptana.projects.webnature</nature>
17
+ </natures>
18
+ </projectDescription>
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@conjur-cli --create
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in conjur.gemspec
4
+ gemspec
5
+
6
+ gem 'slosilo', git: 'https://github.com/inscitiv/slosilo.git'
7
+ gem 'conjur-api', git: 'https://github.com/inscitiv/api-ruby.git', branch: 'master'
8
+ gem 'conjur-asset-environment', git: 'https://inscitiv-ops-dev:Me5aswes@github.com/inscitiv/conjur-asset-environment', branch: 'master'
9
+ gem 'conjur-asset-deployment', git: 'https://inscitiv-ops-dev:Me5aswes@github.com/inscitiv/conjur-asset-deployment', branch: 'master'
10
+ gem 'conjur-asset-cmi-study', git: 'https://inscitiv-ops-dev:Me5aswes@github.com/inscitiv/conjur-asset-cmi-study', branch: 'master'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rafał Rzepecki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Conjur
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'conjur'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install conjur
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ rescue LoadError
8
+ $stderr.puts "RSpec Rake tasks not available in environment #{ENV['RACK_ENV']}"
9
+ end
10
+
11
+ task :jenkins do
12
+ if ENV['BUILD_NUMBER']
13
+ File.write('build_number', ENV['BUILD_NUMBER'])
14
+ end
15
+ require 'ci/reporter/rake/rspec'
16
+ Rake::Task["ci:setup:rspec"].invoke
17
+ Rake::Task["spec"].invoke
18
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'conjur/cli'
4
+
5
+ exit Conjur::CLI.run(ARGV)
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/conjur/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rafa\305\202 Rzepecki", "Kevin Gilpin"]
6
+ gem.email = ["divided.mind@gmail.com", "kevin.gilpin@inscitiv.com",]
7
+ gem.summary = %q{Conjur command line interface}
8
+ gem.homepage = ""
9
+
10
+ gem.files = `git ls-files`.split($\) + Dir['build_number']
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "conjur-cli"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Conjur::VERSION
16
+
17
+ gem.add_dependency 'conjur-api'
18
+ gem.add_dependency 'gli'
19
+ gem.add_dependency 'highline'
20
+ gem.add_dependency 'netrc'
21
+
22
+ gem.add_runtime_dependency 'cas_rest_client'
23
+
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'simplecov'
26
+ end
@@ -0,0 +1,2 @@
1
+ require "conjur/version"
2
+
@@ -0,0 +1,62 @@
1
+ require 'highline'
2
+ require 'conjur/api'
3
+ require 'netrc'
4
+
5
+ module Conjur::Authn
6
+ class << self
7
+ def login(options = {})
8
+ delete_credentials
9
+ get_credentials(options)
10
+ end
11
+
12
+ def delete_credentials
13
+ netrc.delete host
14
+ netrc.save
15
+ end
16
+
17
+ def host
18
+ Conjur::Authn::API.host
19
+ end
20
+
21
+ def netrc
22
+ @netrc ||= Netrc.read
23
+ end
24
+
25
+ def get_credentials(options = {})
26
+ @credentials ||= (read_credentials || fetch_credentials(options))
27
+ end
28
+
29
+ def read_credentials
30
+ netrc[host]
31
+ end
32
+
33
+ def fetch_credentials(options = {})
34
+ ask_for_credentials(options)
35
+ write_credentials
36
+ end
37
+
38
+ def write_credentials
39
+ netrc[host] = @credentials
40
+ netrc.save
41
+ @credentials
42
+ end
43
+
44
+ def ask_for_credentials(options = {})
45
+ raise "No credentials provided or found" if options[:noask]
46
+
47
+ hl = HighLine.new
48
+ user = options[:username] || hl.ask("Enter your username to log into Conjur: ")
49
+ pass = options[:password] || hl.ask("Please enter your password (it will not be echoed): "){ |q| q.echo = false }
50
+ api_key = if cas_server = options[:"cas-server"]
51
+ Conjur::API.login_cas(user, pass, cas_server)
52
+ else
53
+ Conjur::API.login(user, pass)
54
+ end
55
+ @credentials = [user, api_key]
56
+ end
57
+
58
+ def connect(cls = Conjur::API, options = {})
59
+ cls.new_from_key(*get_credentials(options))
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,66 @@
1
+ require 'gli'
2
+ require 'conjur/config'
3
+
4
+ module Conjur
5
+ class CLI
6
+ extend GLI::App
7
+
8
+ class << self
9
+ def load_config
10
+ [ File.join("/etc", "conjur.conf"), ( ENV['CONJURRC'] || File.join(ENV['HOME'], ".conjurrc") ) ].each do |f|
11
+ if File.exists?(f)
12
+ $stderr.puts "Loading #{f}"
13
+ Conjur::Config.merge YAML.load(IO.read(f))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ load_config
20
+
21
+ ENV['CONJUR_ENV'] = Config[:env] if Config[:env]
22
+ ENV['CONJUR_STACK'] = Config[:stack] if Config[:stack]
23
+
24
+ Conjur::Config.plugins.each do |plugin|
25
+ require "conjur-asset-#{plugin}"
26
+ end
27
+
28
+ commands_from 'conjur/command'
29
+
30
+ $stderr.puts "Using host #{Conjur::Authn::API.host}"
31
+
32
+ pre do |global,command,options,args|
33
+ require 'active_support/core_ext'
34
+ options.delete_if{|k,v| v.blank?}
35
+ options.symbolize_keys!
36
+
37
+ if as_group = options.delete(:"as-group")
38
+ group = Conjur::Command.api.group(as_group)
39
+ role = Conjur::Command.api.role(group.roleid)
40
+ exit_now!("Group '#{as_group}' doesn't exist, or you don't have permission to use it") unless role.exists?
41
+ options[:"ownerid"] = group.roleid
42
+ end
43
+ if as_role = options.delete(:"as-role")
44
+ role = Conjur::Command.api.role(as_role)
45
+ exit_now!("Role '#{as_role}' does not exist, or you don't have permission to use it") unless role.exists?
46
+ options[:"ownerid"] = role.id
47
+ end
48
+
49
+ true
50
+ end
51
+
52
+ on_error do |exception|
53
+ if exception.is_a?(GLI::StandardException)
54
+ # pass
55
+ elsif exception.is_a?(RestClient::Exception)
56
+ begin
57
+ body = JSON.parse(exception.response.body)
58
+ $stderr.puts body['error']
59
+ rescue
60
+ $stderr.puts exception.response.body if exception.response
61
+ end
62
+ end
63
+ true
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,42 @@
1
+ module Conjur
2
+ class Command
3
+ class << self
4
+ attr_accessor :prefix
5
+
6
+ def method_missing *a
7
+ Conjur::CLI.send *a
8
+ end
9
+
10
+ def command name, *a, &block
11
+ Conjur::CLI.command "#{prefix}:#{name}", *a, &block
12
+ end
13
+
14
+ def require_arg(args, name)
15
+ args.shift or raise "Missing parameter: #{name}"
16
+ end
17
+
18
+ def api
19
+ Conjur::Authn.connect
20
+ end
21
+
22
+ def acting_as_option(command)
23
+ command.arg_name 'Perform all actions as the specified Group'
24
+ command.flag [:"as-group"]
25
+
26
+ command.arg_name 'Perform all actions as the specified Role'
27
+ command.flag [:"as-role"]
28
+ end
29
+
30
+ def display(obj, options = {})
31
+ str = if obj.respond_to?(:attributes)
32
+ JSON.pretty_generate obj.attributes
33
+ elsif obj.respond_to?(:id)
34
+ obj.id
35
+ else
36
+ JSON.pretty_generate obj
37
+ end
38
+ puts str
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Assets < Conjur::Command
5
+ self.prefix = :asset
6
+
7
+ desc "Create an asset"
8
+ arg_name "kind id"
9
+ command :create do |c|
10
+ acting_as_option(c)
11
+
12
+ c.action do |global_options, options, args|
13
+ kind = require_arg(args, 'kind')
14
+
15
+ m = "create_#{kind}"
16
+ record = if api.method(m).arity == 1
17
+ id = args.shift
18
+ if id
19
+ options[:id] = id
20
+ end
21
+ api.send(m, options)
22
+ else
23
+ id = require_arg(args, 'id')
24
+ api.send(m, id, options)
25
+ end
26
+ display(record, options)
27
+ end
28
+ end
29
+
30
+ desc "Show an asset"
31
+ arg_name "kind id"
32
+ command :show do |c|
33
+ c.action do |global_options,options,args|
34
+ kind = require_arg(args, "kind")
35
+ id = require_arg(args, "resource-id")
36
+ display api.send(kind, id).attributes
37
+ end
38
+ end
39
+
40
+ desc "Checks for the existance of an asset"
41
+ arg_name "kind id"
42
+ command :exists do |c|
43
+ c.action do |global_options,options,args|
44
+ kind = require_arg(args, "kind")
45
+ id = require_arg(args, "id")
46
+ puts api.send(kind, id).exists?
47
+ end
48
+ end
49
+
50
+ desc "List an asset"
51
+ arg_name "kind"
52
+ command :list do |c|
53
+ c.action do |global_options,options,args|
54
+ kind = require_arg(args, "kind")
55
+ api.send(kind.pluralize).each do |e|
56
+ display(e, options)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,38 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Authn < Conjur::Command
5
+ self.prefix = :authn
6
+
7
+ desc "Logs in and caches credentials to netrc"
8
+ long_desc <<-DESC
9
+ After successful login, subsequent commands automatically use the cached credentials. To switch users, login again using the new user credentials.
10
+ To erase credentials, use the authn:logout command.
11
+
12
+ If specified, the CAS server URL should be in the form https://<hostname>/v1.
13
+ It should be running the CAS RESTful services at the /v1 path
14
+ (or other path as specified by this argument).
15
+ DESC
16
+ command :login do |c|
17
+ c.arg_name 'username'
18
+ c.flag [:u,:username]
19
+
20
+ c.arg_name 'password'
21
+ c.flag [:p,:password]
22
+
23
+ c.arg_name 'CAS server'
24
+ c.desc 'Specifies a CAS server URL to use for login'
25
+ c.flag [:"cas-server"]
26
+
27
+ c.action do |global_options,options,args|
28
+ Conjur::Authn.login(options)
29
+ end
30
+ end
31
+
32
+ desc "Logs out"
33
+ command :logout do |c|
34
+ c.action do
35
+ Conjur::Authn.delete_credentials
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Groups < Conjur::Command
5
+ self.prefix = :group
6
+
7
+ desc "Create a new group"
8
+ arg_name "id"
9
+ command :create do |c|
10
+ acting_as_option(c)
11
+
12
+ c.action do |global_options,options,args|
13
+ id = require_arg(args, 'id')
14
+
15
+ group = api.create_group(id, options)
16
+ puts "Created #{group}"
17
+ end
18
+ end
19
+
20
+ desc "Add a new group member"
21
+ arg_name "group"
22
+ arg_name "member"
23
+ command :"members:add" do |c|
24
+ c.desc "Grant with admin option"
25
+ c.switch [:a, :admin]
26
+
27
+ c.action do |global_options,options,args|
28
+ group = require_arg(args, 'group')
29
+ member = require_arg(args, 'member')
30
+
31
+ group = api.group(group)
32
+ api.role(group.roleid).grant_to member, !!options[:admin]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Hosts < Conjur::Command
5
+ self.prefix = :host
6
+
7
+ desc "Create a new host"
8
+ arg_name "host"
9
+ command :create do |c|
10
+ c.arg_name "password"
11
+ c.flag [:p,:password]
12
+
13
+ acting_as_option(c)
14
+
15
+ c.action do |global_options,options,args|
16
+ id = args.shift
17
+ options[:id] = id if id
18
+ display api.create_host(options), options
19
+ end
20
+ end
21
+
22
+ desc "Enroll a new host into conjur"
23
+ arg_name "host"
24
+ command :enroll do |c|
25
+ c.action do |global_options, options, args|
26
+ id = require_arg(args, 'host')
27
+ enrollment_url = api.host(id).enrollment_url
28
+ puts enrollment_url
29
+ $stderr.puts "On the target host, please execute the following command:"
30
+ $stderr.puts "sudo true && curl -L #{enrollment_url} | sudo bash"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Resources < Conjur::Command
5
+ self.prefix = :permission
6
+
7
+ desc "Grants permission on a resource to a role"
8
+ arg_name "resource-kind"
9
+ arg_name "resource-id"
10
+ arg_name "role"
11
+ arg_name "privilege"
12
+ command :grant do |c|
13
+ c.desc "Whether to give the grant option"
14
+ c.switch :grant
15
+
16
+ c.action do |global_options,options,args|
17
+ kind = args.shift or raise "Missing parameter: resource-kind"
18
+ resource_id = args.shift or raise "Missing parameter: resource-id"
19
+ role = args.shift or raise "Missing parameter: role"
20
+ privilege = args.shift or raise "Missing parameter: privilege"
21
+ resource = api.resource(kind, resource_id)
22
+ options = {}
23
+ options[:grant_option] = true if options[:grant]
24
+ resource.permit privilege, role, options
25
+ end
26
+ end
27
+
28
+ desc "Check whether a role has a privilege on a resource"
29
+ arg_name "resource-kind"
30
+ arg_name "resource-id"
31
+ arg_name "role"
32
+ arg_name "privilege"
33
+ command :check do |c|
34
+ c.action do |global_options,options,args|
35
+ kind = args.shift or raise "Missing parameter: resource-kind"
36
+ resource_id = args.shift or raise "Missing parameter: resource-id"
37
+ role = args.shift or raise "Missing parameter: role"
38
+ privilege = args.shift or raise "Missing parameter: privilege"
39
+ role = api.role(role)
40
+ begin
41
+ role.permitted? kind, resource_id, privilege
42
+ puts "true"
43
+ rescue RestClient::ResourceNotFound
44
+ puts "false"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,86 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Resources < Conjur::Command
5
+ self.prefix = :resource
6
+
7
+ desc "Create a new resource"
8
+ arg_name "kind resource-id"
9
+ command :create do |c|
10
+ acting_as_option(c)
11
+
12
+ c.action do |global_options,options,args|
13
+ kind = require_arg(args, "kind")
14
+ id = require_arg(args, "resource-id")
15
+ resource = api.resource(kind, id)
16
+ resource.create(options)
17
+ end
18
+ end
19
+
20
+ desc "Show a resource"
21
+ arg_name "kind resource-id"
22
+ command :show do |c|
23
+ c.action do |global_options,options,args|
24
+ kind = require_arg(args, "kind")
25
+ id = require_arg(args, "resource-id")
26
+ display api.resource(kind, id).attributes
27
+ end
28
+ end
29
+
30
+ desc "Determines whether a resource exists"
31
+ arg_name "kind resource-id"
32
+ command :exists do |c|
33
+ c.action do |global_options,options,args|
34
+ kind = require_arg(args, "kind")
35
+ id = require_arg(args, "resource-id")
36
+ resource = api.resource(kind, id)
37
+ puts resource.exists?
38
+ end
39
+ end
40
+
41
+ desc "Grant a privilege on a resource"
42
+ arg_name "kind resource-id role privilege"
43
+ command :permit do |c|
44
+ c.action do |global_options,options,args|
45
+ kind = require_arg(args, "kind")
46
+ id = require_arg(args, "resource-id")
47
+ role = require_arg(args, "role")
48
+ privilege = require_arg(args, "privilege")
49
+ api.resource(kind, id).permit privilege, role
50
+ end
51
+ end
52
+
53
+ desc "Revoke a privilege on a resource"
54
+ arg_name "kind resource-id role privilege"
55
+ command :deny do |c|
56
+ c.action do |global_options,options,args|
57
+ kind = require_arg(args, "kind")
58
+ id = require_arg(args, "resource-id")
59
+ role = require_arg(args, "role")
60
+ privilege = require_arg(args, "privilege")
61
+ api.resource(kind, id).deny privilege, role
62
+ end
63
+ end
64
+
65
+ desc "Grant ownership on a resource to a new owner"
66
+ arg_name "kind resource-id owner"
67
+ command :give do |c|
68
+ c.action do |global_options,options,args|
69
+ kind = require_arg(args, "kind")
70
+ id = require_arg(args, "resource-id")
71
+ owner = require_arg(args, "owner")
72
+ api.resource(kind, id).give_to owner
73
+ end
74
+ end
75
+
76
+ desc "List roles with a specified permission on the resource"
77
+ arg_name "kind resource-id permission"
78
+ command :permitted_roles do |c|
79
+ c.action do |global_options,options,args|
80
+ kind = require_arg(args, "kind")
81
+ id = require_arg(args, "resource-id")
82
+ permission = require_arg(args, "permission")
83
+ display api.resource(kind, id).permitted_roles(permission)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,64 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Roles < Conjur::Command
5
+ self.prefix = :role
6
+
7
+ desc "Create a new role"
8
+ arg_name "role"
9
+ command :create do |c|
10
+ acting_as_option(c)
11
+
12
+ c.action do |global_options,options,args|
13
+ id = require_arg(args, 'role')
14
+ role = api.role(id)
15
+ role.create(options)
16
+ end
17
+ end
18
+
19
+ desc "Determines whether a role exists"
20
+ arg_name "role"
21
+ command :exists do |c|
22
+ c.action do |global_options,options,args|
23
+ id = require_arg(args, 'role')
24
+ role = api.role(id)
25
+ puts role.exists?
26
+ end
27
+ end
28
+
29
+ desc "Lists role memberships"
30
+ arg_name "role"
31
+ command :memberships do |c|
32
+ c.action do |global_options,options,args|
33
+ role = args.shift || api.username
34
+ display api.role(role).all.map(&:id)
35
+ end
36
+ end
37
+
38
+ desc "Grant a role to another role. You must have admin permission on the granting role."
39
+ arg_name "role"
40
+ arg_name "member"
41
+ command :grant_to do |c|
42
+ c.desc "Whether to grant with admin option"
43
+ c.switch :admin
44
+
45
+ c.action do |global_options,options,args|
46
+ id = require_arg(args, 'role')
47
+ member = require_arg(args, 'member')
48
+ role = api.role(id)
49
+ role.grant_to member, options[:admin]
50
+ end
51
+ end
52
+
53
+ desc "Revoke a role from another role."
54
+ arg_name "role"
55
+ arg_name "member"
56
+ command :revoke_from do |c|
57
+ c.action do |global_options,options,args|
58
+ id = require_arg(args, 'role')
59
+ member = require_arg(args, 'member')
60
+ role = api.role(id)
61
+ role.revoke_from member
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Secrets < Conjur::Command
5
+ self.prefix = :secret
6
+
7
+ desc "Create and store a secret"
8
+ arg_name "secret"
9
+ command :create do |c|
10
+ acting_as_option(c)
11
+
12
+ c.action do |global_options,options,args|
13
+ secret = args.shift or raise "Missing parameter: secret"
14
+ display api.create_secret(secret, options), options
15
+ end
16
+ end
17
+
18
+ desc "Retrieve a secret"
19
+ arg_name "id"
20
+ command :value do |c|
21
+ c.action do |global_options,options,args|
22
+ id = args.shift or raise "Missing parameter: id"
23
+ puts api.secret(id).value
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Users < Conjur::Command
5
+ self.prefix = :user
6
+
7
+ desc "Create a new user"
8
+ arg_name "login"
9
+ command :create do |c|
10
+ c.desc "Prompt for a password for the user"
11
+ c.switch [:p,:password]
12
+
13
+ acting_as_option(c)
14
+
15
+ c.action do |global_options,options,args|
16
+ login = require_arg(args, 'login')
17
+
18
+ opts = options.slice(:ownerid)
19
+ if options[:p]
20
+ hl = HighLine.new
21
+ password = hl.ask("Enter the password (it will not be echoed): "){ |q| q.echo = false }
22
+ confirmation = hl.ask("Confirm the password: "){ |q| q.echo = false }
23
+
24
+ raise "Password does not match confirmation" unless password == confirmation
25
+
26
+ opts[:password] = password
27
+ end
28
+
29
+ display api.create_user(login, opts)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ require 'conjur/authn'
2
+ require 'conjur/command'
3
+
4
+ class Conjur::Command::Variables < Conjur::Command
5
+ self.prefix = :variable
6
+
7
+ desc "Create and store a variable"
8
+ command :create do |c|
9
+ c.arg_name "mime_type"
10
+ c.flag [:m, :"mime-type"]
11
+
12
+ c.arg_name "kind"
13
+ c.flag [:k, :"kind"]
14
+
15
+ acting_as_option(c)
16
+
17
+ c.action do |global_options,options,args|
18
+ var = api.create_variable(options[:m], options[:k], options)
19
+ display(var, options)
20
+ end
21
+ end
22
+
23
+ desc "Show a variable"
24
+ arg_name "id"
25
+ command :show do |c|
26
+ c.action do |global_options,options,args|
27
+ id = require_arg(args, 'id')
28
+ display(api.variable(id), options)
29
+ end
30
+ end
31
+
32
+ desc "Add a value"
33
+ arg_name "variable value"
34
+ command :"values:add" do |c|
35
+ c.action do |global_options,options,args|
36
+ id = require_arg(args, 'variable')
37
+ value = args.shift || STDIN.read
38
+
39
+ api.variable(id).add_value(value)
40
+ end
41
+ end
42
+
43
+ desc "Get a value"
44
+ arg_name "variable"
45
+ command :value do |c|
46
+ c.desc "Version number"
47
+ c.flag [:v, :version]
48
+
49
+ c.action do |global_options,options,args|
50
+ id = require_arg(args, 'variable')
51
+ puts api.variable(id).value(options[:version])
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ module Conjur
2
+ class Config
3
+ @@attributes = {}
4
+
5
+ class << self
6
+ def inspect
7
+ @@attributes.inspect
8
+ end
9
+
10
+ def plugins
11
+ plugins = @@attributes['plugins']
12
+ if plugins
13
+ plugins.is_a?(Array) ? plugins : plugins.split(',')
14
+ else
15
+ []
16
+ end
17
+ end
18
+
19
+ def merge(a)
20
+ a = {} unless a
21
+ @@attributes.merge!(a)
22
+ end
23
+
24
+ def [](key)
25
+ @@attributes[key.to_s]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Conjur
2
+ VERSION = "2.1.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe Conjur::Command::Authn do
5
+ let(:netrcfile) { Tempfile.new 'authtest' }
6
+ before do
7
+ Conjur::Auth.stub netrc: Netrc.read(netrcfile.path)
8
+ end
9
+ describe_command 'auth:logout' do
10
+ it "deletes credentials" do
11
+ Conjur::Auth.should_receive :delete_credentials
12
+ invoke
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "simplecov"
5
+ SimpleCov.start
6
+
7
+ module RSpec::Core::DSL
8
+ def describe_command name, *a, &block
9
+ describe name, *a do
10
+ let(:invoke) { Conjur::Cli.run [name] }
11
+ instance_eval &block
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'conjur/cli'
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conjur-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rafał Rzepecki
9
+ - Kevin Gilpin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: conjur-api
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: gli
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: highline
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: netrc
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: cas_rest_client
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description:
128
+ email:
129
+ - divided.mind@gmail.com
130
+ - kevin.gilpin@inscitiv.com
131
+ executables:
132
+ - conjur
133
+ extensions: []
134
+ extra_rdoc_files: []
135
+ files:
136
+ - .gitignore
137
+ - .project
138
+ - .rvmrc
139
+ - Gemfile
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - bin/conjur
144
+ - conjur.gemspec
145
+ - lib/conjur.rb
146
+ - lib/conjur/authn.rb
147
+ - lib/conjur/cli.rb
148
+ - lib/conjur/command.rb
149
+ - lib/conjur/command/assets.rb
150
+ - lib/conjur/command/authn.rb
151
+ - lib/conjur/command/groups.rb
152
+ - lib/conjur/command/hosts.rb
153
+ - lib/conjur/command/permissions.rb
154
+ - lib/conjur/command/resources.rb
155
+ - lib/conjur/command/roles.rb
156
+ - lib/conjur/command/secrets.rb
157
+ - lib/conjur/command/users.rb
158
+ - lib/conjur/command/variables.rb
159
+ - lib/conjur/config.rb
160
+ - lib/conjur/version.rb
161
+ - spec/command/authn_spec.rb
162
+ - spec/spec_helper.rb
163
+ homepage: ''
164
+ licenses: []
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 1.8.24
184
+ signing_key:
185
+ specification_version: 3
186
+ summary: Conjur command line interface
187
+ test_files:
188
+ - spec/command/authn_spec.rb
189
+ - spec/spec_helper.rb