Class: KubesGoogle::Secrets::Fetcher

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Logging
Defined in:
lib/kubes_google/secrets/fetcher.rb,
lib/kubes_google/secrets/fetcher/sdk.rb,
lib/kubes_google/secrets/fetcher/base.rb,
lib/kubes_google/secrets/fetcher/gcloud.rb

Defined Under Namespace

Classes: Base, Gcloud, Sdk

Constant Summary collapse

@@cache =
{}

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Fetcher

Returns a new instance of Fetcher.



6
7
8
# File 'lib/kubes_google/secrets/fetcher.rb', line 6

def initialize(options={})
  @options = options
end

Instance Method Details

#fetch(short_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kubes_google/secrets/fetcher.rb', line 11

def fetch(short_name)
  return @@cache[short_name] if @@cache[short_name]
  if ENV['KUBES_MOCK_SECRET']
    logger.info "KUBES_MOCK_SECRET=1 is set. Mocking secret: #{short_name}" unless ENV['KUBES_MOCK_SECRET_QUIET']
    @@cache[short_name] = "mock"
  else
    logger.debug "Fetching secret: #{short_name}"
    @@cache[short_name] = fetcher.fetch(short_name)
  end
rescue KubesGoogle::VpnSslError
  logger.info "Retry fetching secret with the gcloud strategy"
  fetcher = Gcloud.new(@options)
  fetcher.fetch(short_name)
end

#fetcherObject



26
27
28
29
30
31
32
# File 'lib/kubes_google/secrets/fetcher.rb', line 26

def fetcher
  if KubesGoogle.config.secrets.fetcher == "sdk"
    Sdk.new(@options)
  else
    Gcloud.new(@options)
  end
end