arkana 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb1bab49c8625e2a2bd1cb8bd378789df20767222714a950028af877a4cfeb81
4
- data.tar.gz: 9978033d03df9ea1c29528d8a506e6f82e43040c5675e81e5a84c2dc692a8b59
3
+ metadata.gz: 1f589f9e9d3ccd550915af3bb90a46717e385e5e7691d1a92a69da3352f187eb
4
+ data.tar.gz: 4871dcda8ae09e6c39d2d94ec0bad3798cdb6b9dec6a1b50e4b7fc6e97231980
5
5
  SHA512:
6
- metadata.gz: 06d2d9248ba8d07e6faa667861a163599e246d61544168d7eebac39e974adf2af0ab4fdf28af7f3582727c4f304dd7d18f3692f7a5b521305865af4df7439e84
7
- data.tar.gz: 242062bff10a161e4a5734a828bcebed1694d3de700f2160720e17d87f3566c3ea68406e80f5e1c4c18a74294423df415881e0804ff75853f7ecf78eb410485a
6
+ metadata.gz: 2dbf5f95c13a18d75f82c0598818e0e4b580e10cdbdf9a10c283c6151a7c1b94b21cd740f849dcf70351ace776a50741c320d22871ab1bda086a29136e715c52
7
+ data.tar.gz: 42ac12f877d80cc5f6e858db44fb78106e260fd1775e43bd7e3c82b8bea1206acb9ab174c4e00249d57c2990b0225593ea81bf7790a2b661171025a2f6c2b92e
@@ -12,6 +12,7 @@ module ConfigParser
12
12
  def self.parse(arguments)
13
13
  yaml = YAML.load_file(arguments.config_filepath)
14
14
  config = Config.new(yaml)
15
+ config.include_environments(arguments.include_environments)
15
16
  config.current_flavor = arguments.flavor
16
17
  config.dotenv_filepath = arguments.dotenv_filepath
17
18
  UI.warn("Dotenv file was specified but couldn't be found at '#{config.dotenv_filepath}'") if config.dotenv_filepath && !File.exist?(config.dotenv_filepath)
@@ -4,18 +4,18 @@
4
4
  module SwiftTemplateHelper
5
5
  def self.swift_type(type)
6
6
  case type
7
- when :string then "String"
8
- when :boolean then "Bool"
9
- when :integer then "Int"
10
- else raise "Unknown variable type '#{type}' received.'"
7
+ when :string then "String"
8
+ when :boolean then "Bool"
9
+ when :integer then "Int"
10
+ else raise "Unknown variable type '#{type}' received.'"
11
11
  end
12
12
  end
13
13
 
14
14
  def self.protocol_getter(declaration_strategy)
15
15
  case declaration_strategy
16
- when "lazy var" then "mutating get"
17
- when "var", "let" then "get"
18
- else raise "Unknown declaration strategy '#{declaration_strategy}' received.'"
16
+ when "lazy var" then "mutating get"
17
+ when "var", "let" then "get"
18
+ else raise "Unknown declaration strategy '#{declaration_strategy}' received.'"
19
19
  end
20
20
  end
21
21
  end
@@ -10,12 +10,15 @@ class Arguments
10
10
  attr_reader :dotenv_filepath
11
11
  # @returns [string]
12
12
  attr_reader :flavor
13
+ # @returns [Array<string>]
14
+ attr_reader :include_environments
13
15
 
14
16
  def initialize
15
17
  # Default values
16
18
  @config_filepath = ".arkana.yml"
17
19
  @dotenv_filepath = ".env" if File.exist?(".env")
18
20
  @flavor = nil
21
+ @include_environments = nil
19
22
 
20
23
  OptionParser.new do |opt|
21
24
  opt.on("-c", "--config-filepath /path/to/your/.arkana.yml", "Path to your config file. Defaults to '.arkana.yml'") do |o|
@@ -27,6 +30,9 @@ class Arguments
27
30
  opt.on("-f", "--flavor FrostedFlakes", "Flavors are useful, for instance, when generating secrets for white-label projects. See the README for more information") do |o|
28
31
  @flavor = o
29
32
  end
33
+ opt.on("-i", "--include-environments debug,release", "Optionally pass the environments that you want Arkana to generate secrets for. Useful if you only want to build a certain environment, e.g. just Debug in local machines, while only building Staging and Release in CI. Separate the keys using a comma, without spaces. When ommitted, Arkana generate secrets for all environments.") do |o|
34
+ @include_environments = o.split(",")
35
+ end
30
36
  end.parse!
31
37
  end
32
38
  end
@@ -63,4 +63,10 @@ class Config
63
63
  def all_keys
