mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 21:10:51 +08:00
fix(amp): update explicit API key on config change
This commit is contained in:
@@ -190,6 +190,7 @@ func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error {
|
|||||||
// If API key changed, invalidate the cache
|
// If API key changed, invalidate the cache
|
||||||
if m.secretSource != nil {
|
if m.secretSource != nil {
|
||||||
if ms, ok := m.secretSource.(*MultiSourceSecret); ok {
|
if ms, ok := m.secretSource.(*MultiSourceSecret); ok {
|
||||||
|
ms.UpdateExplicitKey(settings.UpstreamAPIKey)
|
||||||
ms.InvalidateCache()
|
ms.InvalidateCache()
|
||||||
log.Debug("amp secret cache invalidated due to config update")
|
log.Debug("amp secret cache invalidated due to config update")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,17 @@ func (s *MultiSourceSecret) InvalidateCache() {
|
|||||||
s.cache = nil
|
s.cache = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateExplicitKey refreshes the config-provided key and clears cache.
|
||||||
|
func (s *MultiSourceSecret) UpdateExplicitKey(key string) {
|
||||||
|
if s == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.mu.Lock()
|
||||||
|
s.explicitKey = strings.TrimSpace(key)
|
||||||
|
s.cache = nil
|
||||||
|
s.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// StaticSecretSource returns a fixed API key (for testing)
|
// StaticSecretSource returns a fixed API key (for testing)
|
||||||
type StaticSecretSource struct {
|
type StaticSecretSource struct {
|
||||||
key string
|
key string
|
||||||
|
|||||||
Reference in New Issue
Block a user