Skip to content

Commit

Permalink
feat: support configurable scheme for serverURL
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Jan 13, 2025
1 parent 49fb24a commit 7c57f1d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/ltkeycloak/from_mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func RunSyncFromMattermostCommandF(cmd *cobra.Command, _ []string) error {
siteURL = mattermostHost
}

mmClient := model.NewAPIv4Client("http://" + siteURL)
mmClient := model.NewAPIv4Client(deploymentConfig.ServerScheme + "://" + siteURL)

_, _, err = mmClient.Login(cmd.Context(), deploymentConfig.AdminEmail, deploymentConfig.AdminPassword)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"S3BucketDumpURI" : "",
"DBDumpURI": "",
"SiteURL": "",
"ServerURL": "",
"ServerScheme": "http",
"EnableNetPeekMetrics": false,
"TerraformDBSettings": {
"InstanceCount": 1,
Expand Down
6 changes: 5 additions & 1 deletion config/deployer.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ MattermostDownloadURL = 'https://latest.mattermost.com/mattermost-enterprise-lin
MattermostLicenseFile = ''
S3BucketDumpURI = ''
SiteURL = ''
EnableNetPeekMetrics = false
ServerURL = ''
ServerScheme = 'http'

# Agent configuration
AgentInstanceCount = 2
Expand Down Expand Up @@ -46,6 +47,9 @@ ProxyInstanceType = 'c5.xlarge'
ProxyInstanceCount = 1
ProxyAllocatePublicIPAddress = true

# Metrics
EnableNetPeekMetrics = false

[ClusterSubnetIDs]
App = []
Job = []
Expand Down
2 changes: 2 additions & 0 deletions deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type Config struct {
// Mattermost servers. This is used to override the server URL in the agent's config in case there's a
// proxy in front of the Mattermost server.
ServerURL string `default:""`
// ServerScheme is the scheme to use when connecting to the Mattermost server.
ServerScheme string `default:"http" validate:"oneof:{http,https}"`
// UsersFilePath specifies the path to an optional file containing a list of credentials for the controllers
// to use. If present, it is used to automatically upload it to the agents and override the agent's config's
// own UsersFilePath.
Expand Down
9 changes: 7 additions & 2 deletions deployment/terraform/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ func (t *Terraform) generateLoadtestAgentConfig() (*loadtest.Config, error) {

url := getServerURL(t.output, t.config)

cfg.ConnectionConfiguration.ServerURL = "http://" + url
cfg.ConnectionConfiguration.WebSocketURL = "ws://" + url
websocketScheme := "ws"
if t.config.ServerScheme == "https" {
websocketScheme = "wss"
}

cfg.ConnectionConfiguration.ServerURL = t.Config().ServerScheme + "://" + url
cfg.ConnectionConfiguration.WebSocketURL = websocketScheme + "://" + url
cfg.ConnectionConfiguration.AdminEmail = t.config.AdminEmail
cfg.ConnectionConfiguration.AdminPassword = t.config.AdminPassword

Expand Down
11 changes: 7 additions & 4 deletions deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,21 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
switch {
// SiteURL defined, multiple app nodes: we use SiteURL, since that points to the proxy itself
case t.config.SiteURL != "" && t.output.HasProxy():
siteURL = "http://" + t.config.SiteURL
siteURL = t.config.ServerScheme + "://" + t.config.SiteURL
// SiteURL defined, single app node: we use SiteURL plus the port, since SiteURL points to the app node (which is listening in 8065)
case t.config.SiteURL != "":
siteURL = "http://" + t.config.SiteURL + ":8065"
siteURL = t.config.ServerScheme + "://" + t.config.SiteURL + ":8065"
// SiteURL not defined, multiple app nodes: we use the proxy's public DNS
case t.output.HasProxy():
// This case will only succeed if siteURL is empty.
// And it's an error to have siteURL empty and set multiple proxies. (see (c *Config) validateProxyConfig)
// So we can safely take the DNS of the first entry.
siteURL = "http://" + t.output.Proxies[0].PublicDNS
siteURL = t.config.ServerScheme + "://" + t.output.Proxies[0].PublicDNS
// SiteURL not defined, single app node: we use the app node's public DNS plus port
case t.config.ServerURL != "":
siteURL = t.config.ServerScheme + "://" + t.config.ServerURL
default:
siteURL = "http://" + t.output.Instances[0].PublicDNS + ":8065"
siteURL = t.config.ServerScheme + "://" + t.output.Instances[0].PublicDNS + ":8065"
}

// Updating the config.json for each instance of app server
Expand All @@ -245,6 +247,7 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
pingURL = t.output.Proxies[0].PublicDNS
}

// Non-ssl is used for pinging the server
if err := pingServer("http://" + pingURL); err != nil {
return fmt.Errorf("error whiling pinging server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/terraform/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (t *Terraform) setupKeycloakAppConfig(sshc *ssh.Client, cfg *model.Config)
cfg.SamlSettings.IdpDescriptorURL = model.NewPointer(keycloakUrl + "/realms/" + t.config.ExternalAuthProviderSettings.KeycloakRealmName)
cfg.SamlSettings.IdpMetadataURL = model.NewPointer(keycloakUrl + "/realms/" + t.config.ExternalAuthProviderSettings.KeycloakRealmName + "/protocol/saml/descriptor")
cfg.SamlSettings.ServiceProviderIdentifier = model.NewPointer(t.config.ExternalAuthProviderSettings.KeycloakSAMLClientID)
cfg.SamlSettings.AssertionConsumerServiceURL = model.NewPointer("http://" + getServerURL(t.output, t.config) + "/login/sso/saml")
cfg.SamlSettings.AssertionConsumerServiceURL = model.NewPointer(t.config.ServerScheme + "://" + getServerURL(t.output, t.config) + "/login/sso/saml")
cfg.SamlSettings.SignatureAlgorithm = model.NewPointer("RSAwithSHA1")
cfg.SamlSettings.CanonicalAlgorithm = model.NewPointer("Canonical1.0")
cfg.SamlSettings.ScopingIDPProviderId = model.NewPointer("")
Expand Down
12 changes: 12 additions & 0 deletions docs/config/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,18 @@ The name of a host that will be used for two purposes:
- It will populate a new entry in the /etc/hosts file of the app nodes, so that it points to the proxy private IP or, if there's no proxy, to the current app node.
This config is used for tests that require an existing database dump that contains permalinks. These permalinks point to a specific hostname. Without this setting, that hostname is not known by the nodes of a new deployment and the permalinks cannot be resolved.

## ServerURL

*string*

The URL of the Mattermost server. This is used to override the server's `SiteURL` setting for specific scenarios where a different URL is needed on deployments without the proxy server.

## ServerScheme

*string*

The scheme of the Mattermost server. Defaults to `http`.

## UsersFilePath

*string*
Expand Down

0 comments on commit 7c57f1d

Please sign in to comment.