Sha256: d79aa4a59adc4d096c32778fd8e584cdda9c264cbfb4686a6ba45771313e1af7

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

#
# Copyright (C) 2014 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/command'

class Conjur::DSLCommand < Conjur::Command
  class << self
    def file_or_stdin_arg(args)
    end

    def run_script(args, options, &block)
      filename = nil
      script = if script = args.pop
        filename = script
        script = File.read(script)
      else
        STDIN.read
      end
      
      require 'conjur/dsl/runner'
      runner = Conjur::DSL::Runner.new(script, filename)

      if context = options[:context]
        runner.context = begin
          JSON.parse(File.read(context)) 
        rescue Errno::ENOENT 
          {}
        end
      end
      
      if block_given?
        block.call(runner) do
          runner.execute
        end
      else
        runner.execute
      end
      
      if context
        File.write(context, JSON.pretty_generate(runner.context))
        File.chmod(0600, context)
      end

      puts JSON.pretty_generate(runner.context)
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
conjur-cli-4.8.0 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.5 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.4 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.3 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.2 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.1 lib/conjur/command/dsl_command.rb
conjur-cli-4.7.0 lib/conjur/command/dsl_command.rb