github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/api/resources/applications.go (about) 1 package resources 2 3 import ( 4 "strings" 5 "time" 6 7 "code.cloudfoundry.org/cli/cf/models" 8 ) 9 10 type PaginatedApplicationResources struct { 11 Resources []ApplicationResource 12 } 13 14 type AppRouteEntity struct { 15 Host string 16 Domain struct { 17 Resource 18 Entity struct { 19 Name string 20 } 21 } 22 } 23 24 type AppRouteResource struct { 25 Resource 26 Entity AppRouteEntity 27 } 28 29 type IntegrityFields struct { 30 Sha1 string `json:"sha1"` 31 Size int64 `json:"size"` 32 } 33 34 type AppFileResource struct { 35 Sha1 string `json:"sha1"` 36 Size int64 `json:"size"` 37 Path string `json:"fn"` 38 Mode string `json:"mode"` 39 } 40 41 type ApplicationResource struct { 42 Resource 43 Entity ApplicationEntity 44 } 45 46 type ApplicationEntity struct { 47 Name *string `json:"name,omitempty"` 48 Command *string `json:"command,omitempty"` 49 DetectedStartCommand *string `json:"detected_start_command,omitempty"` 50 State *string `json:"state,omitempty"` 51 SpaceGUID *string `json:"space_guid,omitempty"` 52 Instances *int `json:"instances,omitempty"` 53 Memory *int64 `json:"memory,omitempty"` 54 DiskQuota *int64 `json:"disk_quota,omitempty"` 55 StackGUID *string `json:"stack_guid,omitempty"` 56 Stack *StackResource `json:"stack,omitempty"` 57 Routes *[]AppRouteResource `json:"routes,omitempty"` 58 Buildpack *string `json:"buildpack,omitempty"` 59 DetectedBuildpack *string `json:"detected_buildpack,omitempty"` 60 EnvironmentJSON *map[string]interface{} `json:"environment_json,omitempty"` 61 HealthCheckType *string `json:"health_check_type,omitempty"` 62 HealthCheckHTTPEndpoint *string `json:"health_check_http_endpoint,omitempty"` 63 HealthCheckTimeout *int `json:"health_check_timeout,omitempty"` 64 PackageState *string `json:"package_state,omitempty"` 65 StagingFailedReason *string `json:"staging_failed_reason,omitempty"` 66 Diego *bool `json:"diego,omitempty"` 67 DockerImage *string `json:"docker_image,omitempty"` 68 EnableSSH *bool `json:"enable_ssh,omitempty"` 69 PackageUpdatedAt *time.Time `json:"package_updated_at,omitempty"` 70 AppPorts *[]int `json:"ports,omitempty"` 71 } 72 73 func (resource AppRouteResource) ToFields() (route models.RouteSummary) { 74 route.GUID = resource.Metadata.GUID 75 route.Host = resource.Entity.Host 76 return 77 } 78 79 func (resource AppRouteResource) ToModel() (route models.RouteSummary) { 80 route.GUID = resource.Metadata.GUID 81 route.Host = resource.Entity.Host 82 route.Domain.GUID = resource.Entity.Domain.Metadata.GUID 83 route.Domain.Name = resource.Entity.Domain.Entity.Name 84 return 85 } 86 87 func (resource AppFileResource) ToIntegrityFields() IntegrityFields { 88 return IntegrityFields{ 89 Sha1: resource.Sha1, 90 Size: resource.Size, 91 } 92 } 93 94 func NewApplicationEntityFromAppParams(app models.AppParams) ApplicationEntity { 95 entity := ApplicationEntity{ 96 Buildpack: app.BuildpackURL, 97 Name: app.Name, 98 SpaceGUID: app.SpaceGUID, 99 Instances: app.InstanceCount, 100 Memory: app.Memory, 101 DiskQuota: app.DiskQuota, 102 StackGUID: app.StackGUID, 103 Command: app.Command, 104 HealthCheckType: app.HealthCheckType, 105 HealthCheckTimeout: app.HealthCheckTimeout, 106 HealthCheckHTTPEndpoint: app.HealthCheckHTTPEndpoint, 107 DockerImage: app.DockerImage, 108 Diego: app.Diego, 109 EnableSSH: app.EnableSSH, 110 PackageUpdatedAt: app.PackageUpdatedAt, 111 AppPorts: app.AppPorts, 112 } 113 114 if app.State != nil { 115 state := strings.ToUpper(*app.State) 116 entity.State = &state 117 } 118 119 if app.EnvironmentVars != nil && *app.EnvironmentVars != nil { 120 entity.EnvironmentJSON = app.EnvironmentVars 121 } 122 123 return entity 124 } 125 126 func (resource ApplicationResource) ToFields() (app models.ApplicationFields) { 127 entity := resource.Entity 128 app.GUID = resource.Metadata.GUID 129 130 if entity.Name != nil { 131 app.Name = *entity.Name 132 } 133 if entity.Memory != nil { 134 app.Memory = *entity.Memory 135 } 136 if entity.DiskQuota != nil { 137 app.DiskQuota = *entity.DiskQuota 138 } 139 if entity.Instances != nil { 140 app.InstanceCount = *entity.Instances 141 } 142 if entity.State != nil { 143 app.State = strings.ToLower(*entity.State) 144 } 145 if entity.EnvironmentJSON != nil { 146 app.EnvironmentVars = *entity.EnvironmentJSON 147 } 148 if entity.SpaceGUID != nil { 149 app.SpaceGUID = *entity.SpaceGUID 150 } 151 if entity.DetectedStartCommand != nil { 152 app.DetectedStartCommand = *entity.DetectedStartCommand 153 } 154 if entity.Command != nil { 155 app.Command = *entity.Command 156 } 157 if entity.PackageState != nil { 158 app.PackageState = *entity.PackageState 159 } 160 if entity.StagingFailedReason != nil { 161 app.StagingFailedReason = *entity.StagingFailedReason 162 } 163 if entity.DockerImage != nil { 164 app.DockerImage = *entity.DockerImage 165 } 166 if entity.Buildpack != nil { 167 app.Buildpack = *entity.Buildpack 168 } 169 if entity.DetectedBuildpack != nil { 170 app.DetectedBuildpack = *entity.DetectedBuildpack 171 } 172 if entity.HealthCheckType != nil { 173 app.HealthCheckType = *entity.HealthCheckType 174 } 175 if entity.HealthCheckHTTPEndpoint != nil { 176 app.HealthCheckHTTPEndpoint = *entity.HealthCheckHTTPEndpoint 177 } 178 if entity.Diego != nil { 179 app.Diego = *entity.Diego 180 } 181 if entity.EnableSSH != nil { 182 app.EnableSSH = *entity.EnableSSH 183 } 184 if entity.PackageUpdatedAt != nil { 185 app.PackageUpdatedAt = entity.PackageUpdatedAt 186 } 187 188 return 189 } 190 191 func (resource ApplicationResource) ToModel() (app models.Application) { 192 app.ApplicationFields = resource.ToFields() 193 194 entity := resource.Entity 195 if entity.Stack != nil { 196 app.Stack = entity.Stack.ToFields() 197 } 198 199 if entity.Routes != nil { 200 for _, routeResource := range *entity.Routes { 201 app.Routes = append(app.Routes, routeResource.ToModel()) 202 } 203 } 204 205 return 206 }