lib/conjur/command/policy.rb in conjur-asset-policy-0.7.1 vs lib/conjur/command/policy.rb in conjur-asset-policy-0.8.0
- old
+ new
@@ -19,13 +19,13 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require 'conjur-asset-policy'
class Conjur::Command::Policy < Conjur::DSLCommand
- def self.load filename, syntax
+ def self.load filename
script = script_from_filename filename
- loader(filename, syntax).load script, filename
+ loader.load script, filename
end
def self.script_from_filename filename
if filename
if File.exists?(filename)
@@ -43,23 +43,12 @@
else
STDIN.read
end
end
- def self.loader filename, syntax
- if syntax.nil? && filename
- filename =~ /\.([^.]+)$/
- syntax = $1
- end
- raise "No syntax provided or detected" unless syntax
- syntax = case syntax
- when 'yaml', 'yml'
- 'YAML'
- when 'rb', 'ruby'
- 'Ruby'
- end
- mod = Conjur::Policy.const_get syntax
+ def self.loader
+ mod = Conjur::Policy.const_get 'YAML'
mod.const_get "Loader"
end
def self.execute api, records, options = {}
actions = []
@@ -134,13 +123,10 @@
acting_as_option(c)
c.desc "Policy namespace (optional)"
c.flag [:namespace]
- c.desc "Syntax (ruby or YAML, will be auto-detected from file extension)"
- c.flag [:syntax]
-
c.desc "Print the actions that would be performed"
c.switch [:"dry-run"]
c.desc "Output format of --dry-run mode (text, yaml)"
c.default_value "yaml"
@@ -154,11 +140,11 @@
c.action do |global_options,options,args|
Conjur.log = "stderr"
filename = args.pop
- records = load filename, options[:syntax]
+ records = load filename
ownerid = options[:ownerid]
unless ownerid
user_kind, user_id = api.username.split('/', 2)
unless user_id
@@ -177,9 +163,10 @@
puts plan.actions.map(&:to_s)
else
puts plan.actions.to_yaml
end
else
+ $stderr.puts plan.actions.map(&:to_s)
context = execute api, plan.actions
if options[:context]
save_context_to_file context, options[:context]
else