string GetSecret(string name, ManifestResolverResult result) { var value = secrets.GetNamedSecret(name); if (value == null) { result.ReportError($"Could not find secret named '{name}'."); } return(value); }
static Uri GetBaseUriFromCluster(ISecretsProvider secrets, string cluster) { if (cluster == "localhost") { return(new Uri("http://localhost:8084")); } if (string.IsNullOrWhiteSpace(cluster)) { cluster = secrets.GetNamedSecret(ClusterEnvironmentVariable) ?? "europe-west1-1"; } return(new Uri($"https://jetfire.{cluster}.cogniteapp.com")); }
static ICredentials GetCredentials(ISecretsProvider secrets) { var apiKey = secrets.GetNamedSecret(ApiKeyEnvironmentVariable).TrimToNull(); var tokenUrl = secrets.GetNamedSecret(TokenUrlEnvironmentVariable).TrimToNull(); var clientId = secrets.GetNamedSecret(ClientIdEnvironmentVariable).TrimToNull(); var clientSecret = secrets.GetNamedSecret(ClientSecretEnvironmentVariable).TrimToNull(); var tokenScopes = secrets.GetNamedSecret(TokenScopesEnvironmentVariable).TrimToNull(); var tokenAudience = secrets.GetNamedSecret(TokenAudienceEnvironmentVariable).TrimToNull(); var project = secrets.GetNamedSecret(ProjectEnvironmentVariable).TrimToNull(); if (apiKey != null) { return(new ApiKeyCredentials(apiKey)); } else if (tokenUrl != null && clientId != null && clientSecret != null && project != null) { var scopeList = new List <string>(); if (tokenScopes != null && tokenScopes != "") { scopeList = new List <string>(tokenScopes.Split(",")); } var authConfig = new AuthenticatorConfig { Implementation = AuthenticatorConfig.AuthenticatorImplementation.Basic, ClientId = clientId, Secret = clientSecret, TokenUrl = tokenUrl, Scopes = scopeList, Audience = tokenAudience }; return(new TokenCredentials(authConfig, project)); } else { throw new JetfireCliException($"Either the {ApiKeyEnvironmentVariable} environment variable, or the {TokenUrlEnvironmentVariable}, {ClientIdEnvironmentVariable}, {ClientSecretEnvironmentVariable}, {TokenScopesEnvironmentVariable} and {ProjectEnvironmentVariable} environment variables must be set"); } }