From 9297420c7a9f4afa041cc024867272f4a3508042 Mon Sep 17 00:00:00 2001 From: "Cuong. Duong Manh" Date: Tue, 15 Oct 2024 16:34:23 +0700 Subject: [PATCH] [build][fix] api list system tags --- test/endpoint_test.go | 10 +++++----- test/identity_test.go | 10 ++++++++-- vngcloud/gateway/gateway.go | 4 ++++ vngcloud/gateway/igateway.go | 2 ++ vngcloud/gateway/vnetwork_gateway.go | 4 ++++ vngcloud/services/network/v1/endpoint.go | 2 ++ vngcloud/services/network/v1/endpoint_request.go | 13 ++++++++++++- vngcloud/services/network/v1/irequest.go | 6 ++++-- 8 files changed, 41 insertions(+), 10 deletions(-) diff --git a/test/endpoint_test.go b/test/endpoint_test.go index 5e29eb0..a0a2203 100644 --- a/test/endpoint_test.go +++ b/test/endpoint_test.go @@ -78,18 +78,18 @@ func TestEndpoint(t *ltesting.T) { } func TestListEndpointTags(t *ltesting.T) { - vngcloud := validSdkConfig() - opt := lsnwv1.NewListEndpointsRequest(1, 100).WithUuid("enp-9349271b-af44-4e39-8829-615d945fa6c2") + vngcloud := validSuperSdkConfig() + opt := lsnwv1.NewListTagsByEndpointIdRequest("60108", "enp-7e8e4476-feeb-414c-ac03-3501aae607d0") - lb, sdkerr := vngcloud.VNetworkGateway().V1().NetworkService().ListEndpoints(opt) + lb, sdkerr := vngcloud.VNetworkGateway().InternalV1().NetworkService().ListTagsByEndpointId(opt) if sdkerr != nil { - t.Fatalf("Expect nil but got %+v", sdkerr.GetErrorCode()) + t.Logf("Expect nil but got %+v", sdkerr.GetErrorCode()) } if lb == nil { t.Fatalf("Expect not nil but got nil") } - t.Log("Result: ", lb.At(0)) + t.Log("Result: ", lb) t.Log("PASS") } diff --git a/test/identity_test.go b/test/identity_test.go index fb06fa1..0a969ee 100644 --- a/test/identity_test.go +++ b/test/identity_test.go @@ -2,6 +2,7 @@ package test import ( lctx "context" + "fmt" ltesting "testing" lgodotenv "github.com/joho/godotenv" @@ -121,10 +122,12 @@ func validSuperSdkConfig() lsclient.IClient { sdkConfig := lsclient.NewSdkConfigure(). WithClientId(clientId). WithClientSecret(clientSecret). + WithZoneId(getValueOfEnv("VNGCLOUD_ZONE_ID")). WithProjectId(getValueOfEnv("VNGCLOUD_PROJECT_ID")). WithIamEndpoint("https://iamapis.vngcloud.vn/accounts-api"). WithVServerEndpoint("https://hcm-3.api.vngcloud.vn/vserver/vserver-gateway"). - WithVLBEndpoint("https://hcm-3.api.vngcloud.vn/vserver/vlb-gateway") + WithVLBEndpoint("https://hcm-3.api.vngcloud.vn/vserver/vlb-gateway"). + WithVNetworkEndpoint("https://vnetwork-hcm03-api.vngcloud.vn/vnetwork-gateway") return lsclient.NewClient(lctx.TODO()).WithRetryCount(1).WithSleep(10).Configure(sdkConfig) } @@ -223,6 +226,8 @@ func TestAuthenPass(t *ltesting.T) { t.Log("PASS") } + + func TestASuperuthenPass(t *ltesting.T) { clientId, clientSecret := getValueOfEnv("VNGCLOUD_SUPER_CLIENT_ID"), getValueOfEnv("VNGCLOUD_SUPER_CLIENT_SECRET") vngcloud := validSdkConfig() @@ -233,7 +238,8 @@ func TestASuperuthenPass(t *ltesting.T) { t.Error("This testcase MUST pass") } - t.Log("RESULT:", token) + fmt.Println("RESULT 2:", token.Token) + t.Log("RESULT:", token.Token) t.Log("PASS") } diff --git a/vngcloud/gateway/gateway.go b/vngcloud/gateway/gateway.go index f5cea67..322b228 100644 --- a/vngcloud/gateway/gateway.go +++ b/vngcloud/gateway/gateway.go @@ -135,3 +135,7 @@ func (s *vnetworkGateway) V1() IVNetworkGatewayV1 { func (s *vnetworkGateway) GetEndpoint() string { return s.endpoint } + +func (s *vnetworkGateway) InternalV1() IVNetworkGatewayInternalV1 { + return s.vnetworkGatewayInternalV1 +} diff --git a/vngcloud/gateway/igateway.go b/vngcloud/gateway/igateway.go index 48681f6..04f4413 100644 --- a/vngcloud/gateway/igateway.go +++ b/vngcloud/gateway/igateway.go @@ -27,6 +27,7 @@ type IVServerGateway interface { type IVNetworkGateway interface { V1() IVNetworkGatewayV1 + InternalV1() IVNetworkGatewayInternalV1 GetEndpoint() string } @@ -51,6 +52,7 @@ type IVNetworkGatewayV1 interface { } type IVNetworkGatewayInternalV1 interface { + NetworkService() lsnetworkSvc.INetworkServiceInternalV1 } type IVLBGatewayInternal interface { diff --git a/vngcloud/gateway/vnetwork_gateway.go b/vngcloud/gateway/vnetwork_gateway.go index 0131a8e..78e9625 100644 --- a/vngcloud/gateway/vnetwork_gateway.go +++ b/vngcloud/gateway/vnetwork_gateway.go @@ -17,6 +17,10 @@ func (s *vnetworkGatewayV1) NetworkService() lsnwSvc.INetworkServiceV1 { return s.networkService } +func (s *vnetworkGatewayInternalV1) NetworkService() lsnwSvc.INetworkServiceInternalV1 { + return s.networkService +} + func NewVNetworkGatewayV1(psvcClient lsclient.IServiceClient) IVNetworkGatewayV1 { return &vnetworkGatewayV1{ networkService: lsnwSvc.NewNetworkServiceV1(psvcClient), diff --git a/vngcloud/services/network/v1/endpoint.go b/vngcloud/services/network/v1/endpoint.go index 0cf5328..82698d6 100644 --- a/vngcloud/services/network/v1/endpoint.go +++ b/vngcloud/services/network/v1/endpoint.go @@ -97,6 +97,8 @@ func (s *NetworkServiceInternalV1) ListTagsByEndpointId(popts IListTagsByEndpoin resp := new(ListTagsByEndpointIdResponse) errResp := lserr.NewErrorResponse(lserr.NetworkGatewayErrorType) req := lsclient.NewRequest(). + WithMapHeaders(popts.GetMapHeaders()). + WithHeader("User-Agent", popts.ParseUserAgent()). WithOkCodes(200). WithJsonResponse(resp). WithJsonError(errResp) diff --git a/vngcloud/services/network/v1/endpoint_request.go b/vngcloud/services/network/v1/endpoint_request.go index cb1319b..b7e7a49 100644 --- a/vngcloud/services/network/v1/endpoint_request.go +++ b/vngcloud/services/network/v1/endpoint_request.go @@ -58,10 +58,11 @@ func NewListEndpointsRequest(ppage, psize int) IListEndpointsRequest { } } -func NewListTagsByEndpointIdRequest(pendpointId string) IListTagsByEndpointIdRequest { +func NewListTagsByEndpointIdRequest(puserId, pendpointId string) IListTagsByEndpointIdRequest { opt := new(ListTagsByEndpointIdRequest) opt.Id = pendpointId opt.EndpointId = pendpointId + opt.SetPortalUserId(puserId) return opt } @@ -300,6 +301,7 @@ func (s *ListEndpointsRequest) AddUserAgent(pagent ...string) IListEndpointsRequ type ListTagsByEndpointIdRequest struct { lscommon.UserAgent lscommon.EndpointCommon + lscommon.PortalUser Id string `q:"resourceUuid"` } @@ -331,3 +333,12 @@ func (s *ListTagsByEndpointIdRequest) GetParameters() map[string]interface{} { return res } + +func (s *ListTagsByEndpointIdRequest) GetMapHeaders() map[string]string { + return s.PortalUser.GetMapHeaders() +} + +func (s *ListTagsByEndpointIdRequest) AddUserAgent(pagent ...string) IListTagsByEndpointIdRequest { + s.UserAgent.Agent = append(s.UserAgent.Agent, pagent...) + return s +} \ No newline at end of file diff --git a/vngcloud/services/network/v1/irequest.go b/vngcloud/services/network/v1/irequest.go index e419703..33c317d 100644 --- a/vngcloud/services/network/v1/irequest.go +++ b/vngcloud/services/network/v1/irequest.go @@ -41,9 +41,11 @@ type IListEndpointsRequest interface { GetParameters() map[string]interface{} } - type IListTagsByEndpointIdRequest interface { ToListQuery() (string, error) GetDefaultQuery() string GetParameters() map[string]interface{} -} \ No newline at end of file + GetMapHeaders() map[string]string + ParseUserAgent() string + AddUserAgent(pagent ...string) IListTagsByEndpointIdRequest +}