Sha256: 4655020605c32bf0da1104882da15be5b30d3b4dab051f1f2438c1db351fa34f

Contents?: true

Size: 1.83 KB

Versions: 68

Compression:

Stored size: 1.83 KB

Contents

require 'json'
require 'logger'
require 'plan-step-class'

class AddEnv
    def initialize (_raw = false)
        @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
        @raw = _raw
    end

    def add (key, value)
        extraConfig = Canzea::config[:config_location] + "/env.json"
        envs = loadFile()
        envs["vars"][key] = value
        File.write(extraConfig, JSON.generate(envs))
    end

    def addSecret (key, value)
        extraConfig = Canzea::config[:config_location] + "/env.json"
        envs = loadFile()
        envs['secrets'][key] = value
        File.write(extraConfig, JSON.generate(envs))
    end

    def loadFile()
        extraConfig = Canzea::config[:config_location] + "/env.json"
        if File.exists?(extraConfig)
            file = File.read(extraConfig)
            envs = JSON.parse(file)
        else
            envs = {"vars"=>{}, "secrets"=>{}}
        end
        return envs
    end

    def injectEnvironmentVariables()
        extraConfig = Canzea::config[:config_location] + "/env.json"
        @log.info "Looking at for env vars: #{extraConfig}"
        if File.exists?(extraConfig)
            pputs "-- Reading #{extraConfig}"
            file = File.read(extraConfig)
            envs = JSON.parse(file)
            envs['vars'].keys.each { | key |
                val = envs['vars'][key]
                pputs "--    #{key} == #{val}"
                @log.info "Setting: #{key} == #{val}"
                ENV.store(key, val)
            }
            envs['secrets'].keys.each { | key |
                val = envs['secrets'][key]
                pputs "--    #{key} == XXXXXX"
                @log.info "Setting: #{key} == XXXXXXX"
                ENV.store(key, val)
            }
        end
    end

    def pputs (s)
        if (@raw == false)
            puts "#{s}"
        end
    end

end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
canzea-0.1.180 lib/commands/add-env.rb
canzea-0.1.179 lib/commands/add-env.rb
canzea-0.1.178 lib/commands/add-env.rb
canzea-0.1.177 lib/commands/add-env.rb
canzea-0.1.176 lib/commands/add-env.rb
canzea-0.1.175 lib/commands/add-env.rb
canzea-0.1.174 lib/commands/add-env.rb
canzea-0.1.173 lib/commands/add-env.rb
canzea-0.1.172 lib/commands/add-env.rb
canzea-0.1.171 lib/commands/add-env.rb
canzea-0.1.170 lib/commands/add-env.rb
canzea-0.1.169 lib/commands/add-env.rb
canzea-0.1.167 lib/commands/add-env.rb
canzea-0.1.166 lib/commands/add-env.rb
canzea-0.1.165 lib/commands/add-env.rb
canzea-0.1.160 lib/commands/add-env.rb
canzea-0.1.159 lib/commands/add-env.rb
canzea-0.1.158 lib/commands/add-env.rb
canzea-0.1.157 lib/commands/add-env.rb
canzea-0.1.156 lib/commands/add-env.rb