Class: KubeSecretsEncode::Command

Inherits:
Object
  • Object
show all
Includes:
Executable
Defined in:
lib/kube_secrets_encode.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.usage_nameObject



41
42
43
# File 'lib/kube_secrets_encode.rb', line 41

def self.usage_name
  "kube_secrets"
end

Instance Method Details

#callObject

kube_secrets enables you to encode and decode the base64 encoding of secrets in place within your config files making it easier to modify them.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kube_secrets_encode.rb', line 46

def call()
  documents = []
  if file && File.exists?(file)
    YAML.load_stream(File.open(file)) do |document|
      if document["kind"] == "Secret"
        if document["data"]
          document["data"].each do |k,v|
            if decode?
              document["data"][k] = Base64.strict_decode64(v)
            else
              document["data"][k] = Base64.strict_encode64(v)
            end
          end
        end
      end
      documents << document
    end
    yaml = documents.map{|d| d.to_yaml}.join

    puts yaml
    if yes?
      File.open(file, 'w') { |file| file.write(yaml) }
    end
  else
    cli.show_help
  end
  exit
end

#decode=(bool) ⇒ Object

switch from default encode to decode mode



27
28
29
# File 'lib/kube_secrets_encode.rb', line 27

def decode=(bool)
  @decode = bool
end

#decode?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/kube_secrets_encode.rb', line 30

def decode?
  @decode
end

#fileObject



15
16
17
# File 'lib/kube_secrets_encode.rb', line 15

def file
  @file
end

#file=(filename) ⇒ Object

filename of file being encoded or decoded



12
13
14
# File 'lib/kube_secrets_encode.rb', line 12

def file=(filename)
  @file = filename
end

#help?Boolean Also known as: h?

Show this message.

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/kube_secrets_encode.rb', line 35

def help?
  cli.show_help
  exit
end

#yes=(bool) ⇒ Object

enables write after decode or encode



20
21
22
# File 'lib/kube_secrets_encode.rb', line 20

def yes=(bool)
  @yes = bool
end

#yes?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/kube_secrets_encode.rb', line 23

def yes?
  @yes
end