Sha256: 8d3c40cec5581be85908110b607d625a8afba798a6549bab01f5769bd9826c11

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'thor'
require 'encrypted_env'

module EncryptedEnv
  class Cli < Thor
    desc "bash key=value key1=value1 ...", "prints output that bash can understand"
    method_option :key, :aliases => '-k', :type => :string, :required => true
    def bash(*args)
      encrypt(*args) do |key,value|
        puts %Q(export "#{key}"="#{value}")
      end
    end

    desc "heroku key=value key1=value1 ...", 'prints output that heroku can understand'
    method_option :remote, :aliases => '-r', :type => :string
    method_option :key, :aliases => '-k', :type => :string, :required => true
    def heroku(*args)
      heroku_opt = "-r #{options[:remote]}" if options[:remote]
      encrypt(*args) do |key,value|
        puts %Q(heroku config:add #{heroku_opt} "#{key}=#{value}")
      end
    end

    no_tasks do
      def encrypt(*args, &block)
        EncryptedEnv.default_options = {:key => options[:key]}
        args.each do |arg|
          key,value = arg.split('=')
          yield key, EncryptedEnv.encrypt(value)
        end
      end
    end

    desc 'decrypt key ...', 'Decrypts a key in the ENV'
    method_option :key, :aliases => '-k', :type => :string, :required => true
    def decrypt(*args)
      EncryptedEnv.default_options = {:key => options[:key]}
      args.each do |key|
        puts "#{key}: #{::ENV.decrypt key}" rescue nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
encrypted_env-0.0.1 lib/encrypted_env/cli.rb