Skip to content

Commit a0e1c43

Browse files
committed
separate out routeservice changes
1 parent c89a5a4 commit a0e1c43

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

cloudfoundry/managers/session.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,25 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
231231
if tokFromStore.IsSet() {
232232
accessToken = tokFromStore.AccessToken
233233
refreshToken = tokFromStore.RefreshToken
234-
goClientConfigOptions = goConfig.Token(accessToken, refreshToken)
235234
} else if configSess.SSOPasscode != "" {
236235
// try connecting with SSO passcode to retrieve access token and refresh token
237236
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
238237
"passcode": configSess.SSOPasscode,
239238
}, configSess.Origin, constant.GrantTypePassword)
240239
errType = "SSO passcode"
241-
goClientConfigOptions = goConfig.Token(accessToken, refreshToken)
242240
} else if config.CFUsername() != "" {
243241
// try connecting with pair given on uaa to retrieve access token and refresh token
244242
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
245243
"username": config.CFUsername(),
246244
"password": config.CFPassword(),
247245
}, configSess.Origin, constant.GrantTypePassword)
248246
errType = "username/password"
249-
goClientConfigOptions = goConfig.UserPassword(config.CFUsername(), config.CFPassword())
250247
} else if config.UAAOAuthClient() != "cf" {
251248
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
252249
"client_id": config.UAAOAuthClient(),
253250
"client_secret": config.UAAOAuthClientSecret(),
254251
}, configSess.Origin, constant.GrantTypeClientCredentials)
255252
errType = "client_id/client_secret"
256-
goClientConfigOptions = goConfig.Token(accessToken, refreshToken)
257253
}
258254
if err != nil {
259255
return fmt.Errorf("Error when authenticate on cf using %s: %s", errType, err)
@@ -265,6 +261,7 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
265261
config.SetAccessToken(fmt.Sprintf("bearer %s", accessToken))
266262
config.SetRefreshToken(refreshToken)
267263

264+
goClientConfigOptions = goConfig.Token(accessToken, refreshToken)
268265
goconfig, err := goConfig.New(config.ConfigFile.Target, goClientConfigOptions)
269266

270267
if err != nil {

cloudfoundry/managers/v3appdeployers/runbinder.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package v3appdeployers
22

33
import (
4-
"context"
54
"fmt"
65
"time"
76

@@ -10,7 +9,6 @@ import (
109
"code.cloudfoundry.org/cli/resources"
1110
"code.cloudfoundry.org/cli/types"
1211
goClient "github.com/cloudfoundry/go-cfclient/v3/client"
13-
goResource "github.com/cloudfoundry/go-cfclient/v3/resource"
1412
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/common"
1513
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers/noaa"
1614
)
@@ -44,14 +42,7 @@ func (r RunBinder) MapRoutes(appDeploy AppDeploy) ([]resources.Route, error) {
4442
continue
4543
}
4644

47-
insertOrReplaceDestinations := goResource.RouteDestinationInsertOrReplace{
48-
App: goResource.RouteDestinationApp{
49-
GUID: &appGUID,
50-
},
51-
Port: &mappingCur.Port,
52-
}
53-
_, err = r.clientGo.Routes.InsertDestinations(context.Background(), mappingCur.GUID, []*goResource.RouteDestinationInsertOrReplace{&insertOrReplaceDestinations})
54-
45+
_, err = r.client.MapRoute(mappingCur.GUID, appGUID)
5546
if err != nil {
5647
return mappings, err
5748
}
@@ -60,12 +51,18 @@ func (r RunBinder) MapRoutes(appDeploy AppDeploy) ([]resources.Route, error) {
6051
// mostly due to route emitter to perform its action inside diego
6152
time.Sleep(1 * time.Second)
6253

63-
mappingCreated, err = r.mappingExists(appGUID, mappingCur)
64-
54+
routeMappings, _, err := r.client.GetRouteDestinations(mappingCur.GUID)
6555
if err != nil {
6656
return mappings, err
6757
}
6858

59+
for _, mapping := range routeMappings {
60+
if mapping.App.GUID == appGUID {
61+
mappings = append(mappings, mappingCur)
62+
mappingCreated = true
63+
}
64+
}
65+
6966
if !mappingCreated {
7067
return mappings, fmt.Errorf("Failed to map route %s", mappingCur.GUID)
7168
}
@@ -75,18 +72,16 @@ func (r RunBinder) MapRoutes(appDeploy AppDeploy) ([]resources.Route, error) {
7572
}
7673

7774
func (r RunBinder) mappingExists(appGUID string, curMapping resources.Route) (bool, error) {
78-
destinations, err := r.clientGo.Routes.GetDestinations(context.Background(), curMapping.GUID)
75+
mappings, _, err := r.client.GetRouteDestinations(curMapping.GUID)
7976

8077
if err != nil {
8178
return false, err
8279
}
8380

84-
for _, destination := range destinations.Destinations {
85-
if *destination.App.GUID == appGUID &&
86-
*destination.Port == curMapping.Port {
81+
for _, mapping := range mappings {
82+
if mapping.App.GUID == appGUID {
8783
return true, nil
8884
}
89-
9085
}
9186

9287
return false, nil

0 commit comments

Comments
 (0)