Skip to content

Commit

Permalink
[chore] enhance api update tag for lb
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Aug 30, 2024
1 parent 38bcf81 commit 6d477a0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions vngcloud/sdk_error/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
const (
patternOutOfPoc = "you do not have sufficient credits to complete the purchase"
patternPagingInvalid = "page or size invalid"
patternTagKeyInvalid = "the value for the tag key contains illegal characters"
)

func ErrorHandler(perr error, popts ...func(psdkErr IError)) IError {
Expand Down Expand Up @@ -95,6 +96,21 @@ func WithErrorOutOfPoc(perrResp IErrorRespone) func(sdkError IError) {
}
}

func WithErrorTagKeyInvalid(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}

errMsg := perrResp.GetMessage()
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternTagKeyInvalid) {
sdkError.WithErrorCode(EcTagKeyInvalid).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
}
}
}

func WithErrorPagingInvalid(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
Expand Down
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
EcInternalServerError = ErrorCode("VngCloudApiInternalServerError")
EcServiceMaintenance = ErrorCode("VngCloudServiceMaintenance")
EcPagingInvalid = ErrorCode("VngCloudApiPagingInvalid")
EcTagKeyInvalid = ErrorCode("VngCloudApiTagKeyInvalid")
EcPermissionDenied = ErrorCode("VngCloudApiPermissionDenied")
EcUnexpectedError = ErrorCode("VngCloudApiUnexpectedError")
)
Expand Down
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ type IUpdateTagsRequest interface {
ToRequestBody(plstTags *lsentity.ListTags) interface{}
ParseUserAgent() string
WithTags(ptags ...string) IUpdateTagsRequest
ToMap() map[string]interface{}
}
3 changes: 2 additions & 1 deletion vngcloud/services/loadbalancer/v2/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (s *LoadBalancerServiceV2) UpdateTags(popts IUpdateTagsRequest) lserr.IErro
WithJsonError(errResp)

if _, sdkErr = s.VServerClient.Put(url, req); sdkErr != nil {
return lserr.SdkErrorHandler(sdkErr, errResp)
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorTagKeyInvalid(errResp)).WithParameters(popts.ToMap())
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions vngcloud/services/loadbalancer/v2/tag_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ func (s *UpdateTagsRequest) WithTags(ptags ...string) IUpdateTagsRequest {

return s
}

func (s *UpdateTagsRequest) ToMap() map[string]interface{} {
res := make(map[string]interface{})
for _, tag := range s.TagRequestList {
res[tag.Key] = tag.Value
}
return res
}

0 comments on commit 6d477a0

Please sign in to comment.