Skip to content

Commit

Permalink
fix: api not found
Browse files Browse the repository at this point in the history
Signed-off-by: Kiloson <[email protected]>
  • Loading branch information
kilosonc committed Jan 10, 2024
1 parent f7e8111 commit 868754f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
15 changes: 11 additions & 4 deletions core/http/api/v2/badge/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@ func (a *API) Create(c *gin.Context) {
}
}

func (a *API) Update(c *gin.Context) {
// op := "badge: update"
resourceType, resourceID, err := getResourceContext(c)
func (a *API) UpdateClusterBadge(c *gin.Context) {
clusterIDStr := c.Param(common.ParamClusterID)
clusterID, err := strconv.ParseUint(clusterIDStr, 10, 0)

if err != nil {
errMsg := fmt.Sprintf("invalid : %s, err: %s", clusterIDStr, err.Error())
response.AbortWithRPCError(c, rpcerror.ParamError.WithErrMsg(errMsg))
return
}
a.update(c, common.ResourceCluster, uint(clusterID))
}

func (a *API) update(c *gin.Context, resourceType string, resourceID uint) {
// op := "badge: update"
badgeIDorName := c.Param(_paramBadgeIDorName)

badgeID, err := strconv.ParseUint(badgeIDorName, 10, 0)
Expand All @@ -100,7 +107,7 @@ func (a *API) Update(c *gin.Context) {
response.SuccessWithData(c, b)
}
} else {
if b, err := a.badgeCtl.UpdateBadgeByName(c, resourceType, resourceID, badgeName, &badgeUpdate); err != nil {
if b, err := a.badgeCtl.UpdateBadgeByName(c, resourceType, uint(resourceID), badgeName, &badgeUpdate); err != nil {
response.AbortWithRPCError(c, rpcerror.InternalError.WithErrMsg(fmt.Sprintf("failed to update badge, err: %s",
err.Error())))
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/http/api/v2/badge/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func (a *API) RegisterRoute(engine *gin.Engine) {
},
{
Method: http.MethodPut,
Pattern: fmt.Sprintf("/:%v/:%v/badges/:%v",
common.ParamResourceType, common.ParamResourceID, _paramBadgeIDorName),
HandlerFunc: a.Update,
Pattern: fmt.Sprintf("/clusters/:%v/badges/:%v",
common.ParamClusterID, _paramBadgeIDorName),
HandlerFunc: a.UpdateClusterBadge,
},
{
Method: http.MethodDelete,
Expand Down
4 changes: 4 additions & 0 deletions roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Roles:
- clusters/resume
- clusters/containers
- clusters/webhooks
- clusters/badges
verbs:
- "*"
scopes:
Expand Down Expand Up @@ -302,6 +303,7 @@ Roles:
- clusters/accesstokens
- personalaccesstokens
- accesstokens
- clusters/badges
verbs:
- "*"
scopes:
Expand Down Expand Up @@ -457,6 +459,7 @@ Roles:
- clusters/accesstokens
- personalccesstokens
- accesstokens
- clusters/badges
verbs:
- "*"
scopes:
Expand Down Expand Up @@ -514,6 +517,7 @@ Roles:
- applications/accesstokens
- clusters/accesstokens
- personalaccesstokens
- clusters/badges
verbs:
- get
scopes:
Expand Down
1 change: 1 addition & 0 deletions scopes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ roles:
- clusters/step
- clusters/resourcetree
- clusters/upgrade
- clusters/badges
verbs:
- "*"
scopes:
Expand Down

0 comments on commit 868754f

Please sign in to comment.