Skip to content

Commit 27b7c9b

Browse files
authored
Merge pull request #5064 from cloudfoundry/fix_cf_pushapp_for_cf_cli_v8
Fix cf pushapp for cf cli v8 (From anynines:fix_cf_pushapp_for_cf_cli_v8 by @mafolz)
2 parents 4a66269 + 7eb4a99 commit 27b7c9b

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

src/jetstream/api/structs.go

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ type AuthProvider struct {
2323
UserInfo GetUserInfoFromToken
2424
}
2525

26+
type ApiRoot struct {
27+
Links struct {
28+
LogCache struct {
29+
Href string `json:"href"`
30+
} `json:"log_cache"`
31+
} `json:"links"`
32+
}
33+
2634
// V2Info is the response for the Cloud Foundry /v2/info API
2735
type V2Info struct {
2836
AuthorizationEndpoint string `json:"authorization_endpoint"`
@@ -37,6 +45,11 @@ type V2Info struct {
3745
MinRecommendedCLIVersion string `json:"min_recommended_cli_version"`
3846
}
3947

48+
type EndpointInfo struct {
49+
ApiRoot ApiRoot
50+
V2Info V2Info
51+
}
52+
4053
type InfoFunc func(apiEndpoint string, skipSSLValidation bool, caCert string) (CNSIRecord, interface{}, error)
4154

4255
// TODO this could be moved back to cnsis subpackage, and extensions could import it?

src/jetstream/plugins/cfapppush/info.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ func (c *CFPushApp) setEndpointInfo(config *configv3.Config) error {
2626
return err
2727
}
2828

29-
if info, ok := endpointInfo.(api.V2Info); ok {
29+
if info, ok := endpointInfo.(api.EndpointInfo); ok {
3030
// Got the info we need - update the config with it
3131
config.SetTargetInformation(
3232
configv3.TargetInformationArgs{
3333
Api: apiEndpoint,
34-
ApiVersion: info.APIVersion,
35-
Auth: info.AuthorizationEndpoint,
36-
MinCLIVersion: info.MinCLIVersion,
37-
Doppler: info.DopplerLoggingEndpoint,
38-
Routing: info.RoutingEndpoint,
34+
ApiVersion: info.V2Info.APIVersion,
35+
Auth: info.V2Info.AuthorizationEndpoint,
36+
MinCLIVersion: info.V2Info.MinCLIVersion,
37+
Doppler: info.V2Info.DopplerLoggingEndpoint,
38+
LogCache: info.ApiRoot.Links.LogCache.Href,
39+
Routing: info.V2Info.RoutingEndpoint,
3940
SkipSSLValidation: skipSSLValidation,
4041
},
4142
)

src/jetstream/plugins/cfapppush/pushapp.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212

1313
"code.cloudfoundry.org/cli/actor/sharedaction"
1414
"code.cloudfoundry.org/cli/actor/v7action"
15+
"code.cloudfoundry.org/cli/actor/v7pushaction"
1516
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
1617
"code.cloudfoundry.org/cli/cf/commandregistry"
1718
"code.cloudfoundry.org/cli/command"
1819
"code.cloudfoundry.org/clock"
1920

2021
"code.cloudfoundry.org/cli/util/configv3"
22+
"code.cloudfoundry.org/cli/util/manifestparser"
2123
"code.cloudfoundry.org/cli/util/progressbar"
2224
"code.cloudfoundry.org/cli/util/ui"
2325
"github.com/gorilla/websocket"
@@ -223,6 +225,8 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp
223225

224226
// Manifest path
225227
c.pushCommand.PathToManifest = flag.ManifestPathWithExistenceCheck(manifestPath)
228+
c.pushCommand.ManifestLocator = manifestparser.NewLocator()
229+
c.pushCommand.ManifestParser = manifestparser.ManifestParser{}
226230

227231
return nil
228232
}
@@ -231,6 +235,8 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp
231235
func (c *CFPushApp) setConfig(config *configv3.Config) error {
232236
config.SetOrganizationInformation(c.config.OrgGUID, c.config.OrgName)
233237
config.SetSpaceInformation(c.config.SpaceGUID, c.config.SpaceName, false)
238+
c.pushCommand.VersionActor = c.pushCommand.Actor
239+
c.pushCommand.PushActor = v7pushaction.NewActor(c.pushCommand.Actor, sharedaction.NewActor(config))
234240
return nil
235241
}
236242

@@ -263,7 +269,11 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso
263269
defer commandUI.FlushDeferred()
264270

265271
err = c.setup(config, commandUI, msgSender, clientWebsocket)
266-
// err = c.pushCommand.Setup(config, commandUI)
272+
if err != nil {
273+
return handleError(err, *commandUI)
274+
}
275+
276+
err = c.pushCommand.Setup(config, commandUI)
267277
if err != nil {
268278
return handleError(err, *commandUI)
269279
}
@@ -276,6 +286,7 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso
276286

277287
// Set to a null progress bar
278288
c.pushCommand.ProgressBar = &cfPushProgressBar{}
289+
c.pushCommand.DiffDisplayer = shared.NewManifestDiffDisplayer(commandUI)
279290

280291
// Perform the push
281292
args := make([]string, 0)
@@ -294,7 +305,7 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy
294305
sharedActor := sharedaction.NewActor(config)
295306
cmd.SharedActor = sharedActor
296307

297-
ccClient, uaaClient, routingClient, err := shared.GetNewClientsAndConnectToCF(config, ui, ccversion.MinSupportedClientVersionV8)
308+
ccClient, uaaClient, routingClient, err := shared.GetNewClientsAndConnectToCF(config, ui, ccversion.MinSupportedV2ClientVersion)
298309
if err != nil {
299310
return err
300311
}
@@ -313,6 +324,7 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy
313324
return err
314325
}
315326

327+
ccClientV3.Requester = ccClient.Requester
316328
v7Actor := v7action.NewActor(ccClientV3, config, sharedActor, uaaClient, routingClient, clock.NewClock())
317329

318330
cmd.Actor = v7Actor

src/jetstream/plugins/cloudfoundry/main.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ func (c *CloudFoundrySpecification) AddSessionGroupRoutes(echoGroup *echo.Group)
202202
func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation bool, caCert string) (api.CNSIRecord, interface{}, error) {
203203
log.Debug("Info")
204204
var v2InfoResponse api.V2Info
205+
var apiRootResponse api.ApiRoot
206+
var endpointInfo api.EndpointInfo
205207
var newCNSI api.CNSIRecord
206208

207209
newCNSI.CNSIType = EndpointType
@@ -211,7 +213,6 @@ func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation b
211213
return newCNSI, nil, err
212214
}
213215

