Skip to content

Commit

Permalink
Merge pull request #970 from vmware/vmc-version-api
Browse files Browse the repository at this point in the history
Use version API for VMC
  • Loading branch information
annakhm authored Sep 18, 2023
2 parents f6310a3 + bb57f5f commit 77dc8d4
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,17 +701,21 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
return nil
}

err = configureLicenses(getPolicyConnector(*clients), clients.CommonConfig.LicenseDiff)
if err != nil {
return err
if !isVMC {
err = configureLicenses(getPolicyConnectorForInit(*clients), clients.CommonConfig.LicenseDiff)
if err != nil {
return err
}
}

if isVMC {
// Special treatment for VMC since MP API is not available there
err = initNSXVersion(getPolicyConnectorForInit(*clients))
if err != nil && isVMC {
// In case version API does not work for VMC, we workaround by testing version-specific APIs
// TODO - remove this when /node/version API works for all auth methods on VMC
initNSXVersionVMC(*clients)
return nil
}
return initNSXVersion(getPolicyConnector(*clients))
return err
}

func getConfiguredSecurityContext(clients *nsxtClients, vmcAccessToken string, vmcAuthHost string, vmcAuthMode string, username string, password string) (*core.SecurityContextImpl, error) {
Expand All @@ -726,10 +730,10 @@ func getConfiguredSecurityContext(clients *nsxtClients, vmcAccessToken string, v
return nil, err
}

if vmcAuthMode == "Bearer" {
clients.CommonConfig.BearerToken = apiToken
} else {

// We'll be sending Bearer token anyway even with scp-auth-token auth
// For now, node API is not working on VMC without Bearer token present
clients.CommonConfig.BearerToken = apiToken
if vmcAuthMode != "Bearer" {
securityCtx.SetProperty(security.AUTHENTICATION_SCHEME_ID, security.OAUTH_SCHEME_ID)
securityCtx.SetProperty(security.ACCESS_TOKEN, apiToken)
}
Expand Down Expand Up @@ -957,10 +961,14 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}

func getPolicyConnector(clients interface{}) client.Connector {
return getPolicyConnectorWithHeaders(clients, nil)
return getPolicyConnectorWithHeaders(clients, nil, false)
}

func getPolicyConnectorForInit(clients interface{}) client.Connector {
return getPolicyConnectorWithHeaders(clients, nil, true)
}

func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[string]string) client.Connector {
func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[string]string, initFlow bool) client.Connector {
c := clients.(nsxtClients)

retryFunc := func(retryContext retry.RetryContext) bool {
Expand Down Expand Up @@ -1038,7 +1046,7 @@ func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[strin
connector := client.NewConnector(c.Host, connectorOptions...)
// Init NSX version on demand if not done yet
// This is also our indication to apply licenses, in case of delayed connection
if nsxVersion == "" {
if nsxVersion == "" && !initFlow {
initNSXVersion(connector)
err := configureLicenses(connector, c.CommonConfig.LicenseDiff)
if err != nil {
Expand Down

0 comments on commit 77dc8d4

Please sign in to comment.