From c08862ec7bd099227f215842944bee8236199822 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Wed, 5 Feb 2025 12:32:15 +0100 Subject: [PATCH 1/2] feat!: support typed map --- client_generated.go | 4 + config.yaml | 2 + generator/models.go | 32 ++- .../organizationprojects.go | 73 +++++++ handler/project/project.go | 85 ++++---- handler/user/user.go | 189 +++++++++--------- 6 files changed, 237 insertions(+), 148 deletions(-) create mode 100644 handler/organizationprojects/organizationprojects.go diff --git a/client_generated.go b/client_generated.go index 380c8ce..d17d973 100644 --- a/client_generated.go +++ b/client_generated.go @@ -31,6 +31,7 @@ import ( mysql "github.com/aiven/go-client-codegen/handler/mysql" opensearch "github.com/aiven/go-client-codegen/handler/opensearch" organization "github.com/aiven/go-client-codegen/handler/organization" + organizationprojects "github.com/aiven/go-client-codegen/handler/organizationprojects" organizationuser "github.com/aiven/go-client-codegen/handler/organizationuser" postgresql "github.com/aiven/go-client-codegen/handler/postgresql" privatelink "github.com/aiven/go-client-codegen/handler/privatelink" @@ -77,6 +78,7 @@ func newClient(doer doer) Client { MySQLHandler: mysql.NewHandler(doer), OpenSearchHandler: opensearch.NewHandler(doer), OrganizationHandler: organization.NewHandler(doer), + OrganizationProjectsHandler: organizationprojects.NewHandler(doer), OrganizationUserHandler: organizationuser.NewHandler(doer), PostgreSQLHandler: postgresql.NewHandler(doer), PrivatelinkHandler: privatelink.NewHandler(doer), @@ -118,6 +120,7 @@ type client struct { mysql.MySQLHandler opensearch.OpenSearchHandler organization.OrganizationHandler + organizationprojects.OrganizationProjectsHandler organizationuser.OrganizationUserHandler postgresql.PostgreSQLHandler privatelink.PrivatelinkHandler @@ -157,6 +160,7 @@ type Client interface { mysql.Handler opensearch.Handler organization.Handler + organizationprojects.Handler organizationuser.Handler postgresql.Handler privatelink.Handler diff --git a/config.yaml b/config.yaml index 0aeb2f1..2b46c7c 100644 --- a/config.yaml +++ b/config.yaml @@ -205,6 +205,8 @@ Organization: - PermissionsUpdate - UserOrganizationCreate - UserOrganizationsList +OrganizationProjects: + - OrganizationProjectsCreate OrganizationUser: - OrganizationUserAuthenticationMethodsList - OrganizationUserDelete diff --git a/generator/models.go b/generator/models.go index 175be9d..91de59d 100644 --- a/generator/models.go +++ b/generator/models.go @@ -150,6 +150,18 @@ const ( SchemaTypeAny = "any" ) +// anyKey This is what "schemaless" map looks like in the Aiven API +// +// { +// "type": "object", +// "properties": { +// "ANY": { +// "type": "string", +// } +// } +// } +const anyKey = "ANY" + // Schema represents a parsed OpenAPI schema. type Schema struct { Type SchemaType `json:"type"` @@ -282,6 +294,18 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) { s.Items.init(doc, scope, toSingle(name)) } + // See anyKey const + if s.isTypedMap() { + s.AdditionalProperties = s.Properties[anyKey] + s.AdditionalProperties.init(doc, scope, toSingle(name)) + s.Properties = nil + } + + // Removes pointers from map values + if s.AdditionalProperties != nil { + s.AdditionalProperties.required = true + } + if s.isObject() { s.propertyNames = sortedKeys(s.Properties) for _, k := range s.propertyNames { @@ -359,6 +383,11 @@ func (s *Schema) isMap() bool { return s.Type == SchemaTypeObject && len(s.Properties) == 0 } +// isTypedMap it has only one field with "ANY" key +func (s *Schema) isTypedMap() bool { + return s.Type == SchemaTypeObject && len(s.Properties) == 1 && s.Properties[anyKey] != nil +} + func (s *Schema) isEnum() bool { return len(s.Enum) != 0 } @@ -451,10 +480,9 @@ func getType(s *Schema) *jen.Statement { } return withPointer(o, s.required) - case s.isMap(): + case s.isMap(), s.isTypedMap(): a := withPointer(jen.Map(jen.String()), s.required || s.isOut()) if s.AdditionalProperties != nil { - s.AdditionalProperties.required = true return a.Add(getType(s.AdditionalProperties)) } else if s.name == "tags" { // tags are everywhere in the schema, better not to use the patch diff --git a/handler/organizationprojects/organizationprojects.go b/handler/organizationprojects/organizationprojects.go new file mode 100644 index 0000000..a619bb6 --- /dev/null +++ b/handler/organizationprojects/organizationprojects.go @@ -0,0 +1,73 @@ +// Code generated by Aiven. DO NOT EDIT. + +package organizationprojects + +import ( + "context" + "encoding/json" + "fmt" + "net/url" +) + +type Handler interface { + // OrganizationProjectsCreate [EXPERIMENTAL] Create project under the organization + // POST /v1/organization/{organization_id}/projects + // https://api.aiven.io/doc/#tag/Organizations/operation/OrganizationProjectsCreate + OrganizationProjectsCreate(ctx context.Context, organizationId string, in *OrganizationProjectsCreateIn) (*OrganizationProjectsCreateOut, error) +} + +// doer http client +type doer interface { + Do(ctx context.Context, operationID, method, path string, in any, query ...[2]string) ([]byte, error) +} + +func NewHandler(doer doer) OrganizationProjectsHandler { + return OrganizationProjectsHandler{doer} +} + +type OrganizationProjectsHandler struct { + doer doer +} + +func (h *OrganizationProjectsHandler) OrganizationProjectsCreate(ctx context.Context, organizationId string, in *OrganizationProjectsCreateIn) (*OrganizationProjectsCreateOut, error) { + path := fmt.Sprintf("/v1/organization/%s/projects", url.PathEscape(organizationId)) + b, err := h.doer.Do(ctx, "OrganizationProjectsCreate", "POST", path, in) + if err != nil { + return nil, err + } + out := new(OrganizationProjectsCreateOut) + err = json.Unmarshal(b, out) + if err != nil { + return nil, err + } + return out, nil +} + +// EndOfLifeExtension ServiceEndOfLifeExtension +type EndOfLifeExtension struct { + EolDate string `json:"eol_date"` // Extended EOL date + Version string `json:"version"` // Service version +} + +// OrganizationProjectsCreateIn OrganizationProjectsCreateRequestBody +type OrganizationProjectsCreateIn struct { + BillingGroupId string `json:"billing_group_id"` // Billing group ID to assign to the project. + ParentId *string `json:"parent_id,omitempty"` // Organization or unit ID to where to move the project + ProjectId string `json:"project_id"` // Project ID + Tags map[string]string `json:"tags"` // Tags +} + +// OrganizationProjectsCreateOut OrganizationProjectsCreateResponse +type OrganizationProjectsCreateOut struct { + AccountId *string `json:"account_id,omitempty"` // Account ID to where the project belongs + BillingGroupId *string `json:"billing_group_id,omitempty"` // Billing group ID + EndOfLifeExtension map[string]EndOfLifeExtension `json:"end_of_life_extension"` // End of life extension information + Features map[string]bool `json:"features,omitempty"` // Feature flags + ParentId *string `json:"parent_id,omitempty"` // Organization or unit ID to where the project belongs + ProjectId string `json:"project_id"` // Project ID + Tags map[string]string `json:"tags"` // Tags + TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses +} +type TechEmailOut struct { + Email string `json:"email"` // Technical contact email +} diff --git a/handler/project/project.go b/handler/project/project.go index ab62aae..5d4df8b 100644 --- a/handler/project/project.go +++ b/handler/project/project.go @@ -444,43 +444,6 @@ type AlloydbomniOut struct { LatestAvailableVersion *string `json:"latest_available_version,omitempty"` // Latest available version of the service UserConfigSchema map[string]any `json:"user_config_schema"` // JSON-Schema for the 'user_config' properties } -type AnyType string - -const ( - AnyTypeAdmin AnyType = "admin" - AnyTypeDeveloper AnyType = "developer" - AnyTypeOperator AnyType = "operator" - AnyTypeOrganizationAppUsersWrite AnyType = "organization:app_users:write" - AnyTypeOrganizationAuditLogsRead AnyType = "organization:audit_logs:read" - AnyTypeOrganizationDomainsWrite AnyType = "organization:domains:write" - AnyTypeOrganizationGroupsWrite AnyType = "organization:groups:write" - AnyTypeOrganizationIdpsWrite AnyType = "organization:idps:write" - AnyTypeOrganizationNetworkingRead AnyType = "organization:networking:read" - AnyTypeOrganizationNetworkingWrite AnyType = "organization:networking:write" - AnyTypeOrganizationProjectsWrite AnyType = "organization:projects:write" - AnyTypeOrganizationUsersWrite AnyType = "organization:users:write" - AnyTypeProjectAuditLogsRead AnyType = "project:audit_logs:read" - AnyTypeProjectIntegrationsRead AnyType = "project:integrations:read" - AnyTypeProjectIntegrationsWrite AnyType = "project:integrations:write" - AnyTypeProjectNetworkingRead AnyType = "project:networking:read" - AnyTypeProjectNetworkingWrite AnyType = "project:networking:write" - AnyTypeProjectPermissionsRead AnyType = "project:permissions:read" - AnyTypeProjectServicesRead AnyType = "project:services:read" - AnyTypeProjectServicesWrite AnyType = "project:services:write" - AnyTypeReadOnly AnyType = "read_only" - AnyTypeRoleOrganizationAdmin AnyType = "role:organization:admin" - AnyTypeRoleServicesMaintenance AnyType = "role:services:maintenance" - AnyTypeRoleServicesRecover AnyType = "role:services:recover" - AnyTypeServiceConfigurationWrite AnyType = "service:configuration:write" - AnyTypeServiceDataWrite AnyType = "service:data:write" - AnyTypeServiceLogsRead AnyType = "service:logs:read" - AnyTypeServiceSecretsRead AnyType = "service:secrets:read" - AnyTypeServiceUsersWrite AnyType = "service:users:write" -) - -func AnyTypeChoices() []string { - return []string{"admin", "developer", "operator", "organization:app_users:write", "organization:audit_logs:read", "organization:domains:write", "organization:groups:write", "organization:idps:write", "organization:networking:read", "organization:networking:write", "organization:projects:write", "organization:users:write", "project:audit_logs:read", "project:integrations:read", "project:integrations:write", "project:networking:read", "project:networking:write", "project:permissions:read", "project:services:read", "project:services:write", "read_only", "role:organization:admin", "role:services:maintenance", "role:services:recover", "service:configuration:write", "service:data:write", "service:logs:read", "service:secrets:read", "service:users:write"} -} // BackupConfigOut Backup configuration for this service plan type BackupConfigOut struct { @@ -817,20 +780,48 @@ type ProjectInviteIn struct { // ProjectListOut ProjectListResponse type ProjectListOut struct { - ProjectMembership ProjectMembershipOut `json:"project_membership"` // Project membership and type of membership - ProjectMemberships ProjectMembershipsOut `json:"project_memberships"` // List of project membership and type of membership - Projects []ProjectOut `json:"projects"` // List of projects + ProjectMembership map[string]ProjectMembershipType `json:"project_membership"` // Project membership and type of membership + ProjectMemberships map[string][]string `json:"project_memberships"` // List of project membership and type of membership + Projects []ProjectOut `json:"projects"` // List of projects } +type ProjectMembershipType string -// ProjectMembershipOut Project membership and type of membership -type ProjectMembershipOut struct { - Any AnyType `json:"ANY,omitempty"` // Project member type -} +const ( + ProjectMembershipTypeAdmin ProjectMembershipType = "admin" + ProjectMembershipTypeDeveloper ProjectMembershipType = "developer" + ProjectMembershipTypeOperator ProjectMembershipType = "operator" + ProjectMembershipTypeOrganizationAppUsersWrite ProjectMembershipType = "organization:app_users:write" + ProjectMembershipTypeOrganizationAuditLogsRead ProjectMembershipType = "organization:audit_logs:read" + ProjectMembershipTypeOrganizationDomainsWrite ProjectMembershipType = "organization:domains:write" + ProjectMembershipTypeOrganizationGroupsWrite ProjectMembershipType = "organization:groups:write" + ProjectMembershipTypeOrganizationIdpsWrite ProjectMembershipType = "organization:idps:write" + ProjectMembershipTypeOrganizationNetworkingRead ProjectMembershipType = "organization:networking:read" + ProjectMembershipTypeOrganizationNetworkingWrite ProjectMembershipType = "organization:networking:write" + ProjectMembershipTypeOrganizationProjectsWrite ProjectMembershipType = "organization:projects:write" + ProjectMembershipTypeOrganizationUsersWrite ProjectMembershipType = "organization:users:write" + ProjectMembershipTypeProjectAuditLogsRead ProjectMembershipType = "project:audit_logs:read" + ProjectMembershipTypeProjectIntegrationsRead ProjectMembershipType = "project:integrations:read" + ProjectMembershipTypeProjectIntegrationsWrite ProjectMembershipType = "project:integrations:write" + ProjectMembershipTypeProjectNetworkingRead ProjectMembershipType = "project:networking:read" + ProjectMembershipTypeProjectNetworkingWrite ProjectMembershipType = "project:networking:write" + ProjectMembershipTypeProjectPermissionsRead ProjectMembershipType = "project:permissions:read" + ProjectMembershipTypeProjectServicesRead ProjectMembershipType = "project:services:read" + ProjectMembershipTypeProjectServicesWrite ProjectMembershipType = "project:services:write" + ProjectMembershipTypeReadOnly ProjectMembershipType = "read_only" + ProjectMembershipTypeRoleOrganizationAdmin ProjectMembershipType = "role:organization:admin" + ProjectMembershipTypeRoleServicesMaintenance ProjectMembershipType = "role:services:maintenance" + ProjectMembershipTypeRoleServicesRecover ProjectMembershipType = "role:services:recover" + ProjectMembershipTypeServiceConfigurationWrite ProjectMembershipType = "service:configuration:write" + ProjectMembershipTypeServiceDataWrite ProjectMembershipType = "service:data:write" + ProjectMembershipTypeServiceLogsRead ProjectMembershipType = "service:logs:read" + ProjectMembershipTypeServiceSecretsRead ProjectMembershipType = "service:secrets:read" + ProjectMembershipTypeServiceUsersWrite ProjectMembershipType = "service:users:write" +) -// ProjectMembershipsOut List of project membership and type of membership -type ProjectMembershipsOut struct { - Any []string `json:"ANY,omitempty"` // List of project member type +func ProjectMembershipTypeChoices() []string { + return []string{"admin", "developer", "operator", "organization:app_users:write", "organization:audit_logs:read", "organization:domains:write", "organization:groups:write", "organization:idps:write", "organization:networking:read", "organization:networking:write", "organization:projects:write", "organization:users:write", "project:audit_logs:read", "project:integrations:read", "project:integrations:write", "project:networking:read", "project:networking:write", "project:permissions:read", "project:services:read", "project:services:write", "read_only", "role:organization:admin", "role:services:maintenance", "role:services:recover", "service:configuration:write", "service:data:write", "service:logs:read", "service:secrets:read", "service:users:write"} } + type ProjectOut struct { AccountId string `json:"account_id"` // Account ID AccountName *string `json:"account_name,omitempty"` // Account name diff --git a/handler/user/user.go b/handler/user/user.go index caceb4b..ad676e8 100644 --- a/handler/user/user.go +++ b/handler/user/user.go @@ -533,44 +533,6 @@ func ActionTypeChoices() []string { return []string{"azure_oauth", "github_oauth", "google_oauth", "hasura_oauth", "password", "saml", "signup"} } -type AnyType string - -const ( - AnyTypeAdmin AnyType = "admin" - AnyTypeDeveloper AnyType = "developer" - AnyTypeOperator AnyType = "operator" - AnyTypeOrganizationAppUsersWrite AnyType = "organization:app_users:write" - AnyTypeOrganizationAuditLogsRead AnyType = "organization:audit_logs:read" - AnyTypeOrganizationDomainsWrite AnyType = "organization:domains:write" - AnyTypeOrganizationGroupsWrite AnyType = "organization:groups:write" - AnyTypeOrganizationIdpsWrite AnyType = "organization:idps:write" - AnyTypeOrganizationNetworkingRead AnyType = "organization:networking:read" - AnyTypeOrganizationNetworkingWrite AnyType = "organization:networking:write" - AnyTypeOrganizationProjectsWrite AnyType = "organization:projects:write" - AnyTypeOrganizationUsersWrite AnyType = "organization:users:write" - AnyTypeProjectAuditLogsRead AnyType = "project:audit_logs:read" - AnyTypeProjectIntegrationsRead AnyType = "project:integrations:read" - AnyTypeProjectIntegrationsWrite AnyType = "project:integrations:write" - AnyTypeProjectNetworkingRead AnyType = "project:networking:read" - AnyTypeProjectNetworkingWrite AnyType = "project:networking:write" - AnyTypeProjectPermissionsRead AnyType = "project:permissions:read" - AnyTypeProjectServicesRead AnyType = "project:services:read" - AnyTypeProjectServicesWrite AnyType = "project:services:write" - AnyTypeReadOnly AnyType = "read_only" - AnyTypeRoleOrganizationAdmin AnyType = "role:organization:admin" - AnyTypeRoleServicesMaintenance AnyType = "role:services:maintenance" - AnyTypeRoleServicesRecover AnyType = "role:services:recover" - AnyTypeServiceConfigurationWrite AnyType = "service:configuration:write" - AnyTypeServiceDataWrite AnyType = "service:data:write" - AnyTypeServiceLogsRead AnyType = "service:logs:read" - AnyTypeServiceSecretsRead AnyType = "service:secrets:read" - AnyTypeServiceUsersWrite AnyType = "service:users:write" -) - -func AnyTypeChoices() []string { - return []string{"admin", "developer", "operator", "organization:app_users:write", "organization:audit_logs:read", "organization:domains:write", "organization:groups:write", "organization:idps:write", "organization:networking:read", "organization:networking:write", "organization:projects:write", "organization:users:write", "project:audit_logs:read", "project:integrations:read", "project:integrations:write", "project:networking:read", "project:networking:write", "project:permissions:read", "project:services:read", "project:services:write", "read_only", "role:organization:admin", "role:services:maintenance", "role:services:recover", "service:configuration:write", "service:data:write", "service:logs:read", "service:secrets:read", "service:users:write"} -} - type AuthenticationMethodOut struct { AuthenticationMethodAccountId string `json:"authentication_method_account_id"` // Account ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC @@ -652,15 +614,44 @@ func MethodTypeChoices() []string { return []string{"GET", "POST"} } -// ProjectMembershipOut Project membership and type of membership -type ProjectMembershipOut struct { - Any AnyType `json:"ANY,omitempty"` // Project member type -} +type ProjectMembershipType string + +const ( + ProjectMembershipTypeAdmin ProjectMembershipType = "admin" + ProjectMembershipTypeDeveloper ProjectMembershipType = "developer" + ProjectMembershipTypeOperator ProjectMembershipType = "operator" + ProjectMembershipTypeOrganizationAppUsersWrite ProjectMembershipType = "organization:app_users:write" + ProjectMembershipTypeOrganizationAuditLogsRead ProjectMembershipType = "organization:audit_logs:read" + ProjectMembershipTypeOrganizationDomainsWrite ProjectMembershipType = "organization:domains:write" + ProjectMembershipTypeOrganizationGroupsWrite ProjectMembershipType = "organization:groups:write" + ProjectMembershipTypeOrganizationIdpsWrite ProjectMembershipType = "organization:idps:write" + ProjectMembershipTypeOrganizationNetworkingRead ProjectMembershipType = "organization:networking:read" + ProjectMembershipTypeOrganizationNetworkingWrite ProjectMembershipType = "organization:networking:write" + ProjectMembershipTypeOrganizationProjectsWrite ProjectMembershipType = "organization:projects:write" + ProjectMembershipTypeOrganizationUsersWrite ProjectMembershipType = "organization:users:write" + ProjectMembershipTypeProjectAuditLogsRead ProjectMembershipType = "project:audit_logs:read" + ProjectMembershipTypeProjectIntegrationsRead ProjectMembershipType = "project:integrations:read" + ProjectMembershipTypeProjectIntegrationsWrite ProjectMembershipType = "project:integrations:write" + ProjectMembershipTypeProjectNetworkingRead ProjectMembershipType = "project:networking:read" + ProjectMembershipTypeProjectNetworkingWrite ProjectMembershipType = "project:networking:write" + ProjectMembershipTypeProjectPermissionsRead ProjectMembershipType = "project:permissions:read" + ProjectMembershipTypeProjectServicesRead ProjectMembershipType = "project:services:read" + ProjectMembershipTypeProjectServicesWrite ProjectMembershipType = "project:services:write" + ProjectMembershipTypeReadOnly ProjectMembershipType = "read_only" + ProjectMembershipTypeRoleOrganizationAdmin ProjectMembershipType = "role:organization:admin" + ProjectMembershipTypeRoleServicesMaintenance ProjectMembershipType = "role:services:maintenance" + ProjectMembershipTypeRoleServicesRecover ProjectMembershipType = "role:services:recover" + ProjectMembershipTypeServiceConfigurationWrite ProjectMembershipType = "service:configuration:write" + ProjectMembershipTypeServiceDataWrite ProjectMembershipType = "service:data:write" + ProjectMembershipTypeServiceLogsRead ProjectMembershipType = "service:logs:read" + ProjectMembershipTypeServiceSecretsRead ProjectMembershipType = "service:secrets:read" + ProjectMembershipTypeServiceUsersWrite ProjectMembershipType = "service:users:write" +) -// ProjectMembershipsOut List of project membership and type of membership -type ProjectMembershipsOut struct { - Any []string `json:"ANY,omitempty"` // List of project member type +func ProjectMembershipTypeChoices() []string { + return []string{"admin", "developer", "operator", "organization:app_users:write", "organization:audit_logs:read", "organization:domains:write", "organization:groups:write", "organization:idps:write", "organization:networking:read", "organization:networking:write", "organization:projects:write", "organization:users:write", "project:audit_logs:read", "project:integrations:read", "project:integrations:write", "project:networking:read", "project:networking:write", "project:permissions:read", "project:services:read", "project:services:write", "read_only", "role:organization:admin", "role:services:maintenance", "role:services:recover", "service:configuration:write", "service:data:write", "service:logs:read", "service:secrets:read", "service:users:write"} } + type TokenOut struct { CreateTime time.Time `json:"create_time"` // Timestamp when the access token was created CreatedManually bool `json:"created_manually"` // True for tokens explicitly created via the access_tokens API, false for tokens created via login. @@ -771,46 +762,46 @@ type UserGroupOut struct { // UserInfoOut User information type UserInfoOut struct { - Auth []string `json:"auth"` // List of user's required authentication methods - City *string `json:"city,omitempty"` - Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 - CreateTime *time.Time `json:"create_time,omitempty"` // User registration time - Department *string `json:"department,omitempty"` // Job department - Features map[string]any `json:"features,omitempty"` // Feature flags - Invitations []InvitationOut `json:"invitations"` // List of pending invitations - JobTitle *string `json:"job_title,omitempty"` // Job title - ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status - ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID - ProjectMembership ProjectMembershipOut `json:"project_membership"` // Project membership and type of membership - ProjectMemberships ProjectMembershipsOut `json:"project_memberships"` // List of project membership and type of membership - Projects []string `json:"projects"` // List of projects the user is a member of - RealName string `json:"real_name"` // User real name - State string `json:"state"` // User account state - TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp - User string `json:"user"` // User email address - UserId string `json:"user_id"` // User ID + Auth []string `json:"auth"` // List of user's required authentication methods + City *string `json:"city,omitempty"` + Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 + CreateTime *time.Time `json:"create_time,omitempty"` // User registration time + Department *string `json:"department,omitempty"` // Job department + Features map[string]any `json:"features,omitempty"` // Feature flags + Invitations []InvitationOut `json:"invitations"` // List of pending invitations + JobTitle *string `json:"job_title,omitempty"` // Job title + ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status + ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID + ProjectMembership map[string]ProjectMembershipType `json:"project_membership"` // Project membership and type of membership + ProjectMemberships map[string][]string `json:"project_memberships"` // List of project membership and type of membership + Projects []string `json:"projects"` // List of projects the user is a member of + RealName string `json:"real_name"` // User real name + State string `json:"state"` // User account state + TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp + User string `json:"user"` // User email address + UserId string `json:"user_id"` // User ID } // UserOut User information type UserOut struct { - Auth []string `json:"auth"` // List of user's required authentication methods - City *string `json:"city,omitempty"` - Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 - CreateTime *time.Time `json:"create_time,omitempty"` // User registration time - Department *string `json:"department,omitempty"` // Job department - Features map[string]any `json:"features,omitempty"` // Feature flags - Invitations []InvitationOut `json:"invitations"` // List of pending invitations - JobTitle *string `json:"job_title,omitempty"` // Job title - ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status - ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID - ProjectMembership ProjectMembershipOut `json:"project_membership"` // Project membership and type of membership - ProjectMemberships ProjectMembershipsOut `json:"project_memberships"` // List of project membership and type of membership - Projects []string `json:"projects"` // List of projects the user is a member of - RealName string `json:"real_name"` // User real name - State string `json:"state"` // User account state - TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp - User string `json:"user"` // User email address - UserId string `json:"user_id"` // User ID + Auth []string `json:"auth"` // List of user's required authentication methods + City *string `json:"city,omitempty"` + Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 + CreateTime *time.Time `json:"create_time,omitempty"` // User registration time + Department *string `json:"department,omitempty"` // Job department + Features map[string]any `json:"features,omitempty"` // Feature flags + Invitations []InvitationOut `json:"invitations"` // List of pending invitations + JobTitle *string `json:"job_title,omitempty"` // Job title + ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status + ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID + ProjectMembership map[string]ProjectMembershipType `json:"project_membership"` // Project membership and type of membership + ProjectMemberships map[string][]string `json:"project_memberships"` // List of project membership and type of membership + Projects []string `json:"projects"` // List of projects the user is a member of + RealName string `json:"real_name"` // User real name + State string `json:"state"` // User account state + TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp + User string `json:"user"` // User email address + UserId string `json:"user_id"` // User ID } // UserPasswordChangeIn UserPasswordChangeRequestBody @@ -840,24 +831,24 @@ type UserUpdateIn struct { // UserUpdateOut User information type UserUpdateOut struct { - Auth []string `json:"auth"` // List of user's required authentication methods - City *string `json:"city,omitempty"` - Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 - CreateTime *time.Time `json:"create_time,omitempty"` // User registration time - Department *string `json:"department,omitempty"` // Job department - Features map[string]any `json:"features,omitempty"` // Feature flags - Invitations []InvitationOut `json:"invitations"` // List of pending invitations - JobTitle *string `json:"job_title,omitempty"` // Job title - ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status - ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID - ProjectMembership ProjectMembershipOut `json:"project_membership"` // Project membership and type of membership - ProjectMemberships ProjectMembershipsOut `json:"project_memberships"` // List of project membership and type of membership - Projects []string `json:"projects"` // List of projects the user is a member of - RealName string `json:"real_name"` // User real name - State string `json:"state"` // User account state - TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp - User string `json:"user"` // User email address - UserId string `json:"user_id"` // User ID + Auth []string `json:"auth"` // List of user's required authentication methods + City *string `json:"city,omitempty"` + Country *string `json:"country,omitempty"` // Country code ISO 3166-1 alpha-2 + CreateTime *time.Time `json:"create_time,omitempty"` // User registration time + Department *string `json:"department,omitempty"` // Job department + Features map[string]any `json:"features,omitempty"` // Feature flags + Invitations []InvitationOut `json:"invitations"` // List of pending invitations + JobTitle *string `json:"job_title,omitempty"` // Job title + ManagedByScim *bool `json:"managed_by_scim,omitempty"` // User management status + ManagingOrganizationId *string `json:"managing_organization_id,omitempty"` // Organization ID + ProjectMembership map[string]ProjectMembershipType `json:"project_membership"` // Project membership and type of membership + ProjectMemberships map[string][]string `json:"project_memberships"` // List of project membership and type of membership + Projects []string `json:"projects"` // List of projects the user is a member of + RealName string `json:"real_name"` // User real name + State string `json:"state"` // User account state + TokenValidityBegin *string `json:"token_validity_begin,omitempty"` // Earliest valid authentication token timestamp + User string `json:"user"` // User email address + UserId string `json:"user_id"` // User ID } // UserVerifyEmailOut Details of verified invite From 7870a77c617c61807678fa0224396b2d311647a4 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Wed, 5 Feb 2025 12:33:57 +0100 Subject: [PATCH 2/2] feat: add OrganizationProjects handlers --- config.yaml | 3 + .../organizationprojects.go | 85 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/config.yaml b/config.yaml index 2b46c7c..7d12c99 100644 --- a/config.yaml +++ b/config.yaml @@ -207,6 +207,9 @@ Organization: - UserOrganizationsList OrganizationProjects: - OrganizationProjectsCreate + - OrganizationProjectsDelete + - OrganizationProjectsList + - OrganizationProjectsUpdate OrganizationUser: - OrganizationUserAuthenticationMethodsList - OrganizationUserDelete diff --git a/handler/organizationprojects/organizationprojects.go b/handler/organizationprojects/organizationprojects.go index a619bb6..43db91b 100644 --- a/handler/organizationprojects/organizationprojects.go +++ b/handler/organizationprojects/organizationprojects.go @@ -14,6 +14,21 @@ type Handler interface { // POST /v1/organization/{organization_id}/projects // https://api.aiven.io/doc/#tag/Organizations/operation/OrganizationProjectsCreate OrganizationProjectsCreate(ctx context.Context, organizationId string, in *OrganizationProjectsCreateIn) (*OrganizationProjectsCreateOut, error) + + // OrganizationProjectsDelete [EXPERIMENTAL] Delete project under the organization + // DELETE /v1/organization/{organization_id}/projects/{project_id} + // https://api.aiven.io/doc/#tag/Organizations/operation/OrganizationProjectsDelete + OrganizationProjectsDelete(ctx context.Context, organizationId string, projectId string) error + + // OrganizationProjectsList [EXPERIMENTAL] List projects under the organization + // GET /v1/organization/{organization_id}/projects + // https://api.aiven.io/doc/#tag/Organizations/operation/OrganizationProjectsList + OrganizationProjectsList(ctx context.Context, organizationId string) (*OrganizationProjectsListOut, error) + + // OrganizationProjectsUpdate [EXPERIMENTAL] Update project under the organization + // PATCH /v1/organization/{organization_id}/projects/{project_id} + // https://api.aiven.io/doc/#tag/Organizations/operation/OrganizationProjectsUpdate + OrganizationProjectsUpdate(ctx context.Context, organizationId string, projectId string, in *OrganizationProjectsUpdateIn) (*OrganizationProjectsUpdateOut, error) } // doer http client @@ -42,6 +57,37 @@ func (h *OrganizationProjectsHandler) OrganizationProjectsCreate(ctx context.Con } return out, nil } +func (h *OrganizationProjectsHandler) OrganizationProjectsDelete(ctx context.Context, organizationId string, projectId string) error { + path := fmt.Sprintf("/v1/organization/%s/projects/%s", url.PathEscape(organizationId), url.PathEscape(projectId)) + _, err := h.doer.Do(ctx, "OrganizationProjectsDelete", "DELETE", path, nil) + return err +} +func (h *OrganizationProjectsHandler) OrganizationProjectsList(ctx context.Context, organizationId string) (*OrganizationProjectsListOut, error) { + path := fmt.Sprintf("/v1/organization/%s/projects", url.PathEscape(organizationId)) + b, err := h.doer.Do(ctx, "OrganizationProjectsList", "GET", path, nil) + if err != nil { + return nil, err + } + out := new(OrganizationProjectsListOut) + err = json.Unmarshal(b, out) + if err != nil { + return nil, err + } + return out, nil +} +func (h *OrganizationProjectsHandler) OrganizationProjectsUpdate(ctx context.Context, organizationId string, projectId string, in *OrganizationProjectsUpdateIn) (*OrganizationProjectsUpdateOut, error) { + path := fmt.Sprintf("/v1/organization/%s/projects/%s", url.PathEscape(organizationId), url.PathEscape(projectId)) + b, err := h.doer.Do(ctx, "OrganizationProjectsUpdate", "PATCH", path, in) + if err != nil { + return nil, err + } + out := new(OrganizationProjectsUpdateOut) + err = json.Unmarshal(b, out) + if err != nil { + return nil, err + } + return out, nil +} // EndOfLifeExtension ServiceEndOfLifeExtension type EndOfLifeExtension struct { @@ -68,6 +114,45 @@ type OrganizationProjectsCreateOut struct { Tags map[string]string `json:"tags"` // Tags TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses } + +// OrganizationProjectsListOut OrganizationProjectsListResponse +type OrganizationProjectsListOut struct { + Projects []ProjectOut `json:"projects"` // List of projects + TotalProjectCount int `json:"total_project_count"` // Total number of projects +} + +// OrganizationProjectsUpdateIn OrganizationProjectsUpdateRequestBody +type OrganizationProjectsUpdateIn struct { + BillingGroupId *string `json:"billing_group_id,omitempty"` // Billing group ID to assign to the project. It's required when moving projects between organizations + ParentId *string `json:"parent_id,omitempty"` // Organization or unit ID to where to move the project + ProjectId *string `json:"project_id,omitempty"` // New Project ID + Tags *map[string]string `json:"tags,omitempty"` // Tags + TechEmails *[]TechEmailIn `json:"tech_emails,omitempty"` // Technical contact emails +} + +// OrganizationProjectsUpdateOut OrganizationProjectsUpdateResponse +type OrganizationProjectsUpdateOut struct { + AccountId *string `json:"account_id,omitempty"` // Account ID to where the project belongs + BillingGroupId *string `json:"billing_group_id,omitempty"` // Billing group ID + EndOfLifeExtension map[string]EndOfLifeExtension `json:"end_of_life_extension"` // End of life extension information + Features map[string]bool `json:"features,omitempty"` // Feature flags + ParentId *string `json:"parent_id,omitempty"` // Organization or unit ID to where the project belongs + ProjectId string `json:"project_id"` // Project ID + Tags map[string]string `json:"tags"` // Tags + TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses +} +type ProjectOut struct { + AccountId *string `json:"account_id,omitempty"` // Account ID to where the project belongs + BillingGroupId *string `json:"billing_group_id,omitempty"` // Billing group ID + EndOfLifeExtension map[string]EndOfLifeExtension `json:"end_of_life_extension"` // End of life extension information + ParentId *string `json:"parent_id,omitempty"` // Organization or unit ID to where the project belongs + ProjectId string `json:"project_id"` // Project ID + Tags map[string]string `json:"tags"` // Tags + TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses +} +type TechEmailIn struct { + Email string `json:"email"` // Technical contact email +} type TechEmailOut struct { Email string `json:"email"` // Technical contact email }