in src/library/Connect/Environment/EnvironmentTokenParser.cs [19:66]
public static EnvironmentTokenBase Parse(string tokenStr, bool isReplacementToken, LocalProcessConfigFile config)
{
if (!isReplacementToken)
{
return new VerbatimToken(tokenStr);
}
if (tokenStr == null || tokenStr.Length <= 3 || tokenStr[0] != '$' || tokenStr[1] != '(' || tokenStr[tokenStr.Length - 1] != ')')
{
throw new ArgumentException($"Token '{tokenStr}' must be of format $(..)");
}
string token = tokenStr.Substring(2, tokenStr.Length - 3); // unwrap the token from $()
// TODO: implement real file token, in the documentation we talk about the possiblity of mounting files without specifying volumes but this doesn't actually work today
// Parse for volumes, services and external endpoints tokens.
int i = token.IndexOf(':');
if (i < 0)
{
throw new ArgumentException($"Unknown token in '{tokenStr}'");
}
// Volume tokens start with "volumeMounts:" while service tokens start with "services:", and external endpoint tokens start with "externalEndpoints:".
var tokenType = token.Substring(0, i);
string leftOver = token.Substring(i + 1);
if (string.IsNullOrWhiteSpace(leftOver))
{
throw new ArgumentException($"Unknown token in '{tokenStr}'");
}
if (StringComparer.OrdinalIgnoreCase.Equals(tokenType, Config.Tokens.VolumeMounts))
{
return ParseVolumeToken(leftOver, config);
}
else if (StringComparer.OrdinalIgnoreCase.Equals(tokenType, Config.Tokens.Services))
{
return ParseServiceToken(leftOver);
}
else if (StringComparer.OrdinalIgnoreCase.Equals(tokenType, Config.Tokens.ExternalEndpoints))
{
return ParseExternalEndpointToken(leftOver);
}
else
{
throw new ArgumentException($"Unknown token type '{tokenType}' in '{tokenStr}'");
}
}