feat: allow production provider bootstrap
This commit is contained in:
@@ -97,7 +97,7 @@ func LoadEnvironment(path string, environment map[string]string) (map[string]str
|
||||
}
|
||||
merged := cloneStrings(environment)
|
||||
for key, value := range file {
|
||||
if _, allowed := fieldIndex[key]; !allowed {
|
||||
if !allowedEnvironmentKey(key) {
|
||||
continue
|
||||
}
|
||||
if _, exists := merged[key]; !exists {
|
||||
@@ -108,14 +108,25 @@ func LoadEnvironment(path string, environment map[string]string) (map[string]str
|
||||
}
|
||||
|
||||
func RuntimeSettingKeys() []string {
|
||||
keys := make([]string, 0, len(fieldIndex))
|
||||
keys := make([]string, 0, len(fieldIndex)+len(runtimeOnlyKeys))
|
||||
for key := range fieldIndex {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
for key := range runtimeOnlyKeys {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func allowedEnvironmentKey(key string) bool {
|
||||
if _, allowed := fieldIndex[key]; allowed {
|
||||
return true
|
||||
}
|
||||
_, allowed := runtimeOnlyKeys[key]
|
||||
return allowed
|
||||
}
|
||||
|
||||
func (s *Service) WithBillingAccountWriter(writer BillingAccountWriter) *Service {
|
||||
s.billing = writer
|
||||
return s
|
||||
@@ -483,3 +494,9 @@ var fieldIndex = func() map[string]Field {
|
||||
result["VIDEO_GENERATE_ENGINE"] = Field{Key: "VIDEO_GENERATE_ENGINE", Label: "视频生成", Type: "select", DefaultValue: "bailian", Options: []Option{{Label: "Seedance", Value: "seedance"}, {Label: "阿里云百炼 Wan 2.7", Value: "bailian"}}}
|
||||
return result
|
||||
}()
|
||||
|
||||
// runtimeOnlyKeys are read from the process/settings file by the Go startup
|
||||
// loader but are intentionally not exposed as editable settings-panel fields.
|
||||
var runtimeOnlyKeys = map[string]struct{}{
|
||||
"ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS": {},
|
||||
}
|
||||
|
||||
@@ -100,6 +100,23 @@ func TestServiceGetUsesInjectedEnvironmentWithoutMutatingProcess(t *testing.T) {
|
||||
assertSecretProjection(t, value, "SEEDANCE_API_KEY", true)
|
||||
}
|
||||
|
||||
func TestLoadEnvironmentAllowsBootstrapRuntimeFlagButIgnoresUnknownKeys(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), ".env.local")
|
||||
if err := os.WriteFile(path, []byte("ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS=true\nUNKNOWN_RUNTIME_FLAG=true\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values, err := LoadEnvironment(path, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if values["ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS"] != "true" {
|
||||
t.Fatalf("bootstrap flag = %q", values["ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS"])
|
||||
}
|
||||
if _, exists := values["UNKNOWN_RUNTIME_FLAG"]; exists {
|
||||
t.Fatal("unknown runtime flag was loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceSynchronizesBillingAccountWithoutRequiringRestart(t *testing.T) {
|
||||
writer := &billingWriterStub{}
|
||||
service := New(filepath.Join(t.TempDir(), ".env.local"), nil, nil).WithBillingAccountWriter(writer)
|
||||
|
||||
Reference in New Issue
Block a user