Class: AddEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/add-env.rb

Instance Method Summary collapse

Constructor Details

#initialize(_raw = false) ⇒ AddEnv

Returns a new instance of AddEnv.



6
7
8
9
# File 'lib/commands/add-env.rb', line 6

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

Instance Method Details

#add(key, value) ⇒ Object



11
12
13
14
15
16
# File 'lib/commands/add-env.rb', line 11

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

#addSecret(key, value) ⇒ Object



18
19
20
21
22
23
# File 'lib/commands/add-env.rb', line 18

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

#injectEnvironmentVariablesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/commands/add-env.rb', line 36

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

#loadFileObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/commands/add-env.rb', line 25

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

#pputs(s) ⇒ Object



58
59
60
61
62
# File 'lib/commands/add-env.rb', line 58

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