From a4bdb391e4bed6f8ccfb7a80066ba4774e2b4119 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Thu, 18 Jul 2024 09:56:14 +0200 Subject: [PATCH] refactor(projectuser): isolate handlers --- client_generated.go | 4 ++ config.yaml | 7 +- handler/project/project.go | 72 ------------------- handler/projectuser/projectuser.go | 111 +++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 75 deletions(-) create mode 100644 handler/projectuser/projectuser.go diff --git a/client_generated.go b/client_generated.go index 7a3d7bc..22062c3 100644 --- a/client_generated.go +++ b/client_generated.go @@ -32,6 +32,7 @@ import ( privatelink "github.com/aiven/go-client-codegen/handler/privatelink" project "github.com/aiven/go-client-codegen/handler/project" projectbilling "github.com/aiven/go-client-codegen/handler/projectbilling" + projectuser "github.com/aiven/go-client-codegen/handler/projectuser" service "github.com/aiven/go-client-codegen/handler/service" serviceintegration "github.com/aiven/go-client-codegen/handler/serviceintegration" serviceuser "github.com/aiven/go-client-codegen/handler/serviceuser" @@ -75,6 +76,7 @@ func newClient(doer doer) Client { PrivatelinkHandler: privatelink.NewHandler(doer), ProjectBillingHandler: projectbilling.NewHandler(doer), ProjectHandler: project.NewHandler(doer), + ProjectUserHandler: projectuser.NewHandler(doer), ServiceHandler: service.NewHandler(doer), ServiceIntegrationHandler: serviceintegration.NewHandler(doer), ServiceUserHandler: serviceuser.NewHandler(doer), @@ -114,6 +116,7 @@ type client struct { privatelink.PrivatelinkHandler project.ProjectHandler projectbilling.ProjectBillingHandler + projectuser.ProjectUserHandler service.ServiceHandler serviceintegration.ServiceIntegrationHandler serviceuser.ServiceUserHandler @@ -151,6 +154,7 @@ type Client interface { privatelink.Handler project.Handler projectbilling.Handler + projectuser.Handler service.Handler serviceintegration.Handler serviceuser.Handler diff --git a/config.yaml b/config.yaml index ed6232e..0bf7bb8 100644 --- a/config.yaml +++ b/config.yaml @@ -233,15 +233,16 @@ Project: - ProjectTagsReplace - ProjectTagsUpdate - ProjectUpdate - - ProjectUserList - - ProjectUserRemove - - ProjectUserUpdate ProjectBilling: - InvoiceGet - ProjectCreditsClaim - ProjectCreditsList - ProjectInvoiceGet - ProjectInvoiceList +ProjectUser: + - ProjectUserList + - ProjectUserRemove + - ProjectUserUpdate Service: - ListProjectServiceTypes - ListPublicServiceTypes diff --git a/handler/project/project.go b/handler/project/project.go index 580a052..8cc4ec6 100644 --- a/handler/project/project.go +++ b/handler/project/project.go @@ -95,21 +95,6 @@ type Handler interface { // PUT /v1/project/{project} // https://api.aiven.io/doc/#tag/Project/operation/ProjectUpdate ProjectUpdate(ctx context.Context, project string, in *ProjectUpdateIn) (*ProjectUpdateOut, error) - - // ProjectUserList list users with access to the project. May contain same user multiple times if they belong to multiple teams associated to the project - // GET /v1/project/{project}/users - // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserList - ProjectUserList(ctx context.Context, project string) (*ProjectUserListOut, error) - - // ProjectUserRemove remove user from the project - // DELETE /v1/project/{project}/user/{user_email} - // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserRemove - ProjectUserRemove(ctx context.Context, project string, userEmail string) error - - // ProjectUserUpdate update a project user - // PUT /v1/project/{project}/user/{user_email} - // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserUpdate - ProjectUserUpdate(ctx context.Context, project string, userEmail string, in *ProjectUserUpdateIn) error } func NewHandler(doer doer) ProjectHandler { @@ -305,29 +290,6 @@ func (h *ProjectHandler) ProjectUpdate(ctx context.Context, project string, in * } return &out.Project, nil } -func (h *ProjectHandler) ProjectUserList(ctx context.Context, project string) (*ProjectUserListOut, error) { - path := fmt.Sprintf("/v1/project/%s/users", url.PathEscape(project)) - b, err := h.doer.Do(ctx, "ProjectUserList", "GET", path, nil) - if err != nil { - return nil, err - } - out := new(ProjectUserListOut) - err = json.Unmarshal(b, out) - if err != nil { - return nil, err - } - return out, nil -} -func (h *ProjectHandler) ProjectUserRemove(ctx context.Context, project string, userEmail string) error { - path := fmt.Sprintf("/v1/project/%s/user/%s", url.PathEscape(project), url.PathEscape(userEmail)) - _, err := h.doer.Do(ctx, "ProjectUserRemove", "DELETE", path, nil) - return err -} -func (h *ProjectHandler) ProjectUserUpdate(ctx context.Context, project string, userEmail string, in *ProjectUserUpdateIn) error { - path := fmt.Sprintf("/v1/project/%s/user/%s", url.PathEscape(project), url.PathEscape(userEmail)) - _, err := h.doer.Do(ctx, "ProjectUserUpdate", "PUT", path, in) - return err -} type AlertOut struct { CreateTime time.Time `json:"create_time"` // Event creation timestamp (ISO 8601) @@ -410,18 +372,6 @@ type EventOut struct { ServiceName string `json:"service_name"` // Service name Time string `json:"time"` // Timestamp in ISO 8601 format, always in UTC } -type GroupUserOut struct { - MemberType MemberType `json:"member_type"` // Project member type - RealName string `json:"real_name"` // User real name - UserEmail string `json:"user_email"` // User email address - UserGroupId string `json:"user_group_id"` // User group ID -} -type InvitationOut struct { - InviteTime time.Time `json:"invite_time"` // Timestamp in ISO 8601 format, always in UTC - InvitedUserEmail string `json:"invited_user_email"` // User email address - InvitingUserEmail string `json:"inviting_user_email"` // User email address - MemberType MemberType `json:"member_type"` // Project member type -} type MemberType string const ( @@ -661,34 +611,12 @@ type ProjectUpdateOut struct { VatId string `json:"vat_id"` // EU VAT Identification Number ZipCode *string `json:"zip_code,omitempty"` // Address zip code } - -// ProjectUserListOut ProjectUserListResponse -type ProjectUserListOut struct { - GroupUsers []GroupUserOut `json:"group_users"` // List of users in groups that have access to the project - Invitations []InvitationOut `json:"invitations"` // List of pending invitations - Users []UserOut `json:"users"` // List of project's users -} - -// ProjectUserUpdateIn ProjectUserUpdateRequestBody -type ProjectUserUpdateIn struct { - MemberType MemberType `json:"member_type"` // Project member type -} type TechEmailIn struct { Email string `json:"email"` // User email address } type TechEmailOut struct { Email string `json:"email"` // User email address } -type UserOut struct { - Auth []string `json:"auth"` // List of user's required authentication methods - BillingContact bool `json:"billing_contact"` // Set for project's billing contacts - CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - MemberType MemberType `json:"member_type"` // Project member type - RealName *string `json:"real_name,omitempty"` // User real name - TeamId string `json:"team_id"` // Team ID - TeamName string `json:"team_name"` // Team name - UserEmail string `json:"user_email"` // User email address -} type VpcPeeringConnectionType string const ( diff --git a/handler/projectuser/projectuser.go b/handler/projectuser/projectuser.go new file mode 100644 index 0000000..a4fa015 --- /dev/null +++ b/handler/projectuser/projectuser.go @@ -0,0 +1,111 @@ +// Code generated by Aiven. DO NOT EDIT. + +package projectuser + +import ( + "context" + "encoding/json" + "fmt" + "net/url" + "time" +) + +type Handler interface { + // ProjectUserList list users with access to the project. May contain same user multiple times if they belong to multiple teams associated to the project + // GET /v1/project/{project}/users + // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserList + ProjectUserList(ctx context.Context, project string) (*ProjectUserListOut, error) + + // ProjectUserRemove remove user from the project + // DELETE /v1/project/{project}/user/{user_email} + // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserRemove + ProjectUserRemove(ctx context.Context, project string, userEmail string) error + + // ProjectUserUpdate update a project user + // PUT /v1/project/{project}/user/{user_email} + // https://api.aiven.io/doc/#tag/Project/operation/ProjectUserUpdate + ProjectUserUpdate(ctx context.Context, project string, userEmail string, in *ProjectUserUpdateIn) error +} + +func NewHandler(doer doer) ProjectUserHandler { + return ProjectUserHandler{doer} +} + +type doer interface { + Do(ctx context.Context, operationID, method, path string, v any) ([]byte, error) +} + +type ProjectUserHandler struct { + doer doer +} + +func (h *ProjectUserHandler) ProjectUserList(ctx context.Context, project string) (*ProjectUserListOut, error) { + path := fmt.Sprintf("/v1/project/%s/users", url.PathEscape(project)) + b, err := h.doer.Do(ctx, "ProjectUserList", "GET", path, nil) + if err != nil { + return nil, err + } + out := new(ProjectUserListOut) + err = json.Unmarshal(b, out) + if err != nil { + return nil, err + } + return out, nil +} +func (h *ProjectUserHandler) ProjectUserRemove(ctx context.Context, project string, userEmail string) error { + path := fmt.Sprintf("/v1/project/%s/user/%s", url.PathEscape(project), url.PathEscape(userEmail)) + _, err := h.doer.Do(ctx, "ProjectUserRemove", "DELETE", path, nil) + return err +} +func (h *ProjectUserHandler) ProjectUserUpdate(ctx context.Context, project string, userEmail string, in *ProjectUserUpdateIn) error { + path := fmt.Sprintf("/v1/project/%s/user/%s", url.PathEscape(project), url.PathEscape(userEmail)) + _, err := h.doer.Do(ctx, "ProjectUserUpdate", "PUT", path, in) + return err +} + +type GroupUserOut struct { + MemberType MemberType `json:"member_type"` // Project member type + RealName string `json:"real_name"` // User real name + UserEmail string `json:"user_email"` // User email address + UserGroupId string `json:"user_group_id"` // User group ID +} +type InvitationOut struct { + InviteTime time.Time `json:"invite_time"` // Timestamp in ISO 8601 format, always in UTC + InvitedUserEmail string `json:"invited_user_email"` // User email address + InvitingUserEmail string `json:"inviting_user_email"` // User email address + MemberType MemberType `json:"member_type"` // Project member type +} +type MemberType string + +const ( + MemberTypeAdmin MemberType = "admin" + MemberTypeDeveloper MemberType = "developer" + MemberTypeOperator MemberType = "operator" + MemberTypeReadOnly MemberType = "read_only" +) + +func MemberTypeChoices() []string { + return []string{"admin", "developer", "operator", "read_only"} +} + +// ProjectUserListOut ProjectUserListResponse +type ProjectUserListOut struct { + GroupUsers []GroupUserOut `json:"group_users"` // List of users in groups that have access to the project + Invitations []InvitationOut `json:"invitations"` // List of pending invitations + Users []UserOut `json:"users"` // List of project's users +} + +// ProjectUserUpdateIn ProjectUserUpdateRequestBody +type ProjectUserUpdateIn struct { + MemberType MemberType `json:"member_type"` // Project member type +} +type UserOut struct { + Auth []string `json:"auth"` // List of user's required authentication methods + BillingContact bool `json:"billing_contact"` // Set for project's billing contacts + CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC + MemberType MemberType `json:"member_type"` // Project member type + RealName *string `json:"real_name,omitempty"` // User real name + TeamId string `json:"team_id"` // Team ID + TeamName string `json:"team_name"` // Team name + UserEmail string `json:"user_email"` // User email address +}