Class: Conjur::Command::DSL2
- Defined in:
- lib/conjur/command/dsl2.rb
Class Method Summary collapse
- .execute(api, records, options = {}) ⇒ Object
- .load(filename, syntax) ⇒ Object
- .loader(filename, syntax) ⇒ Object
- .save_context_to_file(context, path) ⇒ Object
- .script_from_filename(filename) ⇒ Object
Class Method Details
.execute(api, records, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/conjur/command/dsl2.rb', line 64 def self.execute api, records, = {} actions = [] records.each do |record| executor_class = Conjur::DSL2::Executor.class_for(record) executor = Conjur::DSL2::Executor.class_for(record).new(record, actions) executor.execute end Conjur::DSL2::HTTPExecutor.new(api).execute actions end |
.load(filename, syntax) ⇒ Object
24 25 26 27 |
# File 'lib/conjur/command/dsl2.rb', line 24 def self.load filename, syntax script = script_from_filename filename loader(filename, syntax).load script, filename end |
.loader(filename, syntax) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/conjur/command/dsl2.rb', line 48 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::DSL2.const_get syntax mod.const_get "Loader" end |
.save_context_to_file(context, path) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/conjur/command/dsl2.rb', line 75 def self.save_context_to_file context, path existing = if File.file?(path) JSON.load(File.read(path)) else {} end File.write(path, existing.merge(context).to_json) rescue => ex # It would suck to lose all your API keys by fat-fingering the filename -- write it to the stdout if # anything goes wrong. $stderr.puts "Error saving context to #{path}: #{ex}. Context will be written to the stdout" $stderr.puts ex.backtrace.join("\n\t") if ENV['DEBUG'] puts context.to_json end |
.script_from_filename(filename) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/conjur/command/dsl2.rb', line 29 def self.script_from_filename filename if filename if File.exists?(filename) File.read(filename) else require 'open-uri' uri = URI.parse(filename) raise "Unable to read this kind of URL : #{filename}" unless uri.respond_to?(:read) begin uri.read rescue OpenURI::HTTPError raise "Unable to read URI #{filename} : #{$!.}" end end else STDIN.read end end |