Class: Conjur::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/conjur/command.rb
Direct Known Subclasses
Assets, Authn, Field, Groups, Hosts, Id, Resources, Roles, Secrets, Users, Variables
Defined Under Namespace
Classes: Assets, Authn, Field, Groups, Hosts, Id, Resources, Roles, Secrets, Users, Variables
Constant Summary
collapse
- @@api =
nil
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.prefix ⇒ Object
Returns the value of attribute prefix.
26
27
28
|
# File 'lib/conjur/command.rb', line 26
def prefix
@prefix
end
|
Class Method Details
.acting_as_option(command) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/conjur/command.rb', line 70
def acting_as_option(command)
command.arg_name 'Perform all actions as the specified Group'
command.flag [:"as-group"]
command.arg_name 'Perform all actions as the specified Role'
command.flag [:"as-role"]
end
|
.api ⇒ Object
40
41
42
|
# File 'lib/conjur/command.rb', line 40
def api
@@api ||= Conjur::Authn.connect
end
|
.command(name, *a, &block) ⇒ Object
32
33
34
|
# File 'lib/conjur/command.rb', line 32
def command name, *a, &block
Conjur::CLI.command "#{prefix}:#{name}", *a, &block
end
|
.conjur_account ⇒ Object
66
67
68
|
# File 'lib/conjur/command.rb', line 66
def conjur_account
Conjur::Core::API.conjur_account
end
|
.display(obj, options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/conjur/command.rb', line 78
def display(obj, options = {})
str = if obj.respond_to?(:attributes)
JSON.pretty_generate obj.attributes
elsif obj.respond_to?(:id)
obj.id
else
JSON.pretty_generate obj
end
puts str
end
|
.full_resource_id(id) ⇒ Object
injects account into 2-tokens id
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/conjur/command.rb', line 45
def full_resource_id id
parts = id.split(':') unless id.nil?
if id.blank? or parts.size < 2
raise "Expecting at least two tokens in #{id}"
end
if parts.size == 2
id = [conjur_account, parts].flatten.join(":")
end
id
end
|
.get_kind_and_id_from_args(args, argname = 'id') ⇒ Object
removes accounts from 3+-tokens id, extracts kind
57
58
59
60
61
62
63
64
|
# File 'lib/conjur/command.rb', line 57
def get_kind_and_id_from_args args, argname='id'
flat_id = require_arg(args, argname)
tokens=flat_id.split(':')
raise "At least 2 tokens expected in #{flat_id}" if tokens.size<2
tokens.shift if tokens.size>=3
kind=tokens.shift.gsub('-','_')
[kind, tokens.join(':')]
end
|
.method_missing(*a) ⇒ Object
28
29
30
|
# File 'lib/conjur/command.rb', line 28
def method_missing *a
Conjur::CLI.send *a
end
|
.require_arg(args, name) ⇒ Object
36
37
38
|
# File 'lib/conjur/command.rb', line 36
def require_arg(args, name)
args.shift or raise "Missing parameter: #{name}"
end
|