lib/conjur/command/host_factories.rb in conjur-cli-5.6.6 vs lib/conjur/command/host_factories.rb in conjur-cli-6.0.0.rc1
- old
+ new
@@ -21,70 +21,10 @@
class Conjur::Command::HostFactories < Conjur::Command
desc "Manage host factories"
command :hostfactory do |hf|
- hf.desc "Create a new host factory [DEPRECATED]"
- hf.arg_name "id"
- hf.command :create do |c|
- acting_as_option(c)
-
- c.arg_name "layer"
- c.desc "A space-delimited list of layers to which new hosts will belong"
- c.flag [:l, :layer]
-
- c.action do |global_options,options,args|
- notify_deprecated
-
- id = require_arg(args, 'hostfactory')
-
- unless options[:ownerid]
- exit_now! "Use --as-group or --as-role to indicate the host factory role"
- end
-
- owner_role = api.role(options[:ownerid])
-
- layers = (options[:layer] || "").split(/\s/)
- exit_now! "Provide at least one layer" unless layers.count > 0
-
- unless has_admin?(current_role, owner_role)
- exit_now! "#{owner_role.id} must be an admin of role '#{owner_role.roleid}' to create a host factory for it"
- end
- layers.each do |layerid|
- layer = api.layer(layerid)
- exit_now! "Layer '#{layerid}' does not exist" unless layer.exists?
- unless has_admin?(owner_role, layer.role)
- exit_now! "#{owner_role.id} must be an admin of layer '#{layerid}' to create a host factory for it"
- end
- end
-
- command_options = options.dup
- command_options[:layers] = layers
- command_options[:roleid] = options[:ownerid]
-
- host_factory = api.create_host_factory id, command_options
- display host_factory
- end
- end
-
- hf.desc "Show a host factory"
- hf.arg_name "id"
- hf.command :show do |c|
- c.action do |global_options,options,args|
- id = require_arg(args, 'id')
- display(api.host_factory(id), options)
- end
- end
-
- hf.desc "List host factories"
- hf.command :list do |c|
- command_options_for_list c
- c.action do |global_options, options, args|
- command_impl_for_list global_options, options.merge(kind: "host_factory"), args
- end
- end
-
hf.desc "Operations on tokens"
hf.long_desc <<-DESC
This command creates one or more identical tokens. A token is always created with an
expiration time, which by default is 1 hour from now. The expiration time can be customized
with command arguments specifying the number of minutes, hours, days for which the token
@@ -129,16 +69,14 @@
if duration == 0
duration = 1.hour
end
expiration = Time.now + duration
count = (options[:count] || 1).to_i
- command_options = {}
cidr = format_cidr(options.delete(:cidr))
- command_options[:cidr] = cidr unless cidr.nil?
- tokens = api.host_factory(id).create_tokens expiration, count, command_options
+ tokens = api.resource(full_resource_id("host_factory:#{id}")).create_tokens expiration, count: count, cidr: cidr
display tokens.map(&:to_json)
end
end
tokens.desc "Revoke (delete) a token"
@@ -149,30 +87,20 @@
api.revoke_host_factory_token token
puts "Token revoked"
end
end
-
- tokens.desc "Show a token"
- tokens.arg_name "token"
- tokens.command :show do |c|
- c.action do |global_options,options,args|
- token = require_arg(args, 'token')
-
- display api.show_host_factory_token(token), options
- end
- end
end
hf.desc "Operations on hosts"
hf.command :hosts do |hosts|
hosts.desc "Use a token to create a host"
hosts.arg_name "token host-id"
hosts.command :create do |c|
c.action do |global_options,options,args|
token = require_arg(args, 'token')
id = require_arg(args, 'host-id')
-
+
host = Conjur::API.host_factory_create_host token, id, options
display host
end
end
end