Class: OnContainer::Secrets::GoogleCloud::Fetcher

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

Constant Summary collapse

PROJECT_PATTERN =
%r{\Aprojects\/(\w+)\/.*}.freeze
SECRET_NAME_PATTERN =
%r{secrets\/([\w-]+)\/?}.freeze
SECRET_VERSION_PATTERN =
%r{versions\/(\d+|latest)\z}.freeze

Instance Attribute Summary collapse

Attributes inherited from ServiceBase

#client

Instance Method Summary collapse

Methods included from Common::SafePerformable

included, #perform

Constructor Details

#initialize(given_key, client: nil) ⇒ Fetcher

Returns a new instance of Fetcher.



16
17
18
19
20
21
# File 'lib/on_container/secrets/google_cloud/fetcher.rb', line 16

def initialize(given_key, client: nil)
  @client = client
  @project = extract_project given_key
  @secret_version = extract_secret_version given_key
  @secret_name = extract_secret_name given_key
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



14
15
16
# File 'lib/on_container/secrets/google_cloud/fetcher.rb', line 14

def project
  @project
end

#secret_nameObject (readonly)

Returns the value of attribute secret_name.



14
15
16
# File 'lib/on_container/secrets/google_cloud/fetcher.rb', line 14

def secret_name
  @secret_name
end

#secret_versionObject (readonly)

Returns the value of attribute secret_version.



14
15
16
# File 'lib/on_container/secrets/google_cloud/fetcher.rb', line 14

def secret_version
  @secret_version
end

Instance Method Details

#perform!Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/on_container/secrets/google_cloud/fetcher.rb', line 23

def perform!
  # Build the resource name of the secret version.
  name = client.secret_version_path project:        @project,
                                    secret:         @secret_name,
                                    secret_version: @secret_version
      
  version = client.access_secret_version name: name
      
  YAML.load version.payload.data
end