github.com/aiven/aiven-go-client@v1.36.0/service.go (about) 1 package aiven 2 3 type ( 4 // Service represents the Service model on Aiven. 5 Service struct { 6 ACL []*KafkaACL `json:"acl"` 7 SchemaRegistryACL []*KafkaSchemaRegistryACL `json:"schema_registry_acl"` 8 Backups []*Backup `json:"backups"` 9 CloudName string `json:"cloud_name"` 10 ConnectionPools []*ConnectionPool `json:"connection_pools"` 11 CreateTime string `json:"create_time"` 12 UpdateTime string `json:"update_time"` 13 GroupList []string `json:"group_list"` 14 NodeCount int `json:"node_count"` 15 Plan string `json:"plan"` 16 Name string `json:"service_name"` 17 Type string `json:"service_type"` 18 ProjectVPCID *string `json:"project_vpc_id"` 19 URI string `json:"service_uri"` 20 URIParams map[string]string `json:"service_uri_params"` 21 State string `json:"state"` 22 Metadata interface{} `json:"metadata"` 23 Users []*ServiceUser `json:"users"` 24 UserConfig map[string]interface{} `json:"user_config"` 25 ConnectionInfo ConnectionInfo `json:"connection_info"` 26 TerminationProtection bool `json:"termination_protection"` 27 MaintenanceWindow MaintenanceWindow `json:"maintenance"` 28 Integrations []*ServiceIntegration `json:"service_integrations"` 29 Components []*ServiceComponents `json:"components"` 30 Powered bool `json:"powered"` 31 NodeStates []*NodeState `json:"node_states"` 32 DiskSpaceMB int `json:"disk_space_mb"` 33 Features ServiceFeatures `json:"features"` 34 } 35 36 ServiceFeatures struct { 37 EnhancedLogging bool `json:"enhanced_logging"` 38 ImprovedTopicManagement bool `json:"improved_topic_management"` 39 ServiceIntegrations bool `json:"service_integrations"` 40 KafkaConnectServiceIntegration bool `json:"kafka_connect_service_integration"` 41 PGAllowReplication bool `json:"pg_allow_replication"` 42 Letsencrypt bool `json:"letsencrypt"` 43 IndexPatterns bool `json:"index_patterns"` 44 Karapace bool `json:"karapace"` 45 KarapaceRest bool `json:"karapace_rest"` 46 KarapaceJSONSchema bool `json:"karapace_json_schema"` 47 KafkaConfigBackupsEnabled bool `json:"kafka_config_backups_enabled"` 48 TopicManagement bool `json:"topic_management"` 49 KafkaStrictAccessCertChecks bool `json:"kafka_strict_access_cert_checks"` 50 KafkaTopicInfo bool `json:"kafka_topic_info"` 51 KafkaConnect bool `json:"kafka_connect"` 52 KafkaMirrormaker bool `json:"kafka_mirrormaker"` 53 KafkaRest bool `json:"kafka_rest"` 54 SchemaRegistry bool `json:"schema_registry"` 55 } 56 57 // NodeState represents the Node State model on Aiven 58 NodeState struct { 59 Name string `json:"name"` 60 ProgressUpdates []ProgressUpdate `json:"progress_updates"` 61 Role string `json:"role"` 62 State string `json:"state"` 63 } 64 65 // ProgressUpdate state represents the Progress Update model on Aiven 66 ProgressUpdate struct { 67 Completed bool `json:"completed"` 68 Current int `json:"current"` 69 Max int `json:"max"` 70 Min int `json:"min"` 71 Phase string `json:"phase"` 72 Unit string `json:"unit"` 73 } 74 75 // ServiceComponents represents Service Components which may contain 76 // information regarding service components Dynamic/Public DNS records 77 ServiceComponents struct { 78 Component string `json:"component"` 79 Host string `json:"host"` 80 Port int `json:"port"` 81 Route string `json:"route"` 82 Usage string `json:"usage"` 83 Ssl *bool `json:"ssl"` 84 KafkaAuthenticationMethod string `json:"kafka_authentication_method"` 85 } 86 87 // Backup represents an individual backup of service data on Aiven 88 Backup struct { 89 BackupTime string `json:"backup_time"` 90 BackupName string `json:"backup_name"` 91 DataSize int `json:"data_size"` 92 StorageLocation string `json:"storage_location"` 93 AdditionalRegions []*BackupAdditionalRegion `json:"additional_regions"` 94 } 95 96 // BackupAdditionalRegion represents a remote region where the backup is synchronized 97 BackupAdditionalRegion struct { 98 Cloud string `json:"cloud"` 99 Region string `json:"region"` 100 } 101 102 // ConnectionInfo represents the Service Connection information on Aiven. 103 ConnectionInfo struct { 104 CassandraHosts []string `json:"cassandra"` 105 106 ElasticsearchURIs []string `json:"elasticsearch"` 107 ElasticsearchUsername string `json:"elasticsearch_username"` 108 ElasticsearchPassword string `json:"elasticsearch_password"` 109 KibanaURI string `json:"kibana_uri"` 110 111 OpensearchURIs []string `json:"opensearch"` 112 OpensearchDashboardsURI string `json:"opensearch_dashboards_uri"` 113 OpensearchPassword string `json:"opensearch_password"` 114 OpensearchUsername string `json:"opensearch_username"` 115 116 GrafanaURIs []string `json:"grafana"` 117 118 InfluxDBURIs []string `json:"influxdb"` 119 InfluxDBDatabaseName string `json:"influxdb_dbname"` 120 InfluxDBUsername string `json:"influxdb_username"` 121 InfluxDBPassword string `json:"influxdb_password"` 122 123 KafkaHosts []string `json:"kafka"` 124 KafkaAccessCert string `json:"kafka_access_cert"` 125 KafkaAccessKey string `json:"kafka_access_key"` 126 KafkaConnectURI string `json:"kafka_connect_uri"` 127 KafkaRestURI string `json:"kafka_rest_uri"` 128 SchemaRegistryURI string `json:"schema_registry_uri"` 129 130 PostgresParams []PostgresParams `json:"pg_params"` 131 PostgresReplicaURI string `json:"pg_replica_uri"` 132 PostgresStandbyURIs []string `json:"pg_standby"` 133 PostgresURIs []string `json:"pg"` 134 135 RedisPassword string `json:"redis_password"` 136 RedisSlaveURIs []string `json:"redis_slave"` 137 RedisURIs []string `json:"redis"` 138 139 FlinkHostPorts []string `json:"flink"` 140 141 MySQLURIs []string `json:"mysql"` 142 MySQLParams []MySQLParams `json:"mysql_params"` 143 MySQLReplicaURI string `json:"mysql_replica_uri"` 144 MySQLStandbyURIs []string `json:"mysql_standby"` 145 } 146 147 // PostgresParams represents individual parameters for a PostgreSQL ConnectionInfo 148 PostgresParams struct { 149 DatabaseName string `json:"dbname"` 150 Host string `json:"host"` 151 Password string `json:"password"` 152 Port string `json:"port"` 153 SSLMode string `json:"sslmode"` 154 User string `json:"user"` 155 } 156 157 // MySQLParams represents individual parameters for a MySQL ConnectionInfo 158 MySQLParams struct { 159 DatabaseName string `json:"dbname"` 160 Host string `json:"host"` 161 Password string `json:"password"` 162 Port string `json:"port"` 163 SSLMode string `json:"ssl-mode"` 164 User string `json:"user"` 165 } 166 167 // KafkaACL represents a Kafka ACL entry on Aiven. 168 KafkaACL struct { 169 ID string `json:"id"` 170 Permission string `json:"permission"` 171 Topic string `json:"topic"` 172 Username string `json:"username"` 173 } 174 175 // KafkaSchemaRegistryACL represents a Kafka Schema Registry ACL entry on Aiven. 176 KafkaSchemaRegistryACL struct { 177 ID string `json:"id"` 178 Permission string `json:"permission"` 179 Resource string `json:"resource"` 180 Username string `json:"username"` 181 } 182 183 // ConnectionPool represents a PostgreSQL PGBouncer connection pool on Aiven 184 ConnectionPool struct { 185 ConnectionURI string `json:"connection_uri"` 186 Database string `json:"database"` 187 PoolMode string `json:"pool_mode"` 188 PoolName string `json:"pool_name"` 189 PoolSize int `json:"pool_size"` 190 Username string `json:"username"` 191 } 192 193 // MaintenanceWindow during which maintenance operations should take place 194 MaintenanceWindow struct { 195 DayOfWeek string `json:"dow"` 196 TimeOfDay string `json:"time"` 197 Updates []*MaintenanceUpdate `json:"updates,omitempty"` 198 } 199 200 // MaintenanceUpdate represents a maintenance needing to be applied on the service. 201 MaintenanceUpdate struct { 202 Deadline *string `json:"deadline,omitempty"` 203 Description string `json:"description,omitempty"` 204 StartAfter string `json:"start_after,omitempty"` 205 StartAt *string `json:"start_at,omitempty"` 206 } 207 208 // ServicesHandler is the client that interacts with the Service API 209 // endpoints on Aiven. 210 ServicesHandler struct { 211 client *Client 212 } 213 214 // CreateServiceRequest are the parameters to create a Service. 215 CreateServiceRequest struct { 216 Cloud string `json:"cloud,omitempty"` 217 GroupName string `json:"group_name,omitempty"` 218 MaintenanceWindow *MaintenanceWindow `json:"maintenance,omitempty"` 219 Plan string `json:"plan,omitempty"` 220 ProjectVPCID *string `json:"project_vpc_id"` 221 ServiceName string `json:"service_name"` 222 ServiceType string `json:"service_type"` 223 TerminationProtection bool `json:"termination_protection"` 224 UserConfig map[string]interface{} `json:"user_config,omitempty"` 225 ServiceIntegrations []NewServiceIntegration `json:"service_integrations"` 226 DiskSpaceMB int `json:"disk_space_mb,omitempty"` 227 StaticIPs []string `json:"static_ips,omitempty"` 228 } 229 230 // UpdateServiceRequest are the parameters to update a Service. 231 UpdateServiceRequest struct { 232 Cloud string `json:"cloud,omitempty"` 233 GroupName string `json:"group_name,omitempty"` 234 MaintenanceWindow *MaintenanceWindow `json:"maintenance,omitempty"` 235 Plan string `json:"plan,omitempty"` 236 ProjectVPCID *string `json:"project_vpc_id"` 237 Powered bool `json:"powered"` 238 TerminationProtection bool `json:"termination_protection"` 239 UserConfig map[string]interface{} `json:"user_config,omitempty"` 240 DiskSpaceMB int `json:"disk_space_mb,omitempty"` 241 Karapace *bool `json:"karapace,omitempty"` 242 } 243 244 // ServiceResponse represents the response from Aiven after interacting with 245 // the Service API. 246 ServiceResponse struct { 247 APIResponse 248 Service *Service `json:"service"` 249 } 250 251 // ServiceListResponse represents the response from Aiven for listing 252 // services. 253 ServiceListResponse struct { 254 APIResponse 255 Services []*Service `json:"services"` 256 } 257 ) 258 259 // Hostname provides host name for the service. This method is provided for backwards 260 // compatibility, typically it is easier to just get the value from URIParams directly. 261 func (s *Service) Hostname() (string, error) { 262 return s.URIParams["host"], nil 263 } 264 265 // Port provides port for the service. This method is provided for backwards 266 // compatibility, typically it is easier to just get the value from URIParams directly. 267 func (s *Service) Port() (string, error) { 268 return s.URIParams["port"], nil 269 } 270 271 // Create creates the given Service on Aiven. 272 func (h *ServicesHandler) Create(project string, req CreateServiceRequest) (*Service, error) { 273 path := buildPath("project", project, "service") 274 bts, err := h.client.doPostRequest(path, req) 275 if err != nil { 276 return nil, err 277 } 278 279 var r ServiceResponse 280 errR := checkAPIResponse(bts, &r) 281 282 return r.Service, errR 283 } 284 285 // Get gets a specific service from Aiven. 286 func (h *ServicesHandler) Get(project, service string) (*Service, error) { 287 path := buildPath("project", project, "service", service) 288 bts, err := h.client.doGetRequest(path, nil) 289 if err != nil { 290 return nil, err 291 } 292 293 var r ServiceResponse 294 errR := checkAPIResponse(bts, &r) 295 296 return r.Service, errR 297 } 298 299 // Update will update the given service with the given parameters. 300 func (h *ServicesHandler) Update(project, service string, req UpdateServiceRequest) (*Service, error) { 301 path := buildPath("project", project, "service", service) 302 bts, err := h.client.doPutRequest(path, req) 303 if err != nil { 304 return nil, err 305 } 306 307 var r ServiceResponse 308 errR := checkAPIResponse(bts, &r) 309 310 return r.Service, errR 311 } 312 313 // Delete will delete the given service from Aiven. 314 func (h *ServicesHandler) Delete(project, service string) error { 315 path := buildPath("project", project, "service", service) 316 bts, err := h.client.doDeleteRequest(path, nil) 317 if err != nil { 318 return err 319 } 320 321 return checkAPIResponse(bts, nil) 322 } 323 324 // List will fetch all services for a given project. 325 func (h *ServicesHandler) List(project string) ([]*Service, error) { 326 path := buildPath("project", project, "service") 327 bts, err := h.client.doGetRequest(path, nil) 328 if err != nil { 329 return nil, err 330 } 331 332 var r ServiceListResponse 333 errR := checkAPIResponse(bts, &r) 334 335 return r.Services, errR 336 }