Sha256: b69dae3c7f75452bc364cdc61d9732025588a1bb0659a7d08c6a594733995b23

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

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

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

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

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

    def loadFile()
        extraConfig = Canzea::config[:catalog_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[:catalog_location] + "/env.json"
        @log.info "Looking at for env vars: #{extraConfig}"
        if File.exists?(extraConfig)
            puts "-- Reading #{extraConfig}"
            file = File.read(extraConfig)
            envs = JSON.parse(file)
            envs['vars'].keys.each { | key |
                val = envs['vars'][key]
                puts "-- #{key} == #{val}"
                @log.info "Setting: #{key} == #{val}"
                ENV.store(key, val)
            }
            envs['secrets'].keys.each { | key |
                val = envs['secrets'][key]
                puts "-- #{key} == XXXXXX"
                @log.info "Setting: #{key} == XXXXXXX"
                ENV.store(key, val)
            }
        end
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
canzea-0.1.77 lib/commands/add-env.rb
canzea-0.1.76 lib/commands/add-env.rb
canzea-0.1.74 lib/commands/add-env.rb
canzea-0.1.73 lib/commands/add-env.rb
canzea-0.1.72 lib/commands/add-env.rb
canzea-0.1.71 lib/commands/add-env.rb
canzea-0.1.70 lib/commands/add-env.rb