diff options
| author | 2025-05-20 11:47:40 +0200 | |
|---|---|---|
| committer | 2025-05-20 11:47:40 +0200 | |
| commit | ec4d4d01150ae979896496651bc64e4148d94a06 (patch) | |
| tree | 3ce9426b450659f573ef00465a1646d44e58b99d /internal/config/helpers.gen.go | |
| parent | [bugfix] fix case of failed timeline preload causing lockups (#4182) (diff) | |
| download | gotosocial-ec4d4d01150ae979896496651bc64e4148d94a06.tar.xz | |
[feature] Allow exposing allows, implement `/api/v1/domain_blocks` and `/api/v1/domain_allows` (#4169)
- adds config flags `instance-expose-allowlist` and `instance-expose-allowlist-web` to allow instance admins to expose their allowlist via the web + api.
- renames `instance-expose-suspended` and `instance-expose-suspended-web` to `instance-expose-blocklist` and `instance-expose-blocklist-web`.
- deprecates the `suspended` filter on `/api/v1/instance/peers` endpoint and adds `blocked` and `allowed` filters
- adds the `flat` query param to `/api/v1/instance/peers` to allow forcing return of a flat list of domains
- implements `/api/v1/instance/domain_blocks` and `/api/v1/instance/domain_allows` endpoints with or without auth depending on config
- rejigs the instance about page to include a general section on domain permissions, with block and allow subsections (and appropriate links)
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3847
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4150
Prerequisite to https://codeberg.org/superseriousbusiness/gotosocial/issues/3711
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4169
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/config/helpers.gen.go')
| -rw-r--r-- | internal/config/helpers.gen.go | 142 |
1 files changed, 106 insertions, 36 deletions
diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index a41c95861..269aa7abc 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -63,8 +63,10 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { flags.String("instance-federation-mode", cfg.InstanceFederationMode, "Set instance federation mode.") flags.Bool("instance-federation-spam-filter", cfg.InstanceFederationSpamFilter, "Enable basic spam filter heuristics for messages coming from other instances, and drop messages identified as spam") flags.Bool("instance-expose-peers", cfg.InstanceExposePeers, "Allow unauthenticated users to query /api/v1/instance/peers?filter=open") - flags.Bool("instance-expose-suspended", cfg.InstanceExposeSuspended, "Expose suspended instances via web UI, and allow unauthenticated users to query /api/v1/instance/peers?filter=suspended") - flags.Bool("instance-expose-suspended-web", cfg.InstanceExposeSuspendedWeb, "Expose list of suspended instances as webpage on /about/suspended") + flags.Bool("instance-expose-blocklist", cfg.InstanceExposeBlocklist, "Expose list of blocked domains via web UI, and allow unauthenticated users to query /api/v1/instance/peers?filter=blocked and /api/v1/instance/domain_blocks") + flags.Bool("instance-expose-blocklist-web", cfg.InstanceExposeBlocklistWeb, "Expose list of explicitly blocked domains as webpage on /about/domain_blocks") + flags.Bool("instance-expose-allowlist", cfg.InstanceExposeAllowlist, "Expose list of allowed domains via web UI, and allow unauthenticated users to query /api/v1/instance/peers?filter=allowed and /api/v1/instance/domain_allows") + flags.Bool("instance-expose-allowlist-web", cfg.InstanceExposeAllowlistWeb, "Expose list of explicitly allowed domains as webpage on /about/domain_allows") flags.Bool("instance-expose-public-timeline", cfg.InstanceExposePublicTimeline, "Allow unauthenticated users to query /api/v1/timelines/public") flags.Bool("instance-deliver-to-shared-inboxes", cfg.InstanceDeliverToSharedInboxes, "Deliver federated messages to shared inboxes, if they're available.") flags.Bool("instance-inject-mastodon-version", cfg.InstanceInjectMastodonVersion, "This injects a Mastodon compatible version in /api/v1/instance to help Mastodon clients that use that version for feature detection") @@ -79,7 +81,7 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { flags.Int("accounts-registration-backlog-limit", cfg.AccountsRegistrationBacklogLimit, "Limit how big the 'accounts pending approval' queue can grow before registration is closed. 0 or less = no limit.") flags.Bool("accounts-allow-custom-css", cfg.AccountsAllowCustomCSS, "Allow accounts to enable custom CSS for their profile pages and statuses.") flags.Int("accounts-custom-css-length", cfg.AccountsCustomCSSLength, "Maximum permitted length (characters) of custom CSS for accounts.") - flags.Int("accounts-max-profile-fields", cfg.AccountsMaxProfileFields, "Maximum amount of profile fields an account can have.") + flags.Int("accounts-max-profile-fields", cfg.AccountsMaxProfileFields, "Maximum number of profile fields allowed for each account.") flags.Int("media-description-min-chars", cfg.MediaDescriptionMinChars, "Min required chars for an image description") flags.Int("media-description-max-chars", cfg.MediaDescriptionMaxChars, "Max permitted chars for an image description") flags.Int("media-remote-cache-days", cfg.MediaRemoteCacheDays, "Number of days to locally cache media from remote instances. If set to 0, remote media will be kept indefinitely.") @@ -207,7 +209,7 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { } func (cfg *Configuration) MarshalMap() map[string]any { - cfgmap := make(map[string]any, 182) + cfgmap := make(map[string]any, 184) cfgmap["log-level"] = cfg.LogLevel cfgmap["log-timestamp-format"] = cfg.LogTimestampFormat cfgmap["log-db-queries"] = cfg.LogDbQueries @@ -242,8 +244,10 @@ func (cfg *Configuration) MarshalMap() map[string]any { cfgmap["instance-federation-mode"] = cfg.InstanceFederationMode cfgmap["instance-federation-spam-filter"] = cfg.InstanceFederationSpamFilter cfgmap["instance-expose-peers"] = cfg.InstanceExposePeers - cfgmap["instance-expose-suspended"] = cfg.InstanceExposeSuspended - cfgmap["instance-expose-suspended-web"] = cfg.InstanceExposeSuspendedWeb + cfgmap["instance-expose-blocklist"] = cfg.InstanceExposeBlocklist + cfgmap["instance-expose-blocklist-web"] = cfg.InstanceExposeBlocklistWeb + cfgmap["instance-expose-allowlist"] = cfg.InstanceExposeAllowlist + cfgmap["instance-expose-allowlist-web"] = cfg.InstanceExposeAllowlistWeb cfgmap["instance-expose-public-timeline"] = cfg.InstanceExposePublicTimeline cfgmap["instance-deliver-to-shared-inboxes"] = cfg.InstanceDeliverToSharedInboxes cfgmap["instance-inject-mastodon-version"] = cfg.InstanceInjectMastodonVersion @@ -674,19 +678,35 @@ func (cfg *Configuration) UnmarshalMap(cfgmap map[string]any) error { } } - if ival, ok := cfgmap["instance-expose-suspended"]; ok { + if ival, ok := cfgmap["instance-expose-blocklist"]; ok { var err error - cfg.InstanceExposeSuspended, err = cast.ToBoolE(ival) + cfg.InstanceExposeBlocklist, err = cast.ToBoolE(ival) if err != nil { - return fmt.Errorf("error casting %#v -> bool for 'instance-expose-suspended': %w", ival, err) + return fmt.Errorf("error casting %#v -> bool for 'instance-expose-blocklist': %w", ival, err) } } - if ival, ok := cfgmap["instance-expose-suspended-web"]; ok { + if ival, ok := cfgmap["instance-expose-blocklist-web"]; ok { var err error - cfg.InstanceExposeSuspendedWeb, err = cast.ToBoolE(ival) + cfg.InstanceExposeBlocklistWeb, err = cast.ToBoolE(ival) if err != nil { - return fmt.Errorf("error casting %#v -> bool for 'instance-expose-suspended-web': %w", ival, err) + return fmt.Errorf("error casting %#v -> bool for 'instance-expose-blocklist-web': %w", ival, err) + } + } + + if ival, ok := cfgmap["instance-expose-allowlist"]; ok { + var err error + cfg.InstanceExposeAllowlist, err = cast.ToBoolE(ival) + if err != nil { + return fmt.Errorf("error casting %#v -> bool for 'instance-expose-allowlist': %w", ival, err) + } + } + + if ival, ok := cfgmap["instance-expose-allowlist-web"]; ok { + var err error + cfg.InstanceExposeAllowlistWeb, err = cast.ToBoolE(ival) + if err != nil { + return fmt.Errorf("error casting %#v -> bool for 'instance-expose-allowlist-web': %w", ival, err) } } @@ -2742,55 +2762,105 @@ func GetInstanceExposePeers() bool { return global.GetInstanceExposePeers() } // SetInstanceExposePeers safely sets the value for global configuration 'InstanceExposePeers' field func SetInstanceExposePeers(v bool) { global.SetInstanceExposePeers(v) } -// InstanceExposeSuspendedFlag returns the flag name for the 'InstanceExposeSuspended' field -func InstanceExposeSuspendedFlag() string { return "instance-expose-suspended" } +// InstanceExposeBlocklistFlag returns the flag name for the 'InstanceExposeBlocklist' field +func InstanceExposeBlocklistFlag() string { return "instance-expose-blocklist" } + +// GetInstanceExposeBlocklist safely fetches the Configuration value for state's 'InstanceExposeBlocklist' field +func (st *ConfigState) GetInstanceExposeBlocklist() (v bool) { + st.mutex.RLock() + v = st.config.InstanceExposeBlocklist + st.mutex.RUnlock() + return +} + +// SetInstanceExposeBlocklist safely sets the Configuration value for state's 'InstanceExposeBlocklist' field +func (st *ConfigState) SetInstanceExposeBlocklist(v bool) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.InstanceExposeBlocklist = v + st.reloadToViper() +} + +// GetInstanceExposeBlocklist safely fetches the value for global configuration 'InstanceExposeBlocklist' field +func GetInstanceExposeBlocklist() bool { return global.GetInstanceExposeBlocklist() } + +// SetInstanceExposeBlocklist safely sets the value for global configuration 'InstanceExposeBlocklist' field +func SetInstanceExposeBlocklist(v bool) { global.SetInstanceExposeBlocklist(v) } + +// InstanceExposeBlocklistWebFlag returns the flag name for the 'InstanceExposeBlocklistWeb' field +func InstanceExposeBlocklistWebFlag() string { return "instance-expose-blocklist-web" } + +// GetInstanceExposeBlocklistWeb safely fetches the Configuration value for state's 'InstanceExposeBlocklistWeb' field +func (st *ConfigState) GetInstanceExposeBlocklistWeb() (v bool) { + st.mutex.RLock() + v = st.config.InstanceExposeBlocklistWeb + st.mutex.RUnlock() + return +} + +// SetInstanceExposeBlocklistWeb safely sets the Configuration value for state's 'InstanceExposeBlocklistWeb' field +func (st *ConfigState) SetInstanceExposeBlocklistWeb(v bool) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.InstanceExposeBlocklistWeb = v + st.reloadToViper() +} + +// GetInstanceExposeBlocklistWeb safely fetches the value for global configuration 'InstanceExposeBlocklistWeb' field +func GetInstanceExposeBlocklistWeb() bool { return global.GetInstanceExposeBlocklistWeb() } + +// SetInstanceExposeBlocklistWeb safely sets the value for global configuration 'InstanceExposeBlocklistWeb' field +func SetInstanceExposeBlocklistWeb(v bool) { global.SetInstanceExposeBlocklistWeb(v) } + +// InstanceExposeAllowlistFlag returns the flag name for the 'InstanceExposeAllowlist' field +func InstanceExposeAllowlistFlag() string { return "instance-expose-allowlist" } -// GetInstanceExposeSuspended safely fetches the Configuration value for state's 'InstanceExposeSuspended' field -func (st *ConfigState) GetInstanceExposeSuspended() (v bool) { +// GetInstanceExposeAllowlist safely fetches the Configuration value for state's 'InstanceExposeAllowlist' field +func (st *ConfigState) GetInstanceExposeAllowlist() (v bool) { st.mutex.RLock() - v = st.config.InstanceExposeSuspended + v = st.config.InstanceExposeAllowlist st.mutex.RUnlock() return } -// SetInstanceExposeSuspended safely sets the Configuration value for state's 'InstanceExposeSuspended' field -func (st *ConfigState) SetInstanceExposeSuspended(v bool) { +// SetInstanceExposeAllowlist safely sets the Configuration value for state's 'InstanceExposeAllowlist' field +func (st *ConfigState) SetInstanceExposeAllowlist(v bool) { st.mutex.Lock() defer st.mutex.Unlock() - st.config.InstanceExposeSuspended = v + st.config.InstanceExposeAllowlist = v st.reloadToViper() } -// GetInstanceExposeSuspended safely fetches the value for global configuration 'InstanceExposeSuspended' field -func GetInstanceExposeSuspended() bool { return global.GetInstanceExposeSuspended() } +// GetInstanceExposeAllowlist safely fetches the value for global configuration 'InstanceExposeAllowlist' field +func GetInstanceExposeAllowlist() bool { return global.GetInstanceExposeAllowlist() } -// SetInstanceExposeSuspended safely sets the value for global configuration 'InstanceExposeSuspended' field -func SetInstanceExposeSuspended(v bool) { global.SetInstanceExposeSuspended(v) } +// SetInstanceExposeAllowlist safely sets the value for global configuration 'InstanceExposeAllowlist' field +func SetInstanceExposeAllowlist(v bool) { global.SetInstanceExposeAllowlist(v) } -// InstanceExposeSuspendedWebFlag returns the flag name for the 'InstanceExposeSuspendedWeb' field -func InstanceExposeSuspendedWebFlag() string { return "instance-expose-suspended-web" } +// InstanceExposeAllowlistWebFlag returns the flag name for the 'InstanceExposeAllowlistWeb' field +func InstanceExposeAllowlistWebFlag() string { return "instance-expose-allowlist-web" } -// GetInstanceExposeSuspendedWeb safely fetches the Configuration value for state's 'InstanceExposeSuspendedWeb' field -func (st *ConfigState) GetInstanceExposeSuspendedWeb() (v bool) { +// GetInstanceExposeAllowlistWeb safely fetches the Configuration value for state's 'InstanceExposeAllowlistWeb' field +func (st *ConfigState) GetInstanceExposeAllowlistWeb() (v bool) { st.mutex.RLock() - v = st.config.InstanceExposeSuspendedWeb + v = st.config.InstanceExposeAllowlistWeb st.mutex.RUnlock() return } -// SetInstanceExposeSuspendedWeb safely sets the Configuration value for state's 'InstanceExposeSuspendedWeb' field -func (st *ConfigState) SetInstanceExposeSuspendedWeb(v bool) { +// SetInstanceExposeAllowlistWeb safely sets the Configuration value for state's 'InstanceExposeAllowlistWeb' field +func (st *ConfigState) SetInstanceExposeAllowlistWeb(v bool) { st.mutex.Lock() defer st.mutex.Unlock() - st.config.InstanceExposeSuspendedWeb = v + st.config.InstanceExposeAllowlistWeb = v st.reloadToViper() } -// GetInstanceExposeSuspendedWeb safely fetches the value for global configuration 'InstanceExposeSuspendedWeb' field -func GetInstanceExposeSuspendedWeb() bool { return global.GetInstanceExposeSuspendedWeb() } +// GetInstanceExposeAllowlistWeb safely fetches the value for global configuration 'InstanceExposeAllowlistWeb' field +func GetInstanceExposeAllowlistWeb() bool { return global.GetInstanceExposeAllowlistWeb() } -// SetInstanceExposeSuspendedWeb safely sets the value for global configuration 'InstanceExposeSuspendedWeb' field -func SetInstanceExposeSuspendedWeb(v bool) { global.SetInstanceExposeSuspendedWeb(v) } +// SetInstanceExposeAllowlistWeb safely sets the value for global configuration 'InstanceExposeAllowlistWeb' field +func SetInstanceExposeAllowlistWeb(v bool) { global.SetInstanceExposeAllowlistWeb(v) } // InstanceExposePublicTimelineFlag returns the flag name for the 'InstanceExposePublicTimeline' field func InstanceExposePublicTimelineFlag() string { return "instance-expose-public-timeline" } |
