in SDK/AppCenter/Microsoft.AppCenter.Shared/AppCenter.cs [31:92]
internal static string GetSecretAndTargetForPlatform(string secrets, string platformIdentifier)
{
var platformTargetIdentifier = platformIdentifier + TargetKeyNameUpper;
if (string.IsNullOrEmpty(secrets))
{
throw new AppCenterException("App secrets string is null or empty");
}
// If there are no equals signs, then there are no named identifiers, but log a message in case the developer made
// a typing error.
if (!secrets.Contains(PlatformKeyValueDelimiter))
{
AppCenterLog.Debug(AppCenterLog.LogTag, "No named identifier found in appSecret; using as-is");
return secrets;
}
// Iterate over matching patterns.
var secretsDictionary = new Dictionary<string, string>();
var matches = _secretsRegex.Matches(secrets);
foreach (Match match in matches)
{
secretsDictionary[match.Groups[1].Value] = match.Groups[2].Value;
}
// Extract the secrets for the current platform.
if (secretsDictionary.ContainsKey(TargetKeyName))
{
AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'target=' identifier in the secret; using as-is.");
return secrets;
}
if (secretsDictionary.ContainsKey(AppSecretKeyName))
{
AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'appSecret=' identifier in the secret; using as-is.");
return secrets;
}
var platformSecret = string.Empty;
var platformTargetToken = string.Empty;
if (secretsDictionary.ContainsKey(platformIdentifier))
{
secretsDictionary.TryGetValue(platformIdentifier, out platformSecret);
}
if (secretsDictionary.ContainsKey(platformTargetIdentifier))
{
secretsDictionary.TryGetValue(platformTargetIdentifier, out platformTargetToken);
}
if (string.IsNullOrEmpty(platformSecret) && string.IsNullOrEmpty(platformTargetToken))
{
throw new AppCenterException($"Error parsing key for '{platformIdentifier}'");
}
// Format the string as "appSecret={};target={}" or "target={}" if needed.
if (!string.IsNullOrEmpty(platformTargetToken))
{
// If there is an app secret
if (!string.IsNullOrEmpty(platformSecret))
{
platformSecret = AppSecretKeyName + PlatformKeyValueDelimiter + platformSecret + SecretDelimiter;
}
platformSecret += TargetKeyName + PlatformKeyValueDelimiter + platformTargetToken;
}
return platformSecret;
}