mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-30 18:51:03 +00:00
Improve the make-user command
This commit is contained in:
parent
b40ce46ddf
commit
b9c868f971
@ -17,10 +17,13 @@ so that it is accessible at a top-level domain or sub-domain at the URL:
|
|||||||
|
|
||||||
{{ .Addr.HashURI }}
|
{{ .Addr.HashURI }}
|
||||||
|
|
||||||
|
mkdir -p .well-known/salty
|
||||||
|
cat > .well-known/salty/{{ .Addr.Hash }}.json << EOF
|
||||||
{
|
{
|
||||||
"endpoint": "{{ .Config.Endpoint }}",
|
"endpoint": "{{ .Config.Endpoint }}",
|
||||||
"key": "{{ .Config.Key }}"
|
"key": "{{ .Config.Key }}"
|
||||||
}
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
To verify you have done this correctly:
|
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)
|
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
|
// Formatted returns a formatted user used in the Salty Message Format
|
||||||
// <timestamp\t(<user>) <message>\n
|
// <timestamp\t(<user>) <message>\n
|
||||||
func (a Addr) Formatted() string {
|
func (a Addr) Formatted() string {
|
||||||
@ -39,7 +44,7 @@ func (a Addr) URI() string {
|
|||||||
|
|
||||||
// HashURI returns the Well-Known HashURI for this Addr
|
// HashURI returns the Well-Known HashURI for this Addr
|
||||||
func (a Addr) HashURI() string {
|
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
|
// ParseAddr parsers a Salty Address for a user into it's user and domain
|
||||||
|
7
utils.go
7
utils.go
@ -4,15 +4,14 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/sprig/v3"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,9 +53,7 @@ func FileExists(name string) bool {
|
|||||||
// context `ctx` as input into the template.
|
// context `ctx` as input into the template.
|
||||||
// Typically used to render the results into a Markdown document.
|
// Typically used to render the results into a Markdown document.
|
||||||
func RenderString(s string, ctx interface{}) (string, error) {
|
func RenderString(s string, ctx interface{}) (string, error) {
|
||||||
t := template.Must(
|
t := template.Must(template.New("s").Parse(s))
|
||||||
template.New("s").Funcs(sprig.FuncMap()).Parse(s),
|
|
||||||
)
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
err := t.Execute(buf, ctx)
|
err := t.Execute(buf, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user