summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-07-19 18:42:08 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-19 18:42:08 +0200
commitb1a4f38e383279d14d10b6b4575f752ca4b54f73 (patch)
tree813429385388f6ce7f6255d53210ce9ba914e796 /internal
parentDb tls (#102) (diff)
downloadgotosocial-b1a4f38e383279d14d10b6b4575f752ca4b54f73.tar.xz
allow different host + accountDomain (#103)
* allow different host + accountDomain * use accountDomain in tags
Diffstat (limited to 'internal')
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go16
-rw-r--r--internal/config/config.go12
-rw-r--r--internal/config/default.go2
-rw-r--r--internal/processing/federation.go2
-rw-r--r--internal/typeutils/internaltoas.go2
5 files changed, 24 insertions, 10 deletions
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index 416a75f3b..1d723e67c 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -50,23 +50,23 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
return
}
- usernameDomain := strings.Split(withAcct[1], "@")
- if len(usernameDomain) != 2 {
+ usernameAndAccountDomain := strings.Split(withAcct[1], "@")
+ if len(usernameAndAccountDomain) != 2 {
l.Debugf("aborting request because username and domain could not be parsed from %s", withAcct[1])
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
return
}
- username := strings.ToLower(usernameDomain[0])
- domain := strings.ToLower(usernameDomain[1])
- if username == "" || domain == "" {
+ username := strings.ToLower(usernameAndAccountDomain[0])
+ accountDomain := strings.ToLower(usernameAndAccountDomain[1])
+ if username == "" || accountDomain == "" {
l.Debug("aborting request because username or domain was empty")
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
return
}
- if domain != m.config.Host {
- l.Debugf("aborting request because domain %s does not belong to this instance", domain)
- c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("domain %s does not belong to this instance", domain)})
+ if accountDomain != m.config.AccountDomain {
+ l.Debugf("aborting request because accountDomain %s does not belong to this instance", accountDomain)
+ c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("accountDomain %s does not belong to this instance", accountDomain)})
return
}
diff --git a/internal/config/config.go b/internal/config/config.go
index 323b7de81..958926975 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -48,6 +48,7 @@ type Config struct {
LogLevel string `yaml:"logLevel"`
ApplicationName string `yaml:"applicationName"`
Host string `yaml:"host"`
+ AccountDomain string `yaml:"accountDomain"`
Protocol string `yaml:"protocol"`
DBConfig *DBConfig `yaml:"db"`
TemplateConfig *TemplateConfig `yaml:"template"`
@@ -133,6 +134,13 @@ func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
return errors.New("host was not set")
}
+ if c.AccountDomain == "" || f.IsSet(fn.AccountDomain) {
+ c.AccountDomain = f.String(fn.AccountDomain)
+ }
+ if c.AccountDomain == "" {
+ c.AccountDomain = c.Host // default to whatever the host is, if this is empty
+ }
+
if c.Protocol == "" || f.IsSet(fn.Protocol) {
c.Protocol = f.String(fn.Protocol)
}
@@ -290,6 +298,7 @@ type Flags struct {
ApplicationName string
ConfigPath string
Host string
+ AccountDomain string
Protocol string
DbType string
@@ -336,6 +345,7 @@ type Defaults struct {
ApplicationName string
ConfigPath string
Host string
+ AccountDomain string
Protocol string
SoftwareVersion string
@@ -385,6 +395,7 @@ func GetFlagNames() Flags {
ApplicationName: "application-name",
ConfigPath: "config-path",
Host: "host",
+ AccountDomain: "account-domain",
Protocol: "protocol",
DbType: "db-type",
@@ -434,6 +445,7 @@ func GetEnvNames() Flags {
ApplicationName: "GTS_APPLICATION_NAME",
ConfigPath: "GTS_CONFIG_PATH",
Host: "GTS_HOST",
+ AccountDomain: "GTS_ACCOUNT_DOMAIN",
Protocol: "GTS_PROTOCOL",
DbType: "GTS_DB_TYPE",
diff --git a/internal/config/default.go b/internal/config/default.go
index 7a030beb5..099eead1c 100644
--- a/internal/config/default.go
+++ b/internal/config/default.go
@@ -118,6 +118,7 @@ func GetDefaults() Defaults {
ApplicationName: "gotosocial",
ConfigPath: "",
Host: "",
+ AccountDomain: "",
Protocol: "https",
DbType: "postgres",
@@ -166,6 +167,7 @@ func GetTestDefaults() Defaults {
ApplicationName: "gotosocial",
ConfigPath: "",
Host: "localhost:8080",
+ AccountDomain: "",
Protocol: "http",
DbType: "postgres",
diff --git a/internal/processing/federation.go b/internal/processing/federation.go
index 6299d5e7e..966dab08d 100644
--- a/internal/processing/federation.go
+++ b/internal/processing/federation.go
@@ -304,7 +304,7 @@ func (p *processor) GetWebfingerAccount(ctx context.Context, requestedUsername s
// return the webfinger representation
return &apimodel.WellKnownResponse{
- Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.Host),
+ Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.AccountDomain),
Aliases: []string{
requestedAccount.URI,
requestedAccount.URL,
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 809cedc45..b24b07e13 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -580,7 +580,7 @@ func (c *converter) MentionToAS(m *gtsmodel.Mention) (vocab.ActivityStreamsMenti
// name -- this should be the namestring of the mentioned user, something like @whatever@example.org
var domain string
if m.GTSAccount.Domain == "" {
- domain = c.config.Host
+ domain = c.config.AccountDomain
} else {
domain = m.GTSAccount.Domain
}