Skip to content

Commit 7e956e3

Browse files
authored
feat(webhosting): add a magic link autologin url for webhosting (scaleway#2059)
1 parent 45db456 commit 7e956e3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

api/webhosting/v1alpha1/webhosting_sdk.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@ type CreateHostingRequest struct {
568568
DomainConfiguration *CreateHostingRequestDomainConfiguration `json:"domain_configuration,omitempty"`
569569
}
570570

571+
// CreateSessionRequest: create session request.
572+
type CreateSessionRequest struct {
573+
// Region: region to target. If none is passed will use default region from the config.
574+
Region scw.Region `json:"-"`
575+
576+
// HostingID: hosting ID.
577+
HostingID string `json:"-"`
578+
}
579+
571580
// DNSRecords: dns records.
572581
type DNSRecords struct {
573582
// Records: list of DNS records.
@@ -747,6 +756,12 @@ type RestoreHostingRequest struct {
747756
HostingID string `json:"-"`
748757
}
749758

759+
// Session: session.
760+
type Session struct {
761+
// URL: logged user's session URL.
762+
URL string `json:"url"`
763+
}
764+
750765
// UpdateHostingRequest: update hosting request.
751766
type UpdateHostingRequest struct {
752767
// Region: region to target. If none is passed will use default region from the config.
@@ -1103,3 +1118,39 @@ func (s *API) ListControlPanels(req *ListControlPanelsRequest, opts ...scw.Reque
11031118
}
11041119
return &resp, nil
11051120
}
1121+
1122+
// CreateSession: Create a user session.
1123+
func (s *API) CreateSession(req *CreateSessionRequest, opts ...scw.RequestOption) (*Session, error) {
1124+
var err error
1125+
1126+
if req.Region == "" {
1127+
defaultRegion, _ := s.client.GetDefaultRegion()
1128+
req.Region = defaultRegion
1129+
}
1130+
1131+
if fmt.Sprint(req.Region) == "" {
1132+
return nil, errors.New("field Region cannot be empty in request")
1133+
}
1134+
1135+
if fmt.Sprint(req.HostingID) == "" {
1136+
return nil, errors.New("field HostingID cannot be empty in request")
1137+
}
1138+
1139+
scwReq := &scw.ScalewayRequest{
1140+
Method: "POST",
1141+
Path: "/webhosting/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/hostings/" + fmt.Sprint(req.HostingID) + "/sessions",
1142+
}
1143+
1144+
err = scwReq.SetBody(req)
1145+
if err != nil {
1146+
return nil, err
1147+
}
1148+
1149+
var resp Session
1150+
1151+
err = s.client.Do(scwReq, &resp, opts...)
1152+
if err != nil {
1153+
return nil, err
1154+
}
1155+
return &resp, nil
1156+
}

0 commit comments

Comments
 (0)