From 2ecfda07b004bccfcaba9101dda9be9b14c639ae Mon Sep 17 00:00:00 2001 From: Carlos Date: Sun, 30 Jun 2024 19:28:03 +0100 Subject: [PATCH] Added new option to not infere the type of the secret and leave it as String --- lib/arkana.rb | 2 ++ lib/arkana/encoder.rb | 4 ++-- lib/arkana/models/config.rb | 2 ++ lib/arkana/models/type.rb | 4 ++++ spec/encoder_spec.rb | 2 +- template.yml | 1 + 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/arkana.rb b/lib/arkana.rb index 589754a..a4448db 100644 --- a/lib/arkana.rb +++ b/lib/arkana.rb @@ -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 diff --git a/lib/arkana/encoder.rb b/lib/arkana/encoder.rb index 6aa3653..ab64052 100644 --- a/lib/arkana/encoder.rb +++ b/lib/arkana/encoder.rb @@ -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 diff --git a/lib/arkana/models/config.rb b/lib/arkana/models/config.rb index 83d496a..0f7d1d0 100644 --- a/lib/arkana/models/config.rb +++ b/lib/arkana/models/config.rb @@ -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 diff --git a/lib/arkana/models/type.rb b/lib/arkana/models/type.rb index f700616..f94116d 100644 --- a/lib/arkana/models/type.rb +++ b/lib/arkana/models/type.rb @@ -20,4 +20,8 @@ def self.new(string_value:) STRING end end + + def self.default_string + return STRING + end end diff --git a/spec/encoder_spec.rb b/spec/encoder_spec.rb index cb744a0..0a12c0e 100644 --- a/spec/encoder_spec.rb +++ b/spec/encoder_spec.rb @@ -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) { [] } diff --git a/template.yml b/template.yml index 2b83c93..176100f 100644 --- a/template.yml +++ b/template.yml @@ -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