From 544daf57560317f1bd3c5e2ce35d70a849a1c4f9 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 27 Nov 2019 11:30:27 -0500 Subject: [PATCH] handle missing secrets Missing secrets will give a blank string instead of exploding. Also, an example of a custom property --- Shared/Secrets.swift.gyb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Shared/Secrets.swift.gyb b/Shared/Secrets.swift.gyb index 8157424a2..b20e8bf56 100644 --- a/Shared/Secrets.swift.gyb +++ b/Shared/Secrets.swift.gyb @@ -18,11 +18,11 @@ def snake_to_camel(snake_str): salt = [ord(byte) for byte in os.urandom(64)] }% enum Secrets { - % for secret in secrets: + static var ${snake_to_camel(secret)}: String { let encoded: [UInt8] = [ - % for chunk in chunks(encode(os.environ.get(secret), salt), 8): + % for chunk in chunks(encode(os.environ.get(secret) or "", salt), 8): ${"".join(["0x%02x, " % byte for byte in chunk])} % end ] @@ -30,7 +30,10 @@ enum Secrets { return decode(encoded, salt: salt) } % end - + + %{ + # custom example: static let myVariable = "${os.environ.get('MY_CUSTOM_VARIABLE')}" + }% } private extension Secrets {