github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/resources/deployment_resource.go (about) 1 package resources 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 8 ) 9 10 type Deployment struct { 11 GUID string 12 State constant.DeploymentState 13 StatusValue constant.DeploymentStatusValue 14 StatusReason constant.DeploymentStatusReason 15 RevisionGUID string 16 DropletGUID string 17 CreatedAt string 18 UpdatedAt string 19 Relationships Relationships 20 NewProcesses []Process 21 } 22 23 // MarshalJSON converts a Deployment into a Cloud Controller Deployment. 24 func (d Deployment) MarshalJSON() ([]byte, error) { 25 type Revision struct { 26 GUID string `json:"guid,omitempty"` 27 } 28 type Droplet struct { 29 GUID string `json:"guid,omitempty"` 30 } 31 32 var ccDeployment struct { 33 Droplet *Droplet `json:"droplet,omitempty"` 34 Revision *Revision `json:"revision,omitempty"` 35 Relationships Relationships `json:"relationships,omitempty"` 36 } 37 38 if d.DropletGUID != "" { 39 ccDeployment.Droplet = &Droplet{d.DropletGUID} 40 } 41 42 if d.RevisionGUID != "" { 43 ccDeployment.Revision = &Revision{d.RevisionGUID} 44 } 45 46 ccDeployment.Relationships = d.Relationships 47 48 return json.Marshal(ccDeployment) 49 } 50 51 // UnmarshalJSON helps unmarshal a Cloud Controller Deployment response. 52 func (d *Deployment) UnmarshalJSON(data []byte) error { 53 var ccDeployment struct { 54 GUID string `json:"guid,omitempty"` 55 CreatedAt string `json:"created_at,omitempty"` 56 Relationships Relationships `json:"relationships,omitempty"` 57 State constant.DeploymentState `json:"state,omitempty"` 58 Status struct { 59 Value constant.DeploymentStatusValue `json:"value"` 60 Reason constant.DeploymentStatusReason `json:"reason"` 61 } `json:"status"` 62 Droplet Droplet `json:"droplet,omitempty"` 63 NewProcesses []Process `json:"new_processes,omitempty"` 64 } 65 err := cloudcontroller.DecodeJSON(data, &ccDeployment) 66 if err != nil { 67 return err 68 } 69 70 d.GUID = ccDeployment.GUID 71 d.CreatedAt = ccDeployment.CreatedAt 72 d.Relationships = ccDeployment.Relationships 73 d.State = ccDeployment.State 74 d.StatusValue = ccDeployment.Status.Value 75 d.StatusReason = ccDeployment.Status.Reason 76 d.DropletGUID = ccDeployment.Droplet.GUID 77 d.NewProcesses = ccDeployment.NewProcesses 78 79 return nil 80 }