Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cmp url #81

Merged
merged 9 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading