Skip to content

feat(webhosting): add domain api #2143

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

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
58 changes: 58 additions & 0 deletions api/webhosting/v1alpha1/webhosting_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,24 @@ type Offer struct {
ControlPanelName string `json:"control_panel_name"`
}

// CheckUserOwnsDomainRequest: check user owns domain request.
type CheckUserOwnsDomainRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`

// Domain: domain for which ownership is to be verified.
Domain string `json:"-"`

// ProjectID: ID of the project currently in use.
ProjectID string `json:"project_id"`
}

// CheckUserOwnsDomainResponse: check user owns domain response.
type CheckUserOwnsDomainResponse struct {
// OwnsDomain: indicates whether the specified project owns the domain.
OwnsDomain bool `json:"owns_domain"`
}

// CreateHostingRequest: create hosting request.
type CreateHostingRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -1143,6 +1161,46 @@ func (s *API) GetDomainDNSRecords(req *GetDomainDNSRecordsRequest, opts ...scw.R
return &resp, nil
}

// CheckUserOwnsDomain: "Check whether you own this domain or not.".
func (s *API) CheckUserOwnsDomain(req *CheckUserOwnsDomainRequest, opts ...scw.RequestOption) (*CheckUserOwnsDomainResponse, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "project_id", req.ProjectID)

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

if fmt.Sprint(req.Domain) == "" {
return nil, errors.New("field Domain cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/webhosting/v1/regions/" + fmt.Sprint(req.Region) + "/domains/" + fmt.Sprint(req.Domain) + "/check-ownership",
Query: query,
}

var resp CheckUserOwnsDomainResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// ListOffers: List the different Web Hosting offers, and their options, available to order from Scaleway.
func (s *API) ListOffers(req *ListOffersRequest, opts ...scw.RequestOption) (*ListOffersResponse, error) {
var err error
Expand Down
Loading