Skip to content

Allow using dash and underscore in domains #3961

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

Draft
wants to merge 11 commits into
base: development
Choose a base branch
from
22 changes: 22 additions & 0 deletions packages/grid_client/src/helpers/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ function IsAlphanumericExpectUnderscore(validationOptions?: ClassValidatorValida
});
};
}

function IsAlphanumericExpectDashAndUnderscore(validationOptions?: ClassValidatorValidationOptions) {
return function (object: any, propertyName: string) {
registerDecorator({
name: "IsAlphanumericExpectDashAndUnderscore",
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [`${propertyName} must contain only letters, numbers, dashes, and underscores`],
validator: {
validate(value: any) {
return /^[a-zA-Z0-9_-]+$/.test(value);
},
defaultMessage: buildMessage(
eachPrefix => eachPrefix + "$property must contain only letters, numbers, dashes, and underscores",
validationOptions,
),
},
});
};
}
interface ValidationOptions {
props?: boolean | string | string[];
methods?: boolean | string | string[];
Expand Down Expand Up @@ -205,4 +226,5 @@ export {
type ValidationOptions,
ValidateMembers,
IsAlphanumericExpectUnderscore,
IsAlphanumericExpectDashAndUnderscore,
};
6 changes: 3 additions & 3 deletions packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ValidateNested,
} from "class-validator";

import { Features, IsAlphanumericExpectUnderscore } from "../helpers";
import { Features, IsAlphanumericExpectDashAndUnderscore, IsAlphanumericExpectUnderscore } from "../helpers";
import { Deployment } from "../zos/deployment";
import { ZdbModes } from "../zos/zdb";
import { blockchainType } from "./blockchainInterface";
Expand Down Expand Up @@ -254,7 +254,7 @@ class QSFSZDBGetModel extends BaseGetDeleteModel {}
class QSFSZDBDeleteModel extends BaseGetDeleteModel {}

class BaseGatewayNameModel {
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string;
@Expose() @IsString() @IsNotEmpty() @IsAlphanumericExpectDashAndUnderscore() @MaxLength(NameLength) name: string;
}

