Created
September 21, 2019 10:15
-
-
Save CyrilCermak/59b2b4e4c4f528571d9edb03f3666973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "dotgpg" | |
class SecretsHandler | |
@secret_output_path = "./" #Path to your secret sturct in the project | |
def decrypt | |
decrytped_secrets = decrypt_secrets() | |
secrets_dict = extract_secrets_from(decrypt_secrets) | |
inject_into_swift(secrets_dict) | |
end | |
def dry_run *nil_secrets | |
secrets_dict = {} | |
nil_secrets.map { |s| secrets_dict[s] = "nil" } | |
inject_into_swift secrets_dict | |
end | |
private | |
def decrypt_secrets | |
gpg = Dotgpg::Dir.new "./" | |
output = StringIO.new | |
gpg.decrypt "secrets.gpg", output | |
output.string | |
end | |
def extract_secrets_from secrets_payload | |
secrets = {} | |
secrets_payload.split("\n").each do |l| | |
keysWithsecret = l.split("=") | |
secrets[keysWithsecret[0].strip] = keysWithsecret[1].strip | |
end | |
secrets | |
end | |
def inject_into_swift secrets_dict | |
content = "struct AppSecrets {\n" | |
secrets_dict.each { |key, value| content << "\tstatic let #{key}: String? = #{value}\n" } | |
content << "}" | |
File.open("#{@secret_output_path}secrets.swift", "w") { |f| f.puts content } | |
end | |
end | |
if ARGV.include? "--dry-run" | |
SecretsHandler.new.dry_run "firebaseKey", "googleMapsKey", "imageRendererKey" | |
else | |
SecretsHandler.new.decrypt | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment