forked from MathewSachin/Captura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapikeys.cake
36 lines (27 loc) · 870 Bytes
/
apikeys.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#l "constants.cake"
#l "backup.cake"
using System.Text.RegularExpressions;
IEnumerable<string> GetVariables(string ApiKeysContent)
{
var match = Regex.Match(ApiKeysContent, "Get\\(\"(.*)\"\\)");
while (match.Success)
{
yield return match.Groups[1].ToString();
match = match.NextMatch();
}
}
void EmbedApiKeys()
{
var apiKeysPath = sourceFolder + File("Captura.Core/ApiKeys.cs");
Information("Embedding Api Keys from Environment Variables ...");
CreateBackup(apiKeysPath, tempFolder + File("ApiKeys.cs"));
var content = FileRead(apiKeysPath);
foreach (var variable in GetVariables(content))
{
if (HasEnvironmentVariable(variable))
{
content = content.Replace($"Get(\"{variable}\")", $"\"{EnvironmentVariable(variable)}\"");
}
}
FileWrite(apiKeysPath, content);
}