Class: Conjur::Command
Direct Known Subclasses
Assets, Audit, Authn, Field, Groups, Hosts, Id, Init, Resources, Roles, Secrets, Users, Variables, DSLCommand
Defined Under Namespace
Classes: Assets, Audit, Authn, Field, Groups, Hosts, Id, Init, Policy, Resources, Roles, Script, Secrets, Users, Variables
Constant Summary
collapse
- @@api =
nil
Class Attribute Summary collapse
Class Method Summary
collapse
conjur_account, full_resource_id, get_kind_and_id_from_args
Class Attribute Details
.prefix ⇒ Object
Returns the value of attribute prefix.
28
29
30
|
# File 'lib/conjur/command.rb', line 28
def prefix
@prefix
end
|
Class Method Details
.acting_as_option(command) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/conjur/command.rb', line 46
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
42
43
44
|
# File 'lib/conjur/command.rb', line 42
def api
@@api ||= Conjur::Authn.connect
end
|
.command(name, *a, &block) ⇒ Object
34
35
36
|
# File 'lib/conjur/command.rb', line 34
def command name, *a, &block
Conjur::CLI.command "#{prefix}:#{name}", *a, &block
end
|
.command_impl_for_list(global_options, options, args) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/conjur/command.rb', line 74
def command_impl_for_list(global_options, options, args)
opts = options.slice(:search, :limit, :options, :kind)
opts[:acting_as] = options[:role] if options[:role]
resources = api.resources(opts)
if options[:ids]
puts resources.map(&:resourceid)
else
resources = resources.map &:attributes
unless options[:'raw-annotations']
resources = resources.map do |r|
r['annotations'] = (r['annotations'] || []).inject({}) do |hash, annot|
hash[annot['name']] = annot['value']
hash
end
r
end
end
puts JSON.pretty_generate resources
end
end
|
.command_options_for_list(c) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/conjur/command.rb', line 54
def command_options_for_list(c)
c.desc "Role to act as. By default, the current logged-in role is used."
c.flag [:role]
c.desc "Full-text search on resource id and annotation values"
c.flag [:s, :search]
c.desc "Maximum number of records to return"
c.flag [:l, :limit]
c.desc "Offset to start from"
c.flag [:o, :offset]
c.desc "Show only ids"
c.switch [:i, :ids]
c.desc "Show annotations in 'raw' format"
c.switch [:r, :"raw-annotations"]
end
|
.display(obj, options = {}) ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/conjur/command.rb', line 111
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
|
.display_members(members, options) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/conjur/command.rb', line 96
def display_members(members, options)
result = if options[:V]
members.collect {|member|
{
member: member.member.roleid,
grantor: member.grantor.roleid,
admin_option: member.admin_option
}
}
else
members.map(&:member).map(&:roleid)
end
display result
end
|
.method_missing(*a) ⇒ Object
30
31
32
|
# File 'lib/conjur/command.rb', line 30
def method_missing *a
Conjur::CLI.send *a
end
|
.require_arg(args, name) ⇒ Object
38
39
40
|
# File 'lib/conjur/command.rb', line 38
def require_arg(args, name)
args.shift or raise "Missing parameter: #{name}"
end
|