diff --git a/src/jetstream/api/structs.go b/src/jetstream/api/structs.go index c4a9119fb..31dcfa8f2 100644 --- a/src/jetstream/api/structs.go +++ b/src/jetstream/api/structs.go @@ -23,6 +23,14 @@ type AuthProvider struct { UserInfo GetUserInfoFromToken } +type ApiRoot struct { + Links struct { + LogCache struct { + Href string `json:"href"` + } `json:"log_cache"` + } `json:"links"` +} + // V2Info is the response for the Cloud Foundry /v2/info API type V2Info struct { AuthorizationEndpoint string `json:"authorization_endpoint"` @@ -37,6 +45,11 @@ type V2Info struct { MinRecommendedCLIVersion string `json:"min_recommended_cli_version"` } +type EndpointInfo struct { + ApiRoot ApiRoot + V2Info V2Info +} + type InfoFunc func(apiEndpoint string, skipSSLValidation bool, caCert string) (CNSIRecord, interface{}, error) // TODO this could be moved back to cnsis subpackage, and extensions could import it? diff --git a/src/jetstream/plugins/cfapppush/info.go b/src/jetstream/plugins/cfapppush/info.go index 3b2991b8b..de5d01165 100644 --- a/src/jetstream/plugins/cfapppush/info.go +++ b/src/jetstream/plugins/cfapppush/info.go @@ -26,16 +26,17 @@ func (c *CFPushApp) setEndpointInfo(config *configv3.Config) error { return err } - if info, ok := endpointInfo.(api.V2Info); ok { + if info, ok := endpointInfo.(api.EndpointInfo); ok { // Got the info we need - update the config with it config.SetTargetInformation( configv3.TargetInformationArgs{ Api: apiEndpoint, - ApiVersion: info.APIVersion, - Auth: info.AuthorizationEndpoint, - MinCLIVersion: info.MinCLIVersion, - Doppler: info.DopplerLoggingEndpoint, - Routing: info.RoutingEndpoint, + ApiVersion: info.V2Info.APIVersion, + Auth: info.V2Info.AuthorizationEndpoint, + MinCLIVersion: info.V2Info.MinCLIVersion, + Doppler: info.V2Info.DopplerLoggingEndpoint, + LogCache: info.ApiRoot.Links.LogCache.Href, + Routing: info.V2Info.RoutingEndpoint, SkipSSLValidation: skipSSLValidation, }, ) diff --git a/src/jetstream/plugins/cfapppush/pushapp.go b/src/jetstream/plugins/cfapppush/pushapp.go index dc958596a..e8fa3cafe 100644 --- a/src/jetstream/plugins/cfapppush/pushapp.go +++ b/src/jetstream/plugins/cfapppush/pushapp.go @@ -12,12 +12,14 @@ import ( "code.cloudfoundry.org/cli/actor/sharedaction" "code.cloudfoundry.org/cli/actor/v7action" + "code.cloudfoundry.org/cli/actor/v7pushaction" "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" "code.cloudfoundry.org/cli/cf/commandregistry" "code.cloudfoundry.org/cli/command" "code.cloudfoundry.org/clock" "code.cloudfoundry.org/cli/util/configv3" + "code.cloudfoundry.org/cli/util/manifestparser" "code.cloudfoundry.org/cli/util/progressbar" "code.cloudfoundry.org/cli/util/ui" "github.com/gorilla/websocket" @@ -223,6 +225,8 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp // Manifest path c.pushCommand.PathToManifest = flag.ManifestPathWithExistenceCheck(manifestPath) + c.pushCommand.ManifestLocator = manifestparser.NewLocator() + c.pushCommand.ManifestParser = manifestparser.ManifestParser{} return nil } @@ -231,6 +235,8 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp func (c *CFPushApp) setConfig(config *configv3.Config) error { config.SetOrganizationInformation(c.config.OrgGUID, c.config.OrgName) config.SetSpaceInformation(c.config.SpaceGUID, c.config.SpaceName, false) + c.pushCommand.VersionActor = c.pushCommand.Actor + c.pushCommand.PushActor = v7pushaction.NewActor(c.pushCommand.Actor, sharedaction.NewActor(config)) return nil } @@ -263,7 +269,11 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso defer commandUI.FlushDeferred() err = c.setup(config, commandUI, msgSender, clientWebsocket) - // err = c.pushCommand.Setup(config, commandUI) + if err != nil { + return handleError(err, *commandUI) + } + + err = c.pushCommand.Setup(config, commandUI) if err != nil { return handleError(err, *commandUI) } @@ -276,6 +286,7 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso // Set to a null progress bar c.pushCommand.ProgressBar = &cfPushProgressBar{} + c.pushCommand.DiffDisplayer = shared.NewManifestDiffDisplayer(commandUI) // Perform the push args := make([]string, 0) @@ -294,7 +305,7 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy sharedActor := sharedaction.NewActor(config) cmd.SharedActor = sharedActor - ccClient, uaaClient, routingClient, err := shared.GetNewClientsAndConnectToCF(config, ui, ccversion.MinSupportedClientVersionV8) + ccClient, uaaClient, routingClient, err := shared.GetNewClientsAndConnectToCF(config, ui, ccversion.MinSupportedV2ClientVersion) if err != nil { return err } @@ -313,6 +324,7 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy return err } + ccClientV3.Requester = ccClient.Requester v7Actor := v7action.NewActor(ccClientV3, config, sharedActor, uaaClient, routingClient, clock.NewClock()) cmd.Actor = v7Actor diff --git a/src/jetstream/plugins/cloudfoundry/main.go b/src/jetstream/plugins/cloudfoundry/main.go index 3694370e5..08d2d45a3 100644 --- a/src/jetstream/plugins/cloudfoundry/main.go +++ b/src/jetstream/plugins/cloudfoundry/main.go @@ -202,6 +202,8 @@ func (c *CloudFoundrySpecification) AddSessionGroupRoutes(echoGroup *echo.Group) func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation bool, caCert string) (api.CNSIRecord, interface{}, error) { log.Debug("Info") var v2InfoResponse api.V2Info + var apiRootResponse api.ApiRoot + var endpointInfo api.EndpointInfo var newCNSI api.CNSIRecord newCNSI.CNSIType = EndpointType @@ -211,7 +213,6 @@ func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation b return newCNSI, nil, err } - uri.Path = "v2/info" h := c.portalProxy.GetHttpClient(skipSSLValidation, caCert) res, err := h.Get(uri.String()) @@ -228,15 +229,36 @@ func (c *CloudFoundrySpecification) Info(apiEndpoint string, skipSSLValidation b } dec := json.NewDecoder(res.Body) - if err = dec.Decode(&v2InfoResponse); err != nil { + if err = dec.Decode(&apiRootResponse); err != nil { + return newCNSI, nil, err + } + + uri.Path = "v2/info" + + res, err = h.Get(uri.String()) + if err != nil { return newCNSI, nil, err } + if res.StatusCode != 200 { + buf := &bytes.Buffer{} + io.Copy(buf, res.Body) + defer res.Body.Close() + + return newCNSI, nil, fmt.Errorf("%s endpoint returned %d\n%s", uri.String(), res.StatusCode, buf) + } + + dec = json.NewDecoder(res.Body) + if err = dec.Decode(&v2InfoResponse); err != nil { + return newCNSI, nil, err + } newCNSI.TokenEndpoint = v2InfoResponse.TokenEndpoint newCNSI.AuthorizationEndpoint = v2InfoResponse.AuthorizationEndpoint newCNSI.DopplerLoggingEndpoint = v2InfoResponse.DopplerLoggingEndpoint - return newCNSI, v2InfoResponse, nil + endpointInfo.ApiRoot = apiRootResponse + endpointInfo.V2Info = v2InfoResponse + return newCNSI, endpointInfo, nil } func (c *CloudFoundrySpecification) UpdateMetadata(info *api.Info, userGUID string, echoContext echo.Context) {