Class: ClusterSecretAdapter
- Inherits:
-
Object
- Object
- ClusterSecretAdapter
- Defined in:
- lib/adapters/cluster_secret_adapter.rb
Direct Known Subclasses
Constant Summary collapse
- CCLI_FLAG_LABEL =
'cryptopus-sync'
Instance Method Summary collapse
Instance Method Details
#fetch_all_secrets ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/adapters/cluster_secret_adapter.rb', line 23 def fetch_all_secrets raise client_missing_error unless client_installed? raise client_not_logged_in_error unless client_logged_in? secrets, _err = cmd.run("#{client} get secret -o yaml -l #{CCLI_FLAG_LABEL}=true") Psych.load(secrets)['items'].map do |secret| secret.to_yaml end end |
#fetch_secret(name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/adapters/cluster_secret_adapter.rb', line 9 def fetch_secret(name) raise client_missing_error unless client_installed? raise client_not_logged_in_error unless client_logged_in? begin out, _err = cmd.run("#{client} get -o yaml secret --field-selector='metadata.name=#{name}' " \ "-l #{CCLI_FLAG_LABEL}=true") Psych.load(out)['items'].first.to_yaml rescue TTY::Command::ExitError raise OpenshiftSecretNotFoundError end end |
#insert_secret(secret) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/adapters/cluster_secret_adapter.rb', line 33 def insert_secret(secret) raise client_missing_error unless client_installed? raise client_not_logged_in_error unless client_logged_in? File.open("/tmp/#{secret.name}.yml", 'w') do |file| file.write secret.to_yaml end cmd.run("#{client} delete -f /tmp/#{secret.name}.yml --ignore-not-found=true") cmd.run("#{client} create -f /tmp/#{secret.name}.yml") end |