conjur-cli 5.6.6 → 6.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +1 -1
  5. data/APPLIANCE_VERSION +1 -1
  6. data/CHANGELOG.md +3 -42
  7. data/Gemfile +4 -7
  8. data/Humanfile.md +31 -0
  9. data/Jenkinsfile +34 -63
  10. data/README.md +41 -55
  11. data/Rakefile +5 -1
  12. data/bin/conjur +0 -2
  13. data/build-deb.sh +1 -3
  14. data/ci/cli-test.sh +6 -0
  15. data/ci/package.sh +3 -1
  16. data/ci/publish.sh +2 -2
  17. data/ci/secrets/publish.yml +2 -2
  18. data/ci/wait_for_server.sh +10 -0
  19. data/conjur-cli.gemspec +7 -7
  20. data/dev/docker-compose.yml +24 -0
  21. data/dev/start.sh +15 -0
  22. data/dev/stop.sh +5 -0
  23. data/docker-compose.yml +30 -0
  24. data/features/authentication/authenticate.feature +34 -0
  25. data/features/authentication/login.feature +13 -0
  26. data/features/authentication/logout.feature +15 -0
  27. data/{acceptance-features → features}/authentication/whoami.feature +0 -0
  28. data/features/authorization/resource/annotate.feature +22 -0
  29. data/features/authorization/resource/check.feature +47 -0
  30. data/{acceptance-features → features}/authorization/resource/exists.feature +18 -6
  31. data/features/authorization/resource/permitted_roles.feature +35 -0
  32. data/features/authorization/resource/show.feature +34 -0
  33. data/features/authorization/role/exists.feature +28 -0
  34. data/features/authorization/role/members.feature +45 -0
  35. data/features/authorization/role/memberships.feature +43 -0
  36. data/features/conjurenv/check.feature +34 -0
  37. data/features/conjurenv/run.feature +15 -0
  38. data/{acceptance-features → features}/conjurenv/template.feature +8 -3
  39. data/{acceptance-features → features}/directory/user/update_password.feature +8 -2
  40. data/{acceptance-features → features}/directory/variable/value.feature +9 -5
  41. data/{acceptance-features → features}/directory/variable/values-add.feature +8 -3
  42. data/features/hostfactory/tokens.feature +22 -0
  43. data/features/pubkeys/show.feature +18 -0
  44. data/features/step_definitions/authn_steps.rb +22 -0
  45. data/features/step_definitions/cli_steps.rb +28 -0
  46. data/features/step_definitions/file_steps.rb +12 -0
  47. data/features/step_definitions/flow_control_steps.rb +7 -0
  48. data/features/step_definitions/graph_steps.rb +4 -3
  49. data/{acceptance-features → features}/step_definitions/http_steps.rb +0 -0
  50. data/features/step_definitions/overrides.rb +9 -0
  51. data/features/step_definitions/policy_steps.rb +11 -0
  52. data/{acceptance-features → features}/step_definitions/trusted_proxy_steps.rb +0 -0
  53. data/features/support/blank.yml +1 -0
  54. data/features/support/env.rb +21 -7
  55. data/features/support/hooks.rb +31 -116
  56. data/features/support/world.rb +16 -76
  57. data/jenkins.sh +33 -0
  58. data/lib/conjur/authenticator.rb +83 -0
  59. data/lib/conjur/authn.rb +5 -20
  60. data/lib/conjur/cli.rb +13 -6
  61. data/lib/conjur/command.rb +30 -350
  62. data/lib/conjur/command/authn.rb +23 -15
  63. data/lib/conjur/command/host_factories.rb +2 -74
  64. data/lib/conjur/command/hosts.rb +6 -113
  65. data/lib/conjur/command/init.rb +20 -35
  66. data/lib/conjur/command/{secrets.rb → policies.rb} +33 -22
  67. data/lib/conjur/command/pubkeys.rb +3 -63
  68. data/lib/conjur/command/resources.rb +45 -162
  69. data/lib/conjur/command/roles.rb +11 -181
  70. data/lib/conjur/command/rspec/helpers.rb +0 -1
  71. data/lib/conjur/command/rspec/mock_services.rb +4 -4
  72. data/lib/conjur/command/users.rb +2 -159
  73. data/lib/conjur/command/variables.rb +5 -218
  74. data/lib/conjur/complete.rb +2 -2
  75. data/lib/conjur/config.rb +1 -11
  76. data/lib/conjur/conjurenv.rb +12 -9
  77. data/lib/conjur/identifier_manipulation.rb +3 -5
  78. data/lib/conjur/version.rb +2 -2
  79. data/{publish-rubygem.sh → publish.sh} +0 -4
  80. data/spec/authn_spec.rb +4 -0
  81. data/spec/command/hosts_spec.rb +2 -69
  82. data/spec/command/init_spec.rb +16 -11
  83. data/spec/command/pubkeys_spec.rb +1 -46
  84. data/spec/command/resources_spec.rb +21 -170
  85. data/spec/command/roles_spec.rb +5 -181
  86. data/spec/command/users_spec.rb +3 -79
  87. data/spec/command_spec.rb +1 -20
  88. data/spec/complete_spec.rb +1 -23
  89. data/spec/config_spec.rb +1 -1
  90. data/spec/spec_helper.rb +4 -5
  91. data/test.sh +29 -25
  92. metadata +92 -212
  93. data/.githooks/pre_commit/run_specs.rb +0 -23
  94. data/Dockerfile +0 -15
  95. data/Dockerfile.fpm +0 -18
  96. data/Dockerfile.publish +0 -12
  97. data/Dockerfile.standalone +0 -33
  98. data/Dockerfile.validate-packaging +0 -9
  99. data/VERSION +0 -1
  100. data/acceptance-features/audit/audit_event_send.feature +0 -107
  101. data/acceptance-features/audit/fetch.feature +0 -16
  102. data/acceptance-features/audit/send.feature +0 -51
  103. data/acceptance-features/authentication/authenticate.feature +0 -10
  104. data/acceptance-features/authentication/login.feature +0 -12
  105. data/acceptance-features/authentication/logout.feature +0 -13
  106. data/acceptance-features/authorization/resource/annotate.feature +0 -35
  107. data/acceptance-features/authorization/resource/check.feature +0 -24
  108. data/acceptance-features/authorization/resource/create.feature +0 -21
  109. data/acceptance-features/authorization/resource/deny.feature +0 -12
  110. data/acceptance-features/authorization/resource/give.feature +0 -24
  111. data/acceptance-features/authorization/resource/permit.feature +0 -20
  112. data/acceptance-features/authorization/resource/permitted_roles.feature +0 -16
  113. data/acceptance-features/authorization/resource/show.feature +0 -28
  114. data/acceptance-features/authorization/role/create.feature +0 -13
  115. data/acceptance-features/authorization/role/exists.feature +0 -19
  116. data/acceptance-features/authorization/role/grant_to.feature +0 -21
  117. data/acceptance-features/authorization/role/graph.feature +0 -57
  118. data/acceptance-features/authorization/role/members.feature +0 -23
  119. data/acceptance-features/authorization/role/memberships.feature +0 -27
  120. data/acceptance-features/bootstrap.feature +0 -13
  121. data/acceptance-features/conjurenv/check.feature +0 -21
  122. data/acceptance-features/conjurenv/run.feature +0 -10
  123. data/acceptance-features/directory/group/create.feature +0 -20
  124. data/acceptance-features/directory/group/retire.feature +0 -54
  125. data/acceptance-features/directory/host/create.feature +0 -23
  126. data/acceptance-features/directory/host/retire.feature +0 -6
  127. data/acceptance-features/directory/hostfactory/create.feature +0 -28
  128. data/acceptance-features/directory/hostfactory/tokens.feature +0 -16
  129. data/acceptance-features/directory/layer/create.feature +0 -10
  130. data/acceptance-features/directory/layer/hosts-add.feature +0 -9
  131. data/acceptance-features/directory/layer/hosts-remove.feature +0 -10
  132. data/acceptance-features/directory/layer/retire.feature +0 -43
  133. data/acceptance-features/directory/user/create.feature +0 -23
  134. data/acceptance-features/directory/user/retire.feature +0 -6
  135. data/acceptance-features/directory/variable/create.feature +0 -14
  136. data/acceptance-features/directory/variable/retire.feature +0 -17
  137. data/acceptance-features/dsl/policy_owner.feature +0 -45
  138. data/acceptance-features/dsl/resource_owner.feature +0 -17
  139. data/acceptance-features/dsl/retire.feature +0 -15
  140. data/acceptance-features/global-privilege/elevate.feature +0 -20
  141. data/acceptance-features/global-privilege/reveal.privilege +0 -20
  142. data/acceptance-features/pubkeys/add.feature +0 -22
  143. data/acceptance-features/pubkeys/delete.feature +0 -9
  144. data/acceptance-features/pubkeys/names.feature +0 -26
  145. data/acceptance-features/pubkeys/show.feature +0 -27
  146. data/acceptance-features/step_definitions/cli_steps.rb +0 -57
  147. data/acceptance-features/step_definitions/graph_steps.rb +0 -22
  148. data/acceptance-features/step_definitions/user_steps.rb +0 -51
  149. data/acceptance-features/support/env.rb +0 -23
  150. data/acceptance-features/support/hooks.rb +0 -178
  151. data/acceptance-features/support/world.rb +0 -176
  152. data/acceptance-features/trusted_proxies.feature +0 -82
  153. data/bin/conjurize +0 -26
  154. data/bin/jsonfield +0 -70
  155. data/build-standalone +0 -6
  156. data/deprecations.sh +0 -38
  157. data/features/conjurize.feature +0 -134
  158. data/features/dsl_context.feature +0 -36
  159. data/features/dsl_host_create.feature +0 -11
  160. data/features/dsl_ownership.feature +0 -30
  161. data/features/dsl_permission.feature +0 -45
  162. data/features/dsl_resource_create.feature +0 -23
  163. data/features/dsl_role_create.feature +0 -11
  164. data/features/dsl_user_create.feature +0 -23
  165. data/features/jsonfield.feature +0 -49
  166. data/features/role_graph.feature +0 -58
  167. data/features/step_definitions/conjurize_steps.rb +0 -5
  168. data/features/step_definitions/dsl_steps.rb +0 -52
  169. data/features/support/conjur.conf +0 -6
  170. data/lib/conjur/command/assets.rb +0 -121
  171. data/lib/conjur/command/audit.rb +0 -155
  172. data/lib/conjur/command/bootstrap.rb +0 -129
  173. data/lib/conjur/command/dsl_command.rb +0 -75
  174. data/lib/conjur/command/elevate.rb +0 -76
  175. data/lib/conjur/command/field.rb +0 -45
  176. data/lib/conjur/command/groups.rb +0 -208
  177. data/lib/conjur/command/ids.rb +0 -34
  178. data/lib/conjur/command/layers.rb +0 -211
  179. data/lib/conjur/command/ldapsync.rb +0 -118
  180. data/lib/conjur/command/rspec/audit_helpers.rb +0 -68
  181. data/lib/conjur/command/rubydsl.rb +0 -93
  182. data/lib/conjur/command/script.rb +0 -48
  183. data/lib/conjur/command/server.rb +0 -67
  184. data/lib/conjur/conjurize.rb +0 -71
  185. data/lib/conjur/conjurize/script.rb +0 -150
  186. data/lib/conjur/dsl/runner.rb +0 -273
  187. data/publish-deb.sh +0 -6
  188. data/push-image +0 -29
  189. data/spec/command/assets_spec.rb +0 -115
  190. data/spec/command/audit_spec.rb +0 -376
  191. data/spec/command/elevate_spec.rb +0 -28
  192. data/spec/command/env_spec.rb +0 -168
  193. data/spec/command/groups_spec.rb +0 -77
  194. data/spec/command/host_factories_spec.rb +0 -38
  195. data/spec/command/layers_spec.rb +0 -35
  196. data/spec/command/ldapsync_spec.rb +0 -28
  197. data/spec/command/rubydsl_spec.rb +0 -63
  198. data/spec/command/variable_expiration_spec.rb +0 -164
  199. data/spec/command/variables_spec.rb +0 -192
  200. data/spec/conjurize/script_spec.rb +0 -62
  201. data/spec/conjurize_spec.rb +0 -70
  202. data/spec/dsl/runner_spec.rb +0 -93
  203. data/spec/env_spec.rb +0 -214
