@@ -27,12 +27,16 @@ import (
27
27
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers/noaa"
28
28
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers/raw"
29
29
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers/v3appdeployers"
30
+
31
+ goClient "github.com/cloudfoundry/go-cfclient/v3/client"
32
+ goConfig "github.com/cloudfoundry/go-cfclient/v3/config"
30
33
)
31
34
32
35
// Session - wraps the available clients from CF cli
33
36
type Session struct {
34
37
ClientV2 * ccv2.Client
35
38
ClientV3 * ccv3.Client
39
+ ClientGo * goClient.Client
36
40
ClientUAA * uaa.Client
37
41
38
42
// Used for direct endpoint calls
@@ -221,30 +225,35 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
221
225
var accessToken string
222
226
var refreshToken string
223
227
var errType string
228
+ var goClientConfigOptions goConfig.Option
224
229
225
230
tokFromStore := s .loadTokFromStoreIfNeed (configSess .StoreTokensPath , uaaClient .RefreshAccessToken )
226
231
if tokFromStore .IsSet () {
227
232
accessToken = tokFromStore .AccessToken
228
233
refreshToken = tokFromStore .RefreshToken
234
+ goClientConfigOptions = goConfig .Token (accessToken , refreshToken )
229
235
} else if configSess .SSOPasscode != "" {
230
236
// try connecting with SSO passcode to retrieve access token and refresh token
231
237
accessToken , refreshToken , err = uaaClient .Authenticate (map [string ]string {
232
238
"passcode" : configSess .SSOPasscode ,
233
239
}, configSess .Origin , constant .GrantTypePassword )
234
240
errType = "SSO passcode"
241
+ goClientConfigOptions = goConfig .Token (accessToken , refreshToken )
235
242
} else if config .CFUsername () != "" {
236
243
// try connecting with pair given on uaa to retrieve access token and refresh token
237
244
accessToken , refreshToken , err = uaaClient .Authenticate (map [string ]string {
238
245
"username" : config .CFUsername (),
239
246
"password" : config .CFPassword (),
240
247
}, configSess .Origin , constant .GrantTypePassword )
241
248
errType = "username/password"
249
+ goClientConfigOptions = goConfig .UserPassword (config .CFUsername (), config .CFPassword ())
242
250
} else if config .UAAOAuthClient () != "cf" {
243
251
accessToken , refreshToken , err = uaaClient .Authenticate (map [string ]string {
244
252
"client_id" : config .UAAOAuthClient (),
245
253
"client_secret" : config .UAAOAuthClientSecret (),
246
254
}, configSess .Origin , constant .GrantTypeClientCredentials )
247
255
errType = "client_id/client_secret"
256
+ goClientConfigOptions = goConfig .Token (accessToken , refreshToken )
248
257
}
249
258
if err != nil {
250
259
return fmt .Errorf ("Error when authenticate on cf using %s: %s" , errType , err )
@@ -256,6 +265,18 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
256
265
config .SetAccessToken (fmt .Sprintf ("bearer %s" , accessToken ))
257
266
config .SetRefreshToken (refreshToken )
258
267
268
+ goconfig , err := goConfig .New (config .ConfigFile .Target , goClientConfigOptions )
269
+
270
+ if err != nil {
271
+ return fmt .Errorf ("Error when creating go-cfconfig: %s" , err )
272
+ }
273
+
274
+ goclient , err := goClient .New (goconfig )
275
+ if err != nil {
276
+ return fmt .Errorf ("Error when creating go-cfclient: %s" , err )
277
+ }
278
+ s .ClientGo = goclient
279
+
259
280
// Write access and refresh tokens to file if needed
260
281
err = s .saveTokToStoreIfNeed (configSess .StoreTokensPath , accessToken , refreshToken )
261
282
if err != nil {
@@ -402,7 +423,7 @@ func (s *Session) loadDeployer() {
402
423
s .Deployer = appdeployers .NewDeployer (stdStrategy , bgStrategy )
403
424
404
425
// Initialize deployment strategies in v3
405
- s .V3RunBinder = v3appdeployers .NewRunBinder (s .ClientV3 , s .NOAAClient )
426
+ s .V3RunBinder = v3appdeployers .NewRunBinder (s .ClientV3 , s .ClientGo , s . NOAAClient )
406
427
v3std := v3appdeployers .NewStandard (s .BitsManager , s .ClientV3 , s .V3RunBinder )
407
428
v3bg := v3appdeployers .NewBlueGreen (s .BitsManager , s .ClientV3 , s .RawClient , s .V3RunBinder , v3std )
408
429
0 commit comments