Class: OnContainer::Secrets::GoogleCloud::EnvLoader

Inherits:
ServiceBase
  • Object
show all
Defined in:
lib/on_container/secrets/google_cloud/env_loader.rb

Constant Summary collapse

ENV_KEY_SUFIX =
'_GOOGLE_CLOUD_SECRET'

Instance Attribute Summary

Attributes inherited from ServiceBase

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::SafePerformable

included, #perform

Class Method Details

.secret_manager?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/on_container/secrets/google_cloud/env_loader.rb', line 21

def self.secret_manager?
  defined?(Google::Cloud::SecretManager) == 'constant'
end

Instance Method Details

#env_keysObject



11
12
13
14
15
# File 'lib/on_container/secrets/google_cloud/env_loader.rb', line 11

def env_keys
  @env_keys ||= ENV.keys.select do |key|
    key.end_with?(ENV_KEY_SUFIX)
  end.sort
end

#env_keys?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/on_container/secrets/google_cloud/env_loader.rb', line 17

def env_keys?
  env_keys.any?
end

#perform!Object



29
30
31
32
33
34
35
36
37
# File 'lib/on_container/secrets/google_cloud/env_loader.rb', line 29

def perform!
  return unless env_keys? && secret_manager?
    
  env_keys.each do |key|
    ENV.merge! Fetcher.perform! ENV[key], client: client
  end
    
  true
end

#secret_manager?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/on_container/secrets/google_cloud/env_loader.rb', line 25

def secret_manager?
  self.class.secret_manager?
end