Skip to content
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

Features/handle storage class validation #134

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions deploy-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deploy-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"postinstall": "patch-package"
},
"dependencies": {
"@akashnetwork/akashjs": "0.5.4",
"@akashnetwork/akashjs": "0.5.10",
"@auth0/nextjs-auth0": "^3.1.0",
"@cosmjs/encoding": "^0.29.5",
"@cosmjs/stargate": "^0.29.5",
Expand Down
644 changes: 0 additions & 644 deletions deploy-web/patches/@akashnetwork+akashjs+0.5.4.patch

This file was deleted.

2 changes: 1 addition & 1 deletion deploy-web/public/sw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deploy-web/public/sw.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ export const ManifestUpdate: React.FunctionComponent<Props> = ({ deployment, lea
* Validate the manifest periodically
*/
useEffect(() => {
async function createAndValidateDeploymentData(yamlStr, dseq) {
async function createAndValidateDeploymentData(yamlStr: string, dseq: string) {
try {
if (!editedManifest) return null;

const yamlJson = yaml.load(yamlStr);

await deploymentData.NewDeploymentData(settings.apiEndpoint, yamlJson, dseq, address);
await deploymentData.NewDeploymentData(settings.apiEndpoint, yamlStr, dseq, address);

setParsingError(null);
} catch (err) {
Expand Down Expand Up @@ -134,7 +132,7 @@ export const ManifestUpdate: React.FunctionComponent<Props> = ({ deployment, lea
try {
const doc = yaml.load(editedManifest);

const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, doc, parseInt(deployment.dseq), address); // TODO Flags
const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, editedManifest, deployment.dseq, address); // TODO Flags
const mani = deploymentData.getManifest(doc, true);

// const sdl = getSdl(doc as any, "beta3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { SdlBuilder, SdlBuilderRefType } from "./SdlBuilder";
import { validateDeploymentData } from "@src/utils/deploymentUtils";
import { useChainParam } from "@src/context/ChainParamProvider";

const yaml = require("js-yaml");

const useStyles = makeStyles()(theme => ({
tooltip: {
fontSize: "1rem"
Expand Down Expand Up @@ -98,12 +96,11 @@ export const ManifestEdit: React.FunctionComponent<Props> = ({ editedManifest, s
setEditedManifest(value);
}

async function createAndValidateDeploymentData(yamlStr, dseq = null, deposit = defaultInitialDeposit, depositorAddress = null) {
async function createAndValidateDeploymentData(yamlStr: string, dseq = null, deposit = defaultInitialDeposit, depositorAddress = null) {
try {
if (!yamlStr) return null;

const doc = yaml.load(yamlStr);
const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, doc, dseq, address, deposit, depositorAddress);
const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, yamlStr, dseq, address, deposit, depositorAddress);
validateDeploymentData(dd, selectedTemplate);

setSdlDenom(dd.deposit.denom);
Expand Down
7 changes: 2 additions & 5 deletions deploy-web/src/components/sdl/RentGpusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import { event } from "nextjs-google-analytics";
import { AnalyticsEvents } from "@src/utils/analytics";
import { useChainParam } from "@src/context/ChainParamProvider";

const yaml = require("js-yaml");

type Props = {};

export const RentGpusForm: React.FunctionComponent<Props> = ({}) => {
Expand Down Expand Up @@ -82,12 +80,11 @@ export const RentGpusForm: React.FunctionComponent<Props> = ({}) => {
return () => subscription.unsubscribe();
}, []);

async function createAndValidateDeploymentData(yamlStr, dseq = null, deposit = defaultInitialDeposit, depositorAddress = null) {
async function createAndValidateDeploymentData(yamlStr: string, dseq = null, deposit = defaultInitialDeposit, depositorAddress = null) {
try {
if (!yamlStr) return null;

const doc = yaml.load(yamlStr);
const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, doc, dseq, address, deposit, depositorAddress);
const dd = await deploymentData.NewDeploymentData(settings.apiEndpoint, yamlStr, dseq, address, deposit, depositorAddress);
validateDeploymentData(dd);

setSdlDenom(dd.deposit.denom);
Expand Down
6 changes: 3 additions & 3 deletions deploy-web/src/utils/deploymentData/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export function parseSizeStr(str: string) {

type NetworkType = "beta2" | "beta3";

function isString(value: unknown): value is string {
return typeof value === "object" && value !== null && value.constructor === String;
function isValidString(value: unknown): value is string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace with lodash isString

return typeof value === "string" && !!value;
}

export function getSdl(yamlJson: string | v2Sdl, networkType: NetworkType) {
return isString(yamlJson) ? SDL.fromString(yamlJson, networkType) : new SDL(yamlJson, networkType);
return isValidString(yamlJson) ? SDL.fromString(yamlJson, networkType) : new SDL(yamlJson, networkType);
}

export function DeploymentGroups(yamlJson: string | v2Sdl, networkType: NetworkType) {
Expand Down
25 changes: 21 additions & 4 deletions deploy-web/src/utils/deploymentData/v1beta2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { CustomValidationError, ManifestVersion, getCurrentHeight, Manifest, Dep
import { defaultInitialDeposit } from "../constants";
import { stringToBoolean } from "../stringUtils";
import path from "path";
import yaml from "js-yaml";
import { SDL } from "@akashnetwork/akashjs/build/sdl";

const endpointNameValidationRegex = /^[a-z]+[-_\da-z]+$/;
const endpointKindIP = "ip";

function validate(yamlJson) {
function validate(yamlStr: string, yamlJson) {
try {
SDL.validate(yamlStr, "beta2");
} catch (e) {
throw new CustomValidationError(e.message);
}

const sdl = getSdl(yamlJson, "beta2");

// ENDPOINT VALIDATION
Expand Down Expand Up @@ -185,9 +193,18 @@ export async function getManifestVersion(yamlJson, asString = false) {
}
}

export async function NewDeploymentData(apiEndpoint, yamlJson, dseq, fromAddress, deposit = defaultInitialDeposit, depositorAddress = null) {
export async function NewDeploymentData(
apiEndpoint: string,
yamlStr: string,
dseq: string,
fromAddress: string,
deposit = defaultInitialDeposit,
depositorAddress = null
) {
const yamlJson = yaml.load(yamlStr) as any;

// Validate the integrity of the yaml
validate(yamlJson);
validate(yamlStr, yamlJson);

const groups = DeploymentGroups(yamlJson, "beta2");
const mani = Manifest(yamlJson, "beta2");
Expand All @@ -202,7 +219,7 @@ export async function NewDeploymentData(apiEndpoint, yamlJson, dseq, fromAddress
};

if (!id.dseq) {
id.dseq = await getCurrentHeight(apiEndpoint);
id.dseq = (await getCurrentHeight(apiEndpoint)).toString();
}

return {
Expand Down
25 changes: 21 additions & 4 deletions deploy-web/src/utils/deploymentData/v1beta3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { CustomValidationError, DeploymentGroups, Manifest, ManifestVersion, get
import { defaultInitialDeposit } from "../constants";
import { stringToBoolean } from "../stringUtils";
import path from "path";
import yaml from "js-yaml";
import { getUsdcDenom } from "@src/hooks/useDenom";
import { SDL } from "@akashnetwork/akashjs/build/sdl";

export const endpointNameValidationRegex = /^[a-z]+[-_\da-z]+$/;
export const endpointKindIP = "ip";

function validate(yamlJson) {
function validate(yamlStr: string, yamlJson) {
try {
SDL.validate(yamlStr, "beta3");
} catch (e) {
throw new CustomValidationError(e.message);
}

const sdl = getSdl(yamlJson, "beta3");

// DENOM VALIDATION
Expand Down Expand Up @@ -227,9 +235,18 @@ const getDenomFromSdl = (groups: any[]): string => {
return denoms[0];
};

export async function NewDeploymentData(apiEndpoint, yamlJson, dseq, fromAddress, deposit = defaultInitialDeposit, depositorAddress = null) {
export async function NewDeploymentData(
apiEndpoint: string,
yamlStr: string,
dseq: string,
fromAddress: string,
deposit = defaultInitialDeposit,
depositorAddress = null
) {
const yamlJson = yaml.load(yamlStr) as any;

// Validate the integrity of the yaml
validate(yamlJson);
validate(yamlStr, yamlJson);

const groups = DeploymentGroups(yamlJson, "beta3");
const mani = Manifest(yamlJson, "beta3");
Expand All @@ -245,7 +262,7 @@ export async function NewDeploymentData(apiEndpoint, yamlJson, dseq, fromAddress
};

if (!id.dseq) {
id.dseq = await getCurrentHeight(apiEndpoint);
id.dseq = (await getCurrentHeight(apiEndpoint)).toString();
}

return {
Expand Down
Loading