Ensure sample config only defaults to bare minimum requirements (#826)

* Comment out parts of the sample config that do not need to be on by default

* Update config

* Create 826.misc
This commit is contained in:
Will Hunt 2023-10-11 10:26:23 +01:00 committed by GitHub
parent f7f8e13c44
commit a539ad5e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 172 deletions

1
changelog.d/826.misc Normal file
View File

@ -0,0 +1 @@
Sample config now comments out optional parameters by default.

View File

@ -2,185 +2,27 @@
bridge:
# Basic homeserver configuration
domain: example.com
url: http://localhost:8008
mediaUrl: https://example.com
port: 9993
bindAddress: 127.0.0.1
github:
# (Optional) Configure this to enable GitHub support
auth:
# Authentication for the GitHub App.
id: 123
privateKeyFile: github-key.pem
webhook:
# Webhook settings for the GitHub app.
secret: secrettoken
oauth:
# (Optional) Settings for allowing users to sign in via OAuth.
client_id: foo
client_secret: bar
redirect_uri: https://example.com/bridge_oauth/
defaultOptions:
# (Optional) Default options for GitHub connections.
showIssueRoomLink: false
hotlinkIssues:
prefix: "#"
userIdPrefix:
# (Optional) Prefix used when creating ghost users for GitHub accounts.
_github_
gitlab:
# (Optional) Configure this to enable GitLab support
instances:
gitlab.com:
url: https://gitlab.com
webhook:
secret: secrettoken
publicUrl: https://example.com/hookshot/
userIdPrefix:
# (Optional) Prefix used when creating ghost users for GitLab accounts.
_gitlab_
commentDebounceMs:
# (Optional) Aggregate comments by waiting this many miliseconds before posting them to Matrix. Defaults to 5000 (5 seconds)
5000
figma:
# (Optional) Configure this to enable Figma support
publicUrl: https://example.com/hookshot/
instances:
your-instance:
teamId: your-team-id
accessToken: your-personal-access-token
passcode: your-webhook-passcode
jira:
# (Optional) Configure this to enable Jira support. Only specify `url` if you are using a On Premise install (i.e. not atlassian.com)
webhook:
# Webhook settings for JIRA
secret: secrettoken
oauth:
# (Optional) OAuth settings for connecting users to JIRA. See documentation for more information
client_id: foo
client_secret: bar
redirect_uri: https://example.com/bridge_oauth/
generic:
# (Optional) Support for generic webhook events.
#'allowJsTransformationFunctions' will allow users to write short transformation snippets in code, and thus is unsafe in untrusted environments
enabled: false
enableHttpGet: false
urlPrefix: https://example.com/webhook/
userIdPrefix: _webhooks_
allowJsTransformationFunctions: false
waitForComplete: false
feeds:
# (Optional) Configure this to enable RSS/Atom feed support
enabled: false
pollConcurrency: 4
pollIntervalSeconds: 600
pollTimeoutSeconds: 30
provisioning:
# (Optional) Provisioning API for integration managers
secret: "!secretToken"
passFile:
# A passkey used to encrypt tokens stored inside the bridge.
# Run openssl genpkey -out passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096 to generate
passkey.pem
bot:
# (Optional) Define profile information for the bot user
displayname: Hookshot Bot
avatar: mxc://half-shot.uk/2876e89ccade4cb615e210c458e2a7a6883fe17d
serviceBots:
# (Optional) Define additional bot users for specific services
- localpart: feeds
displayname: Feeds
avatar: ./assets/feeds_avatar.png
prefix: "!feeds"
service: feeds
metrics:
# (Optional) Prometheus metrics support
enabled: true
queue:
# (Optional) Message queue / cache configuration options for large scale deployments.
# For encryption to work, must be set to monolithic mode and have a host & port specified.
monolithic: true
port: 6379
host: localhost
logging:
# (Optional) Logging settings. You can have a severity debug,info,warn,error
# Logging settings. You can have a severity debug,info,warn,error
level: info
colorize: true
json: false
timestampFormat: HH:mm:ss:SSS
widgets:
# (Optional) EXPERIMENTAL support for complimentary widgets
addToAdminRooms: false
disallowedIpRanges:
- 127.0.0.0/8
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
- 100.64.0.0/10
- 192.0.0.0/24
- 169.254.0.0/16
- 192.88.99.0/24
- 198.18.0.0/15
- 192.0.2.0/24
- 198.51.100.0/24
- 203.0.113.0/24
- 224.0.0.0/4
- ::1/128
- fe80::/10
- fc00::/7
- 2001:db8::/32
- ff00::/8
- fec0::/10
roomSetupWidget:
addOnInvite: false
publicUrl: https://example.com/widgetapi/v1/static/
branding:
widgetTitle: Hookshot Configuration
sentry:
# (Optional) Configure Sentry error reporting
dsn: https://examplePublicKey@o0.ingest.sentry.io/0
environment: production
permissions:
# (Optional) Permissions for using the bridge. See docs/setup.md#permissions for help
- actor: example.com
services:
- service: "*"
level: admin
listeners:
# (Optional) HTTP Listener configuration.
# HTTP Listener configuration.
# Bind resource endpoints to ports and addresses.
# 'port' must be specified. Each listener must listen on a unique port.
# 'bindAddress' will default to '127.0.0.1' if not specified, which may not be suited to Docker environments.
# 'resources' may be any of webhooks, widgets, metrics, provisioning
- port: 9000
bindAddress: 0.0.0.0
resources:
@ -195,3 +37,150 @@ listeners:
resources:
- widgets
#github:
# # (Optional) Configure this to enable GitHub support
# auth:
# # Authentication for the GitHub App.
# id: 123
# privateKeyFile: github-key.pem
# webhook:
# # Webhook settings for the GitHub app.
# secret: secrettoken
# oauth:
# # (Optional) Settings for allowing users to sign in via OAuth.
# client_id: foo
# client_secret: bar
# redirect_uri: https://example.com/bridge_oauth/
# defaultOptions:
# # (Optional) Default options for GitHub connections.
# showIssueRoomLink: false
# hotlinkIssues:
# prefix: "#"
# userIdPrefix:
# # (Optional) Prefix used when creating ghost users for GitHub accounts.
# _github_
#gitlab:
# # (Optional) Configure this to enable GitLab support
# instances:
# gitlab.com:
# url: https://gitlab.com
# webhook:
# secret: secrettoken
# publicUrl: https://example.com/hookshot/
# userIdPrefix:
# # (Optional) Prefix used when creating ghost users for GitLab accounts.
# _gitlab_
# commentDebounceMs:
# # (Optional) Aggregate comments by waiting this many miliseconds before posting them to Matrix. Defaults to 5000 (5 seconds)
# 5000
#figma:
# # (Optional) Configure this to enable Figma support
# publicUrl: https://example.com/hookshot/
# instances:
# your-instance:
# teamId: your-team-id
# accessToken: your-personal-access-token
# passcode: your-webhook-passcode
#jira:
# # (Optional) Configure this to enable Jira support. Only specify `url` if you are using a On Premise install (i.e. not atlassian.com)
# webhook:
# # Webhook settings for JIRA
# secret: secrettoken
# oauth:
# # (Optional) OAuth settings for connecting users to JIRA. See documentation for more information
# client_id: foo
# client_secret: bar
# redirect_uri: https://example.com/bridge_oauth/
#generic:
# # (Optional) Support for generic webhook events.
# #'allowJsTransformationFunctions' will allow users to write short transformation snippets in code, and thus is unsafe in untrusted environments
# enabled: false
# enableHttpGet: false
# urlPrefix: https://example.com/webhook/
# userIdPrefix: _webhooks_
# allowJsTransformationFunctions: false
# waitForComplete: false
#feeds:
# # (Optional) Configure this to enable RSS/Atom feed support
# enabled: false
# pollConcurrency: 4
# pollIntervalSeconds: 600
# pollTimeoutSeconds: 30
#provisioning:
# # (Optional) Provisioning API for integration managers
# secret: "!secretToken"
#bot:
# # (Optional) Define profile information for the bot user
# displayname: Hookshot Bot
# avatar: mxc://half-shot.uk/2876e89ccade4cb615e210c458e2a7a6883fe17d
#serviceBots:
# # (Optional) Define additional bot users for specific services
# - localpart: feeds
# displayname: Feeds
# avatar: ./assets/feeds_avatar.png
# prefix: "!feeds"
# service: feeds
#metrics:
# # (Optional) Prometheus metrics support
# enabled: true
#queue:
# # (Optional) Message queue / cache configuration options for large scale deployments.
# # For encryption to work, must be set to monolithic mode and have a host & port specified.
# monolithic: true
# port: 6379
# host: localhost
#widgets:
# # (Optional) EXPERIMENTAL support for complimentary widgets
# addToAdminRooms: false
# disallowedIpRanges:
# - 127.0.0.0/8
# - 10.0.0.0/8
# - 172.16.0.0/12
# - 192.168.0.0/16
# - 100.64.0.0/10
# - 192.0.0.0/24
# - 169.254.0.0/16
# - 192.88.99.0/24
# - 198.18.0.0/15
# - 192.0.2.0/24
# - 198.51.100.0/24
# - 203.0.113.0/24
# - 224.0.0.0/4
# - ::1/128
# - fe80::/10
# - fc00::/7
# - 2001:db8::/32
# - ff00::/8
# - fec0::/10
# roomSetupWidget:
# addOnInvite: false
# publicUrl: https://example.com/widgetapi/v1/static/
# branding:
# widgetTitle: Hookshot Configuration
#sentry:
# # (Optional) Configure Sentry error reporting
# dsn: https://examplePublicKey@o0.ingest.sentry.io/0
# environment: production
#permissions:
# # (Optional) Permissions for using the bridge. See docs/setup.md#permissions for help
# - actor: example.com
# services:
# - service: "*"
# level: admin

View File

@ -491,7 +491,7 @@ export class BridgeConfig {
@configKey(`Message queue / cache configuration options for large scale deployments.
For encryption to work, must be set to monolithic mode and have a host & port specified.`, true)
public readonly queue: BridgeConfigQueue;
@configKey("Logging settings. You can have a severity debug,info,warn,error", true)
@configKey("Logging settings. You can have a severity debug,info,warn,error")
public readonly logging: BridgeConfigLogging;
@configKey(`Permissions for using the bridge. See docs/setup.md#permissions for help`, true)
public readonly permissions: BridgeConfigActorPermission[];
@ -527,7 +527,7 @@ export class BridgeConfig {
Bind resource endpoints to ports and addresses.
'port' must be specified. Each listener must listen on a unique port.
'bindAddress' will default to '127.0.0.1' if not specified, which may not be suited to Docker environments.
'resources' may be any of ${ResourceTypeArray.join(', ')}`, true)
'resources' may be any of ${ResourceTypeArray.join(', ')}`)
public readonly listeners: BridgeConfigListener[];
@configKey("go-neb migrator configuration", true)

View File

@ -7,7 +7,7 @@ export function configKey(comment?: string, optional = false) {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getConfigKeyMetadata(target: any, propertyKey: string): [string, boolean] {
export function getConfigKeyMetadata(target: any, propertyKey: string): [string, boolean]|null {
return Reflect.getMetadata(configKeyMetadataKey, target, propertyKey);
}

View File

@ -156,7 +156,7 @@ export const DefaultConfigRoot: BridgeConfigRoot = {
export const DefaultConfig = new BridgeConfig(DefaultConfigRoot);
function renderSection(doc: YAML.Document, obj: Record<string, unknown>, parentNode?: YAMLSeq) {
function renderSection(doc: YAML.Document, obj: Record<string, unknown>, parentNode: YAMLSeq|YAML.Document = doc, parentIsOptional = false) {
const entries = Object.entries(obj);
entries.forEach(([key, value]) => {
if (keyIsHidden(obj, key)) {
@ -167,10 +167,11 @@ function renderSection(doc: YAML.Document, obj: Record<string, unknown>, parentN
return;
}
const [comment, optional] = getConfigKeyMetadata(obj, key) ?? [];
let newNode: Node;
if (typeof value === "object" && !Array.isArray(value)) {
newNode = doc.createNode({});
renderSection(doc, value as Record<string, unknown>, newNode as YAMLSeq);
renderSection(doc, value as Record<string, unknown>, newNode as YAMLSeq, optional ?? parentIsOptional);
} else if (typeof value === "function") {
if (value.length !== 0) {
throw Error("Only zero-argument functions are allowed as config values");
@ -179,16 +180,23 @@ function renderSection(doc: YAML.Document, obj: Record<string, unknown>, parentN
} else {
newNode = doc.createNode(value);
}
const metadata = getConfigKeyMetadata(obj, key);
if (metadata) {
newNode.commentBefore = `${metadata[1] ? ' (Optional)' : ''} ${metadata[0]}\n`;
if (comment) {
newNode.commentBefore = `${optional ? ' (Optional)' : ''} ${comment}`;
}
if (optional && !parentIsOptional) {
const tempDoc = new YAML.Document();
tempDoc.contents = tempDoc.createNode({});
tempDoc.add({key, value: newNode});
// Apply to the parent node after required options
parentNode.comment = (parentNode.comment || "") + tempDoc.toString() + `\n`;
return;
}
if (parentNode) {
if (optional) {
parentNode.add({key: key, value: newNode});
} else if (parentNode) {
parentNode.add({key, value: newNode});
} else {
doc.add({key, value: newNode});
}
})
}