lib/conjur/command/assets.rb in conjur-cli-2.6.0 vs lib/conjur/command/assets.rb in conjur-cli-4.1.0
- old
+ new
@@ -1,50 +1,73 @@
+#
+# Copyright (C) 2013 Conjur Inc
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+# the Software, and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
require 'conjur/authn'
require 'conjur/command'
class Conjur::Command::Assets < Conjur::Command
self.prefix = :asset
desc "Create an asset"
- arg_name "kind id"
+ arg_name "kind:id"
command :create do |c|
acting_as_option(c)
c.action do |global_options, options, args|
- kind = require_arg(args, 'kind').gsub('-', '_')
-
+ # NOTE: no generic functions there, as :id is optional
+ kind, id = require_arg(args, 'kind:id').split(':')
+ id = nil if id.blank?
+ kind.gsub!('-', '_')
+
+
m = "create_#{kind}"
record = if [ 1, -1 ].member?(api.method(m).arity)
- id = args.shift
if id
options[:id] = id
end
api.send(m, options)
else
- id = require_arg(args, 'id')
+ unless id
+ raise "for kind #{kind} id should be specified explicitly after colon"
+ end
api.send(m, id, options)
end
display(record, options)
end
end
desc "Show an asset"
- arg_name "kind id"
+ arg_name "id"
command :show do |c|
c.action do |global_options,options,args|
- kind = require_arg(args, "kind").gsub('-', '_')
- id = require_arg(args, "resource-id")
+ kind, id = get_kind_and_id_from_args(args, 'id')
display api.send(kind, id).attributes
end
end
desc "Checks for the existance of an asset"
- arg_name "kind id"
+ arg_name "id"
command :exists do |c|
c.action do |global_options,options,args|
- kind = require_arg(args, "kind").gsub('-', '_')
- id = require_arg(args, "id")
+ kind, id = get_kind_and_id_from_args(args, 'id')
puts api.send(kind, id).exists?
end
end
desc "List an asset"
@@ -57,18 +80,17 @@
end
end
end
desc "Add a member to an asset"
- arg_name "kind id role-name member"
+ arg_name "id role-name member"
command :"members:add" do |c|
c.desc "Grant with admin option"
c.flag [:a, :admin]
c.action do |global_options, options, args|
- kind = require_arg(args, "kind").gsub('-', '_')
- id = require_arg(args, "resource-id")
+ kind, id = get_kind_and_id_from_args(args, 'id')
role_name = require_arg(args, 'role-name')
member = require_arg(args, 'member')
admin_option = !options.delete(:admin).nil?
asset = api.send(kind, id)
@@ -79,14 +101,13 @@
puts "Membership granted"
end
end
desc "Remove a member from an asset"
- arg_name "kind id role-name member"
+ arg_name "id role-name member"
command :"members:remove" do |c|
c.action do |global_options, options, args|
- kind = require_arg(args, "kind").gsub('-', '_')
- id = require_arg(args, "resource-id")
+ kind, id = get_kind_and_id_from_args(args, 'id')
role_name = require_arg(args, 'role-name')
member = require_arg(args, 'member')
admin_option = !options.delete(:admin).nil?
asset = api.send(kind, id)
\ No newline at end of file