From 54c1f2e4c203c4cacac269b7d67e0cffbee209ea Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Mon, 18 Nov 2024 10:35:17 +0100 Subject: [PATCH] feat(webhosting): add hosting resource summary (#1573) --- .../clients/src/api/webhosting/v1/api.gen.ts | 21 +++++++++++++++++++ .../src/api/webhosting/v1/index.gen.ts | 2 ++ .../src/api/webhosting/v1/marshalling.gen.ts | 16 ++++++++++++++ .../src/api/webhosting/v1/types.gen.ts | 21 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/packages/clients/src/api/webhosting/v1/api.gen.ts b/packages/clients/src/api/webhosting/v1/api.gen.ts index 2aef2a554..a5e18de76 100644 --- a/packages/clients/src/api/webhosting/v1/api.gen.ts +++ b/packages/clients/src/api/webhosting/v1/api.gen.ts @@ -36,6 +36,7 @@ import { unmarshalListWebsitesResponse, unmarshalMailAccount, unmarshalResetHostingPasswordResponse, + unmarshalResourceSummary, unmarshalSession, } from './marshalling.gen' import type { @@ -63,6 +64,7 @@ import type { HostingApiCreateSessionRequest, HostingApiDeleteHostingRequest, HostingApiGetHostingRequest, + HostingApiGetResourceSummaryRequest, HostingApiListHostingsRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, @@ -81,6 +83,7 @@ import type { MailAccountApiRemoveMailAccountRequest, OfferApiListOffersRequest, ResetHostingPasswordResponse, + ResourceSummary, Session, WebsiteApiListWebsitesRequest, } from './types.gen' @@ -593,6 +596,24 @@ export class HostingAPI extends ParentAPI { }, unmarshalResetHostingPasswordResponse, ) + + /** + * Get the total counts of websites, databases, email accounts, and FTP + * accounts of a Web Hosting plan. + * + * @param request - The request {@link HostingApiGetResourceSummaryRequest} + * @returns A Promise of ResourceSummary + */ + getResourceSummary = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/resource-summary`, + }, + unmarshalResourceSummary, + ) } /** diff --git a/packages/clients/src/api/webhosting/v1/index.gen.ts b/packages/clients/src/api/webhosting/v1/index.gen.ts index a4e80599e..461774cf0 100644 --- a/packages/clients/src/api/webhosting/v1/index.gen.ts +++ b/packages/clients/src/api/webhosting/v1/index.gen.ts @@ -37,6 +37,7 @@ export type { HostingApiCreateSessionRequest, HostingApiDeleteHostingRequest, HostingApiGetHostingRequest, + HostingApiGetResourceSummaryRequest, HostingApiListHostingsRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, @@ -73,6 +74,7 @@ export type { OfferOptionRequest, OfferOptionWarning, ResetHostingPasswordResponse, + ResourceSummary, Session, Website, WebsiteApiListWebsitesRequest, diff --git a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts index f32e305ec..4cab12738 100644 --- a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts +++ b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts @@ -42,6 +42,7 @@ import type { OfferOption, OfferOptionRequest, ResetHostingPasswordResponse, + ResourceSummary, Session, Website, } from './types.gen' @@ -385,6 +386,21 @@ export const unmarshalResetHostingPasswordResponse = ( } as ResetHostingPasswordResponse } +export const unmarshalResourceSummary = (data: unknown): ResourceSummary => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary.`, + ) + } + + return { + databasesCount: data.databases_count, + ftpAccountsCount: data.ftp_accounts_count, + mailAccountsCount: data.mail_accounts_count, + websitesCount: data.websites_count, + } as ResourceSummary +} + export const unmarshalSession = (data: unknown): Session => { if (!isJSONObject(data)) { throw new TypeError( diff --git a/packages/clients/src/api/webhosting/v1/types.gen.ts b/packages/clients/src/api/webhosting/v1/types.gen.ts index 9036ec6ee..7f7090713 100644 --- a/packages/clients/src/api/webhosting/v1/types.gen.ts +++ b/packages/clients/src/api/webhosting/v1/types.gen.ts @@ -539,6 +539,16 @@ export type HostingApiGetHostingRequest = { hostingId: string } +export type HostingApiGetResourceSummaryRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Hosting ID. */ + hostingId: string +} + export type HostingApiListHostingsRequest = { /** * Region to target. If none is passed will use default region from the @@ -768,6 +778,17 @@ export interface ResetHostingPasswordResponse { oneTimePassword: string } +export interface ResourceSummary { + /** Total number of active databases in the Web Hosting plan. */ + databasesCount: number + /** Total number of active email accounts in the Web Hosting plan. */ + mailAccountsCount: number + /** Total number of active FTP accounts in the Web Hosting plan. */ + ftpAccountsCount: number + /** Total number of active domains in the the Web Hosting plan. */ + websitesCount: number +} + export interface Session { /** Logged user's session URL. */ url: string