Class: NeonSecrets::Getter
- Inherits:
-
Object
- Object
- NeonSecrets::Getter
- Defined in:
- lib/neon_secrets.rb
Instance Attribute Summary collapse
-
#gcp_secret_name ⇒ Object
readonly
Returns the value of attribute gcp_secret_name.
-
#secret_name ⇒ Object
readonly
Returns the value of attribute secret_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(secret_name:, gcp_secret_name:) ⇒ Getter
constructor
A new instance of Getter.
- #secret_value ⇒ Object
Constructor Details
#initialize(secret_name:, gcp_secret_name:) ⇒ Getter
Returns a new instance of Getter.
15 16 17 18 |
# File 'lib/neon_secrets.rb', line 15 def initialize(secret_name:, gcp_secret_name:) @secret_name = secret_name.upcase @gcp_secret_name = gcp_secret_name end |
Instance Attribute Details
#gcp_secret_name ⇒ Object (readonly)
Returns the value of attribute gcp_secret_name.
38 39 40 |
# File 'lib/neon_secrets.rb', line 38 def gcp_secret_name @gcp_secret_name end |
#secret_name ⇒ Object (readonly)
Returns the value of attribute secret_name.
38 39 40 |
# File 'lib/neon_secrets.rb', line 38 def secret_name @secret_name end |
Class Method Details
.get(secret_name:, gcp_secret_name: nil) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/neon_secrets.rb', line 8 def self.get(secret_name:, gcp_secret_name: nil) new( secret_name: secret_name, gcp_secret_name: gcp_secret_name ).secret_value end |
Instance Method Details
#secret_value ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/neon_secrets.rb', line 20 def secret_value if neon_env == "development" ENV.fetch(secret_name) else client = Google::Cloud::SecretManager.secret_manager_service version_path = client.secret_version_path( project: "neon-law-#{neon_env.downcase}", secret: gcp_secret_name, secret_version: "latest" ) secret_values = client.access_secret_version name: version_path JSON.parse(secret_values.payload.data).fetch(secret_name) end end |