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