-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Chose service accounts dialog * upsert secret * Run formatter * Fix field rename * Formatter * Fix refactoring bug * PR feedback * PR feedback * Fix tests
- Loading branch information
Showing
16 changed files
with
399 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FirebaseError } from "../../error"; | ||
import * as gcsm from "../../gcp/secretManager"; | ||
import { FIREBASE_MANAGED } from "../../gcp/secretManager"; | ||
import { isFunctionsManaged } from "../../gcp/secretManager"; | ||
import * as utils from "../../utils"; | ||
import * as prompt from "../../prompt"; | ||
|
||
/** | ||
* Ensures a secret exists for use with app hosting, optionally locked to a region. | ||
* If a secret exists, we verify the user is not trying to change the region and verifies a secret | ||
* is not being used for both functions and app hosting as their garbage collection is incompatible | ||
* (client vs server-side). | ||
* @returns true if a secret was created, false if a secret already existed, and null if a user aborts. | ||
*/ | ||
export async function upsertSecret( | ||
project: string, | ||
secret: string, | ||
location?: string, | ||
): Promise<boolean | null> { | ||
let existing: gcsm.Secret; | ||
try { | ||
existing = await gcsm.getSecret(project, secret); | ||
} catch (err: any) { | ||
if (err.status !== 404) { | ||
throw new FirebaseError("Unexpected error loading secret", { original: err }); | ||
} | ||
await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location); | ||
return true; | ||
} | ||
const replication = existing.replication?.userManaged; | ||
if ( | ||
location && | ||
(replication?.replicas?.length !== 1 || replication?.replicas?.[0]?.location !== location) | ||
) { | ||
utils.logLabeledError( | ||
"apphosting", | ||
"Secret replication policies cannot be changed after creation", | ||
); | ||
return null; | ||
} | ||
if (isFunctionsManaged(existing)) { | ||
utils.logLabeledWarning( | ||
"apphosting", | ||
`Cloud Functions for Firebase currently manages versions of ${secret}. Continuing will disable ` + | ||
"automatic deletion of old versions.", | ||
); | ||
const stopTracking = await prompt.confirm({ | ||
message: "Do you wish to continue?", | ||
default: false, | ||
}); | ||
if (!stopTracking) { | ||
return null; | ||
} | ||
delete existing.labels[FIREBASE_MANAGED]; | ||
await gcsm.patchSecret(project, secret, existing.labels); | ||
} | ||
// TODO: consider whether we should prompt a user who has an unmanaged secret to enroll in version control. | ||
// This may not be a great idea until version control is actually implemented. | ||
return false; | ||
} |
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
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.