Skip to content

Commit

Permalink
feat(webhosting): add hosting resource summary (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Nov 18, 2024
1 parent 1966eef commit 54c1f2e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/clients/src/api/webhosting/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
unmarshalListWebsitesResponse,
unmarshalMailAccount,
unmarshalResetHostingPasswordResponse,
unmarshalResourceSummary,
unmarshalSession,
} from './marshalling.gen'
import type {
Expand Down Expand Up @@ -63,6 +64,7 @@ import type {
HostingApiCreateSessionRequest,
HostingApiDeleteHostingRequest,
HostingApiGetHostingRequest,
HostingApiGetResourceSummaryRequest,
HostingApiListHostingsRequest,
HostingApiResetHostingPasswordRequest,
HostingApiUpdateHostingRequest,
Expand All @@ -81,6 +83,7 @@ import type {
MailAccountApiRemoveMailAccountRequest,
OfferApiListOffersRequest,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
WebsiteApiListWebsitesRequest,
} from './types.gen'
Expand Down Expand Up @@ -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<HostingApiGetResourceSummaryRequest>,
) =>
this.client.fetch<ResourceSummary>(
{
method: 'GET',
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/resource-summary`,
},
unmarshalResourceSummary,
)
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/clients/src/api/webhosting/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type {
HostingApiCreateSessionRequest,
HostingApiDeleteHostingRequest,
HostingApiGetHostingRequest,
HostingApiGetResourceSummaryRequest,
HostingApiListHostingsRequest,
HostingApiResetHostingPasswordRequest,
HostingApiUpdateHostingRequest,
Expand Down Expand Up @@ -73,6 +74,7 @@ export type {
OfferOptionRequest,
OfferOptionWarning,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
Website,
WebsiteApiListWebsitesRequest,
Expand Down
16 changes: 16 additions & 0 deletions packages/clients/src/api/webhosting/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
OfferOption,
OfferOptionRequest,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
Website,
} from './types.gen'
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions packages/clients/src/api/webhosting/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54c1f2e

Please sign in to comment.