@@ -1,4 +1,3 @@
1
1
  require 'conjur/command/rspec/describe_command'
2
2
  require 'conjur/command/rspec/output_matchers'
3
3
  require 'conjur/command/rspec/mock_services'
4
- require 'conjur/command/rspec/audit_helpers'
@@ -3,9 +3,10 @@ shared_context "with fake endpoints and test config" do
3
3
  let(:authz_host) { 'https://authz.example.com' }
4
4
  let(:core_host) { 'https://core.example.com/api' }
5
5
  before do
6
- allow(Conjur::Authn::API).to receive(:host) { authn_host }
7
- allow(Conjur::Authz::API).to receive(:host) { authz_host }
8
- allow(Conjur::Core::API).to receive(:host) { core_host }
6
+ allow(Conjur.configuration).to receive(:account) { account }
7
+ allow(Conjur.configuration).to receive(:authn_url) { authn_host }
8
+ allow(Conjur.configuration).to receive(:authz_url) { authz_host }
9
+ allow(Conjur.configuration).to receive(:core_url) { core_host }
9
10
 
10
11
  ENV['GLI_DEBUG'] = 'true'
11
12
  end
@@ -20,7 +21,6 @@ shared_context "with mock authn" do
20
21
  let(:api_key) { 'sekrit' }
