Skip to content

Commit

Permalink
Merge pull request #91 from vngcloud/glb
Browse files Browse the repository at this point in the history
Glb
  • Loading branch information
anngdinh authored Mar 4, 2025
2 parents 140277a + dc6e1e0 commit a65e89d
Show file tree
Hide file tree
Showing 25 changed files with 3,151 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ TestResults.xml
/tmp/
.idea
/secret/
test/env.yaml
9 changes: 9 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type (
vlbGateway lsgateway.IVLBGateway
vbackupGateway lsgateway.IVBackUpGateway
vnetworkGateway lsgateway.IVNetworkGateway
glbGateway lsgateway.IGLBGateway
}
)

Expand Down Expand Up @@ -153,6 +154,10 @@ func (s *client) Configure(psdkCfg ISdkConfigure) IClient {
s.vnetworkGateway = lsgateway.NewVNetworkGateway(psdkCfg.GetVNetworkEndpoint(), psdkCfg.GetZoneId(), s.projectId, s.userId, s.httpClient)
}

if s.glbGateway == nil && psdkCfg.GetGLBEndpoint() != "" {
s.glbGateway = lsgateway.NewGLBGateway(psdkCfg.GetGLBEndpoint(), s.httpClient)
}

s.httpClient.WithReauthFunc(lsclient.IamOauth2, s.usingIamOauth2AsAuthOption(psdkCfg))
s.userAgent = psdkCfg.GetUserAgent()

Expand All @@ -179,6 +184,10 @@ func (s *client) VNetworkGateway() lsgateway.IVNetworkGateway {
return s.vnetworkGateway
}

func (s *client) GLBGateway() lsgateway.IGLBGateway {
return s.glbGateway
}

func (s *client) usingIamOauth2AsAuthOption(pauthConfig ISdkConfigure) func() (lsclient.ISdkAuthentication, lserr.IError) {
authFunc := func() (lsclient.ISdkAuthentication, lserr.IError) {
token, err := s.iamGateway.V2().IdentityService().GetAccessToken(
Expand Down
12 changes: 12 additions & 0 deletions client/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type (
GetIamEndpoint() string
GetVServerEndpoint() string
GetVLBEndpoint() string
GetGLBEndpoint() string
GetVNetworkEndpoint() string
GetUserAgent() string
WithUserId(puserId string) ISdkConfigure
Expand All @@ -24,6 +25,7 @@ type (
WithVServerEndpoint(pvserverEndpoint string) ISdkConfigure
WithVLBEndpoint(pvlbEndpoint string) ISdkConfigure
WithVNetworkEndpoint(pvnetworkEndpoint string) ISdkConfigure
WithGLBEndpoint(pvlbEndpoint string) ISdkConfigure
}
)

Expand All @@ -36,6 +38,7 @@ type sdkConfigure struct {
iamEndpoint string
vserverEndpoint string
vlbEndpoint string
glbEndpoint string
vnetworkEndpoint string
userAgent string
}
Expand Down Expand Up @@ -72,6 +75,10 @@ func (s *sdkConfigure) GetVLBEndpoint() string {
return s.vlbEndpoint
}

func (s *sdkConfigure) GetGLBEndpoint() string {
return s.glbEndpoint
}

func (s *sdkConfigure) GetVNetworkEndpoint() string {
return s.vnetworkEndpoint
}
Expand Down Expand Up @@ -129,3 +136,8 @@ func (s *sdkConfigure) WithVNetworkEndpoint(pvnetworkEndpoint string) ISdkConfig
s.vnetworkEndpoint = ljutils.NormalizeURL(pvnetworkEndpoint)
return s
}

func (s *sdkConfigure) WithGLBEndpoint(pvlbEndpoint string) ISdkConfigure {
s.glbEndpoint = ljutils.NormalizeURL(pvlbEndpoint)
return s
}
1 change: 1 addition & 0 deletions client/iclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ type IClient interface {
VLBGateway() lsgateway.IVLBGateway
VBackUpGateway() lsgateway.IVBackUpGateway
VNetworkGateway() lsgateway.IVNetworkGateway
GLBGateway() lsgateway.IGLBGateway
}
9 changes: 5 additions & 4 deletions test/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ import (
)

func getEnv() (string, string) {
envFile, _ := lgodotenv.Read("/mnt/kalista/git-vngcloud/vngcloud-go-sdk/secret/env")
envFile, _ := lgodotenv.Read("./env.yaml")
clientId := envFile["VNGCLOUD_CLIENT_ID"]
clientSecret := envFile["VNGCLOUD_CLIENT_SECRET"]

return clientId, clientSecret
}

func getEnvDevOps() (string, string) {
envFile, _ := lgodotenv.Read("/mnt/kalista/git-vngcloud/vngcloud-go-sdk/secret/env")
envFile, _ := lgodotenv.Read("./env.yaml")
clientId := envFile["CLIENT_ID_DEVOPS"]
clientSecret := envFile["CLIENT_SECRET_DEVOPS"]

return clientId, clientSecret
}

func getValueOfEnv(pkey string) string {
envFile, _ := lgodotenv.Read("/mnt/kalista/git-vngcloud/vngcloud-go-sdk/secret/env")
envFile, _ := lgodotenv.Read("./env.yaml")
value := envFile[pkey]
return value
}
Expand All @@ -46,7 +46,8 @@ func validSdkConfig() lsclient.IClient {
WithVServerEndpoint("https://hcm-3.api.vngcloud.vn/vserver/vserver-gateway").
WithVLBEndpoint("https://hcm-3.api.vngcloud.vn/vserver/vlb-gateway").
WithVNetworkEndpoint("https://vnetwork-hcm03.vngcloud.vn/vnetwork-gateway/vnetwork").
WithVNetworkEndpoint("https://hcm-3.console.vngcloud.vn/vserver/vnetwork-gateway/vnetwork")
WithVNetworkEndpoint("https://hcm-3.console.vngcloud.vn/vserver/vnetwork-gateway/vnetwork").
WithGLBEndpoint("https://glb.console.vngcloud.vn/glb-controller/")

return lsclient.NewClient(lctx.TODO()).WithRetryCount(1).WithSleep(10).Configure(sdkConfig)
}
Expand Down
Loading

0 comments on commit a65e89d

Please sign in to comment.