From d951cf1e6d134cc10ef5c65d821a2604c74a48e7 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Thu, 6 Feb 2025 13:48:05 +0100 Subject: [PATCH] fix: nested maps --- generator/main.go | 13 ++- generator/models.go | 37 +------- handler/account/account.go | 12 +-- handler/kafka/kafka.go | 6 +- handler/kafkatopic/kafkatopic.go | 13 ++- .../organizationprojects.go | 18 ++-- handler/project/project.go | 34 ++++--- handler/service/service.go | 95 ++++++++++++++----- handler/user/user.go | 6 +- 9 files changed, 136 insertions(+), 98 deletions(-) diff --git a/generator/main.go b/generator/main.go index c03e001..acdb16a 100644 --- a/generator/main.go +++ b/generator/main.go @@ -64,11 +64,10 @@ func main() { } const ( - doerName = "doer" - handlerTypeName = "Handler" - queryParamName = "query" - queryParamTypeSuffix = "Query" - queryParamArraySize = 2 + doerName = "doer" + handlerTypeName = "Handler" + queryParamName = "query" + queryParamArraySize = 2 ) //nolint:funlen,gocognit,gocyclo // It's a generator, it's supposed to be long, and we won't expand it. @@ -513,8 +512,8 @@ func writeStruct(f *jen.File, s *Schema) error { return nil } - if s.Description != "" { - f.Comment(fmt.Sprintf("%s %s", s.CamelName, fmtComment(s.Description))) + if c := fmtComment(s.Description); c != "" && c != s.CamelName { + f.Comment(fmt.Sprintf("%s %s", s.CamelName, c)) } f.Type().Id(s.CamelName).Add(fmtStruct(s)) diff --git a/generator/models.go b/generator/models.go index 91de59d..725c320 100644 --- a/generator/models.go +++ b/generator/models.go @@ -150,18 +150,6 @@ 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"` @@ -294,16 +282,10 @@ 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 + s.AdditionalProperties.init(doc, scope, toSingle(name)) } if s.isObject() { @@ -374,18 +356,13 @@ func (s *Schema) isObject() bool { return s.Type == SchemaTypeObject && len(s.Properties) != 0 } -func (s *Schema) isArray() bool { - return s.Type == SchemaTypeArray -} - // isMap schemaless map 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) isArray() bool { + return s.Type == SchemaTypeArray } func (s *Schema) isEnum() bool { @@ -480,16 +457,12 @@ func getType(s *Schema) *jen.Statement { } return withPointer(o, s.required) - case s.isMap(), s.isTypedMap(): + case s.isMap(): a := withPointer(jen.Map(jen.String()), s.required || s.isOut()) if s.AdditionalProperties != nil { return a.Add(getType(s.AdditionalProperties)) - } else if s.name == "tags" { - // tags are everywhere in the schema, better not to use the patch - return a.String() - } else { - return a.Any() } + return a.Any() default: panic(fmt.Errorf("unknown type %q for %q and parent %q", s.Type, s.name, s.parent.name)) } diff --git a/handler/account/account.go b/handler/account/account.go index ee22014..77c0d2b 100644 --- a/handler/account/account.go +++ b/handler/account/account.go @@ -371,7 +371,7 @@ type AccountCreateOut struct { AccountName string `json:"account_name"` // Account name AccountOwnerTeamId string `json:"account_owner_team_id"` // Team ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags IsAccountMember *bool `json:"is_account_member,omitempty"` // If true, user is part of a team of this or a parent account IsAccountOwner bool `json:"is_account_owner"` // If true, user is part of the owners team for this account OrganizationId string `json:"organization_id"` // Organization ID @@ -389,7 +389,7 @@ type AccountGetOut struct { AccountName string `json:"account_name"` // Account name AccountOwnerTeamId string `json:"account_owner_team_id"` // Team ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags IsAccountMember *bool `json:"is_account_member,omitempty"` // If true, user is part of a team of this or a parent account IsAccountOwner bool `json:"is_account_owner"` // If true, user is part of the owners team for this account OrganizationId string `json:"organization_id"` // Organization ID @@ -412,7 +412,7 @@ type AccountMoveOut struct { AccountName string `json:"account_name"` // Account name AccountOwnerTeamId string `json:"account_owner_team_id"` // Team ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags IsAccountMember *bool `json:"is_account_member,omitempty"` // If true, user is part of a team of this or a parent account IsAccountOwner bool `json:"is_account_owner"` // If true, user is part of the owners team for this account OrganizationId string `json:"organization_id"` // Organization ID @@ -428,7 +428,7 @@ type AccountOut struct { AccountName string `json:"account_name"` // Account name AccountOwnerTeamId string `json:"account_owner_team_id"` // Team ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags IsAccountMember *bool `json:"is_account_member,omitempty"` // If true, user is part of a team of this or a parent account IsAccountOwner bool `json:"is_account_owner"` // If true, user is part of the owners team for this account OrganizationId string `json:"organization_id"` // Organization ID @@ -458,7 +458,7 @@ type AccountUpdateOut struct { AccountName string `json:"account_name"` // Account name AccountOwnerTeamId string `json:"account_owner_team_id"` // Team ID CreateTime time.Time `json:"create_time"` // Timestamp in ISO 8601 format, always in UTC - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags IsAccountMember *bool `json:"is_account_member,omitempty"` // If true, user is part of a team of this or a parent account IsAccountOwner bool `json:"is_account_owner"` // If true, user is part of the owners team for this account OrganizationId string `json:"organization_id"` // Organization ID @@ -640,7 +640,7 @@ type ProjectOut struct { EndOfLifeExtension *EndOfLifeExtensionOut `json:"end_of_life_extension,omitempty"` // End of life extension information EstimatedBalance string `json:"estimated_balance"` // Estimated balance, in USD EstimatedBalanceLocal *string `json:"estimated_balance_local,omitempty"` // Estimated balance, in billing currency - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags OrganizationId string `json:"organization_id"` // Organization ID PaymentMethod string `json:"payment_method"` // Payment method ProjectName string `json:"project_name"` // Project name diff --git a/handler/kafka/kafka.go b/handler/kafka/kafka.go index 0a66a2d..cafb3e4 100644 --- a/handler/kafka/kafka.go +++ b/handler/kafka/kafka.go @@ -68,7 +68,7 @@ type Handler interface { // ServiceKafkaTieredStorageStorageUsageByTopic get the Kafka tiered storage object storage usage by topic // GET /v1/project/{project}/service/{service_name}/kafka/tiered-storage/storage-usage/by-topic // https://api.aiven.io/doc/#tag/Service:_Kafka/operation/ServiceKafkaTieredStorageStorageUsageByTopic - ServiceKafkaTieredStorageStorageUsageByTopic(ctx context.Context, project string, serviceName string) (map[string]any, error) + ServiceKafkaTieredStorageStorageUsageByTopic(ctx context.Context, project string, serviceName string) (map[string]int, error) // ServiceKafkaTieredStorageStorageUsageTotal get the Kafka tiered storage total object storage usage // GET /v1/project/{project}/service/{service_name}/kafka/tiered-storage/storage-usage/total @@ -233,7 +233,7 @@ func (h *KafkaHandler) ServiceKafkaQuotaList(ctx context.Context, project string } return out.Quotas, nil } -func (h *KafkaHandler) ServiceKafkaTieredStorageStorageUsageByTopic(ctx context.Context, project string, serviceName string) (map[string]any, error) { +func (h *KafkaHandler) ServiceKafkaTieredStorageStorageUsageByTopic(ctx context.Context, project string, serviceName string) (map[string]int, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/kafka/tiered-storage/storage-usage/by-topic", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceKafkaTieredStorageStorageUsageByTopic", "GET", path, nil) if err != nil { @@ -510,7 +510,7 @@ type serviceKafkaQuotaListOut struct { // serviceKafkaTieredStorageUsageByTopicOut ServiceKafkaTieredStorageStorageUsageByTopicResponse type serviceKafkaTieredStorageUsageByTopicOut struct { - StorageUsage map[string]any `json:"storage_usage"` // Storage usage by tiered storage by topics + StorageUsage map[string]int `json:"storage_usage"` // Storage usage by tiered storage by topics } // serviceKafkaTieredStorageUsageTotalOut ServiceKafkaTieredStorageStorageUsageTotalResponse diff --git a/handler/kafkatopic/kafkatopic.go b/handler/kafkatopic/kafkatopic.go index 2d6abcd..fde2773 100644 --- a/handler/kafkatopic/kafkatopic.go +++ b/handler/kafkatopic/kafkatopic.go @@ -566,6 +566,11 @@ type OffsetOut struct { Offset *int `json:"offset,omitempty"` // Offset of the message, or null if publishing the message failed Partition *int `json:"partition,omitempty"` // Partition the message was published to, or null if publishing the message failed } + +// Partition Partition / offset mapping +type Partition struct { + Offset int `json:"offset"` // The beginning offset for the fetched messages +} type PartitionOut struct { ConsumerGroups []ConsumerGroupOut `json:"consumer_groups"` // List of Kafka consumer groups EarliestOffset int `json:"earliest_offset"` // Earliest partition message offset @@ -702,10 +707,10 @@ type ServiceKafkaTopicGetOut struct { // ServiceKafkaTopicMessageListIn ServiceKafkaTopicMessageListRequestBody type ServiceKafkaTopicMessageListIn struct { - Format FormatType `json:"format,omitempty"` // The format of consumed messages, which is used to convert messages into a JSON-compatible form. If unspecified, defaults to binary - MaxBytes *int `json:"max_bytes,omitempty"` // The maximum number of bytes of unencoded keys and values that should be included in the response. This provides approximate control over the size of responses and the amount of memory required to store the decoded response. The actual limit will be the minimum of this setting and the server-side configuration consumer.request.max.bytes. Default is unlimited - Partitions map[string]any `json:"partitions"` // Object of desired partition / offset mappings - Timeout *int `json:"timeout,omitempty"` // The maximum total time to wait for messages for a request if the maximum request size has not yet been reached + Format FormatType `json:"format,omitempty"` // The format of consumed messages, which is used to convert messages into a JSON-compatible form. If unspecified, defaults to binary + MaxBytes *int `json:"max_bytes,omitempty"` // The maximum number of bytes of unencoded keys and values that should be included in the response. This provides approximate control over the size of responses and the amount of memory required to store the decoded response. The actual limit will be the minimum of this setting and the server-side configuration consumer.request.max.bytes. Default is unlimited + Partitions map[string]Partition `json:"partitions"` // Object of desired partition / offset mappings + Timeout *int `json:"timeout,omitempty"` // The maximum total time to wait for messages for a request if the maximum request size has not yet been reached } // ServiceKafkaTopicMessageProduceIn ServiceKafkaTopicMessageProduceRequestBody diff --git a/handler/organizationprojects/organizationprojects.go b/handler/organizationprojects/organizationprojects.go index 43db91b..e846c2a 100644 --- a/handler/organizationprojects/organizationprojects.go +++ b/handler/organizationprojects/organizationprojects.go @@ -100,7 +100,7 @@ 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 + Tags map[string]string `json:"tags"` } // OrganizationProjectsCreateOut OrganizationProjectsCreateResponse @@ -111,8 +111,8 @@ type OrganizationProjectsCreateOut struct { 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 + Tags map[string]string `json:"tags"` + TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses } // OrganizationProjectsListOut OrganizationProjectsListResponse @@ -126,8 +126,8 @@ 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 + Tags *map[string]string `json:"tags,omitempty"` + TechEmails *[]TechEmailIn `json:"tech_emails,omitempty"` // Technical contact emails } // OrganizationProjectsUpdateOut OrganizationProjectsUpdateResponse @@ -138,8 +138,8 @@ type OrganizationProjectsUpdateOut struct { 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 + Tags map[string]string `json:"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 @@ -147,8 +147,8 @@ type ProjectOut struct { 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 + Tags map[string]string `json:"tags"` + TechEmails []TechEmailOut `json:"tech_emails"` // List of project technical email addresses } type TechEmailIn struct { Email string `json:"email"` // Technical contact email diff --git a/handler/project/project.go b/handler/project/project.go index 5d4df8b..3035c4a 100644 --- a/handler/project/project.go +++ b/handler/project/project.go @@ -720,7 +720,7 @@ type ProjectCreateOut struct { EndOfLifeExtension *EndOfLifeExtensionOut `json:"end_of_life_extension,omitempty"` // End of life extension information EstimatedBalance string `json:"estimated_balance"` // Estimated balance, in USD EstimatedBalanceLocal *string `json:"estimated_balance_local,omitempty"` // Estimated balance, in billing currency - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags OrganizationId string `json:"organization_id"` // Organization ID PaymentMethod string `json:"payment_method"` // Payment method ProjectName string `json:"project_name"` // Project name @@ -754,7 +754,7 @@ type ProjectGetOut struct { EndOfLifeExtension *EndOfLifeExtensionOut `json:"end_of_life_extension,omitempty"` // End of life extension information EstimatedBalance string `json:"estimated_balance"` // Estimated balance, in USD EstimatedBalanceLocal *string `json:"estimated_balance_local,omitempty"` // Estimated balance, in billing currency - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags OrganizationId string `json:"organization_id"` // Organization ID PaymentMethod string `json:"payment_method"` // Payment method ProjectName string `json:"project_name"` // Project name @@ -842,7 +842,7 @@ type ProjectOut struct { EndOfLifeExtension *EndOfLifeExtensionOut `json:"end_of_life_extension,omitempty"` // End of life extension information EstimatedBalance string `json:"estimated_balance"` // Estimated balance, in USD EstimatedBalanceLocal *string `json:"estimated_balance_local,omitempty"` // Estimated balance, in billing currency - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags OrganizationId string `json:"organization_id"` // Organization ID PaymentMethod string `json:"payment_method"` // Payment method ProjectName string `json:"project_name"` // Project name @@ -971,7 +971,7 @@ type ProjectUpdateOut struct { EndOfLifeExtension *EndOfLifeExtensionOut `json:"end_of_life_extension,omitempty"` // End of life extension information EstimatedBalance string `json:"estimated_balance"` // Estimated balance, in USD EstimatedBalanceLocal *string `json:"estimated_balance_local,omitempty"` // Estimated balance, in billing currency - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags OrganizationId string `json:"organization_id"` // Organization ID PaymentMethod string `json:"payment_method"` // Payment method ProjectName string `json:"project_name"` // Project name @@ -1013,14 +1013,26 @@ type RedisOut 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 } + +// Region Plan details for the given service type in this particular cloud region +type Region struct { + DiskSpaceCapMb *int `json:"disk_space_cap_mb,omitempty"` // Maximum amount of disk space possible for the plan in the given region + DiskSpaceGbPriceUsd *string `json:"disk_space_gb_price_usd,omitempty"` // Hourly additional disk space price per GiB in this region + DiskSpaceMb int `json:"disk_space_mb"` // Combined amount of service disk space of all service nodes in megabytes + DiskSpaceStepMb *int `json:"disk_space_step_mb,omitempty"` // Disk space change step size + NodeCpuCount int `json:"node_cpu_count"` // Number of CPU cores on each service node + NodeMemoryMb int `json:"node_memory_mb"` // Amount of memory on each service node in megabytes + ObjectStorageGbPriceUsd *string `json:"object_storage_gb_price_usd,omitempty"` // Hourly object storage price per GiB in this region + PriceUsd string `json:"price_usd"` // Hourly service price in this region +} type ServicePlanOut struct { - BackupConfig BackupConfigOut `json:"backup_config"` // Backup configuration for this service plan - MaxMemoryPercent *int `json:"max_memory_percent,omitempty"` // Maximum amount of system memory as a percentage (0-100) the service can actually use after taking into account management overhead. This is relevant for memory bound services for which some service management operations require allocating proportional amount of memory on top the basic load. - NodeCount *int `json:"node_count,omitempty"` // Number of nodes in this service plan - Regions map[string]any `json:"regions,omitempty"` // Service plan hourly price per cloud region - ServicePlan string `json:"service_plan"` // Subscription plan - ServiceType string `json:"service_type"` // Service type code - ShardCount *int `json:"shard_count,omitempty"` // Number of shards in this service plan + BackupConfig BackupConfigOut `json:"backup_config"` // Backup configuration for this service plan + MaxMemoryPercent *int `json:"max_memory_percent,omitempty"` // Maximum amount of system memory as a percentage (0-100) the service can actually use after taking into account management overhead. This is relevant for memory bound services for which some service management operations require allocating proportional amount of memory on top the basic load. + NodeCount *int `json:"node_count,omitempty"` // Number of nodes in this service plan + Regions map[string]Region `json:"regions,omitempty"` // Service plan hourly price per cloud region + ServicePlan string `json:"service_plan"` // Subscription plan + ServiceType string `json:"service_type"` // Service type code + ShardCount *int `json:"shard_count,omitempty"` // Number of shards in this service plan } type TechEmailIn struct { Email string `json:"email"` // User email address diff --git a/handler/service/service.go b/handler/service/service.go index 59ec9e4..6b9026f 100644 --- a/handler/service/service.go +++ b/handler/service/service.go @@ -54,7 +54,7 @@ type Handler interface { // ServiceBackupToAnotherRegionReport get service's backup to another region information // POST /v1/project/{project}/service/{service_name}/backup_to_another_region/report // https://api.aiven.io/doc/#tag/Service/operation/ServiceBackupToAnotherRegionReport - ServiceBackupToAnotherRegionReport(ctx context.Context, project string, serviceName string, in *ServiceBackupToAnotherRegionReportIn) (map[string]any, error) + ServiceBackupToAnotherRegionReport(ctx context.Context, project string, serviceName string, in *ServiceBackupToAnotherRegionReportIn) (map[string]Metric, error) // ServiceBackupsGet get service backup information // GET /v1/project/{project}/service/{service_name}/backups @@ -194,7 +194,7 @@ type Handler interface { // ServiceMetricsFetch fetch service metrics // POST /v1/project/{project}/service/{service_name}/metrics // https://api.aiven.io/doc/#tag/Service/operation/ServiceMetricsFetch - ServiceMetricsFetch(ctx context.Context, project string, serviceName string, in *ServiceMetricsFetchIn) (map[string]any, error) + ServiceMetricsFetch(ctx context.Context, project string, serviceName string, in *ServiceMetricsFetchIn) (map[string]Metric, error) // ServiceQueryActivity fetch current queries for the service // POST /v1/project/{project}/service/{service_name}/query/activity @@ -204,7 +204,7 @@ type Handler interface { // ServiceQueryStatisticsReset reset service's query statistics // PUT /v1/project/{project}/service/{service_name}/query/stats/reset // https://api.aiven.io/doc/#tag/Service/operation/ServiceQueryStatisticsReset - ServiceQueryStatisticsReset(ctx context.Context, project string, serviceName string) ([]map[string]any, error) + ServiceQueryStatisticsReset(ctx context.Context, project string, serviceName string) ([]map[string]string, error) // ServiceTaskCreate create a new task for service // POST /v1/project/{project}/service/{service_name}/task @@ -348,7 +348,7 @@ func (h *ServiceHandler) ServiceAlertsList(ctx context.Context, project string, } return out.Alerts, nil } -func (h *ServiceHandler) ServiceBackupToAnotherRegionReport(ctx context.Context, project string, serviceName string, in *ServiceBackupToAnotherRegionReportIn) (map[string]any, error) { +func (h *ServiceHandler) ServiceBackupToAnotherRegionReport(ctx context.Context, project string, serviceName string, in *ServiceBackupToAnotherRegionReportIn) (map[string]Metric, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/backup_to_another_region/report", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceBackupToAnotherRegionReport", "POST", path, in) if err != nil { @@ -674,7 +674,7 @@ func (h *ServiceHandler) ServiceMaintenanceStart(ctx context.Context, project st _, err := h.doer.Do(ctx, "ServiceMaintenanceStart", "PUT", path, nil) return err } -func (h *ServiceHandler) ServiceMetricsFetch(ctx context.Context, project string, serviceName string, in *ServiceMetricsFetchIn) (map[string]any, error) { +func (h *ServiceHandler) ServiceMetricsFetch(ctx context.Context, project string, serviceName string, in *ServiceMetricsFetchIn) (map[string]Metric, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/metrics", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceMetricsFetch", "POST", path, in) if err != nil { @@ -700,7 +700,7 @@ func (h *ServiceHandler) ServiceQueryActivity(ctx context.Context, project strin } return out.Queries, nil } -func (h *ServiceHandler) ServiceQueryStatisticsReset(ctx context.Context, project string, serviceName string) ([]map[string]any, error) { +func (h *ServiceHandler) ServiceQueryStatisticsReset(ctx context.Context, project string, serviceName string) ([]map[string]string, error) { path := fmt.Sprintf("/v1/project/%s/service/%s/query/stats/reset", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceQueryStatisticsReset", "PUT", path, nil) if err != nil { @@ -934,6 +934,10 @@ type ClickhouseOut struct { ServicePlans []ServicePlanOut `json:"service_plans"` // List of plans available for this type of service UserConfigSchema map[string]any `json:"user_config_schema"` // JSON-Schema for the 'user_config' properties } +type Col struct { + Label string `json:"label"` // Column label + Type string `json:"type"` // Column type +} type ComponentOut struct { Component string `json:"component"` // Service component name Host string `json:"host"` // DNS name for connecting to the service component @@ -1012,6 +1016,9 @@ type ConnectionPoolOut struct { type CreateUserBackupIn struct { BackupName string `json:"backup_name"` // The output file name. } +type Data struct { + Cols []Col `json:"cols"` // Columns +} type DatabaseOut struct { DatabaseName string `json:"database_name"` // Database name or ID LcCollate *string `json:"lc_collate,omitempty"` @@ -1127,6 +1134,9 @@ type GrafanaOut struct { ServicePlans []ServicePlanOut `json:"service_plans"` // List of plans available for this type of service UserConfigSchema map[string]any `json:"user_config_schema"` // JSON-Schema for the 'user_config' properties } +type Hints struct { + Title string `json:"title"` +} // InfluxdbOut Service type information type InfluxdbOut struct { @@ -1426,6 +1436,12 @@ func MethodTypeChoices() []string { return []string{"dump", "mysqldump", "pg_dump", "replication", "scan"} } +// Metric Service metrics in Google chart compatible format +type Metric struct { + Data Data `json:"data"` + Hints Hints `json:"hints"` +} + // MigrationCheckIn Payload to be used with migration_check type MigrationCheckIn struct { IgnoreDbs *string `json:"ignore_dbs,omitempty"` // Comma-separated list of databases, which should be ignored during migration (supported by MySQL and PostgreSQL only at the moment) @@ -1504,6 +1520,13 @@ type MysqlParamOut struct { SslMode string `json:"ssl-mode"` User string `json:"user"` } + +// Node Integration state for node +type Node struct { + Errors []string `json:"errors"` + LikelyErrorCause LikelyErrorCauseType `json:"likely_error_cause,omitempty"` // Most likely cause of the errors + Status NodeStatusType `json:"status"` // Integration status for node +} type NodeStateOut struct { Name string `json:"name"` // Name of the service node ProgressUpdates []ProgressUpdateOut `json:"progress_updates,omitempty"` // Extra information regarding the progress for current state @@ -1526,6 +1549,20 @@ func NodeStateTypeChoices() []string { return []string{"leaving", "running", "setting_up_vm", "syncing_data", "timing_out", "unknown"} } +type NodeStatusType string + +const ( + NodeStatusTypeFailed NodeStatusType = "failed" + NodeStatusTypeInactive NodeStatusType = "inactive" + NodeStatusTypeRunning NodeStatusType = "running" + NodeStatusTypeStarting NodeStatusType = "starting" + NodeStatusTypeUnknown NodeStatusType = "unknown" +) + +func NodeStatusTypeChoices() []string { + return []string{"failed", "inactive", "running", "starting", "unknown"} +} + // OpensearchOut Service type information type OpensearchOut struct { DefaultVersion *string `json:"default_version,omitempty"` // Default version of the service if no explicit version is defined @@ -1744,6 +1781,18 @@ type RedisOut struct { ServicePlans []ServicePlanOut `json:"service_plans"` // List of plans available for this type of service UserConfigSchema map[string]any `json:"user_config_schema"` // JSON-Schema for the 'user_config' properties } + +// Region Plan details for the given service type in this particular cloud region +type Region struct { + DiskSpaceCapMb *int `json:"disk_space_cap_mb,omitempty"` // Maximum amount of disk space possible for the plan in the given region + DiskSpaceGbPriceUsd *string `json:"disk_space_gb_price_usd,omitempty"` // Hourly additional disk space price per GiB in this region + DiskSpaceMb int `json:"disk_space_mb"` // Combined amount of service disk space of all service nodes in megabytes + DiskSpaceStepMb *int `json:"disk_space_step_mb,omitempty"` // Disk space change step size + NodeCpuCount int `json:"node_cpu_count"` // Number of CPU cores on each service node + NodeMemoryMb int `json:"node_memory_mb"` // Amount of memory on each service node in megabytes + ObjectStorageGbPriceUsd *string `json:"object_storage_gb_price_usd,omitempty"` // Hourly object storage price per GiB in this region + PriceUsd string `json:"price_usd"` // Hourly service price in this region +} type ResourceType string const ( @@ -1859,7 +1908,7 @@ type ServiceCreateOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -1914,7 +1963,7 @@ type ServiceGetOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -2137,7 +2186,7 @@ type ServiceOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -2167,13 +2216,13 @@ type ServiceOut struct { Users []UserOut `json:"users,omitempty"` // List of service users } type ServicePlanOut struct { - BackupConfig BackupConfigOut `json:"backup_config"` // Backup configuration for this service plan - MaxMemoryPercent *int `json:"max_memory_percent,omitempty"` // Maximum amount of system memory as a percentage (0-100) the service can actually use after taking into account management overhead. This is relevant for memory bound services for which some service management operations require allocating proportional amount of memory on top the basic load. - NodeCount *int `json:"node_count,omitempty"` // Number of nodes in this service plan - Regions map[string]any `json:"regions,omitempty"` // Service plan hourly price per cloud region - ServicePlan string `json:"service_plan"` // Subscription plan - ServiceType string `json:"service_type"` // Service type code - ShardCount *int `json:"shard_count,omitempty"` // Number of shards in this service plan + BackupConfig BackupConfigOut `json:"backup_config"` // Backup configuration for this service plan + MaxMemoryPercent *int `json:"max_memory_percent,omitempty"` // Maximum amount of system memory as a percentage (0-100) the service can actually use after taking into account management overhead. This is relevant for memory bound services for which some service management operations require allocating proportional amount of memory on top the basic load. + NodeCount *int `json:"node_count,omitempty"` // Number of nodes in this service plan + Regions map[string]Region `json:"regions,omitempty"` // Service plan hourly price per cloud region + ServicePlan string `json:"service_plan"` // Subscription plan + ServiceType string `json:"service_type"` // Service type code + ShardCount *int `json:"shard_count,omitempty"` // Number of shards in this service plan } // ServiceQueryActivityIn ServiceQueryActivityRequestBody @@ -2252,7 +2301,7 @@ type ServiceUpdateOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -2333,7 +2382,7 @@ type ServiceUserCredentialsModifyOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -2375,7 +2424,7 @@ type ServiceUserCredentialsResetOut struct { CreateTime time.Time `json:"create_time"` // Service creation timestamp (ISO 8601) Databases []string `json:"databases,omitempty"` // List of service's user database names DiskSpaceMb *int `json:"disk_space_mb,omitempty"` // Megabytes of disk space for data storage - Features map[string]any `json:"features,omitempty"` // Feature flags + Features map[string]bool `json:"features,omitempty"` // Feature flags GroupList []string `json:"group_list"` // List of service groups the service belongs to. This field is deprecated. It is always set to single element with value 'default' KafkaAcl []KafkaAclOut `json:"kafka_acl,omitempty"` // List of Kafka-native ACL entries Maintenance *MaintenanceOut `json:"maintenance,omitempty"` // Automatic maintenance settings @@ -2464,7 +2513,7 @@ func SortOrderTypeChoices() []string { type StateOut struct { Errors []string `json:"errors"` LikelyErrorCause LikelyErrorCauseType `json:"likely_error_cause,omitempty"` // Most likely cause of the errors - Nodes map[string]any `json:"nodes"` + Nodes map[string]Node `json:"nodes"` Status IntegrationStatusType `json:"status"` // Service integration status } type TargetVersionType string @@ -2613,7 +2662,7 @@ type serviceAlertsListOut struct { // serviceBackupToAnotherRegionReportOut ServiceBackupToAnotherRegionReportResponse type serviceBackupToAnotherRegionReportOut struct { - Metrics map[string]any `json:"metrics"` // Service metrics in Google chart compatible format + Metrics map[string]Metric `json:"metrics"` // Service metrics in Google chart compatible format } // serviceCancelQueryOut ServiceCancelQueryResponse @@ -2708,7 +2757,7 @@ type serviceListOut struct { // serviceMetricsFetchOut ServiceMetricsFetchResponse type serviceMetricsFetchOut struct { - Metrics map[string]any `json:"metrics"` // Service metrics in Google chart compatible format + Metrics map[string]Metric `json:"metrics"` // Service metrics in Google chart compatible format } // serviceQueryActivityOut ServiceQueryActivityResponse @@ -2718,7 +2767,7 @@ type serviceQueryActivityOut struct { // serviceQueryStatisticsResetOut ServiceQueryStatisticsResetResponse type serviceQueryStatisticsResetOut struct { - Queries []map[string]any `json:"queries"` // List of query statistics + Queries []map[string]string `json:"queries"` // List of query statistics } // serviceTaskCreateOut ServiceTaskCreateResponse diff --git a/handler/user/user.go b/handler/user/user.go index ad676e8..6b4324a 100644 --- a/handler/user/user.go +++ b/handler/user/user.go @@ -767,7 +767,7 @@ type UserInfoOut struct { 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 + Features map[string]bool `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 @@ -789,7 +789,7 @@ type UserOut struct { 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 + Features map[string]bool `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 @@ -836,7 +836,7 @@ type UserUpdateOut struct { 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 + Features map[string]bool `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