Skip to content

Commit

Permalink
[build][fix] api create tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 15, 2024
1 parent 9297420 commit ab25b56
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 1 deletion.
17 changes: 17 additions & 0 deletions test/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,20 @@ func TestListEndpointTags(t *ltesting.T) {
t.Log("Result: ", lb)
t.Log("PASS")
}

func TestCreateEndpointTags(t *ltesting.T) {
vngcloud := validSuperSdkConfig()
opt := lsnwv1.NewCreateTagsWithEndpointIdRequest("60108", "enp-7e8e4476-feeb-414c-ac03-3501aae607d0").
AddTag("cuongdm3", "test")

sdkerr := vngcloud.VNetworkGateway().InternalV1().NetworkService().CreateTagsWithEndpointId(opt)
if sdkerr != nil {
t.Logf("Expect nil but got %+v", sdkerr.GetErrorCode())
}


t.Log("Result: ", sdkerr)
t.Log("PASS")
}


1 change: 1 addition & 0 deletions vngcloud/services/network/inetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type INetworkServiceV1 interface {

type INetworkServiceInternalV1 interface {
ListTagsByEndpointId(popts lsnetworkSvcV1.IListTagsByEndpointIdRequest) (*lsentity.ListTags, lserr.IError)
CreateTagsWithEndpointId(popts lsnetworkSvcV1.ICreateTagsWithEndpointIdRequest) lserr.IError
}

type INetworkServiceV2 interface {
Expand Down
19 changes: 19 additions & 0 deletions vngcloud/services/network/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ func (s *NetworkServiceInternalV1) ListTagsByEndpointId(popts IListTagsByEndpoin

return resp.ToEntityListTags(), nil
}

func (s *NetworkServiceInternalV1) CreateTagsWithEndpointId(popts ICreateTagsWithEndpointIdRequest) lserr.IError {
url := createTagsWithEndpointIdUrl(s.VNetworkClient)
errResp := lserr.NewErrorResponse(lserr.NetworkGatewayErrorType)
req := lsclient.NewRequest().
WithMapHeaders(popts.GetMapHeaders()).
WithHeader("User-Agent", popts.ParseUserAgent()).
WithOkCodes(200).
WithJsonBody(popts.ToRequestBody()).
WithJsonError(errResp)

if _, sdkErr := s.VNetworkClient.Post(url, req); sdkErr != nil {
return lserr.SdkErrorHandler(sdkErr, errResp).
WithKVparameters("projectId", s.getProjectId()).
WithParameters(popts.GetParameters())
}

return nil
}
67 changes: 66 additions & 1 deletion vngcloud/services/network/v1/endpoint_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func NewListTagsByEndpointIdRequest(puserId, pendpointId string) IListTagsByEndp
return opt
}

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

return opt
}

type GetEndpointByIdRequest struct {
lscommon.UserAgent
lscommon.EndpointCommon
Expand Down Expand Up @@ -341,4 +351,59 @@ func (s *ListTagsByEndpointIdRequest) GetMapHeaders() map[string]string {
func (s *ListTagsByEndpointIdRequest) AddUserAgent(pagent ...string) IListTagsByEndpointIdRequest {
s.UserAgent.Agent = append(s.UserAgent.Agent, pagent...)
return s
}
}

// _________________________________________________________________ CreateTagsWithEndpointIdRequest

type CreateTagsWithEndpointIdRequest struct {
lscommon.UserAgent
lscommon.EndpointCommon
lscommon.PortalUser

ResourceUuid string `json:"resourceUuid"`
Tags []struct {
TagKey string `json:"tagKey"`
TagValue string `json:"tagValue"`
} `json:"tags"`

SystemTag bool `json:"systemTag"`
}

func (s *CreateTagsWithEndpointIdRequest) GetParameters() map[string]interface{} {
res := map[string]interface{}{
"resourceUuid": s.Id,
}

if s.UserAgent.Agent != nil && len(s.UserAgent.Agent) > 0 {
res["userAgent"] = s.UserAgent.Agent
}

res["tags"] = s.Tags

return res
}

func (s *CreateTagsWithEndpointIdRequest) AddUserAgent(pagent ...string) ICreateTagsWithEndpointIdRequest {
s.UserAgent.Agent = append(s.UserAgent.Agent, pagent...)
return s
}

func (s *CreateTagsWithEndpointIdRequest) GetMapHeaders() map[string]string {
return s.PortalUser.GetMapHeaders()
}

func (s *CreateTagsWithEndpointIdRequest) AddTag(pkey, pvalue string) ICreateTagsWithEndpointIdRequest {
s.Tags = append(s.Tags, struct {
TagKey string `json:"tagKey"`
TagValue string `json:"tagValue"`
}{
TagKey: pkey,
TagValue: pvalue,
})

return s
}

func (s *CreateTagsWithEndpointIdRequest) ToRequestBody() interface{} {
return s
}
9 changes: 9 additions & 0 deletions vngcloud/services/network/v1/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ type IListTagsByEndpointIdRequest interface {
ParseUserAgent() string
AddUserAgent(pagent ...string) IListTagsByEndpointIdRequest
}

type ICreateTagsWithEndpointIdRequest interface {
GetParameters() map[string]interface{}
AddUserAgent(pagent ...string) ICreateTagsWithEndpointIdRequest
GetMapHeaders() map[string]string
AddTag(pkey, pvalue string) ICreateTagsWithEndpointIdRequest
ParseUserAgent() string
ToRequestBody() interface{}
}
6 changes: 6 additions & 0 deletions vngcloud/services/network/v1/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ func listTagsByEndpointIdUrl(psc lsclient.IServiceClient, popts IListTagsByEndpo
psc.GetProjectId(),
"tags") + query
}

func createTagsWithEndpointIdUrl(psc lsclient.IServiceClient) string {
return psc.ServiceURL(
psc.GetProjectId(),
"tags")
}

0 comments on commit ab25b56

Please sign in to comment.