arkana 1.4.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: 22608014d403cf3e16f5d5f13d92cbab02691de72f98492de289c0a1cb53ed64
4
- data.tar.gz: ba1209829e1ac32b881febadcfc74dca440cdaab81a259dc7d034c1ab3363306
3
+ metadata.gz: 1f589f9e9d3ccd550915af3bb90a46717e385e5e7691d1a92a69da3352f187eb
4
+ data.tar.gz: 4871dcda8ae09e6c39d2d94ec0bad3798cdb6b9dec6a1b50e4b7fc6e97231980
5
5
  SHA512:
6
- metadata.gz: 58de3a4b5cf38c589de28dfb656a84f8b9c8e1464996eed8573acd119d6468fb2ec8c3cf0c5fea7df76a57b1cf099b58aa69bf1804a301176ac2b5af583e2c6c
7
- data.tar.gz: 4591ab624fdf27570fbf78b084124b131ed8af389be6dba34ed2a3d81f456f093825ae436c4af6bab5f6250453a4aa6ac6aed7ba7f42013a11c18338f75a1712
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
@@ -24,6 +24,8 @@ class Config
24
24
  attr_reader :should_generate_unit_tests
25
25
  # @returns [string]
26
26
  attr_reader :package_manager
27
+ # @returns [boolean]
28
+ attr_reader :should_cocoapods_cross_import_modules
27
29
 
28
30
  # @returns [string]
29
31
  attr_accessor :current_flavor
@@ -45,6 +47,8 @@ class Config
45
47
  @should_generate_unit_tests = yaml["should_generate_unit_tests"]
46
48
  @should_generate_unit_tests = true if @should_generate_unit_tests.nil?
47
49
  @package_manager = yaml["package_manager"] || "spm"
50
+ @should_cocoapods_cross_import_modules = yaml["should_cocoapods_cross_import_modules"]
51
+ @should_cocoapods_cross_import_modules = true if @should_cocoapods_cross_import_modules.nil?
48
52
  end
49
53
  # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
50
54
 
@@ -59,4 +63,10 @@ class Config
59
63
  def all_keys
60
64
  global_secrets + environment_keys
61
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
62
72
  end
@@ -24,6 +24,8 @@ class TemplateArguments
24
24
  @swift_declaration_strategy = config.swift_declaration_strategy
25
25
  # Whether unit tests should be generated.
26
26
  @should_generate_unit_tests = config.should_generate_unit_tests
27
+ # Whether cocoapods modules should cross import.
28
+ @should_cocoapods_cross_import_modules = config.should_cocoapods_cross_import_modules
27
29
  end
28
30
 
29
31
  def environment_protocol_secrets(environment)
@@ -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
@@ -5,7 +5,14 @@
5
5
  // Automatically generated by Arkana (https://github.com/rogerluan/arkana)
6
6
 
7
7
  import Foundation
8
+ <% if !@should_cocoapods_cross_import_modules %>
9
+ #if COCOAPODS
10
+ #else
11
+ <% end %>
8
12
  import <%= @import_name %>Interfaces
13
+ <% if !@should_cocoapods_cross_import_modules %>
14
+ #endif
15
+ <% end %>
9
16
 
10
17
  public enum <%= @namespace %> {
11
18
  @inline(__always)
@@ -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) %>
@@ -95,6 +135,7 @@ final class <%= @namespace %>Tests: XCTestCase {
95
135
  ]
96
136
  XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "real_$lim_shady")
97
137
  }
138
+ <% if ENV["ARKANA_RUNNING_CI_INTEGRATION_TESTS"] %>
98
139
 
99
140
  func test_decodeEnvVarFromDotfile_withDollarSign__andEscaped_andNoQuotes_shouldDecode() {
100
141
  XCTAssertEqual(globalSecrets.secretWithDollarSignEscapedAndAndNoQuotesKey, "real_$lim_shady")
@@ -119,4 +160,5 @@ final class <%= @namespace %>Tests: XCTestCase {
119
160
  func test_decodeEnvVarFromDotfile_withWeirdCharacters_shouldDecode() {
120
161
  XCTAssertEqual(globalSecrets.secretWithWeirdCharactersKey, "` ~ ! @ # % ^ & * ( ) _ - + = { [ } } | : ; ' < , > . ? /")
121
162
  }
163
+ <% end %>
122
164
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arkana
4
- VERSION = "1.4.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.4.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-03-01 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
@@ -105,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: 2.6.9
108
+ version: '2.7'
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
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