Skip to content

Commit 0cdf149

Browse files
authored
feat(iam): add support for user connection (scaleway#2581)
1 parent 0a56938 commit 0cdf149

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

api/iam/v1alpha1/iam_sdk.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,27 @@ type GetUserRequest struct {
16841684
UserID string `json:"-"`
16851685
}
16861686

1687+
// InitiateUserConnectionRequest: initiate user connection request.
1688+
type InitiateUserConnectionRequest struct {
1689+
// UserID: ID of the user that will be added to your connection.
1690+
UserID string `json:"-"`
1691+
}
1692+
1693+
// InitiateUserConnectionResponse: initiate user connection response.
1694+
type InitiateUserConnectionResponse struct {
1695+
// Token: token to be used in JoinUserConnection.
1696+
Token string `json:"token"`
1697+
}
1698+
1699+
// JoinUserConnectionRequest: join user connection request.
1700+
type JoinUserConnectionRequest struct {
1701+
// UserID: user ID.
1702+
UserID string `json:"-"`
1703+
1704+
// Token: a token returned by InitiateUserConnection.
1705+
Token string `json:"token"`
1706+
}
1707+
16871708
// ListAPIKeysRequest: list api keys request.
16881709
type ListAPIKeysRequest struct {
16891710
// OrderBy: criteria for sorting results.
@@ -2343,6 +2364,15 @@ type RemoveGroupMemberRequest struct {
23432364
ApplicationID *string `json:"application_id,omitempty"`
23442365
}
23452366

2367+
// RemoveUserConnectionRequest: remove user connection request.
2368+
type RemoveUserConnectionRequest struct {
2369+
// UserID: ID of the user you want to manage the connection for.
2370+
UserID string `json:"-"`
2371+
2372+
// TargetUserID: ID of the user you want to remove from your connection.
2373+
TargetUserID string `json:"target_user_id"`
2374+
}
2375+
23462376
// SetGroupMembersRequest: set group members request.
23472377
type SetGroupMembersRequest struct {
23482378
GroupID string `json:"-"`
@@ -3037,6 +3067,83 @@ func (s *API) GetUserConnections(req *GetUserConnectionsRequest, opts ...scw.Req
30373067
return &resp, nil
30383068
}
30393069

3070+
// InitiateUserConnection:
3071+
func (s *API) InitiateUserConnection(req *InitiateUserConnectionRequest, opts ...scw.RequestOption) (*InitiateUserConnectionResponse, error) {
3072+
var err error
3073+
3074+
if fmt.Sprint(req.UserID) == "" {
3075+
return nil, errors.New("field UserID cannot be empty in request")
3076+
}
3077+
3078+
scwReq := &scw.ScalewayRequest{
3079+
Method: "POST",
3080+
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/initiate-connection",
3081+
}
3082+
3083+
err = scwReq.SetBody(req)
3084+
if err != nil {
3085+
return nil, err
3086+
}
3087+
3088+
var resp InitiateUserConnectionResponse
3089+
3090+
err = s.client.Do(scwReq, &resp, opts...)
3091+
if err != nil {
3092+
return nil, err
3093+
}
3094+
return &resp, nil
3095+
}
3096+
3097+
// JoinUserConnection:
3098+
func (s *API) JoinUserConnection(req *JoinUserConnectionRequest, opts ...scw.RequestOption) error {
3099+
var err error
3100+
3101+
if fmt.Sprint(req.UserID) == "" {
3102+
return errors.New("field UserID cannot be empty in request")
3103+
}
3104+
3105+
scwReq := &scw.ScalewayRequest{
3106+
Method: "POST",
3107+
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/join-connection",
3108+
}
3109+
3110+
err = scwReq.SetBody(req)
3111+
if err != nil {
3112+
return err
3113+
}
3114+
3115+
err = s.client.Do(scwReq, nil, opts...)
3116+
if err != nil {
3117+
return err
3118+
}
3119+
return nil
3120+
}
3121+
3122+
// RemoveUserConnection:
3123+
func (s *API) RemoveUserConnection(req *RemoveUserConnectionRequest, opts ...scw.RequestOption) error {
3124+
var err error
3125+
3126+
if fmt.Sprint(req.UserID) == "" {
3127+
return errors.New("field UserID cannot be empty in request")
3128+
}
3129+
3130+
scwReq := &scw.ScalewayRequest{
3131+
Method: "POST",
3132+
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/remove-connection",
3133+
}
3134+
3135+
err = scwReq.SetBody(req)
3136+
if err != nil {
3137+
return err
3138+
}
3139+
3140+
err = s.client.Do(scwReq, nil, opts...)
3141+
if err != nil {
3142+
return err
3143+
}
3144+
return nil
3145+
}
3146+
30403147
// ListApplications: List the applications of an Organization. By default, the applications listed are ordered by creation date in ascending order. This can be modified via the `order_by` field. You must define the `organization_id` in the query path of your request. You can also define additional parameters for your query such as `application_ids`.
30413148
func (s *API) ListApplications(req *ListApplicationsRequest, opts ...scw.RequestOption) (*ListApplicationsResponse, error) {
30423149
var err error

0 commit comments

Comments
 (0)