Class: Global::Backend::GcpSecretManager

Inherits:
Object
  • Object
show all
Defined in:
lib/global/backend/gcp_secret_manager.rb

Overview

Loads Global configuration from the Google Cloud Secret Manager cloud.google.com/secret-manager/docs

This backend requires the ‘google-cloud-secret_manager` gem, so make sure to add it to your Gemfile.

Available options:

  • ‘project_id` (required): Google Cloud project name

  • ‘prefix` (required): the prefix in Secret Manager; all parameters within the prefix will be loaded; make sure to add a undescore, if you want it see cloud.google.com/secret-manager/docs/overview

  • ‘client`: pass you own Google::Cloud::SecretManager instance, or alternatively set:

  • ‘gcp_options`: credentials and other Google cloud configuration options that are passed to Google::Cloud::SecretManager.configure see googleapis.dev/ruby/google-cloud-secret_manager/latest/index.html If Google Cloud access is already configured through environment variables, you don’t need to pass the credentials explicitly.

For Rails:

  • the ‘prefix` is optional and defaults to `[Rails enviroment]-[Name of the app class]-`,

    for example: `production-myapp-`
    
  • to use a different app name, pass ‘app_name`,

    for example: `backend :gcp_secret_manager, app_name: 'new_name_for_my_app'`
    

Constant Summary collapse

GCP_SEPARATOR =
'/'
PATH_SEPARATOR =
'-'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GcpSecretManager

Returns a new instance of GcpSecretManager.



32
33
34
35
36
37
# File 'lib/global/backend/gcp_secret_manager.rb', line 32

def initialize(options = {})
  @project_id = options.fetch(:project_id)
  require_gcp_gem
  init_prefix(options)
  init_client(options)
end

Instance Method Details

#loadObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/global/backend/gcp_secret_manager.rb', line 39

def load
  pages = load_all_parameters_from_gcsm

  configuration = {}
  pages.each do |page|
    configuration.deep_merge!(build_configuration_from_page(page))
  end

  configuration
end