github.com/aiven/aiven-go-client@v1.36.0/project.go (about) 1 package aiven 2 3 type ( 4 // Project represents the Project model on Aiven. 5 Project struct { 6 AvailableCredits string `json:"available_credits"` 7 BillingAddress string `json:"billing_address"` 8 BillingEmails []*ContactEmail `json:"billing_emails"` 9 BillingExtraText string `json:"billing_extra_text"` 10 Card Card `json:"card_info"` 11 Country string `json:"country"` 12 CountryCode string `json:"country_code"` 13 DefaultCloud string `json:"default_cloud"` 14 EstimatedBalance string `json:"estimated_balance"` 15 PaymentMethod string `json:"payment_method"` 16 Name string `json:"project_name"` 17 TechnicalEmails []*ContactEmail `json:"tech_emails"` 18 VatID string `json:"vat_id"` 19 AccountId string `json:"account_id"` 20 BillingCurrency string `json:"billing_currency"` 21 CopyFromProject string `json:"copy_from_project"` 22 BillingGroupId string `json:"billing_group_id"` 23 BillingGroupName string `json:"billing_group_name"` 24 Tags map[string]string `json:"tags"` 25 } 26 27 // ProjectsHandler is the client which interacts with the Projects endpoints 28 // on Aiven. 29 ProjectsHandler struct { 30 client *Client 31 } 32 33 // CreateProjectRequest are the parameters for creating a project. 34 CreateProjectRequest struct { 35 BillingAddress *string `json:"billing_address,omitempty"` 36 BillingEmails *[]*ContactEmail `json:"billing_emails,omitempty"` 37 BillingExtraText *string `json:"billing_extra_text,omitempty"` 38 CardID *string `json:"card_id,omitempty"` 39 Cloud *string `json:"cloud,omitempty"` 40 CopyFromProject string `json:"copy_from_project,omitempty"` 41 CountryCode *string `json:"country_code,omitempty"` 42 Project string `json:"project"` 43 AccountId *string `json:"account_id,omitempty"` 44 TechnicalEmails *[]*ContactEmail `json:"tech_emails,omitempty"` 45 BillingCurrency string `json:"billing_currency,omitempty"` 46 VatID *string `json:"vat_id,omitempty"` 47 UseSourceProjectBillingGroup bool `json:"use_source_project_billing_group,omitempty"` 48 BillingGroupId string `json:"billing_group_id,omitempty"` 49 AddAccountOwnersAdminAccess *bool `json:"add_account_owners_admin_access,omitempty"` 50 Tags map[string]string `json:"tags"` 51 } 52 53 // UpdateProjectRequest are the parameters for updating a project. 54 UpdateProjectRequest struct { 55 Name string `json:"project_name,omitempty"` 56 BillingAddress *string `json:"billing_address,omitempty"` 57 BillingEmails *[]*ContactEmail `json:"billing_emails,omitempty"` 58 BillingExtraText *string `json:"billing_extra_text,omitempty"` 59 CardID *string `json:"card_id,omitempty"` 60 Cloud *string `json:"cloud,omitempty"` 61 CountryCode *string `json:"country_code,omitempty"` 62 AccountId string `json:"account_id"` 63 TechnicalEmails *[]*ContactEmail `json:"tech_emails,omitempty"` 64 BillingCurrency string `json:"billing_currency,omitempty"` 65 VatID *string `json:"vat_id,omitempty"` 66 Tags map[string]string `json:"tags"` 67 AddAccountOwnersAdminAccess *bool `json:"add_account_owners_admin_access,omitempty"` 68 } 69 70 // ContactEmail represents either a technical contact or billing contact. 71 ContactEmail struct { 72 Email string `json:"email"` 73 } 74 75 // ProjectResponse is the response from Aiven for the project endpoints. 76 ProjectResponse struct { 77 APIResponse 78 Project *Project `json:"project"` 79 } 80 81 // ProjectListResponse is the response from Aiven for listing projects. 82 ProjectListResponse struct { 83 APIResponse 84 Projects []*Project `json:"projects"` 85 } 86 87 // ProjectEventLogEntriesResponse is the response from Aiven for project event log entries 88 ProjectEventLogEntriesResponse struct { 89 APIResponse 90 Events []*ProjectEvent `json:"events"` 91 } 92 93 // ProjectEvent represents a project event log entry 94 ProjectEvent struct { 95 Actor string `json:"actor"` 96 EventDesc string `json:"event_desc"` 97 EventType string `json:"event_type"` 98 ServiceName string `json:"service_name"` 99 Time string `json:"time"` 100 } 101 102 // ProjectServiceTypesResponse is the response from Aiven for listing project service types. 103 ProjectServiceTypesResponse struct { 104 APIResponse 105 ServiceTypes map[string]ServiceType `json:"service_types"` 106 } 107 108 // ServiceType represents a service type. 109 ServiceType struct { 110 DefaultVersion string `json:"default_version"` 111 Description string `json:"description"` 112 LatestAvailableVersion string `json:"latest_available_version"` 113 ServicePlans []ServicePlan `json:"service_plans"` 114 UserConfigSchema UserConfigSchema `json:"user_config_schema"` 115 } 116 117 // ServicePlan represents a service plan. 118 ServicePlan struct { 119 BackupConfig *BackupConfig `json:"backup_config"` 120 MaxMemoryPercent int `json:"max_memory_percent"` 121 NodeCount int `json:"node_count"` 122 Regions interface{} `json:"regions"` 123 ServicePlan string `json:"service_plan"` 124 ServiceType string `json:"service_type"` 125 } 126 127 // BackupConfig represents a backup config. 128 BackupConfig struct { 129 FrequentIntervalMinutes int `json:"frequent_interval_minutes"` 130 FrequentOldestAgeMinutes int `json:"frequent_oldest_age_minutes"` 131 InfrequentIntervalMinutes int `json:"infrequent_interval_minutes"` 132 InfrequentOldestAgeMinutes int `json:"infrequent_oldest_age_minutes"` 133 Interval int `json:"interval"` 134 MaxCount int `json:"max_count"` 135 RecoveryMode string `json:"recovery_mode"` 136 } 137 138 // ProjectIntegrationTypesResponse is the response from Aiven for listing project integration types. 139 ProjectIntegrationTypesResponse struct { 140 APIResponse 141 IntegrationTypes []IntegrationType `json:"integration_types"` 142 } 143 144 // IntegrationType represents an integration type. 145 IntegrationType struct { 146 DestDescription string `json:"dest_description"` 147 DestServiceTypes []string `json:"dest_service_types"` 148 IntegrationType string `json:"integration_type"` 149 SourceDescription string `json:"source_description"` 150 SourceServiceTypes []string `json:"source_service_types"` 151 UserConfigSchema UserConfigSchema `json:"user_config_schema"` 152 } 153 154 // ProjectIntegrationEndpointTypesResponse is the response from Aiven for listing project integration endpoint types. 155 ProjectIntegrationEndpointTypesResponse struct { 156 APIResponse 157 EndpointTypes []IntegrationEndpointType `json:"endpoint_types"` 158 } 159 160 // IntegrationEndpointType represents an integration endpoint type. 161 IntegrationEndpointType struct { 162 EndpointType string `json:"endpoint_type"` 163 ServiceTypes []string `json:"service_types"` 164 Title string `json:"title"` 165 UserConfigSchema UserConfigSchema `json:"user_config_schema"` 166 } 167 168 // UserConfigSchema represents a user config schema. 169 UserConfigSchema struct { 170 Title string `json:"title"` 171 Description string `json:"description"` 172 Type interface{} `json:"type"` 173 Default interface{} `json:"default"` 174 Required []string `json:"required"` 175 Properties map[string]UserConfigSchema `json:"properties"` 176 AdditionalProperties interface{} `json:"additionalProperties"` 177 Items *UserConfigSchema `json:"items"` 178 OneOf []UserConfigSchema `json:"oneOf"` 179 Enum []interface{} `json:"enum"` 180 Minimum *float64 `json:"minimum"` 181 Maximum *float64 `json:"maximum"` 182 MinLength *int `json:"minLength"` 183 MaxLength *int `json:"maxLength"` 184 MaxItems *int `json:"maxItems"` 185 CreateOnly bool `json:"createOnly"` 186 Pattern string `json:"pattern"` 187 Example interface{} `json:"example"` 188 UserError string `json:"user_error"` 189 } 190 ) 191 192 // ContactEmailFromStringSlice creates []*ContactEmail from string slice 193 func ContactEmailFromStringSlice(emails []string) *[]*ContactEmail { 194 var result []*ContactEmail 195 for _, e := range emails { 196 result = append(result, &ContactEmail{ 197 Email: e, 198 }) 199 } 200 201 return &result 202 } 203 204 // emailsToStringSlice converts contact emails to string slice 205 func emailsToStringSlice(c []*ContactEmail) []string { 206 var result []string 207 for _, e := range c { 208 result = append(result, e.Email) 209 } 210 211 return result 212 } 213 214 // GetBillingEmailsAsStringSlice retrieves BillingEmails converted to string slice 215 func (p Project) GetBillingEmailsAsStringSlice() []string { 216 return emailsToStringSlice(p.BillingEmails) 217 } 218 219 // GetTechnicalEmailsAsStringSlice retrieves TechnicalEmails converted to string slice 220 func (p Project) GetTechnicalEmailsAsStringSlice() []string { 221 return emailsToStringSlice(p.TechnicalEmails) 222 } 223 224 // Create creates a new project. 225 func (h *ProjectsHandler) Create(req CreateProjectRequest) (*Project, error) { 226 bts, err := h.client.doPostRequest(buildPath("project"), req) 227 if err != nil { 228 return nil, err 229 } 230 231 var r ProjectResponse 232 errR := checkAPIResponse(bts, &r) 233 234 return r.Project, errR 235 } 236 237 // Get returns gets the specified project. 238 func (h *ProjectsHandler) Get(project string) (*Project, error) { 239 bts, err := h.client.doGetRequest(buildPath("project", project), nil) 240 if err != nil { 241 return nil, err 242 } 243 244 var r ProjectResponse 245 errR := checkAPIResponse(bts, &r) 246 247 return r.Project, errR 248 } 249 250 // Update modifies the specified project with the given parameters. 251 func (h *ProjectsHandler) Update(project string, req UpdateProjectRequest) (*Project, error) { 252 bts, err := h.client.doPutRequest(buildPath("project", project), req) 253 if err != nil { 254 return nil, err 255 } 256 257 var r ProjectResponse 258 errR := checkAPIResponse(bts, &r) 259 260 return r.Project, errR 261 } 262 263 // Delete removes the given project. 264 func (h *ProjectsHandler) Delete(project string) error { 265 bts, err := h.client.doDeleteRequest(buildPath("project", project), nil) 266 if err != nil { 267 return err 268 } 269 270 return checkAPIResponse(bts, nil) 271 } 272 273 // List returns all the available projects linked to the account. 274 func (h *ProjectsHandler) List() ([]*Project, error) { 275 bts, err := h.client.doGetRequest(buildPath("project"), nil) 276 if err != nil { 277 return nil, err 278 } 279 280 var r ProjectListResponse 281 errR := checkAPIResponse(bts, &r) 282 283 return r.Projects, errR 284 } 285 286 // GetEventLog returns project event log entries 287 func (h *ProjectsHandler) GetEventLog(project string) ([]*ProjectEvent, error) { 288 bts, err := h.client.doGetRequest(buildPath("project", project, "events"), nil) 289 if err != nil { 290 return nil, err 291 } 292 293 var r ProjectEventLogEntriesResponse 294 errR := checkAPIResponse(bts, &r) 295 296 return r.Events, errR 297 } 298 299 // ServiceTypes returns all the available service types. 300 func (h *ProjectsHandler) ServiceTypes(project string) (map[string]ServiceType, error) { 301 bts, err := h.client.doGetRequest(buildPath("project", project, "service_types"), nil) 302 if err != nil { 303 return nil, err 304 } 305 306 var r ProjectServiceTypesResponse 307 err = checkAPIResponse(bts, &r) 308 309 return r.ServiceTypes, err 310 } 311 312 // IntegrationTypes returns all the available integration types. 313 func (h *ProjectsHandler) IntegrationTypes(project string) ([]IntegrationType, error) { 314 bts, err := h.client.doGetRequest(buildPath("project", project, "integration_types"), nil) 315 if err != nil { 316 return nil, err 317 } 318 319 var r ProjectIntegrationTypesResponse 320 err = checkAPIResponse(bts, &r) 321 322 return r.IntegrationTypes, err 323 } 324 325 // IntegrationEndpointTypes returns all the available integration endpoint types. 326 func (h *ProjectsHandler) IntegrationEndpointTypes(project string) ([]IntegrationEndpointType, error) { 327 bts, err := h.client.doGetRequest(buildPath("project", project, "integration_endpoint_types"), nil) 328 if err != nil { 329 return nil, err 330 } 331 332 var r ProjectIntegrationEndpointTypesResponse 333 err = checkAPIResponse(bts, &r) 334 335 return r.EndpointTypes, err 336 }