Skip to content

Commit

Permalink
Merge pull request #3187 from threefoldtech/development_validate_work…
Browse files Browse the repository at this point in the history
…loads

Add ValidateMembers to all workloads
  • Loading branch information
zaelgohary authored Aug 1, 2024
2 parents 2c29b5b + 49540dd commit deffec0
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/grid_client/src/zos/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Expose } from "class-transformer";
import { ArrayNotEmpty, IsBoolean, IsFQDN, IsNotEmpty, IsOptional, IsString, IsUrl } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

@ValidateMembers()
class GatewayFQDNProxy extends WorkloadData {
@Expose() @IsFQDN() fqdn: string;
@Expose() @IsBoolean() tls_passthrough: boolean;
Expand All @@ -20,7 +22,7 @@ class GatewayFQDNProxy extends WorkloadData {
return out;
}
}

@ValidateMembers()
class GatewayNameProxy extends WorkloadData {
@Expose() @IsString() @IsNotEmpty() name: string;
@Expose() @IsBoolean() tls_passthrough: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/public_ip.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Expose } from "class-transformer";
import { IsBoolean } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

@ValidateMembers()
class PublicIP extends WorkloadData {
@Expose() @IsBoolean() v4: boolean;
@Expose() @IsBoolean() v6: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/qsfs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Expose, Type } from "class-transformer";
import { IsInt, IsNotEmpty, IsString, Min, ValidateNested } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

class Encryption {
Expand Down Expand Up @@ -105,6 +106,7 @@ class QuantumSafeFSConfig {
}
}

@ValidateMembers()
class QuantumSafeFS extends WorkloadData {
@Expose() @IsInt() @Min(250 * 1024 ** 2) cache: number;
@Expose() @Type(() => QuantumSafeFSConfig) @ValidateNested() config: QuantumSafeFSConfig;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/volume.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Expose } from "class-transformer";
import { IsInt, Max, Min } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

@ValidateMembers()
class Volume extends WorkloadData {
@Expose() @IsInt() @Min(100 * 1024 ** 2) @Max(10 * 1024 ** 4) size: number; // in bytes

Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/workload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Expose, Transform, Type } from "class-transformer";
import { IsDefined, IsEnum, IsInt, IsNotEmpty, IsString, Min, ValidateNested } from "class-validator";

import { ValidateMembers } from "../helpers";
import { GatewayFQDNProxy, GatewayNameProxy, GatewayResult } from "./gateway";
import { PublicIPv4, PublicIPv4Result } from "./ipv4"; // TODO: remove deprecated
import { PublicIP, PublicIPResult } from "./public_ip";
Expand Down Expand Up @@ -69,6 +70,7 @@ class DeploymentResult {
| ZlogsResult;
}

@ValidateMembers()
class Workload {
@Expose() @IsInt() @Min(0) version: number;
@Expose() @IsString() @IsNotEmpty() name: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/grid_client/src/zos/zdb.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Expose, Transform } from "class-transformer";
import { IsBoolean, IsEnum, IsInt, IsNotEmpty, IsString, Min } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

enum ZdbModes {
seq = "seq",
user = "user",
}

@ValidateMembers()
class Zdb extends WorkloadData {
@Expose() @IsInt() @Min(1) size: number; // in bytes
@Expose() @Transform(({ value }) => ZdbModes[value]) @IsEnum(ZdbModes) mode: ZdbModes = ZdbModes.seq;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/zlogs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

@ValidateMembers()
class Zlogs extends WorkloadData {
public zmachine: string;
public output: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/zmachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ValidateNested,
} from "class-validator";

import { ValidateMembers } from "../helpers";
import { ComputeCapacity } from "./computecapacity";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

Expand Down Expand Up @@ -58,6 +59,7 @@ class Mount {
}
}

@ValidateMembers()
class Zmachine extends WorkloadData {
@Expose() @IsString() @IsNotEmpty() flist: string;
@Expose() @Type(() => ZmachineNetwork) @ValidateNested() network: ZmachineNetwork;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/src/zos/zmount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Expose } from "class-transformer";
import { IsInt, Max, Min } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData, WorkloadDataResult } from "./workload_base";

@ValidateMembers()
class Zmount extends WorkloadData {
@Expose() @IsInt() @Min(100 * 1024 ** 2) @Max(10 * 1024 ** 4) size: number; // in bytes

Expand Down
13 changes: 3 additions & 10 deletions packages/grid_client/src/zos/znet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { Expose, Type } from "class-transformer";
import {
ArrayNotEmpty,
IsDefined,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
Length,
ValidateNested,
} from "class-validator";
import { ArrayNotEmpty, IsDefined, IsInt, IsNotEmpty, IsOptional, IsString, ValidateNested } from "class-validator";

import { ValidateMembers } from "../helpers";
import { WorkloadData } from "./workload_base";

class Peer {
Expand All @@ -36,6 +28,7 @@ class Mycelium {
@Expose() @IsOptional() @IsString({ each: true }) peers?: string[];
}

@ValidateMembers()
class Znet extends WorkloadData {
@Expose() @IsString() @IsNotEmpty() subnet: string;
@Expose() @IsString() @IsNotEmpty() ip_range: string;
Expand Down

0 comments on commit deffec0

Please sign in to comment.