Skip to content

Commit 093e607

Browse files
authored
feat(webhosting): add hosting resource summary (#2307)
1 parent c47c15a commit 093e607

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

api/webhosting/v1/webhosting_sdk.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"strings"
1515
"time"
1616

17+
std "github.com/scaleway/scaleway-sdk-go/api/std"
1718
"github.com/scaleway/scaleway-sdk-go/errors"
1819
"github.com/scaleway/scaleway-sdk-go/marshaler"
1920
"github.com/scaleway/scaleway-sdk-go/namegenerator"
2021
"github.com/scaleway/scaleway-sdk-go/parameter"
2122
"github.com/scaleway/scaleway-sdk-go/scw"
22-
std "github.com/scaleway/scaleway-sdk-go/api/std"
2323
)
2424

2525
// always import dependencies
@@ -1073,6 +1073,15 @@ type HostingAPIGetHostingRequest struct {
10731073
HostingID string `json:"-"`
10741074
}
10751075

1076+
// HostingAPIGetResourceSummaryRequest: hosting api get resource summary request.
1077+
type HostingAPIGetResourceSummaryRequest struct {
1078+
// Region: region to target. If none is passed will use default region from the config.
1079+
Region scw.Region `json:"-"`
1080+
1081+
// HostingID: hosting ID.
1082+
HostingID string `json:"-"`
1083+
}
1084+
10761085
// HostingAPIListHostingsRequest: hosting api list hostings request.
10771086
type HostingAPIListHostingsRequest struct {
10781087
// Region: region to target. If none is passed will use default region from the config.
@@ -1465,6 +1474,21 @@ type ResetHostingPasswordResponse struct {
14651474
OneTimePassword string `json:"one_time_password"`
14661475
}
14671476

1477+
// ResourceSummary: resource summary.
1478+
type ResourceSummary struct {
1479+
// DatabasesCount: total number of active databases in the Web Hosting plan.
1480+
DatabasesCount uint32 `json:"databases_count"`
1481+
1482+
// MailAccountsCount: total number of active email accounts in the Web Hosting plan.
1483+
MailAccountsCount uint32 `json:"mail_accounts_count"`
1484+
1485+
// FtpAccountsCount: total number of active FTP accounts in the Web Hosting plan.
1486+
FtpAccountsCount uint32 `json:"ftp_accounts_count"`
1487+
1488+
// WebsitesCount: total number of active domains in the the Web Hosting plan.
1489+
WebsitesCount uint32 `json:"websites_count"`
1490+
}
1491+
14681492
// Session: session.
14691493
type Session struct {
14701494
// URL: logged user's session URL.
@@ -2294,6 +2318,37 @@ func (s *HostingAPI) ResetHostingPassword(req *HostingAPIResetHostingPasswordReq
22942318
return &resp, nil
22952319
}
22962320

2321+
// GetResourceSummary: Get the total counts of websites, databases, email accounts, and FTP accounts of a Web Hosting plan.
2322+
func (s *HostingAPI) GetResourceSummary(req *HostingAPIGetResourceSummaryRequest, opts ...scw.RequestOption) (*ResourceSummary, error) {
2323+
var err error
2324+
2325+
if req.Region == "" {
2326+
defaultRegion, _ := s.client.GetDefaultRegion()
2327+
req.Region = defaultRegion
2328+
}
2329+
2330+
if fmt.Sprint(req.Region) == "" {
2331+
return nil, errors.New("field Region cannot be empty in request")
2332+
}
2333+
2334+
if fmt.Sprint(req.HostingID) == "" {
2335+
return nil, errors.New("field HostingID cannot be empty in request")
2336+
}
2337+
2338+
scwReq := &scw.ScalewayRequest{
2339+
Method: "GET",
2340+
Path: "/webhosting/v1/regions/" + fmt.Sprint(req.Region) + "/hostings/" + fmt.Sprint(req.HostingID) + "/resource-summary",
2341+
}
2342+
2343+
var resp ResourceSummary
2344+
2345+
err = s.client.Do(scwReq, &resp, opts...)
2346+
if err != nil {
2347+
return nil, err
2348+
}
2349+
return &resp, nil
2350+
}
2351+
22972352
// This API allows you to manage your FTP accounts for your Web Hosting services.
22982353
type FtpAccountAPI struct {
22992354
client *scw.Client

api/webhosting/v1alpha1/webhosting_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"strings"
1515
"time"
1616

17+
std "github.com/scaleway/scaleway-sdk-go/api/std"
1718
"github.com/scaleway/scaleway-sdk-go/errors"
1819
"github.com/scaleway/scaleway-sdk-go/marshaler"
1920
"github.com/scaleway/scaleway-sdk-go/namegenerator"
2021
"github.com/scaleway/scaleway-sdk-go/parameter"
2122
"github.com/scaleway/scaleway-sdk-go/scw"
22-
std "github.com/scaleway/scaleway-sdk-go/api/std"
2323
)
2424

2525
// always import dependencies

0 commit comments

Comments
 (0)