~samwhited/xmpp

ad83ceb1f6c8ab85290ee6133dde89ed4f6e86db — Sam Whited a month ago cc33bc0
internal/integration/prosody: allow custom modules

Provides an option for loading custom modules.

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 26 insertions(+), 0 deletions(-)

M internal/integration/prosody/config.go
M internal/integration/prosody/prosody.go
M internal/integration/prosody/config.go => internal/integration/prosody/config.go +14 -0
@@ 15,6 15,7 @@ import (
type Config struct {
	Admins  []string
	VHosts  []string
	Modules []string
	C2SPort int
	S2SPort int
}


@@ 28,6 29,7 @@ interfaces = { "::1" }
{{ if .S2SPort }}s2s_ports = { {{ .S2SPort }} }{{ end }}

modules_enabled = {
		{{ luaList .Modules }}

	-- Generally required
		"roster"; -- Allow users to have a roster. Recommended ;)


@@ 60,6 62,7 @@ modules_disabled = {
  {{ if not .S2SPort }}"s2s";{{ end }}
}

plugin_paths = { "{{ .ConfigDir }}" }
allow_registration = false
c2s_require_encryption = true
s2s_require_encryption = true


@@ 89,4 92,15 @@ var cfgTmpl = template.Must(template.New("cfg").Funcs(template.FuncMap{
		}
		return strings.Join(s, ",")
	},
	"luaList": func(s []string) string {
		s = append(s[:0:0], s...)
		for i, ss := range s {
			s[i] = fmt.Sprintf("%q", ss)
		}
		var end string
		if len(s) > 0 {
			end = ";\n"
		}
		return strings.Join(s, ";\n") + end
	},
}).Parse(cfgBase))

M internal/integration/prosody/prosody.go => internal/integration/prosody/prosody.go +12 -0
@@ 164,6 164,18 @@ func CreateUser(ctx context.Context, addr, pass string) integration.Option {
	}
}

// Modules adds custom modules to the enabled modules list.
func Modules(mod ...string) integration.Option {
	return func(cmd *integration.Cmd) error {
		cfg := getConfig(cmd)
		for _, m := range mod {
			cfg.Modules = append(cfg.Modules, m)
		}
		cmd.Config = cfg
		return nil
	}
}

func defaultConfig(cmd *integration.Cmd) error {
	for _, arg := range cmd.Cmd.Args {
		if arg == configFlag {