214-
uri.Path = "v2/info"
215216
h := c.portalProxy.GetHttpClient(skipSSLValidation, caCert)
216217

217218
res, err := h.Get(uri.String())
@@ -228,15 +229,36 @@ func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation b
228229
}
229230

230231
dec := json.NewDecoder(res.Body)
231-
if err = dec.Decode(&v2InfoResponse); err != nil {
232+
if err = dec.Decode(&apiRootResponse); err != nil {
233+
return newCNSI, nil, err
234+
}
235+
236+
uri.Path = "v2/info"
237+
238+
res, err = h.Get(uri.String())
239+
if err != nil {
232240
return newCNSI, nil, err
233241
}
234242

243+
if res.StatusCode != 200 {
244+
buf := &bytes.Buffer{}
245+
io.Copy(buf, res.Body)
246+
defer res.Body.Close()
247+
248+
return newCNSI, nil, fmt.Errorf("%s endpoint returned %d\n%s", uri.String(), res.StatusCode, buf)
249+
}
250+
251+
dec = json.NewDecoder(res.Body)
252+
if err = dec.Decode(&v2InfoResponse); err != nil {
253+
return newCNSI, nil, err
254+
}
235255
newCNSI.TokenEndpoint = v2InfoResponse.TokenEndpoint
236256
newCNSI.AuthorizationEndpoint = v2InfoResponse.AuthorizationEndpoint
237257
newCNSI.DopplerLoggingEndpoint = v2InfoResponse.DopplerLoggingEndpoint
238258

239-
return newCNSI, v2InfoResponse, nil
259+
endpointInfo.ApiRoot = apiRootResponse
260+
endpointInfo.V2Info = v2InfoResponse
261+
return newCNSI, endpointInfo, nil
240262
}
241263

242264
func (c *CloudFoundrySpecification) UpdateMetadata(info *api.Info, userGUID string, echoContext echo.Context) {

0 commit comments

Comments
 (0)