diff --git a/.env.example b/.env.example index 02ebaa3..54d00a3 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # Copy this file to .env and replace the required values. -# Non-empty STICK_* values override values in config.yaml. +# Non-empty STICK_* values override values from earlier configuration providers. # The callback URL for the OIDC client is /auth/callback. # Required application settings. A filesystem path selects SQLite; @@ -44,3 +44,13 @@ STICK_AUTH_SESSION_SECRET=replace-with-at-least-32-random-bytes # STICK_NOTIFICATIONS_SMTP_FROM=noreply@example.com # STICK_NOTIFICATIONS_SMTP_SUBJECT={{.StickName}} is available # STICK_NOTIFICATIONS_SMTP_BODY=The stick you were waiting for just dropped. + +# Optional Azure App Configuration source. This is bootstrap configuration and +# is not read from the application YAML file. Use a managed identity or Azure +# Workload Identity in deployments; do not put a client secret here. +# STICK_CONFIG_PROVIDERS=azure-app-config,environment +# STICK_AZURE_APPCONFIG_ENDPOINT=https://stick-prod.azconfig.io +# STICK_AZURE_APPCONFIG_LABEL=production +# STICK_AZURE_APPCONFIG_KEY_PREFIX=stick/ +# STICK_AZURE_APPCONFIG_KEY_FILTER=stick/* +# STICK_AZURE_APPCONFIG_SEPARATOR=/ diff --git a/README.md b/README.md index 807565a..c161240 100644 --- a/README.md +++ b/README.md @@ -80,11 +80,46 @@ install -d -m 0700 local-data STICK_DATABASE="$PWD/local-data/stick.db" ./stickd -config config.yaml ``` -- Configuration can be provided in YAML, environment variables, or both. -- Non-empty `STICK_*` variables override YAML values. +- Configuration can be provided in YAML, environment variables, Azure App + Configuration, or a combination of providers. +- Non-empty `STICK_*` variables override values from earlier providers. See `.env.example` and `example.config.yaml` for the available settings. +### Azure App Configuration + +Stick can also load configuration from Azure App Configuration. Select it with +the bootstrap setting below; `environment` remains last so ordinary `STICK_*` +overrides retain precedence: + +```sh +STICK_CONFIG_PROVIDERS=azure-app-config,environment +STICK_AZURE_APPCONFIG_ENDPOINT=https://stick-prod.azconfig.io +STICK_AZURE_APPCONFIG_LABEL=production +STICK_AZURE_APPCONFIG_KEY_PREFIX=stick/ +STICK_AZURE_APPCONFIG_SEPARATOR=/ +``` + +When Azure is the only structured source, omit `-config`; when combining it +with a file, use `STICK_CONFIG_PROVIDERS=yaml,azure-app-config,environment`. + +Use slash-separated keys such as `stick/database`, +`stick/server/public_url`, and `stick/auth/oidc/issuer`. Notification lists +should be stored as JSON values with the `application/json` content type. +The hierarchy separator is configurable (supported values include `/`, `.`, +`:` and `__`) and defaults to `/`. +Empty labels select unlabeled settings. Azure App Configuration Key Vault +references are resolved automatically when the identity can read the referenced +secrets. + +Authentication uses Azure's default credential chain. In production, prefer a +managed identity or workload identity and grant it the **App Configuration Data +Reader** role (and **Key Vault Secrets User** when Key Vault references are +used). No Azure credentials are stored in the Stick configuration. + +The provider loads a snapshot during startup. Configuration changes require a +Stick restart. + If you use MongoDB, it must be deployed as a replica set because Stick uses multi-document transactions. ## Development diff --git a/cmd/stickd/main.go b/cmd/stickd/main.go index a92630f..f0101b3 100644 --- a/cmd/stickd/main.go +++ b/cmd/stickd/main.go @@ -9,6 +9,7 @@ import ( "log/slog" "os" "os/signal" + "strings" "syscall" "time" _ "time/tzdata" @@ -46,6 +47,7 @@ func mainContext(parent context.Context, args []string) (err error) { flags := flag.NewFlagSet("stickd", flag.ContinueOnError) flags.SetOutput(os.Stderr) configPath := flags.String("config", "", "path to config YAML file (default: config.yaml in working directory)") + configProviders := flags.String("config-providers", "", "comma-separated configuration providers (default: yaml,environment)") if err := flags.Parse(args); err != nil { return err } @@ -53,10 +55,11 @@ func mainContext(parent context.Context, args []string) (err error) { return fmt.Errorf("unexpected positional arguments: %v", flags.Args()) } - cfg, err := config.Load(parent, - config.YAMLProvider{Path: *configPath}, - config.EnvironmentProvider{}, - ) + providers, err := buildConfigProviders(*configPath, *configProviders) + if err != nil { + return fmt.Errorf("config: %w", err) + } + cfg, err := config.Load(parent, providers...) if err != nil { return fmt.Errorf("config: %w", err) } @@ -107,6 +110,48 @@ func mainContext(parent context.Context, args []string) (err error) { return application.Run(shutdown, components...) } +const defaultConfigProviders = "yaml,environment" + +func buildConfigProviders(configPath, selection string) ([]config.Provider, error) { + selection = strings.TrimSpace(selection) + if selection == "" { + selection = strings.TrimSpace(os.Getenv("STICK_CONFIG_PROVIDERS")) + } + if selection == "" { + selection = defaultConfigProviders + } + + var providers []config.Provider + hasYAML := false + for _, name := range strings.Split(selection, ",") { + name = strings.ToLower(strings.TrimSpace(name)) + if name == "" { + return nil, fmt.Errorf("configuration provider list contains an empty provider name") + } + switch name { + case "yaml": + hasYAML = true + providers = append(providers, config.YAMLProvider{Path: configPath}) + case "environment": + providers = append(providers, config.EnvironmentProvider{}) + case "azure-app-config": + providers = append(providers, config.AzureAppConfigurationProvider{ + Endpoint: os.Getenv("STICK_AZURE_APPCONFIG_ENDPOINT"), + Label: os.Getenv("STICK_AZURE_APPCONFIG_LABEL"), + KeyPrefix: os.Getenv("STICK_AZURE_APPCONFIG_KEY_PREFIX"), + KeyFilter: os.Getenv("STICK_AZURE_APPCONFIG_KEY_FILTER"), + Separator: os.Getenv("STICK_AZURE_APPCONFIG_SEPARATOR"), + }) + default: + return nil, fmt.Errorf("unknown configuration provider %q", name) + } + } + if configPath != "" && !hasYAML { + return nil, fmt.Errorf("-config requires the yaml configuration provider") + } + return providers, nil +} + type backend interface { application.Store outbox.Store diff --git a/cmd/stickd/main_test.go b/cmd/stickd/main_test.go index 9b9700a..edfc615 100644 --- a/cmd/stickd/main_test.go +++ b/cmd/stickd/main_test.go @@ -61,6 +61,75 @@ func TestMainContextLogsBuildMetadata(t *testing.T) { } } +func TestBuildConfigProvidersDefaultsToYAMLThenEnvironment(t *testing.T) { + t.Setenv("STICK_CONFIG_PROVIDERS", "") + providers, err := buildConfigProviders("", "") + if err != nil { + t.Fatalf("buildConfigProviders: %v", err) + } + if len(providers) != 2 { + t.Fatalf("providers = %d, want 2", len(providers)) + } + if _, ok := providers[0].(config.YAMLProvider); !ok { + t.Errorf("providers[0] = %T, want YAMLProvider", providers[0]) + } + if _, ok := providers[1].(config.EnvironmentProvider); !ok { + t.Errorf("providers[1] = %T, want EnvironmentProvider", providers[1]) + } +} + +func TestBuildConfigProvidersReadsSelectionFromEnvironment(t *testing.T) { + t.Setenv("STICK_CONFIG_PROVIDERS", "environment, azure-app-config") + t.Setenv("STICK_AZURE_APPCONFIG_ENDPOINT", "https://stick.azconfig.io") + t.Setenv("STICK_AZURE_APPCONFIG_SEPARATOR", ".") + providers, err := buildConfigProviders("", "") + if err != nil { + t.Fatalf("buildConfigProviders: %v", err) + } + if len(providers) != 2 { + t.Fatalf("providers = %d, want 2", len(providers)) + } + if _, ok := providers[0].(config.EnvironmentProvider); !ok { + t.Errorf("providers[0] = %T, want EnvironmentProvider", providers[0]) + } + azure, ok := providers[1].(config.AzureAppConfigurationProvider) + if !ok { + t.Fatalf("providers[1] = %T, want AzureAppConfigurationProvider", providers[1]) + } + if azure.Endpoint != "https://stick.azconfig.io" { + t.Errorf("Azure endpoint = %q", azure.Endpoint) + } + if azure.Separator != "." { + t.Errorf("Azure separator = %q", azure.Separator) + } +} + +func TestBuildConfigProvidersCLISelectionOverridesEnvironment(t *testing.T) { + t.Setenv("STICK_CONFIG_PROVIDERS", "azure-app-config") + providers, err := buildConfigProviders("", "environment") + if err != nil { + t.Fatalf("buildConfigProviders: %v", err) + } + if len(providers) != 1 { + t.Fatalf("providers = %d, want 1", len(providers)) + } + if _, ok := providers[0].(config.EnvironmentProvider); !ok { + t.Errorf("provider = %T, want EnvironmentProvider", providers[0]) + } +} + +func TestBuildConfigProvidersRequiresYAMLForExplicitConfigPath(t *testing.T) { + if _, err := buildConfigProviders("/etc/stick/config.yaml", "environment"); err == nil || !strings.Contains(err.Error(), "requires the yaml") { + t.Fatalf("buildConfigProviders error = %v", err) + } +} + +func TestBuildConfigProvidersRejectsUnknownProvider(t *testing.T) { + if _, err := buildConfigProviders("", "unknown"); err == nil || !strings.Contains(err.Error(), "unknown configuration provider") { + t.Fatalf("buildConfigProviders error = %v", err) + } +} + func setMinimalRuntimeEnv(t *testing.T, databasePath string) { t.Helper() t.Setenv("STICK_DATABASE", databasePath) diff --git a/example.config.yaml b/example.config.yaml index 0e9d9c0..83937b6 100644 --- a/example.config.yaml +++ b/example.config.yaml @@ -1,6 +1,7 @@ # Stick configuration # Copy this file to config.yaml and replace the required values. -# Non-empty STICK_* environment variables override values in this file. +# Non-empty STICK_* environment variables override values from earlier +# providers. The provider chain itself is selected with STICK_CONFIG_PROVIDERS. # The OIDC callback URL is /auth/callback. # Required: a filesystem path selects SQLite; a postgres://, postgresql://, @@ -35,7 +36,9 @@ auth: # Timezone for displaying notification timestamps (default: UTC). # timezone: Europe/London -# Notifications are optional. Configure any combination of backends. +# Notifications are optional. Configure any combination of backends. When using +# Azure App Configuration, list values should use the application/json content +# type (for example, notifications/webhook). # Webhook URLs must use HTTPS except for loopback addresses used locally. # Each backend can be a mapping for one instance or a list for multiple # instances of the same type. diff --git a/go.mod b/go.mod index 9f75b4d..79f497e 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,10 @@ module stick go 1.27.0 require ( + github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration v1.6.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 + github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.1.0 github.com/coreos/go-oidc/v3 v3.17.0 github.com/golang-jwt/jwt/v5 v5.3.1 github.com/jackc/pgx/v5 v5.10.0 @@ -16,7 +20,11 @@ require ( require ( dario.cat/mergo v1.0.2 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect + github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -36,12 +44,14 @@ require ( github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect + github.com/go-viper/mapstructure/v2 v2.5.0 // indirect github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/klauspost/compress v1.18.7 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e // indirect github.com/magiconair/properties v1.8.10 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -58,6 +68,7 @@ require ( github.com/ncruces/go-strftime v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.1 // indirect + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect @@ -79,6 +90,7 @@ require ( go.opentelemetry.io/otel/metric v1.44.0 // indirect go.opentelemetry.io/otel/trace v1.44.0 // indirect golang.org/x/crypto v0.56.0 // indirect + golang.org/x/net v0.57.0 // indirect golang.org/x/sync v0.22.0 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.41.0 // indirect diff --git a/go.sum b/go.sum index 24bb65b..6e54fa8 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,28 @@ dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= +github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration v1.6.0 h1:YR+6EBZ9yKZ7l9FmLzy+bcC+oUqmmQMDvy6uQTEWkNs= +github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration v1.6.0/go.mod h1:XrGqoOZ3f2KHUMHkxDB6M3h3erhY4mTYzWjsfVrd0c4= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0 h1:fou+2+WFTib47nS+nz/ozhEBnvU96bKHy6LjRsY4E28= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.0/go.mod h1:t76Ruy8AHvUAC8GfMWJMa0ElSbuIcO03NLpynfbgsPA= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 h1:Hk5QBxZQC1jb2Fwj6mpzme37xbCDdNTxU7O9eb5+LB4= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1/go.mod h1:IYus9qsFobWIc2YVwe/WPjcnyCkPKtnHAqUYeebc8z0= +github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY= +github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2/go.mod h1:Pa9ZNPuoNu/GztvBSKk9J1cDJW6vk/n0zLtV4mgd8N8= +github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.1.0 h1:TqbKKfxsORacS569SMzCJ+Y5hgddH/g/iNOPCcUxhp4= +github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.1.0/go.mod h1:oUPt1BeYoggGh+4rhsg84+bcEsvdqPOrf9XC3BKZKKQ= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 h1:9iefClla7iYpfYWdzPCRDozdmndjTm8DXdpCzPajMgA= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2/go.mod h1:XtLgD3ZD34DAaVIIAyG3objl5DynM3CQ/vMcbBNJZGI= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0 h1:/g8S6wk65vfC6m3FIxJ+i5QDyN9JWwXI8Hb0Img10hU= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0/go.mod h1:gpl+q95AzZlKVI3xSoseF9QPrypk0hQqBiJYeB/cR/I= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 h1:nCYfgcSyHZXJI8J0IWE5MsCGlb2xp9fJiXyxWgmOFg4= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0/go.mod h1:ucUjca2JtSZboY8IoUqyQyuuXvwbMBVwFOm0vdQPNhA= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM= +github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE= +github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 h1:XRzhVemXdgvJqCH0sFfrBUTnUJSBrBf7++ypk+twtRs= +github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0/go.mod h1:HKpQxkWaGLJ+D/5H8QRpyQXA1eKjxkFlOMwck5+33Jk= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= @@ -49,6 +69,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= +github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= +github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= @@ -69,12 +91,16 @@ github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0= github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU= +github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXwkPPMeUgOK1k= github.com/klauspost/compress v1.18.7 h1:aUyZsS4kH3QTKurYhAOwAHxllVPnOthb3vPfnF1Ehjw= github.com/klauspost/compress v1.18.7/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e h1:Q6MvJtQK/iRcRtzAscm/zF23XxJlbECiGPyRicsX+Ak= @@ -111,6 +137,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= @@ -171,8 +199,6 @@ go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/ go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= -golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -181,6 +207,8 @@ golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= +golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/internal/config/azure_app_configuration_provider.go b/internal/config/azure_app_configuration_provider.go new file mode 100644 index 0000000..074a0c0 --- /dev/null +++ b/internal/config/azure_app_configuration_provider.go @@ -0,0 +1,160 @@ +package config + +import ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" +) + +// AzureAppConfigurationProvider loads settings from Azure App Configuration +// using an Azure Identity credential. Settings are selected by KeyPrefix (or +// KeyFilter) and Label, then applied to the accumulated configuration. +// +// Azure App Configuration keys use slash-separated paths such as +// "stick/server/public_url". A KeyPrefix, when configured, is removed before +// the path is interpreted. The default label selects unlabeled settings. +// Notification settings should be stored as JSON values with the appropriate +// JSON content type, for example under "stick/notifications/webhook". +// Separator controls how hierarchical keys are constructed. It defaults to +// "/" to match the examples above. +// +// When Credential is nil, Apply uses azidentity.DefaultAzureCredential. This +// supports managed identity and workload identity without putting credentials +// in application configuration. Key Vault references are resolved using the +// same credential. +type AzureAppConfigurationProvider struct { + Endpoint string + Label string + KeyPrefix string + KeyFilter string + Separator string + Credential azcore.TokenCredential + Options *azureappconfiguration.Options +} + +// Apply loads the selected Azure App Configuration settings and applies them +// atomically to the accumulated configuration. +func (p AzureAppConfigurationProvider) Apply(ctx context.Context, config *Config) error { + endpoint, err := validateAzureAppConfigurationEndpoint(p.Endpoint) + if err != nil { + return err + } + if err := ctx.Err(); err != nil { + return err + } + + credential := p.Credential + if credential == nil { + credential, err = azidentity.NewDefaultAzureCredential(nil) + if err != nil { + return fmt.Errorf("creating Azure credential: %w", err) + } + } + + separator, err := normalizeAzureAppConfigurationSeparator(p.Separator) + if err != nil { + return err + } + options := azureAppConfigurationOptions(p.Options, p.KeyPrefix, p.KeyFilter, p.Label, separator, credential) + loaded, err := azureappconfiguration.Load(ctx, azureappconfiguration.AuthenticationOptions{ + Endpoint: endpoint, + Credential: credential, + }, options) + if err != nil { + return fmt.Errorf("loading Azure App Configuration: %w", err) + } + + data, err := loaded.GetBytes(&azureappconfiguration.ConstructionOptions{Separator: separator}) + if err != nil { + return fmt.Errorf("constructing Azure App Configuration values: %w", err) + } + source, err := decodeYAMLConfig(data) + if err != nil { + return fmt.Errorf("parsing Azure App Configuration values: %w", err) + } + + updated := *config + if err := applyYAMLConfig(source, &updated); err != nil { + return fmt.Errorf("applying Azure App Configuration values: %w", err) + } + *config = updated + return nil +} + +func validateAzureAppConfigurationEndpoint(value string) (string, error) { + endpoint := strings.TrimRight(strings.TrimSpace(value), "/") + parsed, err := url.Parse(endpoint) + if err != nil || parsed.Scheme != "https" || parsed.Hostname() == "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" { + return "", fmt.Errorf("invalid Azure App Configuration endpoint: HTTPS URL without credentials, query, or fragment is required") + } + if parsed.Path != "" && parsed.Path != "/" { + return "", fmt.Errorf("invalid Azure App Configuration endpoint: URL path is not supported") + } + return endpoint, nil +} + +func azureAppConfigurationOptions( + base *azureappconfiguration.Options, + keyPrefix, keyFilter, label, separator string, + credential azcore.TokenCredential, +) *azureappconfiguration.Options { + options := azureappconfiguration.Options{} + if base != nil { + options = *base + options.TrimKeyPrefixes = append([]string(nil), base.TrimKeyPrefixes...) + options.Selectors = append([]azureappconfiguration.Selector(nil), base.Selectors...) + } + + keyPrefix = normalizeAzureAppConfigurationPrefix(keyPrefix, separator) + keyFilter = strings.TrimSpace(keyFilter) + if keyFilter == "" { + keyFilter = keyPrefix + "*" + } + label = strings.TrimSpace(label) + options.Selectors = []azureappconfiguration.Selector{{ + KeyFilter: keyFilter, + LabelFilter: label, + }} + if keyPrefix != "" { + options.TrimKeyPrefixes = []string{keyPrefix} + } + + // A single identity can authenticate to both App Configuration and Key + // Vault. Preserve custom Key Vault authentication or a custom resolver, + // while making the normal workload-identity path work out of the box. + if options.KeyVaultOptions.Credential == nil { + options.KeyVaultOptions.Credential = credential + } + return &options +} + +const azureAppConfigurationDefaultSeparator = "/" + +func normalizeAzureAppConfigurationSeparator(value string) (string, error) { + separator := strings.TrimSpace(value) + if separator == "" { + return azureAppConfigurationDefaultSeparator, nil + } + switch separator { + case ".", ",", ";", "-", "_", "__", "/", ":": + return separator, nil + default: + return "", fmt.Errorf("invalid Azure App Configuration hierarchy separator %q", separator) + } +} + +func normalizeAzureAppConfigurationPrefix(value, separator string) string { + prefix := strings.TrimSpace(value) + if prefix == "" { + return "" + } + if !strings.HasSuffix(prefix, separator) { + prefix += separator + } + return prefix +} diff --git a/internal/config/azure_app_configuration_provider_test.go b/internal/config/azure_app_configuration_provider_test.go new file mode 100644 index 0000000..9248d16 --- /dev/null +++ b/internal/config/azure_app_configuration_provider_test.go @@ -0,0 +1,261 @@ +package config + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2" +) + +const azureTestSecret = "0123456789abcdef0123456789abcdef" + +type testAzureCredential struct{} + +func (testAzureCredential) GetToken(context.Context, policy.TokenRequestOptions) (azcore.AccessToken, error) { + return azcore.AccessToken{Token: "test-token", ExpiresOn: time.Now().Add(time.Hour)}, nil +} + +type testAzureTransport struct { + transport http.RoundTripper +} + +func (t testAzureTransport) Do(request *http.Request) (*http.Response, error) { + return t.transport.RoundTrip(request) +} + +func azureTestOptions(transport http.RoundTripper) *azureappconfiguration.Options { + return &azureappconfiguration.Options{ + ReplicaDiscoveryEnabled: boolPointer(false), + ClientOptions: &azappconfig.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Transport: testAzureTransport{transport: transport}, + Retry: policy.RetryOptions{MaxRetries: -1}, + }, + }, + } +} + +func boolPointer(value bool) *bool { + return &value +} + +func TestAzureAppConfigurationProviderLoadsSettings(t *testing.T) { + settings := []map[string]any{ + {"key": "stick/database", "value": "/tmp/azure.db", "label": "production"}, + {"key": "stick/server/public_url", "value": "http://localhost:8080", "label": "production"}, + {"key": "stick/auth/oidc/issuer", "value": "https://issuer.example.com", "label": "production"}, + {"key": "stick/auth/oidc/client_id", "value": "client-id", "label": "production"}, + {"key": "stick/auth/oidc/client_secret", "value": "client-secret", "label": "production"}, + {"key": "stick/auth/session_secret", "value": azureTestSecret, "label": "production"}, + {"key": "stick/auth/admin_emails", "value": `["Alice@example.com","bob@example.com"]`, "label": "production", "content_type": "application/json"}, + {"key": "stick/timezone", "value": "America/New_York", "label": "production"}, + {"key": "stick/notifications/webhook", "value": `[{"url":"https://hooks.example.com/stick"}]`, "label": "production", "content_type": "application/json"}, + } + + var requestSeen bool + server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + requestSeen = true + if r.URL.Path != "/kv" { + t.Errorf("request path = %q, want /kv", r.URL.Path) + } + if got := r.URL.Query().Get("key"); got != "stick/*" { + t.Errorf("key filter = %q, want stick/*", got) + } + if got := r.URL.Query().Get("label"); got != "production" { + t.Errorf("label filter = %q, want production", got) + } + if got := r.Header.Get("Authorization"); got != "Bearer test-token" { + t.Errorf("authorization = %q, want bearer token", got) + } + w.Header().Set("Sync-Token", "id=value;sn=1") + w.Header().Set("Content-Type", "application/vnd.microsoft.appconfig.kvset+json") + _ = json.NewEncoder(w).Encode(map[string]any{"items": settings}) + })) + defer server.Close() + + options := azureTestOptions(server.Client().Transport) + provider := AzureAppConfigurationProvider{ + Endpoint: server.URL, + Label: "production", + KeyPrefix: "stick/", + Credential: testAzureCredential{}, + Options: options, + } + + cfg, err := Load(context.Background(), provider) + if err != nil { + t.Fatalf("Load: %v", err) + } + if !requestSeen { + t.Fatal("provider did not make an HTTP request") + } + if cfg.Database.DSN != "/tmp/azure.db" || cfg.Database.Driver != DatabaseDriverSQLite { + t.Fatalf("database = %+v", cfg.Database) + } + if cfg.Server.PublicURL.String() != "http://localhost:8080" { + t.Errorf("PublicURL = %q", cfg.Server.PublicURL) + } + if got := cfg.Auth.AdminEmails; len(got) != 2 || got[0] != "Alice@example.com" || got[1] != "bob@example.com" { + t.Errorf("AdminEmails = %v", got) + } + if cfg.Timezone.String() != "America/New_York" { + t.Errorf("Timezone = %v", cfg.Timezone) + } + if len(cfg.Notifications.Webhook) != 1 || cfg.Notifications.Webhook[0].URL != "https://hooks.example.com/stick" { + t.Fatalf("Webhook = %+v", cfg.Notifications.Webhook) + } +} + +func TestAzureAppConfigurationProviderUsesDefaultLabelAndFilter(t *testing.T) { + server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if got := r.URL.Query().Get("key"); got != "*" { + t.Errorf("key filter = %q, want *", got) + } + if got := r.URL.Query().Get("label"); got != "\x00" { + t.Errorf("label filter = %q, want no-label filter", got) + } + w.Header().Set("Sync-Token", "id=value;sn=1") + _, _ = w.Write([]byte(`{"items":[]}`)) + })) + defer server.Close() + + provider := AzureAppConfigurationProvider{ + Endpoint: server.URL, + Credential: testAzureCredential{}, + Options: azureTestOptions(server.Client().Transport), + } + if _, err := Load(context.Background(), provider); err == nil || !strings.Contains(err.Error(), "missing required config") { + t.Fatalf("Load error = %v, want missing configuration", err) + } +} + +func TestAzureAppConfigurationProviderSupportsCustomSeparator(t *testing.T) { + settings := []map[string]string{ + {"key": "stick.database", "value": "/tmp/azure-dot.db"}, + {"key": "stick.server.public_url", "value": "http://localhost:8080"}, + {"key": "stick.auth.oidc.issuer", "value": "https://issuer.example.com"}, + {"key": "stick.auth.oidc.client_id", "value": "client-id"}, + {"key": "stick.auth.oidc.client_secret", "value": "client-secret"}, + {"key": "stick.auth.session_secret", "value": azureTestSecret}, + } + server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if got := r.URL.Query().Get("key"); got != "stick.*" { + t.Errorf("key filter = %q, want stick.*", got) + } + w.Header().Set("Sync-Token", "id=value;sn=1") + _ = json.NewEncoder(w).Encode(map[string]any{"items": settings}) + })) + defer server.Close() + + provider := AzureAppConfigurationProvider{ + Endpoint: server.URL, + KeyPrefix: "stick.", + Separator: ".", + Credential: testAzureCredential{}, + Options: azureTestOptions(server.Client().Transport), + } + config, err := Load(context.Background(), provider) + if err != nil { + t.Fatalf("Load: %v", err) + } + if config.Database.DSN != "/tmp/azure-dot.db" || config.Database.Driver != DatabaseDriverSQLite { + t.Fatalf("database = %+v", config.Database) + } +} + +func TestAzureAppConfigurationProviderSupportsEverySeparator(t *testing.T) { + for _, separator := range []string{".", ",", ";", "-", "_", "__", "/", ":"} { + t.Run(separator, func(t *testing.T) { + prefix := "stick" + separator + server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if got, want := r.URL.Query().Get("key"), prefix+"*"; got != want { + t.Errorf("key filter = %q, want %q", got, want) + } + w.Header().Set("Sync-Token", "id=value;sn=1") + _ = json.NewEncoder(w).Encode(map[string]any{"items": []map[string]string{{ + "key": prefix + "database", + "value": "/tmp/azure-" + separator + ".db", + }}}) + })) + defer server.Close() + + provider := AzureAppConfigurationProvider{ + Endpoint: server.URL, + KeyPrefix: "stick", + Separator: separator, + Credential: testAzureCredential{}, + Options: azureTestOptions(server.Client().Transport), + } + var cfg Config + if err := provider.Apply(context.Background(), &cfg); err != nil { + t.Fatalf("Apply: %v", err) + } + if got, want := cfg.Database.DSN, "/tmp/azure-"+separator+".db"; got != want { + t.Errorf("database = %q, want %q", got, want) + } + }) + } +} + +func TestAzureAppConfigurationProviderRejectsInvalidEndpoint(t *testing.T) { + for _, endpoint := range []string{ + "", + "http://appconfig.example.com", + "https://appconfig.example.com?secret=value", + "https://appconfig.example.com/config", + } { + provider := AzureAppConfigurationProvider{ + Endpoint: endpoint, + Credential: testAzureCredential{}, + } + if _, err := Load(context.Background(), provider); err == nil || !strings.Contains(err.Error(), "Azure App Configuration endpoint") { + t.Errorf("endpoint %q error = %v", endpoint, err) + } + } +} + +func TestAzureAppConfigurationProviderRejectsInvalidSeparator(t *testing.T) { + provider := AzureAppConfigurationProvider{ + Endpoint: "https://appconfig.example.com", + Separator: "invalid", + Credential: testAzureCredential{}, + } + if _, err := Load(context.Background(), provider); err == nil || !strings.Contains(err.Error(), "hierarchy separator") { + t.Fatalf("Load error = %v", err) + } +} + +func TestAzureAppConfigurationProviderRejectsUnknownKey(t *testing.T) { + server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Sync-Token", "id=value;sn=1") + _, _ = w.Write([]byte(`{"items":[{"key":"stick/unknown","value":"value"}]}`)) + })) + defer server.Close() + + provider := AzureAppConfigurationProvider{ + Endpoint: server.URL, + KeyPrefix: "stick/", + Credential: testAzureCredential{}, + Options: azureTestOptions(server.Client().Transport), + } + if _, err := Load(context.Background(), provider); err == nil || !strings.Contains(err.Error(), "field unknown not found") { + t.Fatalf("Load error = %v", err) + } +} + +func TestAzureAppConfigurationProviderHonorsContext(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + provider := AzureAppConfigurationProvider{Endpoint: "https://appconfig.example.com"} + if _, err := Load(ctx, provider); err == nil || !strings.Contains(err.Error(), "context canceled") { + t.Fatalf("Load error = %v, want context cancellation", err) + } +} diff --git a/internal/config/yaml_provider.go b/internal/config/yaml_provider.go index fd6edfd..fffbba4 100644 --- a/internal/config/yaml_provider.go +++ b/internal/config/yaml_provider.go @@ -39,57 +39,65 @@ func (p YAMLProvider) Apply(ctx context.Context, config *Config) error { return err } + source, err := decodeYAMLConfig(data) + if err != nil { + return fmt.Errorf("parsing config file %q: %w", filePath, err) + } + + updated := *config + if err := applyYAMLConfig(source, &updated); err != nil { + return err + } + *config = updated + return nil +} + +func decodeYAMLConfig(data []byte) (yamlConfig, error) { source := yamlConfig{} decoder := yaml.NewDecoder(bytes.NewReader(data)) decoder.KnownFields(true) if err := decoder.Decode(&source); err != nil { - return fmt.Errorf("parsing config file %q: %w", filePath, err) + return yamlConfig{}, err } var trailing any if err := decoder.Decode(&trailing); err != io.EOF { if err == nil { err = fmt.Errorf("multiple YAML documents are not supported") } - return fmt.Errorf("parsing config file %q: %w", filePath, err) - } - - updated := *config - if err := applyYAMLConfig(source, &updated); err != nil { - return err + return yamlConfig{}, err } - *config = updated - return nil + return source, nil } type yamlConfig struct { - Server yamlServerConfig `yaml:"server"` - Database *string `yaml:"database"` - Auth yamlAuthConfig `yaml:"auth"` - Timezone *string `yaml:"timezone"` - Notifications yamlNotificationsConfig `yaml:"notifications"` + Server yamlServerConfig `yaml:"server" json:"server"` + Database *string `yaml:"database" json:"database"` + Auth yamlAuthConfig `yaml:"auth" json:"auth"` + Timezone *string `yaml:"timezone" json:"timezone"` + Notifications yamlNotificationsConfig `yaml:"notifications" json:"notifications"` } type yamlServerConfig struct { - PublicURL *string `yaml:"public_url"` - ListenAddr *string `yaml:"listen_addr"` + PublicURL *string `yaml:"public_url" json:"public_url"` + ListenAddr *string `yaml:"listen_addr" json:"listen_addr"` } type yamlAuthConfig struct { - OIDC yamlOIDCConfig `yaml:"oidc"` - SessionSecret *string `yaml:"session_secret"` - AdminEmails *[]string `yaml:"admin_emails"` + OIDC yamlOIDCConfig `yaml:"oidc" json:"oidc"` + SessionSecret *string `yaml:"session_secret" json:"session_secret"` + AdminEmails *[]string `yaml:"admin_emails" json:"admin_emails"` } type yamlOIDCConfig struct { - Issuer *string `yaml:"issuer"` - ClientID *string `yaml:"client_id"` - ClientSecret *string `yaml:"client_secret"` + Issuer *string `yaml:"issuer" json:"issuer"` + ClientID *string `yaml:"client_id" json:"client_id"` + ClientSecret *string `yaml:"client_secret" json:"client_secret"` } type yamlNotificationsConfig struct { - SMTP yamlSMTPConfigs `yaml:"smtp"` - Webhook yamlWebhookConfigs `yaml:"webhook"` - Teams yamlTeamsConfigs `yaml:"teams"` + SMTP yamlSMTPConfigs `yaml:"smtp" json:"smtp"` + Webhook yamlWebhookConfigs `yaml:"webhook" json:"webhook"` + Teams yamlTeamsConfigs `yaml:"teams" json:"teams"` } type yamlSMTPConfigs []*yamlSMTPConfig @@ -97,22 +105,22 @@ type yamlWebhookConfigs []*yamlWebhookConfig type yamlTeamsConfigs []*yamlTeamsConfig type yamlSMTPConfig struct { - Host string `yaml:"host"` - Port int `yaml:"port"` - TLSMode string `yaml:"tls_mode"` - Username string `yaml:"username"` - Password string `yaml:"password"` - From string `yaml:"from"` - Subject string `yaml:"subject"` - Body string `yaml:"body"` + Host string `yaml:"host" json:"host"` + Port int `yaml:"port" json:"port"` + TLSMode string `yaml:"tls_mode" json:"tls_mode"` + Username string `yaml:"username" json:"username"` + Password string `yaml:"password" json:"password"` + From string `yaml:"from" json:"from"` + Subject string `yaml:"subject" json:"subject"` + Body string `yaml:"body" json:"body"` } type yamlWebhookConfig struct { - URL string `yaml:"url"` + URL string `yaml:"url" json:"url"` } type yamlTeamsConfig struct { - URL string `yaml:"url"` + URL string `yaml:"url" json:"url"` } func applyYAMLConfig(source yamlConfig, config *Config) error {