21
22
  let(:api) { Conjur::API.new_from_key(username, api_key) }
22
23
  before do
23
- allow(Conjur::Core::API).to receive(:conjur_account) { account }
24
24
  allow(Conjur::Authn).to receive_messages(netrc: netrc, host: authn_host)
25
25
  Conjur::Config.merge 'account' => account
26
26
  end
@@ -24,116 +24,6 @@ class Conjur::Command::Users < Conjur::Command
24
24
  desc "Manage users"
25
25
  command :user do |user|
26
26
 
27
- user.desc "Create a new user [DEPRECATED]"
28
- user.arg_name "NAME"
29
- user.command :create do |c|
30
- c.desc "Prompt for a password for the user (default: --no-password)"
31
- c.switch [:p,:password]
32
-
33
- c.desc "UID number to be associated with user (optional)"
34
- c.flag [:uidnumber]
35
-
36
- c.desc "A comma-delimited list of CIDR addresses to restrict user to (optional)"
37
- c.flag [:cidr]
38
-
39
- acting_as_option(c)
40
-
41
- interactive_option c
42
-
43
- c.action do |global_options,options,args|
44
- notify_deprecated
45
-
46
- login = args.shift
47
-
48
- interactive = options[:interactive] || login.blank?
49
-
50
- groupid = options[:ownerid]
51
- uidnumber = options[:uidnumber]
52
- cidr = format_cidr(options[:cidr])
53
- password = nil
54
-
55
- validate_uidnumber(uidnumber)
56
-
57
- if interactive
58
- login ||= prompt_for_id :user, "login name"
59
-
60
- groupid ||= prompt_for_group hint: "press enter to have the user own their own record"
61
- uidnumber ||= prompt_for_uidnumber
62
- password = prompt_for_password unless options[:"no-password"]
63
-
64
- attributes = {
65
- "Login" => login,
66
- "Owner" => groupid,
67
- "UID Number" => uidnumber,
68
- "CIDR" => cidr
69
- }
70
- attributes["Password"] = "********" unless password.blank?
71
- prompt_to_confirm :user, attributes
72
- end
73
-
74
- if options[:p] && password.blank?
75
- password = prompt_for_password
76
- end
77
-
78
- user_options = { }
79
- user_options[:ownerid] = groupid if groupid
80
- user_options[:uidnumber] = uidnumber.to_i if uidnumber
81
- user_options[:cidr] = cidr unless cidr.nil?
82
- user_options[:password] = password if password
83
- user = api.create_user(login, user_options)
84
-
85
- display user
86
-
87
- if interactive
88
- public_key = prompt_for_public_key
89
- if public_key
90
- api.add_public_key user.login, public_key
91
- puts "Public key added"
92
- end
93
- end
94
- end
95
- end
96
-
97
- user.desc "Show a user"
98
- user.arg_name "USER"
99
- user.command :show do |c|
100
- c.action do |global_options,options,args|
101
- id = require_arg(args, 'USER')
102
- display(api.user(id), options)
103
- end
104
- end
105
-
106
- user.desc "Decommission a user [DEPRECATED]"
107
- user.arg_name "USER"
108
- user.command :retire do |c|
109
- retire_options c
110
-
111
- c.action do |global_options,options,args|
112
- notify_deprecated
113
-
114
- id = require_arg(args, 'USER')
115
-
116
- user = api.user(id)
117
-
118
- validate_retire_privileges user, options
119
-
120
- retire_resource user
121
- retire_role user
122
- give_away_resource user, options
123
-
124
- puts "User retired"
125
- end
126
- end
127
-
128
- user.desc "List users"
129
- user.command :list do |c|
130
- command_options_for_list c
131
-
132
- c.action do |global_options, options, args|
133
- command_impl_for_list global_options, options.merge(kind: "user"), args
134
- end
135
- end
136
-
137
27
  user.desc "Update the password of the logged-in user"
