From fc8086dcf525a1081ea9f70341328d373ebcc5a2 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:35:20 +0100 Subject: [PATCH] Changed `template ls` command to sync with latest API changes (#508) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added createdBy, createdAt columns - Hidden 'buildCount', 'lastSpawnedAt', 'spawnCount', 'updatedAt' columns - Sync API spec and ts schema to latest --------- Co-authored-by: Mish Ushakov Co-authored-by: Jakub Novák --- .changeset/khaki-owls-refuse.md | 5 ++ packages/cli/src/commands/template/list.ts | 15 ++++- packages/js-sdk/src/api/schema.gen.ts | 61 +++++++++++++++++++ spec/openapi.yml | 71 ++++++++++++++++++++++ 4 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 .changeset/khaki-owls-refuse.md diff --git a/.changeset/khaki-owls-refuse.md b/.changeset/khaki-owls-refuse.md new file mode 100644 index 000000000..2adfdf19d --- /dev/null +++ b/.changeset/khaki-owls-refuse.md @@ -0,0 +1,5 @@ +--- +'@e2b/cli': patch +--- + +Changed template ls command to sync with latest API changes diff --git a/packages/cli/src/commands/template/list.ts b/packages/cli/src/commands/template/list.ts index 6c4fe48c9..46666944f 100644 --- a/packages/cli/src/commands/template/list.ts +++ b/packages/cli/src/commands/template/list.ts @@ -32,6 +32,7 @@ export const listCommand = new commander.Command('list') const table = new tablePrinter.Table({ title: 'Sandbox templates', columns: [ + { name: 'visibility', alignment: 'left', title: 'Access' }, { name: 'templateID', alignment: 'left', title: 'Template ID' }, { name: 'aliases', @@ -42,11 +43,23 @@ export const listCommand = new commander.Command('list') }, { name: 'cpuCount', alignment: 'right', title: 'vCPUs' }, { name: 'memoryMB', alignment: 'right', title: 'RAM MiB' }, + { name: 'createdBy', alignment: 'right', title: 'Created by' }, + { name: 'createdAt', alignment: 'right', title: 'Created at' }, + ], + disabledColumns: [ + 'public', + 'buildID', + 'buildCount', + 'lastSpawnedAt', + 'spawnCount', + 'updatedAt', ], - disabledColumns: ['public', 'buildID'], rows: templates.map((template) => ({ ...template, + visibility: template.public ? 'Public' : 'Private', aliases: listAliases(template.aliases), + createdBy: template.createdBy?.email, + createdAt: new Date(template.createdAt).toLocaleDateString(), })), style: { headerTop: { diff --git a/packages/js-sdk/src/api/schema.gen.ts b/packages/js-sdk/src/api/schema.gen.ts index 62a662f38..3cc9a39e3 100644 --- a/packages/js-sdk/src/api/schema.gen.ts +++ b/packages/js-sdk/src/api/schema.gen.ts @@ -247,6 +247,28 @@ export interface paths { 500: components["responses"]["500"]; }; }; + /** @description Update template */ + patch: { + parameters: { + path: { + templateID: components["parameters"]["templateID"]; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["TemplateUpdateRequest"]; + }; + }; + responses: { + /** @description The template was updated successfully */ + 200: { + content: never; + }; + 400: components["responses"]["400"]; + 401: components["responses"]["401"]; + 500: components["responses"]["500"]; + }; + }; }; "/templates/{templateID}/builds/{buildID}": { /** @description Start the build */ @@ -395,17 +417,52 @@ export interface components { /** @description Identifier of the team */ teamID: string; }; + TeamUser: { + /** @description Email of the user */ + email: string; + /** + * Format: uuid + * @description Identifier of the user + */ + id: string; + }; Template: { /** @description Aliases of the template */ aliases?: string[]; + /** + * Format: int32 + * @description Number of times the template was built + */ + buildCount: number; /** @description Identifier of the last successful build for given template */ buildID: string; cpuCount: components["schemas"]["CPUCount"]; + /** + * Format: date-time + * @description Time when the template was created + */ + createdAt: string; + createdBy: components["schemas"]["TeamUser"] | null; + /** + * Format: date-time + * @description Time when the template was last used + */ + lastSpawnedAt: string; memoryMB: components["schemas"]["MemoryMB"]; /** @description Whether the template is public or only accessible by the team */ public: boolean; + /** + * Format: int64 + * @description Number of times the template was used + */ + spawnCount: number; /** @description Identifier of the template */ templateID: string; + /** + * Format: date-time + * @description Time when the template was last updated + */ + updatedAt: string; }; TemplateBuild: { /** @description Identifier of the build */ @@ -435,6 +492,10 @@ export interface components { /** @description Identifier of the team */ teamID?: string; }; + TemplateUpdateRequest: { + /** @description Whether the template is public or only accessible by the team */ + public?: boolean; + }; }; responses: { /** @description Bad request */ diff --git a/spec/openapi.yml b/spec/openapi.yml index 8fae421e5..17a1db854 100644 --- a/spec/openapi.yml +++ b/spec/openapi.yml @@ -85,6 +85,25 @@ components: type: boolean description: Whether the team is the default team + TeamUser: + required: + - id + - email + properties: + id: + type: string + format: uuid + description: Identifier of the user + email: + type: string + description: Email of the user + + TemplateUpdateRequest: + properties: + public: + type: boolean + description: Whether the template is public or only accessible by the team + CPUCount: type: integer format: int32 @@ -218,6 +237,12 @@ components: - cpuCount - memoryMB - public + - createdAt + - updatedAt + - createdBy + - lastSpawnedAt + - spawnCount + - buildCount properties: templateID: type: string @@ -237,6 +262,30 @@ components: description: Aliases of the template items: type: string + createdAt: + type: string + format: date-time + description: Time when the template was created + updatedAt: + type: string + format: date-time + description: Time when the template was last updated + createdBy: + allOf: + - $ref: "#/components/schemas/TeamUser" + nullable: true + lastSpawnedAt: + type: string + format: date-time + description: Time when the template was last used + spawnCount: + type: integer + format: int64 + description: Number of times the template was used + buildCount: + type: integer + format: int32 + description: Number of times the template was built TemplateBuildRequest: required: @@ -586,6 +635,28 @@ paths: $ref: "#/components/responses/401" "500": $ref: "#/components/responses/500" + patch: + description: Update template + tags: [templates] + security: + - AccessTokenAuth: [] + parameters: + - $ref: "#/components/parameters/templateID" + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/TemplateUpdateRequest" + responses: + "200": + description: The template was updated successfully + "400": + $ref: "#/components/responses/400" + "401": + $ref: "#/components/responses/401" + "500": + $ref: "#/components/responses/500" /templates/{templateID}/builds/{buildID}: post: