Class: ConfigOMat::Op::LoadSecret

Inherits:
LifecycleVM::OpBase
  • Object
show all
Defined in:
lib/config_o_mat/secrets_loader/op/load_secret.rb

Instance Method Summary collapse

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/config_o_mat/secrets_loader/op/load_secret.rb', line 27

def call
  opts = {
    secret_id: loading_secret.secret_id
  }

  if loading_secret.version_id
    opts[:version_id] = loading_secret.version_id
  else
    opts[:version_stage] = loading_secret.version_stage
  end

  response =
    begin
      secretsmanager_client.get_secret_value(opts)
    rescue StandardError => e
      error loading_secret.name, e
      nil
    end

  return if response.nil? || errors?

  loaded_secret = LoadedSecret.new(
    loading_secret.name, loading_secret.secret_id, response.version_id,
    response.secret_string, loading_secret.content_type
  )

  logger&.info(
    :loaded_secret, name: loading_secret.name, arn: response.arn,
    version_id: response.version_id
  )

  begin
    loaded_secret.validate!
  rescue StandardError => e
    logger&.error(
      :invalid_secret, name: loading_secret.name, arn: response.arn,
      version_id: response.version_id, errors: e
    )
    error loaded_secret.name, e
  end

  return if errors?

  secrets_cache[loading_secret.secret_id] = loaded_secret
  loaded_secrets[loading_secret] = loaded_secret
  self.loading_secret = nil
end