138
28
  user.command :update_password do |c|
139
29
  c.desc "Password to use, otherwise you will be prompted"
@@ -155,9 +45,9 @@ class Conjur::Command::Users < Conjur::Command
155
45
  if options.include?(:user)
156
46
  # Make sure we're not trying to rotate our own key with the user flag.
157
47
  if api.username == options[:user]
158
- exit_now! 'To rotate your own API key, use this command without the --user flag'
48
+ exit_now! 'To rotate the API key of the currently logged-in user, use this command without any flags or options'
159
49
  end
160
- puts api.user(options[:user]).rotate_api_key
50
+ puts api.resource([ Conjur.configuration.account, "user", options[:user] ].join(":")).rotate_api_key
161
51
  else
162
52
  username, password = Conjur::Authn.read_credentials
163
53
  new_api_key = Conjur::API.rotate_api_key username, password
@@ -167,49 +57,6 @@ class Conjur::Command::Users < Conjur::Command
167
57
  end
168
58
  end
169
59
  end
170
-
171
- user.desc "Update a user's attributes [DEPRECATED]"
172
- user.arg_name "USER"
173
- user.command :update do |c|
174
- c.desc "UID number to be associated with user (optional)"
175
- c.flag [:uidnumber]
176
-
177
- c.desc "A comma-delimited list of CIDR addresses to restrict user to (optional). Use 'all' to reset"
178
- c.flag [:cidr]
179
-
180
- c.action do |global_options, options, args|
181
- notify_deprecated
182
-
183
- login=require_arg(args,'USER')
184
-
185
- uidnumber = options[:uidnumber]
186
- cidr = format_cidr(options[:cidr])
187
-
188
- validate_uidnumber(uidnumber)
189
-
190
- user_options = { }
191
- user_options[:uidnumber] = uidnumber.to_i if uidnumber
192
- user_options[:cidr] = cidr unless cidr.nil?
193
-
194
- api.user(login).update(user_options)
195
- puts "User updated"
196
- end
197
- end
198
-
199
- user.desc "Find the user by UID"
200
- user.arg_name "uid"
201
- user.command :uidsearch do |c|
202
- c.action do |global_options, options, args|
203
- uidnumber = require_arg(args,'uid')
204
- raise "Uidnumber should be integer" unless /\d+/ =~ uidnumber
205
- uidnumber=uidnumber.to_i
206
- display api.find_users(uidnumber: uidnumber)
207
- end
208
- end
209
- end
210
-
211
- def self.prompt_for_uidnumber
212
- prompt_for_idnumber "uid number"
213
60
  end
