Fix/issue#1289 (#1460)

* fix #1289

* Add unit test case

* fix `jwtTransKey`

* fix `jwtTransKey`

Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
anqiansong
2022-01-18 11:52:30 +08:00
committed by GitHub
parent c903966fc7
commit df0f8ed59e
4 changed files with 35 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import (
)
const (
jwtTransKey = "jwtTransition"
routesFilename = "routes"
routesTemplate = `// Code generated by goctl. DO NOT EDIT.
package handler
@@ -58,6 +59,7 @@ type (
authName string
middlewares []string
prefix string
jwtTrans string
}
route struct {
method string
@@ -96,6 +98,9 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
if g.jwtEnabled {
jwt = fmt.Sprintf("\n rest.WithJwt(serverCtx.Config.%s.AccessSecret),", g.authName)
}
if len(g.jwtTrans) > 0 {
jwt = jwt + fmt.Sprintf("\n rest.WithJwtTransition(serverCtx.Config.%s.PrevSecret,serverCtx.Config.%s.Secret),", g.jwtTrans, g.jwtTrans)
}
var signature, prefix string
if g.signatureEnabled {
signature = "\n rest.WithSignature(serverCtx.Config.Signature),"
@@ -205,6 +210,11 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
groupedRoutes.authName = jwt
groupedRoutes.jwtEnabled = true
}
jwtTrans := g.GetAnnotation(jwtTransKey)
if len(jwtTrans) > 0 {
groupedRoutes.jwtTrans = jwtTrans
}
signature := g.GetAnnotation("signature")
if signature == "true" {
groupedRoutes.signatureEnabled = true