refactor(api): introduce v1 response contract
This commit is contained in:
@@ -9,13 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Env string `yaml:"env"`
|
||||
Port string `yaml:"port"`
|
||||
DSN string `yaml:"dsn"`
|
||||
StorageDir string `yaml:"storage_dir"`
|
||||
AuthSecret string `yaml:"auth_secret"`
|
||||
SystemAIKey string `yaml:"system_ai_key"`
|
||||
AIKeyEncryptionSecret string `yaml:"ai_key_encryption_secret"`
|
||||
Env string `yaml:"env"`
|
||||
Port string `yaml:"port"`
|
||||
DSN string `yaml:"dsn"`
|
||||
StorageDir string `yaml:"storage_dir"`
|
||||
AuthSecret string `yaml:"auth_secret"`
|
||||
SystemAIKey string `yaml:"system_ai_key"`
|
||||
AIKeyEncryptionSecret string `yaml:"ai_key_encryption_secret"`
|
||||
AllowedOrigins []string `yaml:"allowed_origins"`
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
|
||||
@@ -24,6 +24,7 @@ func TestLoadFromDirDefaultsToDevYAML(t *testing.T) {
|
||||
require.Equal(t, "dev-auth", cfg.AuthSecret)
|
||||
require.Equal(t, "dev-system", cfg.SystemAIKey)
|
||||
require.Equal(t, "dev-ai", cfg.AIKeyEncryptionSecret)
|
||||
require.Equal(t, []string{"http://localhost:5173", "http://tauri.localhost"}, cfg.AllowedOrigins)
|
||||
}
|
||||
|
||||
func TestLoadFromDirUsesSENLINAppMode(t *testing.T) {
|
||||
@@ -42,16 +43,22 @@ func TestLoadFromDirUsesSENLINAppMode(t *testing.T) {
|
||||
require.Equal(t, "prod-auth", cfg.AuthSecret)
|
||||
require.Equal(t, "prod-system", cfg.SystemAIKey)
|
||||
require.Equal(t, "prod-ai", cfg.AIKeyEncryptionSecret)
|
||||
require.Equal(t, []string{"https://workbench.example.com"}, cfg.AllowedOrigins)
|
||||
}
|
||||
|
||||
func writeConfig(t *testing.T, dir string, name string, env string, port string, databaseURL string, storageDir string, authSecret string, systemAIKey string, aiKeySecret string) {
|
||||
t.Helper()
|
||||
allowedOrigins := " - http://localhost:5173\n - http://tauri.localhost\n"
|
||||
if env == "production" {
|
||||
allowedOrigins = " - https://workbench.example.com\n"
|
||||
}
|
||||
content := []byte("env: " + env + "\n" +
|
||||
"port: \"" + port + "\"\n" +
|
||||
"dsn: \"" + databaseURL + "\"\n" +
|
||||
"storage_dir: \"" + storageDir + "\"\n" +
|
||||
"auth_secret: \"" + authSecret + "\"\n" +
|
||||
"system_ai_key: \"" + systemAIKey + "\"\n" +
|
||||
"ai_key_encryption_secret: \"" + aiKeySecret + "\"\n")
|
||||
"ai_key_encryption_secret: \"" + aiKeySecret + "\"\n" +
|
||||
"allowed_origins:\n" + allowedOrigins)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, name), content, 0o600))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user