Skip to content

Commit

Permalink
change basepath and add more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Oct 30, 2024
1 parent 3719e78 commit be6b464
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ 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.VmaasCmpAPIBasePath, a.path)
//a.path = fmt.Sprintf("%s/%s", a.client.getHost(), 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
28 changes: 18 additions & 10 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ type APIClientHandler interface {
// GetSCMVersion returns the SCM version for use when creating the Broker client
GetSCMVersion() int
GetCMPVars(ctx context.Context) (models.TFMorpheusDetails, error)
SetCMPMeta(meta interface{}, fn SetScmClientToken) error
SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken) error
SetCMPVersion(ctx context.Context) (err error)
}

// APIClient manages communication with the GreenLake Private Cloud VMaaS CMP API API v1.0.0
// In most cases there should be only one, shared, APIClient.
type APIClient struct {
cfg *Configuration
cmpVersion int
meta interface{}
tokenFunc SetScmClientToken
cfg *Configuration
cmpVersion int
meta interface{}
tokenFunc SetScmClientToken
BrokerClient *APIClient
}

// defaultTokenFunc will use while defining httpClient. defaultTokenFunc
Expand All @@ -77,8 +79,12 @@ func NewAPIClient(cfg *Configuration) *APIClient {
func (c *APIClient) getHost() string {
return c.cfg.Host
}
func (c *APIClient) SetHost(host string) {
func (c *APIClient) SetHostandToken(host, token 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 @@ -114,15 +120,18 @@ func (c *APIClient) GetCMPVars(ctx context.Context) (models.TFMorpheusDetails, e
return cmpBroker.GetMorpheusDetails(ctx)

}
func (c *APIClient) SetCMPMeta(meta interface{}, fn SetScmClientToken) (err error) {
func (c *APIClient) SetCMPMeta(meta interface{}, brokerClient *APIClient, fn SetScmClientToken) (err error) {
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 {
return nil
}
ctx := context.Background()
c.tokenFunc(&ctx, meta)
cmpClient := CmpStatus{
Client: c,
Cfg: *c.cfg,
Expand All @@ -137,7 +146,6 @@ func (c *APIClient) SetCMPMeta(meta interface{}, fn SetScmClientToken) (err erro
return fmt.Errorf("failed to parse cmp build, error: %w", err)
}
c.cmpVersion = versionInt

return
}
func (c *APIClient) SetMetaFnAndVersion(meta interface{}, version int, fn SetScmClientToken) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package common

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

0 comments on commit be6b464

Please sign in to comment.