Skip to content

Commit

Permalink
Regex fix for validation. (#263)
Browse files Browse the repository at this point in the history
Co-authored-by: Tatsinnit <[email protected]>
Co-authored-by: peterbom <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent b104cf1 commit a388ac2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
85 changes: 49 additions & 36 deletions src/panels/CreateClusterPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/CreateCluster/CreateClusterInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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}
/>
Expand Down

0 comments on commit a388ac2

Please sign in to comment.