64
64
  global_secrets + environment_keys
65
65
  end
66
+
67
+ def include_environments(environments)
68
+ return unless environments
69
+
70
+ @environments = @environments.select { |e| environments.map(&:downcase).include?(e.downcase) }
71
+ end
66
72
  end
@@ -8,12 +8,16 @@ module Type
8
8
 
9
9
  def self.new(string_value:)
10
10
  case string_value
11
- when "true", "false"
12
- BOOLEAN
13
- when /^\d+$/
14
- INTEGER
15
- else
16
- STRING
11
+ when "true", "false"
12
+ BOOLEAN
13
+ when /^\d+$/
14
+ # Handles cases like "0001" which should be interpreted as strings
15
+ return STRING if string_value.to_i.to_s != string_value
16
+ # Handle int overflow
17
+ return STRING if string_value.to_i > (2**31) - 1
18
+ INTEGER
19
+ else
20
+ STRING
17
21
  end
18
22
  end
19
23
  end
@@ -86,6 +86,46 @@ final class <%= @namespace %>Tests: XCTestCase {
86
86
  XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), 42)
87
87
  }
88
88
 
89
+ func test_decodeIntValueWithLeadingZeroes_shouldDecodeAsString() {
90
+ <% int_with_leading_zeroes_key = "0001" %>
91
+ <% secret = generate_test_secret(key: int_with_leading_zeroes_key) %>
92
+ let encoded: [UInt8] = [
93
+ <%= secret.encoded_value %>
94
+
95
+ ]
96
+ XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "0001")
97
+ }
98
+
99
+ func test_decodeMassiveIntValue_shouldDecodeAsString() {
100
+ <% int_with_massive_number_key = "92233720368547758079223372036854775807" %>
101
+ <% secret = generate_test_secret(key: int_with_massive_number_key) %>
102
+ let encoded: [UInt8] = [
103
+ <%= secret.encoded_value %>
104
+
105
+ ]
106
+ XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "92233720368547758079223372036854775807")
107
+ }
108
+
109
+ func test_decodeNegativeIntValue_shouldDecodeAsString() {
110
+ <% negative_int_key = "-42" %>
111
+ <% secret = generate_test_secret(key: negative_int_key) %>
112
+ let encoded: [UInt8] = [
113
+ <%= secret.encoded_value %>
114
+
115
+ ]
116
+ XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "-42")
117
+ }
118
+
119
+ func test_decodeFloatingPointValue_shouldDecodeAsString() {
120
+ <% float_key = "3.14" %>
121
+ <% secret = generate_test_secret(key: float_key) %>
122
+ let encoded: [UInt8] = [
123
+ <%= secret.encoded_value %>
124
+
125
+ ]
126
+ XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "3.14")
127
+ }
128
+
89
129
  func test_encodeAndDecodeValueWithDollarSign_shouldDecode() {
90
130
  <% dollar_sign_key = "real_$lim_shady" %>
91
131
  <% secret = generate_test_secret(key: dollar_sign_key) %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arkana
4
- VERSION = "1.5.0"
4
+ VERSION = "1.6.0"
5
5
  end
data/lib/arkana.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "arkana/config_parser"
4
4
  require_relative "arkana/encoder"
5
5
  require_relative "arkana/helpers/dotenv_helper"
6
+ require_relative "arkana/helpers/ui"
6
7
  require_relative "arkana/models/template_arguments"
7
8
  require_relative "arkana/salt_generator"
8
9
  require_relative "arkana/swift_code_generator"
@@ -30,11 +31,11 @@ module Arkana
30
31
  )
31
32
  rescue StandardError => e
32
33
  # TODO: Improve this by creating an Env/Debug helper
33
- puts("Something went wrong when parsing and encoding your secrets.")
34
- puts("Current Flavor: #{config.current_flavor}")
35
- puts("Dotenv Filepath: #{config.dotenv_filepath}")
36
- puts("Config Filepath: #{arguments.config_filepath}")
37
- raise e
34
+ UI.warn("Something went wrong when parsing and encoding your secrets.")
35
+ UI.warn("Current Flavor: #{config.current_flavor}")
36
+ UI.warn("Dotenv Filepath: #{config.dotenv_filepath}")
37
+ UI.warn("Config Filepath: #{arguments.config_filepath}")
38
+ UI.crash(e.message)
38
39
  end
39
40
  template_arguments = TemplateArguments.new(
40
41
  environment_secrets: environment_secrets,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Oba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-29 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.3.7
115
+ rubygems_version: 3.4.10
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Store your keys and secrets away from your source code. Designed for Android