Skip to content

Commit 46f42ea

Browse files
fix(site): Prompting user for missing variables (#7002)
1 parent e33941b commit 46f42ea

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

site/src/api/api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ describe("api.ts", () => {
199199

200200
expect(error).toBeInstanceOf(api.MissingBuildParameters)
201201
// Verify if the correct missing parameters are being passed
202-
// It should not require immutable parameters
203202
expect((error as api.MissingBuildParameters).parameters).toEqual([
204203
MockTemplateVersionParameter1,
204+
{ ...MockTemplateVersionParameter2, mutable: false },
205205
])
206206
})
207207

site/src/api/api.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ import { DeploymentConfig } from "./types"
55
import * as TypesGen from "./typesGenerated"
66

77
// Adds 304 for the default axios validateStatus function
8-
// https://github.com/axios/axios#handling-errors
9-
// Check status here https://httpstatusdogs.com/
8+
// https://github.com/axios/axios#handling-errors Check status here
9+
// https://httpstatusdogs.com/
1010
axios.defaults.validateStatus = (status) => {
1111
return (status >= 200 && status < 300) || status === 304
1212
}
1313

1414
export const hardCodedCSRFCookie = (): string => {
15-
// This is a hard coded CSRF token/cookie pair for local development.
16-
// In prod, the GoLang webserver generates a random cookie with a new token for
17-
// each document request. For local development, we don't use the Go webserver for static files,
18-
// so this is the 'hack' to make local development work with remote apis.
19-
// The CSRF cookie for this token is "JXm9hOUdZctWt0ZZGAy9xiS/gxMKYOThdxjjMnMUyn4="
15+
// This is a hard coded CSRF token/cookie pair for local development. In prod,
16+
// the GoLang webserver generates a random cookie with a new token for each
17+
// document request. For local development, we don't use the Go webserver for
18+
// static files, so this is the 'hack' to make local development work with
19+
// remote apis. The CSRF cookie for this token is
20+
// "JXm9hOUdZctWt0ZZGAy9xiS/gxMKYOThdxjjMnMUyn4="
2021
const csrfToken =
2122
"KNKvagCBEHZK7ihe2t7fj6VeJ0UyTDco1yVUJE8N06oNqxLu5Zx1vRxZbgfC0mJJgeGkVjgs08mgPbcWPBkZ1A=="
2223
axios.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken
2324
return csrfToken
2425
}
2526

26-
// withDefaultFeatures sets all unspecified features to not_entitled and disabled.
27+
// withDefaultFeatures sets all unspecified features to not_entitled and
28+
// disabled.
2729
export const withDefaultFeatures = (
2830
fs: Partial<TypesGen.Entitlements["features"]>,
2931
): TypesGen.Entitlements["features"] => {
@@ -40,9 +42,8 @@ export const withDefaultFeatures = (
4042
return fs as TypesGen.Entitlements["features"]
4143
}
4244

43-
// Always attach CSRF token to all requests.
44-
// In puppeteer the document is undefined. In those cases, just
45-
// do nothing.
45+
// Always attach CSRF token to all requests. In puppeteer the document is
46+
// undefined. In those cases, just do nothing.
4647
const token =
4748
typeof document !== "undefined"
4849
? document.head.querySelector('meta[property="csrf-token"]')
@@ -978,7 +979,8 @@ export class MissingBuildParameters extends Error {
978979
* - Get the latest template to access the latest active version
979980
* - Get the current build parameters
980981
* - Get the template parameters
981-
* - Update the build parameters and check if there are missed parameters for the newest version
982+
* - Update the build parameters and check if there are missed parameters for
983+
* the newest version
982984
* - If there are missing parameters raise an error
983985
* - Create a build with the latest version and updated build parameters
984986
*/
@@ -1017,12 +1019,22 @@ const getMissingParameters = (
10171019
templateParameters: TypesGen.TemplateVersionParameter[],
10181020
) => {
10191021
const missingParameters: TypesGen.TemplateVersionParameter[] = []
1020-
const requiredParameters = templateParameters.filter(
1021-
// It is required
1022-
// and it can be changed
1023-
// and it is not from a legacy variable
1024-
(p) => p.required && p.mutable && p.legacy_variable_name === undefined,
1025-
)
1022+
const requiredParameters: TypesGen.TemplateVersionParameter[] = []
1023+
1024+
templateParameters.forEach((p) => {
1025+
// Legacy parameters should be required. So we can migrate them.
1026+
const isLegacy = p.legacy_variable_name === undefined
1027+
// It is mutable and required. Mutable values can be changed after so we
1028+
// don't need to ask them if they are not required.
1029+
const isMutableAndRequired = p.mutable && p.required
1030+
// Is immutable, so we can check if it is its first time on the build
1031+
const isImmutable = !p.mutable
1032+
1033+
if (isLegacy || isMutableAndRequired || isImmutable) {
1034+
requiredParameters.push(p)
1035+
return
1036+
}
1037+
})
10261038

10271039
for (const parameter of requiredParameters) {
10281040
// Check if there is a new value
@@ -1049,7 +1061,8 @@ const getMissingParameters = (
10491061
/**
10501062
*
10511063
* @param agentId
1052-
* @returns An EventSource that emits agent metadata event objects (ServerSentEvent)
1064+
* @returns An EventSource that emits agent metadata event objects
1065+
* (ServerSentEvent)
10531066
*/
10541067
export const watchAgentMetadata = (agentId: string): EventSource => {
10551068
return new EventSource(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy