-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): provide secrets to template strings
For projects connected with Garden Cloud, any secrets for the project in the given environment can now be used in template strings.
- Loading branch information
Showing
16 changed files
with
448 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
garden-service/src/cloud/secrets/garden-cloud/get-secret.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { got, GotResponse } from "../../../util/http" | ||
import { GetSecretsParams } from ".." | ||
import { StringMap } from "../../../config/common" | ||
|
||
export async function getSecretsFromGardenCloud({ | ||
log, | ||
projectId, | ||
cloudDomain, | ||
clientAuthToken, | ||
environmentName, | ||
}: GetSecretsParams): Promise<StringMap> { | ||
try { | ||
const url = `${cloudDomain}/secrets/project/${projectId}/env/${environmentName}` | ||
const headers = { "x-access-auth-token": clientAuthToken } | ||
const res = await got(url, { headers }).json<GotResponse<any>>() | ||
if (res && res["status"] === "success") { | ||
return res["data"] | ||
} | ||
return {} | ||
} catch (err) { | ||
log.error("An error occurred while fetching secrets for the project.") | ||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { getSecretsFromGardenCloud } from "./garden-cloud/get-secret" | ||
import { LogEntry } from "../../logger/log-entry" | ||
import { StringMap } from "../../config/common" | ||
|
||
export interface GetSecretsParams { | ||
log: LogEntry | ||
projectId: string | ||
cloudDomain: string | ||
clientAuthToken: string | ||
environmentName: string | ||
} | ||
|
||
export async function getSecrets(params: GetSecretsParams): Promise<StringMap> { | ||
const { log } = params | ||
const secrets = await getSecretsFromGardenCloud(params) | ||
const emptyKeys = Object.keys(secrets).filter((key) => !secrets[key]) | ||
if (emptyKeys.length > 0) { | ||
const prefix = | ||
emptyKeys.length === 1 | ||
? "The following secret key has an empty value" | ||
: "The following secret keys have empty values" | ||
log.error(`${prefix}: ${emptyKeys.sort().join(", ")}`) | ||
} | ||
return secrets | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.