Tool that makes easy to store API keys outside of repository.
Secretary </path/to/secrets.plist> </path/to/secrets.swift>
It takes two arguments:
-
Path to
plist
file, containing the real secrets.Secrets.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>keyOne</key> <string>ValueOne</string> <key>keyTwo</key> <string>ValueTwo</string> <key>keyThree</key> <string>ValueThree</string> </dict> </plist>
-
Path to
swift
file with emptyenum
Secrets
.Secrets.swift
enum Secrets { static let keyOne = "<<changeme>>" }
The tool changes the values of variables, that names found in plist
as keys, to corresponding values.
So using with the examples above, after the tool will finish, the file Secrets.swift
will look like this:
enum Secrets {
static let keyOne = "ValueOne"
static let keyTwo = "ValueTwo"
static let keyThree = "ValueThree"
}
-
Create the file that contains only namespace
enum Secrets
with the static variables representing the secrets, as in the example above. -
Create the
plist
file with secrets and exclude it from version control system. -
Add run script build phase prior to
Compile Sources
phase:With script like this:
~/bin/Secretary $SRCROOT/Secrets.plist $SRCROOT/MyProject/Secrets.swift
-
Consider to marking your
Secrets.swift
file withgit update-index --assume-unchanged
command, as the real secrets will be added in it on build.
You should use make install
command to build and install this tool.
For example, to install it to default location at /usr/local/bin
just run:
$ make install
You can specify the installation path by setting the variable INSTALLPATH=~/bin/
like this:
$ make install INSTALLPATH=\~/bin/
- Support secrets in formats:
-
plist
-
json
-
yaml
-
- Add tests.
- Add
Secrets.swift
generation from scratch.