Skip to content

Commit

Permalink
Added new option to not infere the type of the secret and leave it as…
Browse files Browse the repository at this point in the history
… String
  • Loading branch information
CarlosNano committed Jun 30, 2024
1 parent 34826d6 commit 2ecfda0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/arkana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def self.run(arguments)
salt: salt,
current_flavor: config.current_flavor,
environments: config.environments,
inference_secret_type: config.inference_secret_types,
)
global_secrets = Encoder.encode!(
keys: config.global_secrets,
salt: salt,
current_flavor: config.current_flavor,
environments: config.environments,
inference_secret_type: config.inference_secret_types,
)
rescue StandardError => e
# TODO: Improve this by creating an Env/Debug helper
Expand Down
4 changes: 2 additions & 2 deletions lib/arkana/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module Encoder
# Fetches values of each key from ENV, and encodes them using the given salt.
#
# @return [Secret[]] an array of Secret objects, which contain their keys and encoded values.
def self.encode!(keys:, salt:, current_flavor:, environments:)
def self.encode!(keys:, salt:, current_flavor:, environments:, inference_secret_type:)
keys.map do |key|
secret = find_secret!(key: key, current_flavor: current_flavor)
encoded_value = encode(secret, salt.raw)
secret_type = Type.new(string_value: secret)
secret_type = inference_secret_type ? Type.new(string_value: secret) : Type.default_string
protocol_key = protocol_key(key: key, environments: environments)
Secret.new(key: key, protocol_key: protocol_key, encoded_value: encoded_value, type: secret_type)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/arkana/models/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Config
attr_reader :kotlin_jvm_toolchain_version
# @returns [boolean]
attr_reader :is_kotlin_multiplatform_module
# @returns [boolean]
attr_reader :inference_secret_types

# @returns [string]
attr_accessor :current_flavor
Expand Down
4 changes: 4 additions & 0 deletions lib/arkana/models/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ def self.new(string_value:)
STRING
end
end

def self.default_string
return STRING
end
end
2 changes: 1 addition & 1 deletion spec/encoder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Encoder do
subject { described_class.encode!(keys: keys, salt: salt, current_flavor: current_flavor, environments: environments) }
subject { described_class.encode!(keys: keys, salt: salt, current_flavor: current_flavor, environments: environments, inference_secret_type: inference_secret_type) }

let(:salt) { SaltGenerator.generate }
let(:environments) { [] }
Expand Down
1 change: 1 addition & 0 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kotlin_sources_path: 'java' # Optional. The path for the generated Kotlin classe
should_generate_gradle_build_file: true # Optional. Whether a build.gradle file should be generated, when running the Kotlin generator. One of: true, false. Defaults to true.
is_kotlin_multiplatform_module: true # Optional. Whether the generated Kotlin module is a multiplatform module. One of: true, false. Defaults to false.
kotlin_jvm_toolchain_version: 11 # Optional. The kotlin JVM toolchain JDK version to be used in the generated build.gradle file. Defaults to 11.
inference_value_types: true # Optional. Whether if arkana inferences the types of the values. If false the type will always be String. Defaults to true.
environments: # Optional. List of environments that will be used to generate secret keys when you have keys that are different between environments (e.g. debug/staging/prod). Defaults to empty.
- Debug
- Release
Expand Down

0 comments on commit 2ecfda0

Please sign in to comment.