Skip to content

Commit

Permalink
Merge pull request #2573 from threefoldtech/development_normalize_sub…
Browse files Browse the repository at this point in the history
…domain

Edit subdomain char limit
  • Loading branch information
MohamedElmdary authored May 8, 2024
2 parents d436c7f + 040633d commit 426b406
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class GetServiceContractModel {
@Expose() @IsInt() @Min(1) serviceId: number;
}
class NameContractGetModel {
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string;
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength + 20) name: string;
}

class NodeContractUpdateModel {
Expand Down
34 changes: 14 additions & 20 deletions packages/playground/src/components/manage_gateway_dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@
no-data-text="No domains attached to this virtual machine."
>
<template #[`item.name`]="{ item }">
{{
item.value.name.slice(
item.value.name.startsWith(prefix)
? prefix.length
: item.value.name.startsWith(oldPrefix)
? oldPrefix.length
: 0,
)
}}
{{ item.value.name }}
</template>

<template #[`item.tls_passthrough`]="{ item }">
Expand All @@ -117,9 +109,7 @@

<div v-show="gatewayTab === 1">
<form-validator v-model="valid">
<input-tooltip
:tooltip="`Selecting custom domain sets subdomain as gateway name. Prefix(${prefix}) is solution name, twin ID, and deployment name.`"
>
<input-tooltip tooltip="Selecting custom domain sets subdomain as gateway name.">
<input-validator
:value="subdomain"
:rules="[
Expand All @@ -128,15 +118,12 @@
validators.isAlphanumeric('Subdomain should consist of letters and numbers only.'),
subdomain => validators.isAlpha('Subdomain must start with alphabet char.')(subdomain[0]),
validators.minLength('Subdomain must be at least 4 characters.', 4),
subdomain =>
validators.maxLength(
`Subdomain cannot exceed ${35 - prefix.length} characters.`,
35 - prefix.length,
)(subdomain),
subdomain => validators.maxLength('Subdomain cannot exceed 30 characters.', 30)(subdomain),
]"
:async-rules="[validateSubdomain]"
#="{ props }"
>
<v-text-field label="Subdomain" :prefix="prefix" v-model.trim="subdomain" v-bind="props" />
<v-text-field label="Subdomain" v-model.trim="subdomain" v-bind="props" />
</input-validator>
</input-tooltip>

Expand Down Expand Up @@ -236,6 +223,7 @@ import { deployGatewayName, type GridGateway, loadDeploymentGateways } from "../
import { getGrid } from "../utils/grid";
import { normalizeError } from "../utils/helpers";
import { generateName } from "../utils/strings";
import { isAvailableName } from "../utils/validators";
import IconActionBtn from "./icon_action_btn.vue";
import ListTable from "./list_table.vue";
import { useLayout } from "./weblet_layout.vue";
Expand Down Expand Up @@ -268,7 +256,7 @@ export default {
(props.vm.projectName.toLowerCase().includes(ProjectName.Fullvm.toLowerCase()) ? "fvm" : "vm") +
grid!.config.twinId;
prefix.value = oldPrefix.value + props.vm.name;
subdomain.value = generateName({}, 35 - prefix.value.length > 7 ? 7 : 35 - prefix.value.length);
subdomain.value = generateName({ prefix: prefix.value }, 4);
await loadGateways();
});
Expand Down Expand Up @@ -313,7 +301,7 @@ export default {
}
await deployGatewayName(grid, selectionDetails.value!.domain, {
subdomain: prefix.value + subdomain.value,
subdomain: subdomain.value,
ip,
port: port.value,
network: networkName,
Expand Down Expand Up @@ -346,6 +334,11 @@ export default {
}
}
async function validateSubdomain() {
const grid = await getGrid(profileManager.profile!, props.vm.projectName);
return await isAvailableName(grid!, subdomain.value);
}
return {
profileManager,
Expand Down Expand Up @@ -375,6 +368,7 @@ export default {
gatewaysToDelete,
deleting,
deleteSelectedGateways,
validateSubdomain,
};
},
};
Expand Down
8 changes: 8 additions & 0 deletions packages/playground/src/utils/validators.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { GridClient } from "@threefold/grid_client";
import StellarSdk from "stellar-sdk";
import validator from "validator";
import type { Options } from "validator/lib/isBoolean";
Expand Down Expand Up @@ -761,3 +762,10 @@ export async function isValidStellarAddress(target: string): Promise<RuleReturn>
return { message };
}
}

export async function isAvailableName(grid: GridClient, name: string) {
const valid = await grid.contracts.get_name_contract({ name });
if (name && !!valid) {
return { message: "Name is already taken." };
}
}

0 comments on commit 426b406

Please sign in to comment.