diff --git a/cmd/gotosocial/action/debug/config/config.go b/cmd/gotosocial/action/debug/config/config.go index 6c697cbff..24f15e79f 100644 --- a/cmd/gotosocial/action/debug/config/config.go +++ b/cmd/gotosocial/action/debug/config/config.go @@ -21,7 +21,7 @@ package config import ( "context" "encoding/json" - "fmt" + "os" "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -39,13 +39,8 @@ var Config action.GTSAction = func(ctx context.Context) (err error) { return err } - // Marshal map to JSON - b, err := json.Marshal(raw) - if err != nil { - return err - } - - // Print to stdout - fmt.Printf("%s\n", b) - return nil + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + err = enc.Encode(raw) + return err } diff --git a/test/envparsing.sh b/test/envparsing.sh index 85099cb21..8d795b6b3 100755 --- a/test/envparsing.sh +++ b/test/envparsing.sh @@ -2,7 +2,148 @@ set -eu -EXPECT='{"account-domain":"peepee","accounts-allow-custom-css":true,"accounts-approval-required":false,"accounts-reason-required":false,"accounts-registration-open":true,"advanced-cookies-samesite":"strict","advanced-rate-limit-requests":6969,"advanced-throttling-multiplier":-1,"advanced-throttling-retry-after":10000000000,"application-name":"gts","bind-address":"127.0.0.1","cache":{"gts":{"account-max-size":99,"account-sweep-freq":1000000000,"account-ttl":10800000000000,"block-max-size":100,"block-sweep-freq":30000000000,"block-ttl":300000000000,"domain-block-max-size":1000,"domain-block-sweep-freq":60000000000,"domain-block-ttl":86400000000000,"emoji-category-max-size":100,"emoji-category-sweep-freq":30000000000,"emoji-category-ttl":300000000000,"emoji-max-size":500,"emoji-sweep-freq":30000000000,"emoji-ttl":300000000000,"media-max-size":500,"media-sweep-freq":30000000000,"media-ttl":300000000000,"mention-max-size":500,"mention-sweep-freq":30000000000,"mention-ttl":300000000000,"notification-max-size":500,"notification-sweep-freq":30000000000,"notification-ttl":300000000000,"report-max-size":100,"report-sweep-freq":30000000000,"report-ttl":300000000000,"status-max-size":500,"status-sweep-freq":30000000000,"status-ttl":300000000000,"tombstone-max-size":100,"tombstone-sweep-freq":30000000000,"tombstone-ttl":300000000000,"user-max-size":100,"user-sweep-freq":30000000000,"user-ttl":300000000000}},"config-path":"internal/config/testdata/test.yaml","db-address":":memory:","db-database":"gotosocial_prod","db-max-open-conns-multiplier":3,"db-password":"hunter2","db-port":6969,"db-sqlite-busy-timeout":1000000000,"db-sqlite-cache-size":0,"db-sqlite-journal-mode":"DELETE","db-sqlite-synchronous":"FULL","db-tls-ca-cert":"","db-tls-mode":"disable","db-type":"sqlite","db-user":"sex-haver","dry-run":true,"email":"","host":"example.com","instance-deliver-to-shared-inboxes":false,"instance-expose-peers":true,"instance-expose-public-timeline":true,"instance-expose-suspended":true,"instance-expose-suspended-web":true,"landing-page-user":"admin","letsencrypt-cert-dir":"/gotosocial/storage/certs","letsencrypt-email-address":"","letsencrypt-enabled":true,"letsencrypt-port":80,"log-db-queries":true,"log-level":"info","media-description-max-chars":5000,"media-description-min-chars":69,"media-emoji-local-max-size":420,"media-emoji-remote-max-size":420,"media-image-max-size":420,"media-remote-cache-days":30,"media-video-max-size":420,"oidc-admin-groups":["steamy"],"oidc-client-id":"1234","oidc-client-secret":"shhhh its a secret","oidc-enabled":true,"oidc-idp-name":"sex-haver","oidc-issuer":"whoknows","oidc-link-existing":true,"oidc-scopes":["read","write"],"oidc-skip-verification":true,"password":"","path":"","port":6969,"protocol":"http","request-id-header":"X-Trace-Id","smtp-from":"queen.rip.in.piss@terfisland.org","smtp-host":"example.com","smtp-password":"hunter2","smtp-port":4269,"smtp-username":"sex-haver","software-version":"","statuses-cw-max-chars":420,"statuses-max-chars":69,"statuses-media-max-files":1,"statuses-poll-max-options":1,"statuses-poll-option-max-chars":50,"storage-backend":"local","storage-local-base-path":"/root/store","storage-s3-access-key":"minio","storage-s3-bucket":"gts","storage-s3-endpoint":"localhost:9000","storage-s3-proxy":true,"storage-s3-secret-key":"miniostorage","storage-s3-use-ssl":false,"syslog-address":"127.0.0.1:6969","syslog-enabled":true,"syslog-protocol":"udp","tls-certificate-chain":"","tls-certificate-key":"","trusted-proxies":["127.0.0.1/32","docker.host.local"],"username":"","web-asset-base-dir":"/root","web-template-base-dir":"/root"}' +EXPECT=$(cat <<"EOF" +{ + "account-domain": "peepee", + "accounts-allow-custom-css": true, + "accounts-approval-required": false, + "accounts-reason-required": false, + "accounts-registration-open": true, + "advanced-cookies-samesite": "strict", + "advanced-rate-limit-requests": 6969, + "advanced-throttling-multiplier": -1, + "advanced-throttling-retry-after": 10000000000, + "application-name": "gts", + "bind-address": "127.0.0.1", + "cache": { + "gts": { + "account-max-size": 99, + "account-sweep-freq": 1000000000, + "account-ttl": 10800000000000, + "block-max-size": 100, + "block-sweep-freq": 30000000000, + "block-ttl": 300000000000, + "domain-block-max-size": 1000, + "domain-block-sweep-freq": 60000000000, + "domain-block-ttl": 86400000000000, + "emoji-category-max-size": 100, + "emoji-category-sweep-freq": 30000000000, + "emoji-category-ttl": 300000000000, + "emoji-max-size": 500, + "emoji-sweep-freq": 30000000000, + "emoji-ttl": 300000000000, + "media-max-size": 500, + "media-sweep-freq": 30000000000, + "media-ttl": 300000000000, + "mention-max-size": 500, + "mention-sweep-freq": 30000000000, + "mention-ttl": 300000000000, + "notification-max-size": 500, + "notification-sweep-freq": 30000000000, + "notification-ttl": 300000000000, + "report-max-size": 100, + "report-sweep-freq": 30000000000, + "report-ttl": 300000000000, + "status-max-size": 500, + "status-sweep-freq": 30000000000, + "status-ttl": 300000000000, + "tombstone-max-size": 100, + "tombstone-sweep-freq": 30000000000, + "tombstone-ttl": 300000000000, + "user-max-size": 100, + "user-sweep-freq": 30000000000, + "user-ttl": 300000000000 + } + }, + "config-path": "internal/config/testdata/test.yaml", + "db-address": ":memory:", + "db-database": "gotosocial_prod", + "db-max-open-conns-multiplier": 3, + "db-password": "hunter2", + "db-port": 6969, + "db-sqlite-busy-timeout": 1000000000, + "db-sqlite-cache-size": 0, + "db-sqlite-journal-mode": "DELETE", + "db-sqlite-synchronous": "FULL", + "db-tls-ca-cert": "", + "db-tls-mode": "disable", + "db-type": "sqlite", + "db-user": "sex-haver", + "dry-run": true, + "email": "", + "host": "example.com", + "instance-deliver-to-shared-inboxes": false, + "instance-expose-peers": true, + "instance-expose-public-timeline": true, + "instance-expose-suspended": true, + "instance-expose-suspended-web": true, + "landing-page-user": "admin", + "letsencrypt-cert-dir": "/gotosocial/storage/certs", + "letsencrypt-email-address": "", + "letsencrypt-enabled": true, + "letsencrypt-port": 80, + "log-db-queries": true, + "log-level": "info", + "media-description-max-chars": 5000, + "media-description-min-chars": 69, + "media-emoji-local-max-size": 420, + "media-emoji-remote-max-size": 420, + "media-image-max-size": 420, + "media-remote-cache-days": 30, + "media-video-max-size": 420, + "oidc-admin-groups": [ + "steamy" + ], + "oidc-client-id": "1234", + "oidc-client-secret": "shhhh its a secret", + "oidc-enabled": true, + "oidc-idp-name": "sex-haver", + "oidc-issuer": "whoknows", + "oidc-link-existing": true, + "oidc-scopes": [ + "read", + "write" + ], + "oidc-skip-verification": true, + "password": "", + "path": "", + "port": 6969, + "protocol": "http", + "request-id-header": "X-Trace-Id", + "smtp-from": "queen.rip.in.piss@terfisland.org", + "smtp-host": "example.com", + "smtp-password": "hunter2", + "smtp-port": 4269, + "smtp-username": "sex-haver", + "software-version": "", + "statuses-cw-max-chars": 420, + "statuses-max-chars": 69, + "statuses-media-max-files": 1, + "statuses-poll-max-options": 1, + "statuses-poll-option-max-chars": 50, + "storage-backend": "local", + "storage-local-base-path": "/root/store", + "storage-s3-access-key": "minio", + "storage-s3-bucket": "gts", + "storage-s3-endpoint": "localhost:9000", + "storage-s3-proxy": true, + "storage-s3-secret-key": "miniostorage", + "storage-s3-use-ssl": false, + "syslog-address": "127.0.0.1:6969", + "syslog-enabled": true, + "syslog-protocol": "udp", + "tls-certificate-chain": "", + "tls-certificate-key": "", + "trusted-proxies": [ + "127.0.0.1/32", + "docker.host.local" + ], + "username": "", + "web-asset-base-dir": "/root", + "web-template-base-dir": "/root" +} +EOF +) # Set all the environment variables to # ensure that these are parsed without panic