Skip to content

Commit

Permalink
[build][enhance] allow update projectID regarless the cloud client ha…
Browse files Browse the repository at this point in the history
…s been created before
  • Loading branch information
cuongpiger committed May 25, 2024
1 parent b13ace4 commit 387ddae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ func (s *client) WithContext(pctx lctx.Context) IClient {
return s
}

func (s *client) WithProjectId(pprojectId string) IClient {
s.projectId = pprojectId
return s
}

func (s *client) WithAuthOption(pauthOpts lsclient.AuthOpts, pauthConfig ISdkConfigure) IClient {
if s.httpClient == nil {
s.httpClient = lsclient.NewHttpClient(s.context)
Expand Down Expand Up @@ -97,6 +92,20 @@ func (s *client) WithSleep(psleep ltime.Duration) IClient {
return s
}

func (s *client) WithProjectId(pprojectId string) IClient {
s.projectId = pprojectId
if s.httpClient == nil {
return s
}

// So it needs to reconfigure the gateway project Id
if s.vserverGateway != nil {
s.vserverGateway = lsgateway.NewVServerGateway(s.vserverGateway.GetEndpoint(), s.projectId, s.httpClient)
}

return s
}

func (s *client) Configure(psdkCfg ISdkConfigure) IClient {
s.projectId = psdkCfg.GetProjectId()
if s.httpClient == nil {
Expand Down
1 change: 1 addition & 0 deletions client/iclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type IClient interface {
WithKvDefaultHeaders(pargs ...string) IClient
WithRetryCount(pretry int) IClient
WithSleep(psleep ltime.Duration) IClient
WithProjectId(pprojectId string) IClient

// List of functional methods
Configure(psdkCfg ISdkConfigure) IClient
Expand Down
6 changes: 6 additions & 0 deletions vngcloud/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type iamGateway struct {
}

type vserverGateway struct {
endpoint string // Hold the endpoint of the vServer service
vserverGatewayV1 IVServerGatewayV1
vserverGatewayV2 IVServerGatewayV2
}
Expand Down Expand Up @@ -36,6 +37,7 @@ func NewVServerGateway(pendpoint, pprojectId string, phc lsclient.IHttpClient) I
WithProjectId(pprojectId)

return &vserverGateway{
endpoint: pendpoint,
vserverGatewayV1: NewVServerGatewayV1(vserverSvcV1),
vserverGatewayV2: NewVServerGatewayV2(vserverSvcV2),
}
Expand All @@ -52,3 +54,7 @@ func (s *vserverGateway) V1() IVServerGatewayV1 {
func (s *vserverGateway) V2() IVServerGatewayV2 {
return s.vserverGatewayV2
}

func (s *vserverGateway) GetEndpoint() string {
return s.endpoint
}
3 changes: 3 additions & 0 deletions vngcloud/gateway/igateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type IIamGatewayV2 interface {
type IVServerGateway interface {
V1() IVServerGatewayV1
V2() IVServerGatewayV2

// GetEndpoint returns the endpoint of the vServer service
GetEndpoint() string
}

type IVServerGatewayV1 interface {
Expand Down

0 comments on commit 387ddae

Please sign in to comment.