Skip to content

Commit

Permalink
Code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Oct 31, 2024
1 parent be6b464 commit 2b4bf12
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions pkg/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (a *api) do(ctx context.Context, request interface{}, queryParams map[strin
// Set the path
if !a.removeVmaasCMPBasePath {
// Add the base path of the vmaas-cmp API if we are calling the vmaas-cmp API
a.path = fmt.Sprintf("%s/%s/%s", a.client.getHost(), consts.VmaasCmpAPIBasePath, a.path)
//a.path = fmt.Sprintf("%s/%s", a.client.getHost(), a.path)
a.path = fmt.Sprintf("%s/%s/%s", a.client.getHost(), consts.CmpAPIBasePath, a.path)
} else {
// Don't use the base path of the vmaas-cmp API if we are calling the broker API
a.path = fmt.Sprintf("%s/%s", a.client.getHost(), a.path)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
testServiceInstanceID = "18ba6409-ac59-4eac-9414-0147e72d615e"
testAccessToken = "2b9fba7f-7c14-4773-a970-a9ad393811ac"
testRefreshToken = "7806acfb-f847-48b1-a6d5-6119dccb3ffe"
testMorpheusURL = "https://1234-mp.private.greenlake.hpe-gl-intg.com/"
testMorpheusURL = "https://1234-mp.private.greenlake.hpe-gl-intg.com"
testAccessTokenExpires = 1758034360176
testAccessTokenExpiresIn = 3600
)
Expand Down
20 changes: 8 additions & 12 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ type APIClientHandler interface {
SetMetaFnAndVersion(meta interface{}, version int, fn SetScmClientToken)
// GetSCMVersion returns the SCM version for use when creating the Broker client
GetSCMVersion() int
GetCMPVars(ctx context.Context) (models.TFMorpheusDetails, error)
SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken) error
SetHost(host string)
GetCMPDetails(ctx context.Context) (models.TFMorpheusDetails, error)
SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken)
SetCMPVersion(ctx context.Context) (err error)
}

Expand Down Expand Up @@ -79,12 +80,8 @@ func NewAPIClient(cfg *Configuration) *APIClient {
func (c *APIClient) getHost() string {
return c.cfg.Host
}
func (c *APIClient) SetHostandToken(host, token string) {
func (c *APIClient) SetHost(host string) {
c.cfg.Host = host
if c.cfg.DefaultHeader == nil {
c.cfg.DefaultHeader = map[string]string{}
}
c.cfg.AddDefaultHeader("Authorization", "Bearer "+token)
}
func (c *APIClient) SetMeta(meta interface{}, fn SetScmClientToken) error {
c.meta = meta
Expand Down Expand Up @@ -112,21 +109,20 @@ func (c *APIClient) SetMeta(meta interface{}, fn SetScmClientToken) error {

return nil
}
func (c *APIClient) GetCMPVars(ctx context.Context) (models.TFMorpheusDetails, error) {

// GetCMPDetails here APIClient is the brokerClient
func (c *APIClient) GetCMPDetails(ctx context.Context) (models.TFMorpheusDetails, error) {
cmpBroker := BrokerAPIService{
Client: c,
Cfg: *c.cfg,
}
return cmpBroker.GetMorpheusDetails(ctx)

}
func (c *APIClient) SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken) (err error) {
func (c *APIClient) SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken) {
c.meta = meta
c.tokenFunc = fn
// if cmp version already set then skip
c.BrokerClient = brokerClient

return
}
func (c *APIClient) SetCMPVersion(ctx context.Context) (err error) {
if c.cmpVersion != 0 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package common

const (
// VmaasCmpAPIBasePath base cmp api path
VmaasCmpAPIBasePath = "api"
VmaasCmpAPIBasePath = "v1"
// CmpAPIBasePath base cmp api path
CmpAPIBasePath string = "api"
// InstancesPath
InstancesPath = "instances"
// InstanceTypesPath
Expand Down

0 comments on commit 2b4bf12

Please sign in to comment.