fix: fallback workbench admin secret
This commit is contained in:
@@ -47,13 +47,14 @@ func DefaultClient(ctx context.Context) *Client {
|
||||
if timeout <= 0 {
|
||||
timeout = 5 * time.Second
|
||||
}
|
||||
secret := g.Cfg().MustGet(ctx, "imWorkbenchApi.serviceSecret").String()
|
||||
if strings.HasPrefix(secret, "${") && strings.HasSuffix(secret, "}") {
|
||||
secret = os.Getenv(strings.TrimSuffix(strings.TrimPrefix(secret, "${"), "}"))
|
||||
}
|
||||
if secret == "" {
|
||||
secret = os.Getenv("IM_WORKBENCH_API_SECRET")
|
||||
}
|
||||
secret := firstSecret(
|
||||
g.Cfg().MustGet(ctx, "imWorkbenchApi.serviceSecret").String(),
|
||||
os.Getenv("IM_WORKBENCH_API_SECRET"),
|
||||
g.Cfg().MustGet(ctx, "imInternalApi.serviceSecret").String(),
|
||||
os.Getenv("IM_INTERNAL_API_SECRET"),
|
||||
g.Cfg().MustGet(ctx, "imAdminApi.serviceSecret").String(),
|
||||
os.Getenv("IM_ADMIN_API_SECRET"),
|
||||
)
|
||||
conf := Config{
|
||||
BaseURL: g.Cfg().MustGet(ctx, "imWorkbenchApi.baseUrl").String(),
|
||||
ServiceName: g.Cfg().MustGet(ctx, "imWorkbenchApi.serviceName", "hotgo-admin").String(),
|
||||
@@ -180,3 +181,19 @@ func randomNonce() (string, error) {
|
||||
}
|
||||
return hex.EncodeToString(b[:]), nil
|
||||
}
|
||||
|
||||
func firstSecret(values ...string) string {
|
||||
for _, value := range values {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(value, "${") && strings.HasSuffix(value, "}") {
|
||||
value = strings.TrimSpace(os.Getenv(strings.TrimSuffix(strings.TrimPrefix(value, "${"), "}")))
|
||||
}
|
||||
if value != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user