fix: potential use of mismatched tokens (#1092)

Co-authored-by: Kent Dong <ch3cho@qq.com>
This commit is contained in:
pepesi
2024-08-26 15:40:55 +08:00
committed by GitHub
parent 496346fe95
commit f5b8341f7f
2 changed files with 16 additions and 6 deletions

View File

@@ -290,6 +290,15 @@ func (c *ProviderConfig) Validate() error {
return nil
}
func (c *ProviderConfig) GetOrSetTokenWithContext(ctx wrapper.HttpContext) string {
ctxApiKey := ctx.GetContext(ctxKeyApiName)
if ctxApiKey == nil {
ctxApiKey = c.GetRandomToken()
ctx.SetContext(ctxKeyApiName, ctxApiKey)
}
return ctxApiKey.(string)
}
func (c *ProviderConfig) GetRandomToken() string {
apiTokens := c.apiTokens
count := len(apiTokens)