6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-25 16:28:20 +00:00

Improve the make-user command

This commit is contained in:
James Mills 2022-03-20 23:54:54 +10:00
parent b40ce46ddf
commit b9c868f971
3 changed files with 11 additions and 6 deletions

@ -17,10 +17,13 @@ so that it is accessible at a top-level domain or sub-domain at the URL:
{{ .Addr.HashURI }}
mkdir -p .well-known/salty
cat > .well-known/salty/{{ .Addr.Hash }}.json << EOF
{
"endpoint": "{{ .Config.Endpoint }}",
"key": "{{ .Config.Key }}"
}
EOF
To verify you have done this correctly:

@ -26,6 +26,11 @@ func (a Addr) String() string {
return fmt.Sprintf("%s@%s", a.User, a.Domain)
}
// Hash returns the Hex(SHA256Sum()) of the Address
func (a Addr) Hash() string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(a.String())))
}
// Formatted returns a formatted user used in the Salty Message Format
// <timestamp\t(<user>) <message>\n
func (a Addr) Formatted() string {
@ -39,7 +44,7 @@ func (a Addr) URI() string {
// HashURI returns the Well-Known HashURI for this Addr
func (a Addr) HashURI() string {
return fmt.Sprintf("https://%s/.well-known/salty/%x.json", a.Domain, sha256.Sum256([]byte(a.String())))
return fmt.Sprintf("https://%s/.well-known/salty/%s.json", a.Domain, a.Hash())
}
// ParseAddr parsers a Salty Address for a user into it's user and domain

@ -4,15 +4,14 @@ import (
"bytes"
"context"
"fmt"
"html/template"
"io"
"net/http"
"os"
"os/exec"
"syscall"
"text/template"
"time"
"github.com/Masterminds/sprig/v3"
log "github.com/sirupsen/logrus"
)
@ -54,9 +53,7 @@ func FileExists(name string) bool {
// context `ctx` as input into the template.
// Typically used to render the results into a Markdown document.
func RenderString(s string, ctx interface{}) (string, error) {
t := template.Must(
template.New("s").Funcs(sprig.FuncMap()).Parse(s),
)
t := template.Must(template.New("s").Parse(s))
buf := bytes.NewBuffer([]byte{})
err := t.Execute(buf, ctx)
if err != nil {