mirror of
1
Fork 0

[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.
This commit is contained in:
Daenney 2023-03-04 21:56:50 +01:00 committed by GitHub
parent d2f6de0185
commit 65aeeb4442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 147 additions and 11 deletions

View File

@ -21,7 +21,7 @@ package config
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "os"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action" "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/config"
@ -39,13 +39,8 @@ var Config action.GTSAction = func(ctx context.Context) (err error) {
return err return err
} }
// Marshal map to JSON enc := json.NewEncoder(os.Stdout)
b, err := json.Marshal(raw) enc.SetIndent("", " ")
if err != nil { err = enc.Encode(raw)
return err return err
}
// Print to stdout
fmt.Printf("%s\n", b)
return nil
} }

View File

@ -2,7 +2,148 @@
set -eu 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 # Set all the environment variables to
# ensure that these are parsed without panic # ensure that these are parsed without panic