Skip to content

Commit

Permalink
enhance(mock): add admin key rotation (#1174)
Browse files Browse the repository at this point in the history
* enhance(mock): add admin key rotation

* new files, old rules
  • Loading branch information
ecrupper authored Sep 4, 2024
1 parent 0894432 commit 21dfb44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mock/server/rotate_keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0

package server

import (
"net/http"
"strings"

"github.com/gin-gonic/gin"

"github.com/go-vela/server/router/middleware/auth"
"github.com/go-vela/types"
)

// rotateKeys returns success message. Pass `invalid` to auth header to test 401 error.
func rotateKeys(c *gin.Context) {
tkn, _ := auth.RetrieveAccessToken(c.Request)

if strings.EqualFold(tkn, "invalid") {
data := "unauthorized"
c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &data})

return
}

c.JSON(http.StatusOK, "keys rotated successfully")
}
1 change: 1 addition & 0 deletions mock/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func FakeHandler() http.Handler {
// mock endpoints for oidc calls
e.GET("/_services/token/.well-known/openid-configuration", openIDConfig)
e.GET("/_services/token/.well-known/jwks", getJWKS)
e.POST("/api/v1/admin/rotate_oidc_keys", rotateKeys)

// mock endpoint for queue credentials
e.GET("/api/v1/queue/info", getQueueCreds)
Expand Down

0 comments on commit 21dfb44

Please sign in to comment.