gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 65aeeb44427c1fe9d6a6d41829b7e02d5f1896ec
parent d2f6de01856917b19e1f1ba6028f7e05d60e674b
Author: Daenney <daenney@users.noreply.github.com>
Date:   Sat,  4 Mar 2023 21:56:50 +0100

[chore] Print human readable config (#1589)

This changes the config action to print the config in a more human
readable format, indented by 4 spaces and with newlines.

Thanks to this, we can now reasonably construct some JSON in the
envparsing shell script, without needing utilities like jd. It does
assume cat is available in order to not change the shebang to bash.

With the expected JSON now being one key per line it should make it much
easier for multiple PRs that change something around config not to
collide in merge conflicts.
Diffstat:
Mcmd/gotosocial/action/debug/config/config.go | 15+++++----------
Mtest/envparsing.sh | 143++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 147 insertions(+), 11 deletions(-)

diff --git 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 @@ -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