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

@@ -19,6 +19,7 @@ import {{.authImport}}
type Config struct {
rest.RestConf
{{.auth}}
{{.jwtTrans}}
}
`
@@ -26,6 +27,11 @@ type Config struct {
AccessSecret string
AccessExpire int64
}
`
jwtTransTemplate = ` struct {
Secret string
PrevSecret string
}
`
)
@@ -40,6 +46,12 @@ func genConfig(dir string, cfg *config.Config, api *spec.ApiSpec) error {
for _, item := range authNames {
auths = append(auths, fmt.Sprintf("%s %s", item, jwtTemplate))
}
jwtTransNames := getJwtTrans(api)
var jwtTransList []string
for _, item := range jwtTransNames {
jwtTransList = append(jwtTransList, fmt.Sprintf("%s %s", item, jwtTransTemplate))
}
authImportStr := fmt.Sprintf("\"%s/rest\"", vars.ProjectOpenSourceURL)
return genFile(fileGenConfig{
@@ -53,6 +65,7 @@ func genConfig(dir string, cfg *config.Config, api *spec.ApiSpec) error {
data: map[string]string{
"authImport": authImportStr,
"auth": strings.Join(auths, "\n"),
"jwtTrans": strings.Join(jwtTransList, "\n"),
},
})
}