对于 Android 和 iOS 项目,请使用 dotenv 文件。
Your project must be using the Gradle Build Tool.
Your project must be using Swift Package Manager or CocoaPods as dependency manager (or both). No support for Carthage.
Note: this gem was only tested in macOS environments.
Click here to see the Kotlin preview
The image below shows how the auto-generated file looks like.
Usage using the example code above:
import com.arkanakeys.MySecrets
// Designed with testability and DI in mind
println(MySecrets.Global.someBooleanSecret)
println(MySecrets.Global.someIntSecret)
println(MySecrets.Global.mySecretAPIKey)
// Simulating environment selection using a random boolean value
val keys = if (Math.random()
### Swift
Click here to see the Swift preview
The image below shows how the auto-generated file looks like.
Usage using the example code above:
```swift
import ArkanaKeys
// Designed with testability and DI in mind
print(MySecrets.Global().someBooleanSecret)
print(MySecrets.Global().someIntSecret)
print(MySecrets.Global().mySecretAPIKey)
// This is a demo, so we are using Bool.random() to simulate the environment
let keys: MySecretsEnvironmentProtocol = Bool.random() ? MySecrets.Dev() : MySecrets.Staging()
print(keys.serviceKey)Add this gem to your Gemfile if you're using bundler (recommended):
gem 'arkana'And then run bundle install to install it.
Alternatively, you can install it in your entire system instead (not recommended):
gem install arkanaArkana requires the declaration of a YAML config file. Although you can name it whatever, the convention is to name it .arkana.yml. See template.yml for complete options.
Once you have created your config file, you can run Arkana:
Usage: arkana [options]
-c /path/to/your/.arkana.yml, Path to your config file. Defaults to '.arkana.yml'
-e /path/to/your/.env, Path to your dotenv file. Defaults to '.env' if one exists.
-l kotlin Language to produce keys for, e.g. kotlin, swift. Defaults to 'swift'.
…
yaml
environments:
- Release
- Debug
environment_secrets:
- apiKey
global_secrets:
- clientIDCoupled with env vars (or a .env file):
apiKeyDebug = "your_debug_api_key"
apiKeyRelease = "your_release_api_key"
clientID = "your_client_id"[!IMPORTANT] Notice how arkana needs you to name your env var keys by appending the environment name to the environment secrets, e.g.
apiKeyenvironment secret requiresapiKeyDebugandapiKeyReleaseenv vars.
Would generate the following accessors:
// Swift
public extension ArkanaKeys {
struct Global: ArkanaKeysGlobalProtocol {
public let clientID: String = {}
}
}
public extension ArkanaKeys {
struct Release: ArkanaKeysEnvironmentProtocol {
public let apiKey: String = {}
}
}
public extension ArkanaKeys {
struct Debug: ArkanaKeysEnvironmentProtocol {
public let apiKey: String = {}
}
}
…
swift
…
dependencies: [
…
.package(name: "ArkanaKeys", path: "path/to/your/dependencies/ArkanaKeys"),
…
],
…If you're integrating Arkana via CocoaPods (package_manager is set to cocoapods), Arkana will generate its files as a Development Pod.
Add ArkanaKeys and ArkanaKeysInterfaces (or the pod_name option that you passed in your config file) to your list of dependencies in your Podfile file, like this:
pod "ArkanaKeys", path: "path/to/your/dependencies/ArkanaKeys"
pod "ArkanaKeysInterfaces", path: "path/to/your/dependencies/ArkanaKeysInterfaces"
…
kotlin
exec {
commandLine("arkana", "--lang", "kotlin")
}
…
ruby
SecretWithDollarSignEscapedAndAndNoQuotesKey = real_\$lim_shady
SecretWithDollarSignEscapedAndDoubleQuoteKey = "real_\$lim_shady"
SecretWithDollarSignNotEscapedAndSingleQuoteKey = 'real_$lim_shady'These are not valid:
SecretWithDollarSignNotEscapedAndDoubleQuotesKey = "real_$lim_shady"
SecretWithDollarSignNotEscapedAndNoQuotesKey = real_$lim_shadyWhen storing your secret in actual env vars (instead of dotfiles), you will most likely need to escape them too.
\ aka backslash: double scaping will be needed" aka double quotes: escaping is needed` ~ ! @ # % ^ & * ( ) _ - + = { [ } } | : ; ' . ? /
…
ruby
`bundle exec arkana --config-filepath /path/to/your/.arkana.yml --dotenv-filepath /path/to/your/.env`Note: include the back-ticks above, they're required, so that Ruby interprets the snippet as a shell script.
By doing this, your Arkana code generation will be executed everytime you run pod install or pod update.
The only down side of using this strategy is that you wouldn't want to use it if you need to pass in (dynamic) flavors, since it would require you to modify the Podfile on every different flavor you need to build. If that's the case, you should run Arkana before running pod install in your build pipeline, and not use this snippet at all.
Did you know?
The word arcanum (pluralized as "arcana", here spelled as "Arkana") came from Latin arcanus, meaning "secret", and entered English as the Dark Ages gave way to the Renaissance.²
Special thanks to @danilobecke for the inspiration and heavy lifting, and to @orta for the creation of https://github.com/orta/cocoapods-keys which this project is based off of.
After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
To bump the lib's version, run bundle exec rake bump[1.2.3] (replacing the value with the desired version).
To release a new version, make sure the version number in version.rb is the one you want to release (after setting it via bundle exec rake bump as shown above), and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributions to Arkana are warmly welcomed. Whether it's bug reports, feature requests, or code contributions, your input is highly valued. Please feel free to submit issues and pull requests with your ideas and I promise to get back to you within 24 hours!
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
For a list of issues worth tackling check out: https://github.com/rogerluan/arkana/issues
Forget about 'When did release v2.1.3 go live again?' and 'Is the app ready to be tested yet?'
Statused monitors App Store Connect and send you notifications directly on Slack.
Learn more: statused.com
This project is open source and covered by a standard 2-clause BSD license. That means you can use (publicly, commercially and privately), modify and distribute this project's content, as long as you mention Roger Oba as the original author of this code and reproduce the LICENSE text inside your app, repository, project or research paper.
Twitter: @rogerluan_
暂无开放 Issues,或尚未同步最近议题。