github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v6/shared/get_application_changes.go (about) 1 package shared 2 3 import ( 4 "code.cloudfoundry.org/bytefmt" 5 "code.cloudfoundry.org/cli/actor/pushaction" 6 "code.cloudfoundry.org/cli/util/ui" 7 ) 8 9 func GetApplicationChanges(appConfig pushaction.ApplicationConfig) []ui.Change { 10 changes := []ui.Change{ 11 { 12 Header: "name:", 13 CurrentValue: appConfig.CurrentApplication.Name, 14 NewValue: appConfig.DesiredApplication.Name, 15 }, 16 } 17 18 if appConfig.DesiredApplication.DockerImage != "" { 19 changes = append(changes, 20 ui.Change{ 21 Header: "docker image:", 22 CurrentValue: appConfig.CurrentApplication.DockerImage, 23 NewValue: appConfig.DesiredApplication.DockerImage, 24 }) 25 26 if appConfig.CurrentApplication.DockerCredentials.Username != "" || appConfig.DesiredApplication.DockerCredentials.Username != "" { 27 changes = append(changes, 28 ui.Change{ 29 Header: "docker username:", 30 CurrentValue: appConfig.CurrentApplication.DockerCredentials.Username, 31 NewValue: appConfig.DesiredApplication.DockerCredentials.Username, 32 }) 33 } 34 } else { 35 changes = append(changes, 36 ui.Change{ 37 Header: "path:", 38 CurrentValue: appConfig.Path, 39 NewValue: appConfig.Path, 40 }) 41 } 42 43 oldBuildpacks := appConfig.CurrentApplication.CalculatedBuildpacks() 44 newBuildpacks := appConfig.DesiredApplication.CalculatedBuildpacks() 45 if len(oldBuildpacks) > 0 || len(newBuildpacks) > 0 { 46 changes = append(changes, 47 ui.Change{ 48 Header: "buildpacks:", 49 CurrentValue: oldBuildpacks, 50 NewValue: newBuildpacks, 51 }) 52 } 53 54 // Existing command and existing detected start command are mutually exclusive 55 oldCommand := appConfig.CurrentApplication.CalculatedCommand() 56 newCommand := appConfig.DesiredApplication.CalculatedCommand() 57 if oldCommand != "" || newCommand != "" { 58 changes = append(changes, 59 ui.Change{ 60 Header: "command:", 61 CurrentValue: oldCommand, 62 NewValue: newCommand, 63 }) 64 } 65 66 if appConfig.CurrentApplication.DiskQuota.IsSet || appConfig.DesiredApplication.DiskQuota.IsSet { 67 var currentDiskQuota string 68 if appConfig.CurrentApplication.DiskQuota.IsSet { 69 currentDiskQuota = appConfig.CurrentApplication.DiskQuota.String() 70 } 71 changes = append(changes, 72 ui.Change{ 73 Header: "disk quota:", 74 CurrentValue: currentDiskQuota, 75 NewValue: appConfig.DesiredApplication.DiskQuota.String(), 76 }) 77 } 78 79 if appConfig.CurrentApplication.HealthCheckHTTPEndpoint != "" || appConfig.DesiredApplication.HealthCheckHTTPEndpoint != "" { 80 changes = append(changes, 81 ui.Change{ 82 Header: "health check http endpoint:", 83 CurrentValue: appConfig.CurrentApplication.HealthCheckHTTPEndpoint, 84 NewValue: appConfig.DesiredApplication.HealthCheckHTTPEndpoint, 85 }) 86 } 87 88 if appConfig.CurrentApplication.HealthCheckTimeout != 0 || appConfig.DesiredApplication.HealthCheckTimeout != 0 { 89 changes = append(changes, 90 ui.Change{ 91 Header: "health check timeout:", 92 CurrentValue: appConfig.CurrentApplication.HealthCheckTimeout, 93 NewValue: appConfig.DesiredApplication.HealthCheckTimeout, 94 }) 95 } 96 97 if appConfig.CurrentApplication.HealthCheckType != "" || appConfig.DesiredApplication.HealthCheckType != "" { 98 changes = append(changes, 99 ui.Change{ 100 Header: "health check type:", 101 CurrentValue: string(appConfig.CurrentApplication.HealthCheckType), 102 NewValue: string(appConfig.DesiredApplication.HealthCheckType), 103 }) 104 } 105 106 if appConfig.CurrentApplication.Instances.IsSet || appConfig.DesiredApplication.Instances.IsSet { 107 changes = append(changes, 108 ui.Change{ 109 Header: "instances:", 110 CurrentValue: appConfig.CurrentApplication.Instances, 111 NewValue: appConfig.DesiredApplication.Instances, 112 }) 113 } 114 115 if appConfig.CurrentApplication.Memory.IsSet || appConfig.DesiredApplication.Memory.IsSet { 116 var currentMemory string 117 if appConfig.CurrentApplication.Memory.IsSet { 118 currentMemory = appConfig.CurrentApplication.Memory.String() 119 } 120 changes = append(changes, 121 ui.Change{ 122 Header: "memory:", 123 CurrentValue: currentMemory, 124 NewValue: appConfig.DesiredApplication.Memory.String(), 125 }) 126 } 127 128 if appConfig.CurrentApplication.Stack.Name != "" || appConfig.DesiredApplication.Stack.Name != "" { 129 changes = append(changes, 130 ui.Change{ 131 Header: "stack:", 132 CurrentValue: appConfig.CurrentApplication.Stack.Name, 133 NewValue: appConfig.DesiredApplication.Stack.Name, 134 }) 135 } 136 137 var oldServices []string 138 for name := range appConfig.CurrentServices { 139 oldServices = append(oldServices, name) 140 } 141 142 var newServices []string 143 for name := range appConfig.DesiredServices { 144 newServices = append(newServices, name) 145 } 146 147 changes = append(changes, 148 ui.Change{ 149 Header: "services:", 150 CurrentValue: oldServices, 151 NewValue: newServices, 152 }) 153 154 changes = append(changes, 155 ui.Change{ 156 Header: "env:", 157 CurrentValue: appConfig.CurrentApplication.EnvironmentVariables, 158 NewValue: appConfig.DesiredApplication.EnvironmentVariables, 159 }) 160 161 var currentRoutes []string 162 for _, route := range appConfig.CurrentRoutes { 163 currentRoutes = append(currentRoutes, route.String()) 164 } 165 166 var desiredRotues []string 167 for _, route := range appConfig.DesiredRoutes { 168 desiredRotues = append(desiredRotues, route.String()) 169 } 170 171 changes = append(changes, 172 ui.Change{ 173 Header: "routes:", 174 CurrentValue: currentRoutes, 175 NewValue: desiredRotues, 176 }) 177 178 return changes 179 } 180 181 func SelectNonBlankValue(str ...string) string { 182 for _, s := range str { 183 if s != "" { 184 return s 185 } 186 } 187 return "" 188 } 189 190 func MegabytesToString(value uint64) string { 191 return bytefmt.ByteSize(bytefmt.MEGABYTE * uint64(value)) 192 }