github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/api/resources/service_instances.go (about) 1 package resources 2 3 import "code.cloudfoundry.org/cli/cf/models" 4 5 type PaginatedServiceInstanceResources struct { 6 TotalResults int `json:"total_results"` 7 Resources []ServiceInstanceResource 8 } 9 10 type ServiceInstanceResource struct { 11 Resource 12 Entity ServiceInstanceEntity 13 } 14 15 type LastOperation struct { 16 Type string `json:"type"` 17 State string `json:"state"` 18 Description string `json:"description"` 19 CreatedAt string `json:"created_at"` 20 UpdatedAt string `json:"updated_at"` 21 } 22 23 type ServiceInstanceEntity struct { 24 Name string `json:"name"` 25 DashboardURL string `json:"dashboard_url"` 26 Type string `json:"type"` 27 Tags []string `json:"tags"` 28 ServiceBindings []ServiceBindingResource `json:"service_bindings"` 29 ServiceKeys []ServiceKeyResource `json:"service_keys"` 30 ServicePlan ServicePlanResource `json:"service_plan"` 31 LastOperation LastOperation `json:"last_operation"` 32 } 33 34 func (resource ServiceInstanceResource) ToFields() models.ServiceInstanceFields { 35 return models.ServiceInstanceFields{ 36 GUID: resource.Metadata.GUID, 37 Name: resource.Entity.Name, 38 Type: resource.Entity.Type, 39 Tags: resource.Entity.Tags, 40 DashboardURL: resource.Entity.DashboardURL, 41 LastOperation: models.LastOperationFields{ 42 Type: resource.Entity.LastOperation.Type, 43 State: resource.Entity.LastOperation.State, 44 Description: resource.Entity.LastOperation.Description, 45 CreatedAt: resource.Entity.LastOperation.CreatedAt, 46 UpdatedAt: resource.Entity.LastOperation.UpdatedAt, 47 }, 48 } 49 } 50 51 func (resource ServiceInstanceResource) ToModel() (instance models.ServiceInstance) { 52 instance.ServiceInstanceFields = resource.ToFields() 53 instance.ServicePlan = resource.Entity.ServicePlan.ToFields() 54 55 instance.ServiceBindings = []models.ServiceBindingFields{} 56 for _, bindingResource := range resource.Entity.ServiceBindings { 57 instance.ServiceBindings = append(instance.ServiceBindings, bindingResource.ToFields()) 58 } 59 60 instance.ServiceKeys = []models.ServiceKeyFields{} 61 for _, keyResource := range resource.Entity.ServiceKeys { 62 instance.ServiceKeys = append(instance.ServiceKeys, keyResource.ToFields()) 63 } 64 return 65 }