214
61
 
215
62
  def self.format_cidr(cidr)
@@ -222,8 +69,4 @@ class Conjur::Command::Users < Conjur::Command
222
69
  cidr.split(',').each {|x| x.strip!}
223
70
  end
224
71
  end
225
-
226
- def self.validate_uidnumber(uidnumber)
227
- exit_now! 'uidnumber should be integer' unless uidnumber.blank? || /\d+/ =~ uidnumber
228
- end
229
72
  end
@@ -21,116 +21,6 @@
21
21
  class Conjur::Command::Variables < Conjur::Command
22
22
  desc "Manage variables"
23
23
  command :variable do |var|
24
- var.desc "Create and store a variable [DEPRECATED]"
25
- var.arg_name "NAME VALUE"
26
- var.command :create do |c|
27
- c.arg_name "MIME-TYPE"
28
- c.flag [:m, :"mime-type"], default_value: 'text/plain'
29
-
30
- c.arg_name "KIND"
31
- c.flag [:k, :"kind"], default_value: 'secret'
32
-
33
- c.arg_name "VALUE"
34
- c.desc "Initial value, which may also be specified as the second command argument after the variable id"
35
- c.flag [:v, :"value"]
36
-
37
- acting_as_option c
38
-
39
- annotate_option c
40
-
41
- interactive_option c
42
-
43
- c.action do |global_options,options, args|
44
- notify_deprecated
45
-
46
- @default_mime_type = c.flags[:m].default_value
47
- @default_kind = c.flags[:k].default_value
48
-
49
- id = args.shift unless args.empty?
50
- value = args.shift unless args.empty?
51
-
52
- exit_now! "Received conflicting value arguments" if value && options[:value]
53
-
54
- groupid = options[:ownerid]
55
- mime_type = options[:m]
56
- kind = options[:k]
57
- value ||= options[:v]
58
- interactive = options[:interactive] || id.blank?
59
- annotate = options[:annotate]
60
-
61
- exit_now! "Received --annotate option without --interactive" if annotate && !interactive
62
-
63
- annotations = {}
64
- # If the user asked for interactive mode, or he didn't specify and id
65
- # prompt for any missing options.
66
- if interactive
67
- id ||= prompt_for_id :variable
68
-
69
- groupid ||= prompt_for_group
70
-
71
- kind = prompt_for_kind if !kind || kind == @default_kind
72
-
73
- mime_type = prompt_for_mime_type if mime_type.blank? || mime_type == @default_mime_type
74
-
75
- annotations = prompt_for_annotations if annotate
76
-
77
- value ||= prompt_for_value
78
-
79
- prompt_to_confirm :variable, "Id" => id,
80
- "Kind" => kind,
81
- "MIME type" => mime_type,
82
- "Owner" => groupid,
83
- "Value" => value
84
- end
85
-
86
- variable_options = { id: id }
87
- variable_options[:ownerid] = groupid if groupid
88
- variable_options[:value] = value unless value.blank?
89
- var = api.create_variable(mime_type, kind, variable_options)
90
- api.resource(var).annotations.merge!(annotations) if annotations && !annotations.empty?
91
- display(var, options)
92
- end
93
- end
94
-
95
- var.desc "Show a variable"
96
- var.arg_name "VARIABLE"
97
- var.command :show do |c|
98
- c.action do |global_options,options,args|
99
- id = require_arg(args, 'VARIABLE')
100
- display(api.variable(id), options)
101
- end
102
- end
103
-
104
- var.desc "Decommission a variable [DEPRECATED]"
105
- var.arg_name "VARIABLE"
106
- var.command :retire do |c|
107
- retire_options c
108
-
109
- c.action do |global_options,options,args|
110
- notify_deprecated
111
-
112
- id = require_arg(args, 'VARIABLE')
113
-
114
- variable = api.variable(id)
115
-
116
- validate_retire_privileges variable, options
117
-
118
- retire_resource variable
119
- give_away_resource variable, options
120
-
121
- puts "Variable retired"
122
- end
123
- end
124
-
125
- var.desc "List variables"
126
- var.command :list do |c|
127
- command_options_for_list c
128
-
129
- c.action do |global_options, options, args|
130
- command_impl_for_list global_options, options.merge(kind: "variable"), args
131
- end
132
- end
133
-
134
24
  var.desc "Access variable values"
