This commit is contained in:
Simon Ser 2021-08-26 11:14:15 +00:00 committed by Drew DeVault
parent 76279c9b1c
commit f44afb103e
12 changed files with 24 additions and 24 deletions

View File

@ -88,9 +88,9 @@ const (
type Grants struct { type Grants struct {
ReadOnly bool ReadOnly bool
all bool all bool
grants map[string]string grants map[string]string
encoded string encoded string
} }
func DecodeGrants(ctx context.Context, grants string) Grants { func DecodeGrants(ctx context.Context, grants string) Grants {

View File

@ -85,7 +85,7 @@ func authError(w http.ResponseWriter, reason string, code int) {
gqlerr := gqlerror.Errorf("Authentication error: %s", reason) gqlerr := gqlerror.Errorf("Authentication error: %s", reason)
b, err := json.Marshal(struct { b, err := json.Marshal(struct {
Errors []*gqlerror.Error `json:"errors"` Errors []*gqlerror.Error `json:"errors"`
} { }{
Errors: []*gqlerror.Error{gqlerr}, Errors: []*gqlerror.Error{gqlerr},
}) })
if err != nil { if err != nil {

View File

@ -50,7 +50,7 @@ func Execute(ctx context.Context, username string, svc string,
Name: username, Name: username,
ClientID: config.ServiceName(ctx), ClientID: config.ServiceName(ctx),
// TODO: Populate this: // TODO: Populate this:
NodeID: "core-go", NodeID: "core-go",
} }
authBlob, err := json.Marshal(&auth) authBlob, err := json.Marshal(&auth)
if err != nil { if err != nil {

View File

@ -4,9 +4,9 @@ import (
"fmt" "fmt"
"os" "os"
"git.sr.ht/~sircmpwn/core-go/auth"
"git.sr.ht/~sircmpwn/core-go/config" "git.sr.ht/~sircmpwn/core-go/config"
"git.sr.ht/~sircmpwn/core-go/crypto" "git.sr.ht/~sircmpwn/core-go/crypto"
"git.sr.ht/~sircmpwn/core-go/auth"
) )
func main() { func main() {

View File

@ -38,10 +38,10 @@ func LoadConfig(defaultAddr string) ini.File {
} }
for _, path := range []string{ for _, path := range []string{
"config.ini", "config.ini",
"../config.ini", "../config.ini",
"/etc/sr.ht/config.ini", "/etc/sr.ht/config.ini",
} { } {
config, err = ini.LoadFile(path) config, err = ini.LoadFile(path)
if err == nil { if err == nil {
break break

View File

@ -7,9 +7,9 @@ import (
"net/mail" "net/mail"
"strconv" "strconv"
_ "github.com/emersion/go-message/charset"
"github.com/emersion/go-sasl" "github.com/emersion/go-sasl"
"github.com/emersion/go-smtp" "github.com/emersion/go-smtp"
_ "github.com/emersion/go-message/charset"
"git.sr.ht/~sircmpwn/core-go/config" "git.sr.ht/~sircmpwn/core-go/config"
) )

View File

@ -13,10 +13,10 @@ import (
"time" "time"
"git.sr.ht/~sircmpwn/dowork" "git.sr.ht/~sircmpwn/dowork"
_ "github.com/emersion/go-message/charset"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"
"github.com/emersion/go-pgpmail" "github.com/emersion/go-pgpmail"
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
_ "github.com/emersion/go-message/charset"
"git.sr.ht/~sircmpwn/core-go/config" "git.sr.ht/~sircmpwn/core-go/config"
) )

View File

@ -5,9 +5,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
gomail "net/mail"
"runtime" "runtime"
"strings" "strings"
gomail "net/mail"
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"

View File

@ -41,7 +41,7 @@ func NewAuthConfig(ctx context.Context) (AuthConfig, error) {
_clientID := user.BearerToken.ClientID _clientID := user.BearerToken.ClientID
clientID = &_clientID clientID = &_clientID
} }
return AuthConfig { return AuthConfig{
AuthMethod: user.AuthMethod, AuthMethod: user.AuthMethod,
TokenHash: &tokenHash, TokenHash: &tokenHash,
Grants: &grants, Grants: &grants,

View File

@ -13,8 +13,8 @@ import (
"time" "time"
"git.sr.ht/~sircmpwn/dowork" "git.sr.ht/~sircmpwn/dowork"
"github.com/google/uuid"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/google/uuid"
"git.sr.ht/~sircmpwn/core-go/crypto" "git.sr.ht/~sircmpwn/core-go/crypto"
"git.sr.ht/~sircmpwn/core-go/database" "git.sr.ht/~sircmpwn/core-go/database"

View File

@ -11,9 +11,9 @@ import (
"time" "time"
"github.com/DATA-DOG/go-sqlmock" "github.com/DATA-DOG/go-sqlmock"
sq "github.com/Masterminds/squirrel"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/vaughan0/go-ini" "github.com/vaughan0/go-ini"
sq "github.com/Masterminds/squirrel"
"git.sr.ht/~sircmpwn/core-go/crypto" "git.sr.ht/~sircmpwn/core-go/crypto"
"git.sr.ht/~sircmpwn/core-go/database" "git.sr.ht/~sircmpwn/core-go/database"
@ -39,7 +39,7 @@ type argContains struct {
matches []string matches []string
} }
func ArgMatchesAll(matches... string) *argContains { func ArgMatchesAll(matches ...string) *argContains {
return &argContains{matches} return &argContains{matches}
} }
@ -100,7 +100,7 @@ func TestDelivery(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{ WillReturnRows(sqlmock.NewRows([]string{
"sub.id", "sub.created", "sub.url", "sub.events", "sub.id", "sub.created", "sub.url", "sub.events",
}).AddRow(1337, time.Now().UTC(), }).AddRow(1337, time.Now().UTC(),
srv.URL + "/webhook", "profile:update")). srv.URL+"/webhook", "profile:update")).
WithArgs(42, sqlmock.AnyArg()) // Any => events LIKE %profile:update% WithArgs(42, sqlmock.AnyArg()) // Any => events LIKE %profile:update%
mock.ExpectCommit() mock.ExpectCommit()
@ -132,7 +132,7 @@ func TestDelivery(t *testing.T) {
"X-Webhook-Delivery", "X-Webhook-Delivery",
), // Final request headers ), // Final request headers
4096). 4096).
WillReturnResult(sqlmock.NewResult(1, 1)) WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit() mock.ExpectCommit()
ctx = database.Context(context.Background(), db) ctx = database.Context(context.Background(), db)

View File

@ -14,8 +14,8 @@ import (
"git.sr.ht/~sircmpwn/dowork" "git.sr.ht/~sircmpwn/dowork"
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
"github.com/google/uuid"
sq "github.com/Masterminds/squirrel" sq "github.com/Masterminds/squirrel"
"github.com/google/uuid"
"git.sr.ht/~sircmpwn/core-go/auth" "git.sr.ht/~sircmpwn/core-go/auth"
"git.sr.ht/~sircmpwn/core-go/crypto" "git.sr.ht/~sircmpwn/core-go/crypto"
@ -28,9 +28,9 @@ type WebhookQueue struct {
} }
type WebhookSubscription struct { type WebhookSubscription struct {
ID int ID int
URL string URL string
Query string Query string
// See AuthConfig in webhooks/config.go for an explanation of these fields // See AuthConfig in webhooks/config.go for an explanation of these fields
AuthMethod string AuthMethod string
TokenHash *string TokenHash *string
@ -120,7 +120,7 @@ func (queue *WebhookQueue) fetchSubscriptions(ctx context.Context,
var subs []*WebhookSubscription var subs []*WebhookSubscription
if err := database.WithTx(ctx, &sql.TxOptions{ if err := database.WithTx(ctx, &sql.TxOptions{
Isolation: 0, Isolation: 0,
ReadOnly: true, ReadOnly: true,
}, func(tx *sql.Tx) error { }, func(tx *sql.Tx) error {
var ( var (
err error err error