Skip to content

Commit

Permalink
[fix] the group of api admin tags missing user project id
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 17, 2024
1 parent e499e4c commit aee2a78
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 80 deletions.
6 changes: 3 additions & 3 deletions test/endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package test

import (
lsnwv1 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v1"
"net/url"
ltesting "testing"

"net/url"
lsnwv1 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v1"
)

func TestGetEndpointSuccess(t *ltesting.T) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestEndpoint(t *ltesting.T) {

func TestListEndpointTags(t *ltesting.T) {
vngcloud := validSuperSdkConfig()
opt := lsnwv1.NewListTagsByEndpointIdRequest("54507", "enp-4457d867-6e3d-4a75-8ceb-d11a957afbe8")
opt := lsnwv1.NewListTagsByEndpointIdRequest("54507", "pro-88265bae-d2ef-424b-b8a7-9eeb08aec1f7", "enp-4457d867-6e3d-4a75-8ceb-d11a957afbe8")

lb, sdkerr := vngcloud.VNetworkGateway().InternalV1().NetworkService().ListTagsByEndpointId(opt)
if sdkerr != nil {
Expand Down
14 changes: 14 additions & 0 deletions test/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ func validUser11412SdkConfig() lsclient.IClient {
return lsclient.NewClient(lctx.TODO()).WithRetryCount(1).WithSleep(10).Configure(sdkConfig)
}

func validUser11412() lsclient.IClient {
clientId, clientSecret := getValueOfEnv("USER_11412_CLIENT_ID"), getValueOfEnv("USER_11412_CLIENT_SECRET")
sdkConfig := lsclient.NewSdkConfigure().
WithClientId(clientId).
WithClientSecret(clientSecret).
WithProjectId(getValueOfEnv("USER_11412_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").
WithVNetworkEndpoint("https://vnetwork-hcm03-api.vngcloud.vn/vnetwork-gateway")

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

func validSuperSdkConfig2() lsclient.IClient {
clientId, clientSecret := getValueOfEnv("VNGCLOUD_SUPER_CLIENT_ID"), getValueOfEnv("VNGCLOUD_SUPER_CLIENT_SECRET")
sdkConfig := lsclient.NewSdkConfigure().
Expand Down
16 changes: 13 additions & 3 deletions test/portal_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package test

import (
ltesting "testing"

lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error"
lsportalV1 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/portal/v1"
lsportalV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/portal/v2"
ltesting "testing"
)

func TestGetPortalInfoFailed(t *ltesting.T) {
Expand Down Expand Up @@ -133,7 +134,6 @@ func TestGetQuotaByNamePass(t *ltesting.T) {
t.Log("PASS")
}


func TestListProjects(t *ltesting.T) {
vngcloud := validSdkConfig()
projects, err := vngcloud.VServerGateway().V1().PortalService().ListProjects()
Expand All @@ -142,4 +142,14 @@ func TestListProjects(t *ltesting.T) {
}

t.Log("Result: ", projects.At(0))
}
}

func TestListPortalUser11412(t *ltesting.T) {
vngcloud := validUser11412()
projects, err := vngcloud.VServerGateway().V1().PortalService().ListProjects()
if err != nil {
t.Log("Error: ", err)
}

t.Log("Result: ", projects.At(0))
}
97 changes: 24 additions & 73 deletions vngcloud/services/network/v1/endpoint_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,6 @@ const (
defaultListEndpointsRequestSize = 10
)

func NewGetEndpointByIdRequest(pendpointId string) IGetEndpointByIdRequest {
opt := new(GetEndpointByIdRequest)
opt.EndpointId = pendpointId
return opt
}

func NewCreateEndpointRequest(pname, pserviceId, pvpcId, psubnetId string) ICreateEndpointRequest {
opts := new(CreateEndpointRequest)
opts.ResourceInfo.EndpointName = pname
opts.ResourceInfo.ServiceUuid = pserviceId
opts.ResourceInfo.VpcUuid = pvpcId
opts.ResourceInfo.SubnetUuid = psubnetId
opts.ResourceInfo.PackageUuid = defaultPackageId

return opts
}

func NewDeleteEndpointByIdRequest(pendpointId, pvpcId, pendpointServiceId string) IDeleteEndpointByIdRequest {
opt := new(DeleteEndpointByIdRequest)
opt.EndpointId = pendpointId
opt.EndpointUuid = pendpointId
opt.VpcUuid = pvpcId
opt.EndpointServiceUuid = pendpointServiceId

return opt
}

func NewListEndpointsRequest(ppage, psize int) IListEndpointsRequest {
return &ListEndpointsRequest{
Page: ppage,
Size: psize,
}
}

func NewListTagsByEndpointIdRequest(puserId, pendpointId string) IListTagsByEndpointIdRequest {
opt := new(ListTagsByEndpointIdRequest)
opt.Id = pendpointId
opt.EndpointId = pendpointId
opt.SetPortalUserId(puserId)
return opt
}

func NewCreateTagsWithEndpointIdRequest(puserId, pendpointId string) ICreateTagsWithEndpointIdRequest {
opt := new(CreateTagsWithEndpointIdRequest)
opt.ResourceUuid = pendpointId
opt.EndpointId = pendpointId
opt.SystemTag = true
opt.SetPortalUserId(puserId)

return opt
}

func NewDeleteTagOfEndpointRequest(puserId, ptagId string) IDeleteTagOfEndpointRequest {
opt := new(DeleteTagOfEndpointRequest)
opt.TagId = ptagId
opt.SetPortalUserId(puserId)

return opt
}

func NewUpdateTagValueOfEndpointRequest(puserId, ptagId, pvalue string) IUpdateTagValueOfEndpointRequest {
opt := new(UpdateTagValueOfEndpointRequest)
opt.TagId = ptagId
opt.TagValue = pvalue
opt.SetPortalUserId(puserId)

return opt
}

type GetEndpointByIdRequest struct {
lscommon.UserAgent
lscommon.EndpointCommon
Expand Down Expand Up @@ -330,7 +261,8 @@ type ListTagsByEndpointIdRequest struct {
lscommon.EndpointCommon
lscommon.PortalUser

Id string `q:"resourceUuid"`
ProjectId string
Id string `q:"resourceUuid"`
}

func (s *ListTagsByEndpointIdRequest) ToListQuery() (string, error) {
Expand All @@ -343,6 +275,10 @@ func (s *ListTagsByEndpointIdRequest) ToListQuery() (string, error) {
return url.String(), err
}

func (s *ListTagsByEndpointIdRequest) GetProjectId() string {
return s.ProjectId
}

func (s *ListTagsByEndpointIdRequest) GetDefaultQuery() string {
query := lfmt.Sprintf(`{"page":%d,"size":%d}`, defaultListEndpointsRequestPage, defaultListEndpointsRequestSize)
query = "params=" + lurl.QueryEscape(query)
Expand Down Expand Up @@ -377,6 +313,7 @@ type CreateTagsWithEndpointIdRequest struct {
lscommon.EndpointCommon
lscommon.PortalUser

ProjectId string
ResourceUuid string `json:"resourceUuid"`
Tags []struct {
TagKey string `json:"tagKey"`
Expand Down Expand Up @@ -425,13 +362,18 @@ func (s *CreateTagsWithEndpointIdRequest) ToRequestBody() interface{} {
return s
}

func (s *CreateTagsWithEndpointIdRequest) GetProjectId() string {
return s.ProjectId
}

// ____________________________________________________________________ DeleteTagByEndpointIdRequest

type DeleteTagOfEndpointRequest struct {
lscommon.UserAgent
lscommon.PortalUser

TagId string
ProjectId string
TagId string
}

func (s *DeleteTagOfEndpointRequest) GetParameters() map[string]interface{} {
Expand Down Expand Up @@ -459,14 +401,19 @@ func (s *DeleteTagOfEndpointRequest) GetTagId() string {
return s.TagId
}

func (s *DeleteTagOfEndpointRequest) GetProjectId() string {
return s.ProjectId
}

// _________________________________________________________________ UpdateTagValueOfEndpointRequest

type UpdateTagValueOfEndpointRequest struct {
lscommon.UserAgent
lscommon.PortalUser

TagId string
TagValue string `json:"tagValue"`
TagId string
ProjectId string
TagValue string `json:"tagValue"`
}

func (s *UpdateTagValueOfEndpointRequest) GetParameters() map[string]interface{} {
Expand Down Expand Up @@ -498,3 +445,7 @@ func (s *UpdateTagValueOfEndpointRequest) GetTagId() string {
func (s *UpdateTagValueOfEndpointRequest) ToRequestBody() interface{} {
return s
}

func (s *UpdateTagValueOfEndpointRequest) GetProjectId() string {
return s.ProjectId
}
4 changes: 4 additions & 0 deletions vngcloud/services/network/v1/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type IListTagsByEndpointIdRequest interface {
GetParameters() map[string]interface{}
GetMapHeaders() map[string]string
ParseUserAgent() string
GetProjectId() string
AddUserAgent(pagent ...string) IListTagsByEndpointIdRequest
}

Expand All @@ -56,6 +57,7 @@ type ICreateTagsWithEndpointIdRequest interface {
GetMapHeaders() map[string]string
AddTag(pkey, pvalue string) ICreateTagsWithEndpointIdRequest
ParseUserAgent() string
GetProjectId() string
ToRequestBody() interface{}
}

Expand All @@ -65,6 +67,7 @@ type IDeleteTagOfEndpointRequest interface {
GetMapHeaders() map[string]string
ParseUserAgent() string
GetTagId() string
GetProjectId() string
}

type IUpdateTagValueOfEndpointRequest interface {
Expand All @@ -73,5 +76,6 @@ type IUpdateTagValueOfEndpointRequest interface {
GetMapHeaders() map[string]string
ParseUserAgent() string
GetTagId() string
GetProjectId() string
ToRequestBody() interface{}
}
74 changes: 74 additions & 0 deletions vngcloud/services/network/v1/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package v1

func NewGetEndpointByIdRequest(pendpointId string) IGetEndpointByIdRequest {
opt := new(GetEndpointByIdRequest)
opt.EndpointId = pendpointId
return opt
}

func NewCreateEndpointRequest(pname, pserviceId, pvpcId, psubnetId string) ICreateEndpointRequest {
opts := new(CreateEndpointRequest)
opts.ResourceInfo.EndpointName = pname
opts.ResourceInfo.ServiceUuid = pserviceId
opts.ResourceInfo.VpcUuid = pvpcId
opts.ResourceInfo.SubnetUuid = psubnetId
opts.ResourceInfo.PackageUuid = defaultPackageId

return opts
}

func NewDeleteEndpointByIdRequest(pendpointId, pvpcId, pendpointServiceId string) IDeleteEndpointByIdRequest {
opt := new(DeleteEndpointByIdRequest)
opt.EndpointId = pendpointId
opt.EndpointUuid = pendpointId
opt.VpcUuid = pvpcId
opt.EndpointServiceUuid = pendpointServiceId

return opt
}

func NewListEndpointsRequest(ppage, psize int) IListEndpointsRequest {
return &ListEndpointsRequest{
Page: ppage,
Size: psize,
}
}

func NewListTagsByEndpointIdRequest(puserId, pprojectId, pendpointId string) IListTagsByEndpointIdRequest {
opt := new(ListTagsByEndpointIdRequest)
opt.Id = pendpointId
opt.EndpointId = pendpointId
opt.ProjectId = pprojectId
opt.SetPortalUserId(puserId)
return opt
}

func NewCreateTagsWithEndpointIdRequest(puserId, pprojectId, pendpointId string) ICreateTagsWithEndpointIdRequest {
opt := new(CreateTagsWithEndpointIdRequest)
opt.ResourceUuid = pendpointId
opt.EndpointId = pendpointId
opt.SystemTag = true
opt.ProjectId = pprojectId
opt.SetPortalUserId(puserId)

return opt
}

func NewDeleteTagOfEndpointRequest(puserId, pprojectId, ptagId string) IDeleteTagOfEndpointRequest {
opt := new(DeleteTagOfEndpointRequest)
opt.TagId = ptagId
opt.ProjectId = pprojectId
opt.SetPortalUserId(puserId)

return opt
}

func NewUpdateTagValueOfEndpointRequest(puserId, pprojectId, ptagId, pvalue string) IUpdateTagValueOfEndpointRequest {
opt := new(UpdateTagValueOfEndpointRequest)
opt.TagId = ptagId
opt.TagValue = pvalue
opt.ProjectId = pprojectId
opt.SetPortalUserId(puserId)

return opt
}
2 changes: 1 addition & 1 deletion vngcloud/services/network/v1/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func listTagsByEndpointIdUrl(psc lsclient.IServiceClient, popts IListTagsByEndpo
}

return psc.ServiceURL(
psc.GetProjectId(),
popts.GetProjectId(),
"tags") + query
}

Expand Down

0 comments on commit aee2a78

Please sign in to comment.