Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cf pushapp for cf cli v8 #82

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/jetstream/api/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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?
Expand Down
13 changes: 7 additions & 6 deletions src/jetstream/plugins/cfapppush/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down
16 changes: 14 additions & 2 deletions src/jetstream/plugins/cfapppush/pushapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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
Expand Down
28 changes: 25 additions & 3 deletions src/jetstream/plugins/cloudfoundry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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) {
Expand Down
Loading