From a388ac28d1276caf93866194d67dae6001146922 Mon Sep 17 00:00:00 2001 From: Tatsinnit Date: Fri, 13 Oct 2023 09:35:39 +1300 Subject: [PATCH] Regex fix for validation. (#263) Co-authored-by: Tatsinnit Co-authored-by: peterbom --- src/panels/CreateClusterPanel.ts | 85 +++++++++++-------- .../src/CreateCluster/CreateClusterInput.tsx | 4 +- 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/panels/CreateClusterPanel.ts b/src/panels/CreateClusterPanel.ts index 7ae96a5b6..c8b11120d 100644 --- a/src/panels/CreateClusterPanel.ts +++ b/src/panels/CreateClusterPanel.ts @@ -147,43 +147,56 @@ async function createCluster( }); const clusterSpec = getManagedClusterSpec(location, name); - const poller = await containerServiceClient.managedClusters.beginCreateOrUpdate(group.name, name, clusterSpec); - poller.onProgress(state => { - if (state.status === "canceled") { - webview.postMessage({ - command: "progressUpdate", - parameters: { - event: ProgressEventType.Cancelled, - operationDescription, - errorMessage: null - } - }); - } else if (state.status === "failed") { - const errorMessage = state.error ? getErrorMessage(state.error) : "Unknown error"; - window.showErrorMessage(`Error creating AKS cluster ${name}: ${errorMessage}`); - webview.postMessage({ - command: "progressUpdate", - parameters: { - event: ProgressEventType.Failed, - operationDescription, - errorMessage - } - }); - } else if (state.status === "succeeded") { - window.showInformationMessage(`Successfully created AKS cluster ${name}.`); - webview.postMessage({ - command: "progressUpdate", - parameters: { - event: ProgressEventType.Success, - operationDescription, - errorMessage: null - } - }); - } - }); - - await poller.pollUntilDone(); + try { + const poller = await containerServiceClient.managedClusters.beginCreateOrUpdate(group.name, name, clusterSpec); + poller.onProgress(state => { + if (state.status === "canceled") { + webview.postMessage({ + command: "progressUpdate", + parameters: { + event: ProgressEventType.Cancelled, + operationDescription, + errorMessage: null + } + }); + } else if (state.status === "failed") { + const errorMessage = state.error ? getErrorMessage(state.error) : "Unknown error"; + window.showErrorMessage(`Error creating AKS cluster ${name}: ${errorMessage}`); + webview.postMessage({ + command: "progressUpdate", + parameters: { + event: ProgressEventType.Failed, + operationDescription, + errorMessage + } + }); + } else if (state.status === "succeeded") { + window.showInformationMessage(`Successfully created AKS cluster ${name}.`); + webview.postMessage({ + command: "progressUpdate", + parameters: { + event: ProgressEventType.Success, + operationDescription, + errorMessage: null + } + }); + } + }); + + await poller.pollUntilDone(); + } catch (ex) { + const errorMessage = getErrorMessage(ex); + window.showErrorMessage(`Error creating AKS cluster ${name}: ${errorMessage}`); + webview.postMessage({ + command: "progressUpdate", + parameters: { + event: ProgressEventType.Failed, + operationDescription, + errorMessage + } + }); + } } function getManagedClusterSpec(location: string, name: string): ManagedCluster { diff --git a/webview-ui/src/CreateCluster/CreateClusterInput.tsx b/webview-ui/src/CreateCluster/CreateClusterInput.tsx index 2dbc87adb..843b8562c 100644 --- a/webview-ui/src/CreateCluster/CreateClusterInput.tsx +++ b/webview-ui/src/CreateCluster/CreateClusterInput.tsx @@ -46,7 +46,7 @@ export function CreateClusterInput(props: CreateClusterInputProps) { e => e.currentTarget as HTMLInputElement, elem => elem.value || null, elem => elem.checkValidity(), - elem => elem.validity.patternMismatch ? "Cluster name must consist only of letters, numbers, dashes and underscores." + elem => elem.validity.patternMismatch ? "The only allowed characters are letters, numbers, dashes, and underscore. The first and last character must be a letter or a number." : elem.validity.tooShort ? "Cluster name must be at least 1 character long." : elem.validity.tooLong ? "Cluster name must be at most 63 characters long." : elem.validity.valueMissing ? "Cluster name is required." @@ -126,7 +126,7 @@ export function CreateClusterInput(props: CreateClusterInputProps) { required minlength={1} maxlength={63} - pattern="[a-zA-Z0-9_\-]+" + pattern="^[a-zA-Z0-9][a-zA-Z0-9_\-]+[a-zA-Z0-9]$" onBlur={handleNameChange} onInput={handleNameChange} />