135
25
  var.command :values do |values|
136
26
  values.desc "Add a value"
@@ -139,8 +29,9 @@ class Conjur::Command::Variables < Conjur::Command
139
29
  c.action do |global_options,options,args|
140
30
  id = require_arg(args, 'VARIABLE')
141
31
  value = args.shift || STDIN.read
32
+ assert_empty(args)
142
33
 
143
- api.variable(id).add_value(value)
34
+ api.resource(full_resource_id("variable:#{id}")).add_value(value)
144
35
  puts "Value added"
145
36
  end
146
37
  end
@@ -154,114 +45,10 @@ class Conjur::Command::Variables < Conjur::Command
154
45
 
155
46
  c.action do |global_options,options,args|
156
47
  id = require_arg(args, 'VARIABLE')
157
- $stdout.write api.variable(id).value(options[:version])
158
- end
159
- end
160
-
161
- var.desc 'Set the expiration for a variable'
162
- var.command :expire do |c|
163
- c.arg_name "NOW"
164
- c.desc 'Set variable to expire immediately'
165
- min_version c, '4.6.0'
166
- c.switch [:n, :'now'], :negatable => false
167
-
168
- c.arg_name "DAYS"
169
- c.desc 'Set variable to expire after the given number of days'
170
- c.flag [:d, :'days']
171
-
172
- c.arg_name "MONTHS"
173
- c.desc 'Set variable to expire after the given number of months'
174
- c.flag [:m, :'months']
175
-
176
- c.arg_name "DURATION"
177
- c.desc 'Set variable to expire after the given ISO8601 duration'
178
- c.flag [:i, :'in']
179
-
180
- c.action do |global_options, options, args|
181
- id = require_arg(args, 'VARIABLE')
182
-
183
- exit_now! 'Specify only one duration' if durations(options) > 1
184
- exit_now! 'Specify at least one duration' if durations(options) == 0
185
-
186
- now = options[:n]
187
- days = options[:d]
188
- months = options[:m]
189
-
190
- case
191
- when now.present?
192
- duration = 'P0Y'
193
- when days.present?
194
- duration = "P#{days.to_i}D"
195
- when months.present?
196
- duration = "P#{months.to_i}M"
197
- else
198
- duration = options[:i]
199
- end
200
-
201
- display api.variable(id).expires_in(duration)
202
- end
203
- end
204
-
205
- var.desc 'Display expiring variables'
206
- var.long_desc 'Only variables that expire within the given duration are displayed. If no duration is provided, show all visible variables that are set to expire.'
207
- var.command :expirations do |c|
208
- c.arg_name 'DAYS'
209
- c.desc 'Display variables that expire within the given number of days'
210
- min_version c, '4.6.0'
211
- c.flag [:d, :'days']
212
-
213
- c.arg_name 'MONTHS'
214
- c.desc 'Display variables that expire within the given number of months'
215
- c.flag [:m, :'months']
216
-
217
- c.arg_name 'IN'
218
- c.desc 'Display variables that expire within the given ISO8601 interval'
219
- c.flag [:i, :'in']
220
-
221
- c.action do | global_options, options, args|
222
-
223
- days = options[:d]
224
- months = options[:m]
225
- duration = options[:i]
226
-
227
- exit_now! 'Specify only one duration' if durations(options) > 1
228
-
229
- case
230
- when days.present?
231
- duration = "P#{days.to_i}D"
232
- when months.present?
233
- duration = "P#{months.to_i}M"
234
- end
235
-
236
- display api.variable_expirations(duration)
237
- end
238
- end
239
-
240
- end
241
-
242
- class << self
243
- def prompt_for_kind
244
- highline.ask('Enter the kind: ') {|q| q.default = @default_kind }
245
- end
246
-
247
- def prompt_for_mime_type
248
- highline.choose do |menu|
249
- menu.prompt = 'Enter the MIME type: '
250
- menu.choice @default_mime_type
251
- menu.choices *%w(application/json application/xml application/x-yaml application/x-pem-file)
252
- menu.choice "other", nil do |c|
253
- @highline.ask('Enter a custom mime type: ')
254
- end
48
+ assert_empty(args)
49
+
50
+ $stdout.write api.resource(full_resource_id("variable:#{id}")).value(options[:version])
255
51
  end
256
52
  end
257
-
258
- def prompt_for_value
259
- read_till_eof('Enter the secret value (^D on its own line to finish):')
260
- end
261
-
262
- def durations(options)
263
- [options[:n],options[:d],options[:m],options[:i]].count {|o| o.present?}
264
- end
265
53
  end
266
-
267
54
  end