-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support deploying Remote Config server template #9863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,14 +11,22 @@ | |
| * Gets Etag for Remote Config Project Template | ||
| * @param projectNumber Input is the Firebase Project's project number | ||
| * @param versionNumber Firebase Remote Config Template version number | ||
| * @param templateType Template type to get etag for (e.g. "firebase-server") | ||
| * @return {Promise<string>} Returns a Promise of the Remote Config Template Etag string | ||
| */ | ||
| export async function getEtag(projectNumber: string, versionNumber?: string): Promise<string> { | ||
| export async function getEtag( | ||
| projectNumber: string, | ||
| versionNumber?: string, | ||
| templateType?: string, | ||
| ): Promise<string> { | ||
| const reqPath = `/projects/${projectNumber}/remoteConfig`; | ||
| const queryParams: { versionNumber?: string } = {}; | ||
| const queryParams: { versionNumber?: string; templateType?: string } = {}; | ||
| if (versionNumber) { | ||
| queryParams.versionNumber = versionNumber; | ||
| } | ||
| if (templateType) { | ||
| queryParams.templateType = templateType; | ||
| } | ||
| const response = await client.request<void, void>({ | ||
| method: "GET", | ||
| path: reqPath, | ||
|
|
@@ -37,17 +45,17 @@ | |
| export function validateInputRemoteConfigTemplate( | ||
| template: RemoteConfigTemplate, | ||
| ): RemoteConfigTemplate { | ||
| const templateCopy = JSON.parse(JSON.stringify(template)); | ||
| if (!templateCopy || templateCopy === "null" || templateCopy === "undefined") { | ||
| throw new FirebaseError(`Invalid Remote Config template: ${JSON.stringify(templateCopy)}`); | ||
| } | ||
| if (typeof templateCopy.etag !== "string" || templateCopy.etag === "") { | ||
|
Check warning on line 52 in src/deploy/remoteconfig/functions.ts
|
||
| throw new FirebaseError("ETag must be a non-empty string"); | ||
| } | ||
| if (templateCopy.conditions && !Array.isArray(templateCopy.conditions)) { | ||
|
Check warning on line 55 in src/deploy/remoteconfig/functions.ts
|
||
| throw new FirebaseError("Remote Config conditions must be an array"); | ||
| } | ||
| return templateCopy; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -55,7 +63,7 @@ | |
| * If force option is passed, etag value will be set to *. Otherwise, the etag will be created | ||
| * @param projectNumber Input is the Project number string | ||
| * @param template Remote Config template to deploy | ||
| * @param etag Remote Config Template's etag value | ||
|
Check warning on line 66 in src/deploy/remoteconfig/functions.ts
|
||
| * @param options Optional object when publishing a Remote Config template. If the | ||
| * force {boolean} is `true` the Remote Config template is forced to update and circumvent the Etag | ||
| * @return Returns a Promise of a Remote Config template | ||
|
|
@@ -64,15 +72,20 @@ | |
| projectNumber: string, | ||
| template: RemoteConfigTemplate, | ||
| etag: string, | ||
| options?: { force: boolean }, | ||
| options?: { force: boolean; templateType?: string }, | ||
| ): Promise<RemoteConfigTemplate> { | ||
| const reqPath = `/projects/${projectNumber}/remoteConfig`; | ||
| const queryParams: { templateType?: string } = {}; | ||
| if (options?.templateType) { | ||
| queryParams.templateType = options.templateType; | ||
| } | ||
| if (options?.force) { | ||
| etag = "*"; | ||
| } | ||
| const response = await client.request<any, RemoteConfigTemplate>({ | ||
| method: "PUT", | ||
| path: reqPath, | ||
| queryParams, | ||
| headers: { "If-Match": etag }, | ||
| body: { | ||
| conditions: template.conditions, | ||
|
|
@@ -88,7 +101,7 @@ | |
| * Publishes a valid Remote Config template based on the Firebase Project Id using the deployTemplate function | ||
| * @param projectNumber Input is the Project number of the Firebase Project | ||
| * @param template The Remote Config template to be published | ||
| * @param etag Remote Config Template's etag value | ||
|
Check warning on line 104 in src/deploy/remoteconfig/functions.ts
|
||
| * @param options Force boolean option | ||
| * @return Returns a Promise that fulfills with the published Remote Config template | ||
| */ | ||
|
|
@@ -96,7 +109,7 @@ | |
| projectNumber: string, | ||
| template: RemoteConfigTemplate, | ||
| etag: string, | ||
| options?: { force: boolean }, | ||
| options?: { force: boolean; templateType?: string }, | ||
| ): Promise<RemoteConfigTemplate> { | ||
| const temporaryTemplate = { | ||
| conditions: template.conditions, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
etagis fetched again here to avoid race conditions, which is good. However, thetemplateobject passed topublishTemplatestill contains the potentially staleetagfrom thepreparestep. InsidepublishTemplate, validation is performed on this template with its staleetag, which is inconsistent. To ensure validation uses the most up-to-dateetag, you should create a new template object that includes the newly fetchedetagbefore publishing.