From 4f8325f5df55628544f13937975f38c6ef5d17ab Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sun, 18 Dec 2022 18:51:00 -0500 Subject: switch to using go-fed for activitystreams --- go.mod | 1 + go.sum | 8 ++++++++ http/server.go | 43 +++++++++++++++++++++---------------------- registry/registry.go | 4 ++-- resources/profile.go | 37 +++++++++++++++++-------------------- sample-cgi-handler.sh | 9 ++------- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/go.mod b/go.mod index ae73ead..0272442 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/dustin/go-humanize v1.0.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-gonic/gin v1.8.1 // indirect + github.com/go-fed/activity v1.0.0 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.11.1 // indirect diff --git a/go.sum b/go.sum index 0644a6b..b281389 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,7 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/dave/jennifer v1.3.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger/v3 v3.2103.5 h1:ylPa6qzbjYRQMU6jokoj4wzcaweHylt//CH0AKt0akg= @@ -35,6 +36,9 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-fed/activity v1.0.0 h1:j7w3auHZnVCjUcgA1mE+UqSOjFBhvW2Z2res3vNol+o= +github.com/go-fed/activity v1.0.0/go.mod h1:v4QoPaAzjWZ8zN2VFVGL5ep9C02mst0hQYHUpQwso4Q= +github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= @@ -42,6 +46,7 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -54,6 +59,7 @@ github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -158,6 +164,7 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +golang.org/x/crypto v0.0.0-20180527072434-ab813273cd59/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -190,6 +197,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/http/server.go b/http/server.go index e0050b2..d8560bb 100644 --- a/http/server.go +++ b/http/server.go @@ -37,7 +37,7 @@ func (s *Server) Start(zapWriter io.Writer) { // "User" endpoint router.GET("/actors/:actor", func(c *gin.Context) { actorParam := c.Param("actor") - resource := s.registry.LookupByName(actorParam) + resource, _ := s.registry.LookupByName(actorParam) if resource != nil { c.JSON(http.StatusOK, resource) } else { @@ -46,28 +46,27 @@ func (s *Server) Start(zapWriter io.Writer) { }) - // Inbox - router.POST("/actors/:actor/inbox", func(c *gin.Context) { - actorParam := c.Param("actor") - resource := s.registry.LookupByName(actorParam) - if resource != nil { - c.JSON(http.StatusOK, resource) - } else { - c.JSON(http.StatusNotFound, nil) - } + // // Inbox + // router.POST("/actors/:actor/inbox", func(c *gin.Context) { + // actorParam := c.Param("actor") + // resource := s.registry.LookupByName(actorParam) + // if resource != nil { + // c.JSON(http.StatusOK, resource) + // } else { + // c.JSON(http.StatusNotFound, nil) + // } - }) - // Outbox - router.GET("/actors/:actor/outbox", func(c *gin.Context) { - actorParam := c.Param("actor") - resource := s.registry.LookupByName(actorParam) - if resource != nil { - c.JSON(http.StatusOK, resource) - } else { - c.JSON(http.StatusNotFound, nil) - } - - }) + // }) + // // Outbox + // router.GET("/actors/:actor/outbox", func(c *gin.Context) { + // actorParam := c.Param("actor") + // resource := s.registry.LookupByName(actorParam) + // if resource != nil { + // c.JSON(http.StatusOK, resource) + // } else { + // c.JSON(http.StatusNotFound, nil) + // } + // }) router.Run() } diff --git a/registry/registry.go b/registry/registry.go index 7091819..936ff54 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -29,10 +29,10 @@ func NewRegistry(cfg config.Config) *Registry { } // TODO should probably be getprofilebyname -func (r *Registry) LookupByName(name string) *resources.Profile { +func (r *Registry) LookupByName(name string) (map[string]interface{}, error) { fqdn := fmt.Sprintf("acct:%s@%s", name, r.cfg.Domain) if r.LookupResource(fqdn) == nil { - return nil + return nil, nil } return resources.RenderProfile(name, r.cfg.Domain) } diff --git a/resources/profile.go b/resources/profile.go index 83b2159..23b2844 100644 --- a/resources/profile.go +++ b/resources/profile.go @@ -1,26 +1,23 @@ package resources -import "path" +import ( + "net/url" + "path" -type Profile struct { - Context []string `json:"@context"` - Type string `json:"type"` - Id string `json:"id"` - Inbox string `json:"inbox"` - Outbox string `json:"outbox"` - Summary string `json:"summary"` - Username string `json:"preferredUsername"` -} - -type PublicKey struct { -} + "github.com/go-fed/activity/streams" +) -func RenderProfile(name, domain string) *Profile { - p := Profile{ - Context: []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}, - Type: "Service", - Inbox: path.Join("https://", domain, "actors", name, "inbox"), - Outbox: path.Join("https://", domain, "actors", name, "outbox"), +func RenderProfile(name, domain string) (map[string]interface{}, error) { + u, err := url.Parse(path.Join("https://", domain, "actors", name, "inbox")) + if err != nil { + panic(err) } - return &p + + inb := streams.NewActivityStreamsInboxProperty() + inb.SetIRI(u) + + p := streams.NewActivityStreamsService() + p.SetActivityStreamsInbox(inb) + + return p.Serialize() } diff --git a/sample-cgi-handler.sh b/sample-cgi-handler.sh index 55da4a0..afd4ada 100755 --- a/sample-cgi-handler.sh +++ b/sample-cgi-handler.sh @@ -1,10 +1,5 @@ #!/bin/bash -echo "Content-type: text/html" +echo "Content-type: text/plain" echo "" -echo '' -echo 'Hello From Bash
Environment:' -echo '
'
-/usr/bin/env
-echo '
' -echo '' +echo "This is a random value from bash: $RANDOM on $(date)" exit 0 -- cgit v1.2.3