Sha256: de7daae1c47aa57b8afe62d6095737f487e54cb01f5b2d714385c1ee4b515bb0

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

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

class AddEnv

    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"
        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}"
                ENV.store(key, val)
            }
            envs['secrets'].keys.each { | key |
                val = envs['secrets'][key]
                puts "-- #{key} == XXXXXX"
                ENV.store(key, val)
            }
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
canzea-0.1.57 lib/commands/add-env.rb
canzea-0.1.56 lib/commands/add-env.rb
canzea-0.1.55 lib/commands/add-env.rb