Skip to content

Commit

Permalink
Merge pull request #81 from HewlettPackard/update_host
Browse files Browse the repository at this point in the history
Switch to cmp url
  • Loading branch information
arunkumarviswanathan authored Nov 5, 2024
2 parents c0874ac + 8961e26 commit 5e287d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/client/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

consts "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/common"
"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (a *BrokerAPIService) GetMorpheusDetails(ctx context.Context) (models.TFMor
ID: ServiceSubscriptionDetailsResp.ServiceInstanceID,
AccessToken: MorpheusTokenResp.AccessToken,
ValidTill: MorpheusTokenResp.Expires,
URL: ServiceSubscriptionDetailsResp.URL,
URL: strings.TrimSuffix(ServiceSubscriptionDetailsResp.URL, "/"),
}

return ret, nil
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
40 changes: 39 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"net/url"
"path/filepath"
"strings"

"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
)

type SetScmClientToken func(ctx *context.Context, meta interface{})
Expand All @@ -41,6 +43,10 @@ type APIClientHandler interface {
SetMetaFnAndVersion(meta interface{}, version int, fn SetScmClientToken)
// GetSCMVersion returns the SCM version for use when creating the Broker client
GetSCMVersion() int
SetHost(host string)
// GetCMPDetails here the client is the one which has broker host set
GetCMPDetails(ctx context.Context) (models.TFMorpheusDetails, error)
SetCMPVersion(ctx context.Context) (err error)
}

// APIClient manages communication with the GreenLake Private Cloud VMaaS CMP API API v1.0.0
Expand Down Expand Up @@ -73,7 +79,9 @@ func NewAPIClient(cfg *Configuration) *APIClient {
func (c *APIClient) getHost() string {
return c.cfg.Host
}

func (c *APIClient) SetHost(host string) {
c.cfg.Host = host
}
func (c *APIClient) SetMeta(meta interface{}, fn SetScmClientToken) error {
c.meta = meta
c.tokenFunc = fn
Expand Down Expand Up @@ -101,6 +109,36 @@ func (c *APIClient) SetMeta(meta interface{}, fn SetScmClientToken) error {
return nil
}

// 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) SetCMPVersion(ctx context.Context) (err error) {
if c.cmpVersion != 0 {
return nil
}
cmpClient := CmpStatus{
Client: c,
Cfg: *c.cfg,
}
// Get status of cmp
statusResp, err := cmpClient.GetCmpVersion(ctx)
if err != nil {
return
}
versionInt, err := parseVersion(statusResp.Appliance.BuildVersion)
if err != nil {
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) {
c.meta = meta
c.tokenFunc = fn
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package common

const (
// VmaasCmpAPIBasePath base cmp api path
VmaasCmpAPIBasePath = "v1"
// VmaasCmpAPIBasePath base cmp api path - currently used to talk to CMP directly
VmaasCmpAPIBasePath = "api"
// InstancesPath
InstancesPath = "instances"
// InstanceTypesPath
Expand Down

0 comments on commit 5e287d9

Please sign in to comment.