class GatewayFQDNModel extends BaseGatewayNameModel {
Expand Down Expand Up @@ -361,7 +361,7 @@ class GetServiceContractModel {
@Expose() @IsInt() @Min(1) serviceId: number;
}
class NameContractGetModel {
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string;
@Expose() @IsString() @IsNotEmpty() @IsAlphanumericExpectDashAndUnderscore() @MaxLength(NameLength) name: string;
}

class NodeContractUpdateModel {
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/primitives/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GWPrimitive {

const name_workload = new Workload();
name_workload.version = version;
name_workload.name = name;
name_workload.name = name.replace(/-/g, "");
name_workload.type = WorkloadTypes.gatewaynameproxy;
name_workload.data = nameObj;
name_workload.metadata = metadata;
Expand Down
19 changes: 11 additions & 8 deletions packages/playground/src/components/manage_gateway_dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
:deleting="deleting"
no-data-text="No domains attached to this virtual machine."
>
<template #[`item.name`]="{ item }">
{{ item.name }}
</template>

<template #[`item.tls_passthrough`]="{ item }"> {{ item.tls_passthrough ? "Yes" : "No" }} </template>

<template #[`item.backends`]="{ item }">
Expand Down Expand Up @@ -167,7 +163,7 @@
<v-card-title> Are you sure you want to delete the following gateways? </v-card-title>
<v-card-text class="d-flex flex-wrap">
<v-chip label class="mr-1 mb-5" v-for="gw in gatewaysToDelete" :key="gw.name">
{{ gw.name }}
{{ gw.domain }}
</v-chip>
<v-divider />
</v-card-text>
Expand Down Expand Up @@ -289,7 +285,6 @@ export default {

watch(selectedK8SNodeName, getSupportedNetworks, { deep: true });
const tableHeaders = ref([
{ title: "Name", key: "name" },
{ title: "Contract ID", key: "contractId" },
{ title: "Domain", key: "domain" },
{ title: "TLS Passthrough", key: "tls_passthrough" },
Expand Down Expand Up @@ -406,6 +401,7 @@ export default {
deleting.value = true;
const deletedGateways = new Set<GridGateway>();
for (const gw of gatewaysToDelete.value) {
gw.name = gw.domain.split(".")[0];
await grid.gateway
.delete_name(gw)
.then(() => deletedGateways.add(gw))
Expand Down Expand Up @@ -499,8 +495,15 @@ export default {
const subdomainRules = [
validators.required("Subdomain is required."),
validators.isLowercase("Subdomain should consist of lowercase letters only."),
validators.isAlphanumeric("Subdomain should consist of letters and numbers only."),
(subdomain: string) => validators.isAlpha("Subdomain must start with an alphabet char.")(subdomain[0]),
validators.IsAlphanumericExpectDashAndUnderscore(
"Subdomain should consist only letters, numbers, dashes, and underscores",
),
(subdomain: string) =>
validators.isAlphanumeric("Subdomain should start of letters and numbers only.")(subdomain[0]),
(subdomain: string) =>
validators.isAlphanumeric("Subdomain should end with letters and numbers only.")(
subdomain[subdomain.length - 1],
),
validators.minLength("Subdomain must be at least 4 characters.", 4),
(subdomain: string) => validators.maxLength("Subdomain cannot exceed 35 characters.", 35)(subdomain),
];
Expand Down
14 changes: 3 additions & 11 deletions packages/playground/src/components/vm_deployment_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ const filteredHeaders = computed(() => {
if (props.projectName.toLowerCase() === ProjectName.Domains.toLowerCase()) {
return [
{
title: "Name",
key: "domain-name",
title: "Domain",
key: "fqdn",
value(item: any) {
const [workload] = item[0].workloads;
return workload.data.name || workload.name;
return workload.result.data.fqdn || workload.data.fqdn;
},
},
{
Expand All @@ -288,14 +288,6 @@ const filteredHeaders = computed(() => {
},
sortable: false,
},
{
title: "Domain",
key: "fqdn",
value(item: any) {
const [workload] = item[0].workloads;
return workload.result.data.fqdn || workload.data.fqdn;
},
},
{
title: "Health",
key: "health",
Expand Down
11 changes: 9 additions & 2 deletions packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,14 @@
{{ worker.name }}
</v-chip>
</template>
<v-chip class="ma-3">
<template v-if="item.length > 0">
<template v-for="props in item" :key="props.name">
<v-chip class="ma-3">
{{ props.workloads[0].result.data.fqdn }}
</v-chip>
</template>
</template>
<v-chip class="ma-3" v-else>
{{ item.name }}
</v-chip>
</template>
Expand Down Expand Up @@ -517,7 +524,7 @@ async function onDelete(k8s = false) {
if (projectNameLower === ProjectName.Domains.toLowerCase()) {
await deleteGatewayDeployment(
updateGrid(grid, { projectName: projectNameLower }),
item[0].workloads[0].name as string,
item[0].workloads[0].data.name as string,
);
} else {
await deleteDeployment(updateGrid(grid!, { projectName: item.projectName }), {
Expand Down
14 changes: 10 additions & 4 deletions packages/playground/src/weblets/tf_domains.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
:rules="[
validators.required('Subdomain is required.'),
validators.isLowercase('Subdomain should consist of lowercase letters only.'),
validators.isAlphanumeric('Subdomain should consist of letters and numbers only.'),
subdomain => validators.isAlpha('Subdomain must start with alphabet char.')(subdomain[0]),
validators.IsAlphanumericExpectDashAndUnderscore(
'Subdomain should consist only letters, numbers, dashes, and underscores',
),
(subdomain: string) =>
validators.isAlphanumeric('Subdomain should start of letters and numbers only.')(subdomain[0]),
(subdomain: string) =>
validators.isAlphanumeric('Subdomain should end with letters and numbers only.')(
subdomain[subdomain.length - 1],
),
validators.minLength('Subdomain must be at least 4 characters.', 4),
subdomain => validators.maxLength('Subdomain cannot exceed 35 characters.', 35)(subdomain),
(subdomain: string) => validators.maxLength('Subdomain cannot exceed 35 characters.', 35)(subdomain),
]"
:async-rules="[validateSubdomain]"
#="{ props }"
Expand Down Expand Up @@ -139,7 +146,6 @@ async function validateSubdomain() {
</script>

<script lang="ts">
import { deploymentListEnvironments } from "@/constants";
import { isAvailableName } from "@/utils/validators";

import type { SelectionDetails } from "../types/nodeSelector";
Expand Down
Loading