string GetSecret(string name, ManifestResolverResult result) { var value = secrets.GetNamedSecret(name); if (value == null) { result.ReportError($"Could not find secret named '{name}'."); } return(value); }
public ManifestResolverResult Resolve( Transformation manifest, string manifestPath ) { var resolvedManifest = new ResolvedManifest { Transformation = manifest }; var result = new ManifestResolverResult() { ManifestPath = manifestPath, ResolvedManifest = resolvedManifest, }; try { if (manifest.ApiKey != null) { resolvedManifest.ReadApiKey = GetSecret(manifest.ApiKey.Read, result); resolvedManifest.WriteApiKey = GetSecret(manifest.ApiKey.Write, result); } else if (manifest.Authentication != null) { var readScopes = manifest.Authentication.Read.Scopes; var readScopeStringified = ""; if (readScopes != null && readScopes.Length > 0) { readScopeStringified = string.Join(" ", readScopes); } resolvedManifest.ReadCredentials = new FlatOidcCredentials { CdfProjectName = manifest.Authentication.Read.CdfProjectName, ClientId = GetSecret(manifest.Authentication.Read.ClientId, result), ClientSecret = GetSecret(manifest.Authentication.Read.ClientSecret, result), TokenUri = manifest.Authentication.Read.TokenUrl, Scopes = readScopeStringified, Audience = manifest.Authentication.Audience }; var writeScopes = manifest.Authentication.Write.Scopes; var writeScopeStringified = ""; if (writeScopes != null && writeScopes.Length > 0) { writeScopeStringified = string.Join(" ", writeScopes); } resolvedManifest.WriteCredentials = new FlatOidcCredentials { CdfProjectName = manifest.Authentication.Write.CdfProjectName, ClientId = GetSecret(manifest.Authentication.Write.ClientId, result), ClientSecret = GetSecret(manifest.Authentication.Write.ClientSecret, result), TokenUri = manifest.Authentication.Write.TokenUrl, Scopes = writeScopeStringified, Audience = manifest.Authentication.Audience }; } else { result.ReportError("Missing credentials (either apiKey or authentication must be set)"); } var destination = manifest.Destination; if (destination == null) { result.ReportError("Destination type is not defined"); } else { if (destination.Type == DestinationType.Raw) { if (string.IsNullOrWhiteSpace(destination.RawDatabase)) { result.ReportError("RAW database is not defined"); } if (string.IsNullOrWhiteSpace(destination.RawTable)) { result.ReportError("RAW table is not defined"); } } } if (string.IsNullOrWhiteSpace(manifest.ExternalId)) { result.ReportError("ExternalId is not defined"); } if (string.IsNullOrWhiteSpace(manifest.Query)) { result.ReportError("Query is not defined"); } else { var manifestDirectoryPath = Path.GetDirectoryName(manifestPath); var sqlFilePath = Path.GetFullPath(Path.Join(manifestDirectoryPath, manifest.Query)); try { resolvedManifest.Query = File.ReadAllText(sqlFilePath); } catch (FileNotFoundException) { result.ReportError($"SQL file was not found: {sqlFilePath}"); } catch (Exception e) { result.ReportError($"Failed to read SQL file: {e}"); } } } catch (Exception e) { result.ReportError($"Exception thrown while resolving manifest: {e}"); } return(result); }