Explicitly ignore errors from writes to responses
Some checks failed
/ docker (push) Failing after 15m26s

This commit is contained in:
Melody Becker 2025-05-22 17:29:09 +02:00
parent ef95a0552d
commit 4a2462e24e
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
30 changed files with 280 additions and 237 deletions

View file

@ -36,7 +36,7 @@ func ImportRemoteNote(noteId string, requester *models.User) (string, error) {
return "", fmt.Errorf("activitypub: invalid status code: %v", res.StatusCode) return "", fmt.Errorf("activitypub: invalid status code: %v", res.StatusCode)
} }
body, _ := io.ReadAll(res.Body) body, _ := io.ReadAll(res.Body)
res.Body.Close() _ = res.Body.Close()
data := Note{} data := Note{}
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err != nil { if err != nil {

View file

@ -424,7 +424,7 @@ func ImportRemoteAccountByAPUrl(apUrl string) (*models.User, error) {
return nil, other.Error("activitypub", "failed to complete signed request", err) return nil, other.Error("activitypub", "failed to complete signed request", err)
} }
body, _ := io.ReadAll(response.Body) body, _ := io.ReadAll(response.Body)
response.Body.Close() _ = response.Body.Close()
if response.StatusCode != 200 { if response.StatusCode != 200 {
return nil, fmt.Errorf("activitypub: invalid status code: %v", response.StatusCode) return nil, fmt.Errorf("activitypub: invalid status code: %v", response.StatusCode)
} }

View file

@ -88,7 +88,13 @@ func (a *Authenticator) PerformTotpLogin(
} }
// If not verified yet, mark as verified // If not verified yet, mark as verified
if strings.HasSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix) { if strings.HasSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix) {
dbgen.UserAuthMethod. // TODO: Not nice, think about this more
// Problem: What does it mean for a credential to not be verified?
// Does it just mean not used yet?
// Or should it also mean that it's unusable until confirmation during setup?
// I prefer the 2nd one to avoid lockout problems
// In which case, this needs to be modified
_, _ = dbgen.UserAuthMethod.
Where(dbgen.UserAuthMethod.ID. Where(dbgen.UserAuthMethod.ID.
Eq(dbSecrets[foundIndex].ID)). Eq(dbSecrets[foundIndex].ID)).
Update(dbgen.UserAuthMethod.Name, strings.TrimSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix)) Update(dbgen.UserAuthMethod.Name, strings.TrimSuffix(dbSecrets[foundIndex].Name, totpUnverifiedSuffix))

View file

@ -48,7 +48,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
input = file input = file
} }
if *flagOutputFile == "" { if *flagOutputFile == "" {
@ -58,7 +58,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
output = file output = file
} }
@ -204,5 +204,5 @@ func CompareRoles(a, b *models.Role) bool {
outBuilder.WriteString("\n}") outBuilder.WriteString("\n}")
// And write the entire thing to the output // And write the entire thing to the output
fmt.Fprint(output, outBuilder.String()) _, _ = fmt.Fprint(output, outBuilder.String())
} }

View file

@ -37,7 +37,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
input = file input = file
} }
if *flagOutputFile == "" { if *flagOutputFile == "" {
@ -47,7 +47,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
output = file output = file
} }
@ -100,5 +100,5 @@ func main() {
} }
outBuilder.WriteString("}\n}\n") outBuilder.WriteString("}\n}\n")
fmt.Fprint(output, outBuilder.String()) _, _ = fmt.Fprint(output, outBuilder.String())
} }

View file

@ -38,7 +38,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
input = file input = file
} }
if *flagOutputFile == "" { if *flagOutputFile == "" {
@ -48,7 +48,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
output = file output = file
} }
@ -105,7 +105,7 @@ func main() {
} }
outBuilder.WriteString("}") outBuilder.WriteString("}")
fmt.Fprint(output, outBuilder.String()) _, _ = fmt.Fprint(output, outBuilder.String())
} }
func convertGoNameToJsonApiName(name string) string { func convertGoNameToJsonApiName(name string) string {

View file

@ -39,7 +39,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
input = file input = file
} }
if *flagOutputFile == "" { if *flagOutputFile == "" {
@ -49,7 +49,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
output = file output = file
} }
@ -111,7 +111,7 @@ func main() {
role: Role role: Role
} }
}`) }`)
fmt.Fprint(output, outBuilder.String()) _, _ = fmt.Fprint(output, outBuilder.String())
} }
func convertGoTypeToTS(t string) string { func convertGoTypeToTS(t string) string {

View file

@ -43,7 +43,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
input = file input = file
} }
if *flagOutputFile == "" { if *flagOutputFile == "" {
@ -53,7 +53,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer func() { _ = file.Close() }()
output = file output = file
} }
@ -176,5 +176,5 @@ func main() {
outBuilder.WriteString("\n}") outBuilder.WriteString("\n}")
// And write the entire thing to the output // And write the entire thing to the output
fmt.Fprint(output, outBuilder.String()) _, _ = fmt.Fprint(output, outBuilder.String())
} }

View file

@ -23,7 +23,10 @@ func main() {
other.SetupFlags() other.SetupFlags()
flag.Parse() flag.Parse()
other.ConfigureLogging(nil) other.ConfigureLogging(nil)
config.ReadAndWriteToGlobal(*shared.FlagConfigFile) err := config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
if err != nil {
log.Fatal().Err(err).Msg("Failed to get config from file")
}
db, err := gorm.Open( db, err := gorm.Open(
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()), postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),

View file

@ -280,7 +280,7 @@ func WriteDefaultConfig(toFile string) error {
Msg("Failed to create file for default config") Msg("Failed to create file for default config")
return err return err
} }
defer file.Close() defer func() { _ = file.Close() }()
data, err := toml.Marshal(&defaultConfig) data, err := toml.Marshal(&defaultConfig)
if err != nil { if err != nil {

View file

@ -2,10 +2,6 @@ package shared
import ( import (
"flag" "flag"
"fmt"
"os"
"github.com/rs/zerolog/log"
) )
var ( var (
@ -27,7 +23,7 @@ var (
FlagDebugPort *string = flag.String( FlagDebugPort *string = flag.String(
"debugport", "debugport",
"127.0.0.1:3305", "127.0.0.1:3305",
"Set the address the debug server will listen on. Format: IP:Port", "Set the address the debug server will listen on. Format: IP:Port (irrelevant if debug server isn't enabled)",
) )
FlagLogFile *string = flag.String( FlagLogFile *string = flag.String(
"logfile", "logfile",
@ -36,27 +32,27 @@ var (
) )
) )
func flagUsage() { // func flagUsage() {
executable, err := os.Executable() // executable, err := os.Executable()
if err != nil { // if err != nil {
log.Fatal().Err(err).Msg("Failed to get own path") // log.Fatal().Err(err).Msg("Failed to get own path")
} // }
fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable) // fmt.Fprintf(os.Stderr, "Usage of %s:\n", executable)
fmt.Fprintln(os.Stderr, "\t-config string") // fmt.Fprintln(os.Stderr, "\t-config string")
fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")") // fmt.Fprintln(os.Stderr, "\t\tLocation of the config file (default: \"config.toml\")")
fmt.Fprintln(os.Stderr, "\t-loglevel string") // fmt.Fprintln(os.Stderr, "\t-loglevel string")
fmt.Fprintln( // fmt.Fprintln(
os.Stderr, // os.Stderr,
"\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")", // "\t\tSet the logging level. Options are: Trace, Debug, Info, Warning, Error and Fatal. Case insensitive (default: \"Info\")",
) // )
fmt.Fprintln(os.Stderr, "\t-validate-config") // fmt.Fprintln(os.Stderr, "\t-validate-config")
fmt.Fprintln( // fmt.Fprintln(
os.Stderr, // os.Stderr,
"\t\tIf set, the server will only validate the config (or write the default one) and then quit", // "\t\tIf set, the server will only validate the config (or write the default one) and then quit",
) // )
fmt.Fprintln(os.Stderr, "\t-jsonlogs") // fmt.Fprintln(os.Stderr, "\t-jsonlogs")
fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead") // fmt.Fprintln(os.Stderr, "\t\tIf set, writes logging messages as json objects instead")
} // }
// func init() { // func init() {
// flag.Usage = flagUsage // flag.Usage = flagUsage

View file

@ -14,7 +14,7 @@ func TestFSWrapper_Open(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to open /etc/hostname: %v", err) t.Fatalf("failed to open /etc/hostname: %v", err)
} }
defer f.Close() defer func() { _ = f.Close() }()
data, err := os.ReadFile("/etc/hostname") data, err := os.ReadFile("/etc/hostname")
if err != nil { if err != nil {
t.Fatalf("failed to read with full path: %v", err) t.Fatalf("failed to read with full path: %v", err)

View file

@ -11,7 +11,7 @@ func init() {
} }
func tickExpireAccessTokens(now time.Time) { func tickExpireAccessTokens(now time.Time) {
dbgen.AccessToken.Where(dbgen.AccessToken.ExpiresAt.Lt(time.Now())).Delete() _, _ = dbgen.AccessToken.Where(dbgen.AccessToken.ExpiresAt.Lt(time.Now())).Delete()
} }
func buildExpireAccessTokens() (onTick func(time.Time), name string, tickSpeed time.Duration) { func buildExpireAccessTokens() (onTick func(time.Time), name string, tickSpeed time.Duration) {

View file

@ -118,16 +118,16 @@ func createActitiystreamsActivityType(db *gorm.DB) error {
) )
} }
func createActitiystreamsActivityTargetType(db *gorm.DB) error { // func createActitiystreamsActivityTargetType(db *gorm.DB) error {
return migrateEnum( // return migrateEnum(
db, // db,
"activitystreams_activity_target_type", // "activitystreams_activity_target_type",
sliceutils.Map( // sliceutils.Map(
models.AllActivitystreamsActivityTargetTypes, // models.AllActivitystreamsActivityTargetTypes,
func(t models.ActivitystreamsActivityTargetType) string { return string(t) }, // func(t models.ActivitystreamsActivityTargetType) string { return string(t) },
), // ),
) // )
} // }
func createCollectionTarget(db *gorm.DB) error { func createCollectionTarget(db *gorm.DB) error {
return migrateEnum( return migrateEnum(

View file

@ -31,7 +31,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
data := Inbound{} data := Inbound{}
err := dec.Decode(&data) err := dec.Decode(&data)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -49,10 +49,10 @@ func postAs(w http.ResponseWriter, r *http.Request) {
user, err := dbgen.User.GetByUsername(data.Username) user, err := dbgen.User.GetByUsername(data.Username)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
} else { } else {
log.Error().Err(err).Str("name", data.Username).Msg("Failed to find user") log.Error().Err(err).Str("name", data.Username).Msg("Failed to find user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
return return
} }
@ -88,7 +88,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
Str("username", data.Username). Str("username", data.Username).
Str("content", data.Content). Str("content", data.Content).
Msg("Failed to create message") Msg("Failed to create message")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
activity := models.Activity{ activity := models.Activity{
@ -105,28 +105,28 @@ func postAs(w http.ResponseWriter, r *http.Request) {
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to commit note creation") log.Error().Err(err).Msg("Failed to commit note creation")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
u2u := dbgen.UserToUserRelation u2u := dbgen.UserToUserRelation
links, err := u2u.GetFollowerInboxesForId(user.ID) links, err := u2u.GetFollowerInboxesForId(user.ID)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to get follower inbox links for user") log.Error().Err(err).Msg("Failed to get follower inbox links for user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
log.Debug().Strs("links", links).Send() log.Debug().Strs("links", links).Send()
act, err := webap.CreateFromStorage(r.Context(), activity.Id) act, err := webap.CreateFromStorage(r.Context(), activity.Id)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to fetch and format new note") log.Error().Err(err).Msg("Failed to fetch and format new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
act.Context = activitypub.BaseLdContext act.Context = activitypub.BaseLdContext
outData, err := json.Marshal(act) outData, err := json.Marshal(act)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to marshal new note") log.Error().Err(err).Msg("Failed to marshal new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
for _, link := range links { for _, link := range links {
@ -151,13 +151,13 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get user") log.Error().Err(err).Str("name", username).Msg("Failed to get user")
storage.HandleReconnectError(err) storage.HandleReconnectError(err)
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
notes, err := dbgen.Note.GetNotesPaged(user.ID, 0, uint8(models.NOTE_TARGET_PUBLIC)) notes, err := dbgen.Note.GetNotesPaged(user.ID, 0, uint8(models.NOTE_TARGET_PUBLIC))
if err != nil { if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get notes") log.Error().Err(err).Str("name", username).Msg("Failed to get notes")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
publicNotes := sliceutils.Map(notes, func(t models.Note) webshared.Note { publicNotes := sliceutils.Map(notes, func(t models.Note) webshared.Note {
@ -165,7 +165,7 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
n.FromModel(&t) n.FromModel(&t)
return n return n
}) })
webutils.SendJson(w, publicNotes) _ = webutils.SendJson(w, publicNotes)
} }
func inReplyTo(w http.ResponseWriter, r *http.Request) { func inReplyTo(w http.ResponseWriter, r *http.Request) {
@ -176,7 +176,7 @@ func inReplyTo(w http.ResponseWriter, r *http.Request) {
Find() Find()
if err != nil { if err != nil {
log.Error().Err(err).Str("id", noteId).Msg("Error getting replies to note with id") log.Error().Err(err).Str("id", noteId).Msg("Error getting replies to note with id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
_ = webutils.SendJson(w, notes) _ = webutils.SendJson(w, notes)

View file

@ -32,7 +32,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
var err error var err error
page, err = strconv.Atoi(pageStr) page, err = strconv.Atoi(pageStr)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-page", "/errors/bad-page",
@ -43,7 +43,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
return return
} }
if page < 0 { if page < 0 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-page", "/errors/bad-page",
@ -57,7 +57,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
users, err := dbgen.User.GetPagedAllNonDeleted(uint(page)) users, err := dbgen.User.GetPagedAllNonDeleted(uint(page))
if err != nil { if err != nil {
log.Error().Err(err).Int("page", page).Msg("Failed to get non-deleted users") log.Error().Err(err).Int("page", page).Msg("Failed to get non-deleted users")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusInternalServerError, http.StatusInternalServerError,
"/errors/db-failure", "/errors/db-failure",
@ -67,7 +67,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
) )
return return
} }
webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User { _ = webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User {
u := webshared.User{} u := webshared.User{}
u.FromModel(&t) u.FromModel(&t)
return u return u
@ -88,7 +88,7 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
data := Inbound{} data := Inbound{}
err := jsonDecoder.Decode(&data) err := jsonDecoder.Decode(&data)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -111,20 +111,20 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
publicKeyEdBytes, privateKeyEdBytes, err := shared.GenerateKeypair(true) publicKeyEdBytes, privateKeyEdBytes, err := shared.GenerateKeypair(true)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to generate and marshal public key") log.Error().Err(err).Msg("Failed to generate and marshal public key")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
publicKeyRsaBytes, privateKeyRsaBytes, err := shared.GenerateKeypair(false) publicKeyRsaBytes, privateKeyRsaBytes, err := shared.GenerateKeypair(false)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to generate and marshal public key") log.Error().Err(err).Msg("Failed to generate and marshal public key")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
pkeyId := make([]byte, 64) pkeyId := make([]byte, 64)
_, err = rand.Read(pkeyId) _, err = rand.Read(pkeyId)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to generate passkey id") log.Error().Err(err).Msg("Failed to generate passkey id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
@ -174,17 +174,17 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
} }
if err = query.Create(&user); err != nil { if err = query.Create(&user); err != nil {
log.Error().Err(err).Msg("failed to create new local user") log.Error().Err(err).Msg("failed to create new local user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
if err = storage.EnsureLocalUserIdHasLinks(user.ID); err != nil { if err = storage.EnsureLocalUserIdHasLinks(user.ID); err != nil {
log.Error().Err(err).Msg("Failed to add links to new user") log.Error().Err(err).Msg("Failed to add links to new user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }
func deleteUser(w http.ResponseWriter, r *http.Request) { func deleteUser(w http.ResponseWriter, r *http.Request) {
id := r.FormValue("id") id := r.FormValue("id")
dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete() _, _ = dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete()
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
@ -212,7 +212,7 @@ func returnKeypair(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Pem Sanity check failed") hlog.FromRequest(r).Error().Err(err).Msg("Pem Sanity check failed")
} }
fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen) _, _ = fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen)
} }
func issueUserImport(w http.ResponseWriter, r *http.Request) { func issueUserImport(w http.ResponseWriter, r *http.Request) {
@ -235,20 +235,20 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
err := dec.Decode(&data) err := dec.Decode(&data)
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Failed to decode json body") log.Warn().Err(err).Msg("Failed to decode json body")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
log.Debug().Any("data", data).Msg("Received message") log.Debug().Any("data", data).Msg("Received message")
user, err := dbgen.User.GetByUsername(data.From) user, err := dbgen.User.GetByUsername(data.From)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to get user from storage") log.Error().Err(err).Msg("Failed to get user from storage")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
targetId, err := activitypub.ImportRemoteAccountByHandle(data.Target) targetId, err := activitypub.ImportRemoteAccountByHandle(data.Target)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to import target user") log.Error().Err(err).Msg("Failed to import target user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
target, err := dbgen.User.Where(dbgen.User.ID.Eq(targetId)). target, err := dbgen.User.Where(dbgen.User.ID.Eq(targetId)).
@ -256,14 +256,14 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
First() First()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to get target user from db") log.Error().Err(err).Msg("Failed to get target user from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
outBody, err := json.Marshal(data.Message) outBody, err := json.Marshal(data.Message)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to marshal out data") log.Error().Err(err).Msg("Failed to marshal out data")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
log.Debug().Bytes("request-body", outBody).Msg("Body of proxied request") log.Debug().Bytes("request-body", outBody).Msg("Body of proxied request")
@ -275,10 +275,10 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
) )
if err != nil { if err != nil {
log.Error().Err(err).Msg("Request failed") log.Error().Err(err).Msg("Request failed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
defer response.Body.Close() defer func() { _ = response.Body.Close() }()
respBody, _ := io.ReadAll(response.Body) respBody, _ := io.ReadAll(response.Body)
log.Debug(). log.Debug().
Int("status-code", response.StatusCode). Int("status-code", response.StatusCode).
@ -291,9 +291,12 @@ func kickoffFollow(w http.ResponseWriter, r *http.Request) {
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`
} }
log := hlog.FromRequest(r)
var data Inbound var data Inbound
dec := json.NewDecoder(r.Body) dec := json.NewDecoder(r.Body)
dec.Decode(&data) _ = dec.Decode(&data)
log.Error().Msg("Not implemented yet")
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
func requestAs(w http.ResponseWriter, r *http.Request) { func requestAs(w http.ResponseWriter, r *http.Request) {
@ -307,24 +310,24 @@ func requestAs(w http.ResponseWriter, r *http.Request) {
err := dec.Decode(&data) err := dec.Decode(&data)
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Failed to decode json body") log.Warn().Err(err).Msg("Failed to decode json body")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
user, err := dbgen.User.GetByUsername(data.Username) user, err := dbgen.User.GetByUsername(data.Username)
if err != nil { if err != nil {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
} }
res, _, err := webshared.RequestSigned("GET", data.TargetUrl, nil, user) res, _, err := webshared.RequestSigned("GET", data.TargetUrl, nil, user)
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Request failed") log.Warn().Err(err).Msg("Request failed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if res.StatusCode != 200 { if res.StatusCode != 200 {
webutils.ProblemDetailsStatusOnly(w, res.StatusCode) _ = webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
return return
} }
body, _ := io.ReadAll(res.Body) body, _ := io.ReadAll(res.Body)
fmt.Fprint(w, string(body)) _, _ = fmt.Fprint(w, string(body))
} }

View file

@ -32,24 +32,24 @@ func activityAccept(w http.ResponseWriter, r *http.Request) {
activity, err := CreateFromStorage(r.Context(), id) activity, err := CreateFromStorage(r.Context(), id)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil: case nil:
activity.Context = activitypub.BaseLdContext activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity) data, err := json.Marshal(activity)
if err != nil { if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity") log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
default: default:
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started") log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else { } else {
log.Error().Err(err).Msg("Failed to get create activity from db") log.Error().Err(err).Msg("Failed to get create activity from db")
} }
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }

View file

@ -31,24 +31,24 @@ func activityCreate(w http.ResponseWriter, r *http.Request) {
activity, err := CreateFromStorage(r.Context(), id) activity, err := CreateFromStorage(r.Context(), id)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil: case nil:
activity.Context = activitypub.BaseLdContext activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity) data, err := json.Marshal(activity)
if err != nil { if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity") log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
default: default:
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started") log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else { } else {
log.Error().Err(err).Msg("Failed to get create activity from db") log.Error().Err(err).Msg("Failed to get create activity from db")
} }
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }

View file

@ -31,24 +31,24 @@ func activityFollow(w http.ResponseWriter, r *http.Request) {
activity, err := FollowFromStorage(r.Context(), id) activity, err := FollowFromStorage(r.Context(), id)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
case nil: case nil:
activity.Context = activitypub.BaseLdContext activity.Context = activitypub.BaseLdContext
data, err := json.Marshal(activity) data, err := json.Marshal(activity)
if err != nil { if err != nil {
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity") log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
default: default:
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started") log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else { } else {
log.Error().Err(err).Msg("Failed to get create activity from db") log.Error().Err(err).Msg("Failed to get create activity from db")
} }
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }

View file

@ -42,7 +42,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
data := map[string]any{} data := map[string]any{}
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -53,7 +53,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
return return
} }
if _, ok := data["@context"]; !ok { if _, ok := data["@context"]; !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -65,7 +65,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
} }
objectType, ok := data["type"].(string) objectType, ok := data["type"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -77,7 +77,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
} }
_, ok = data["id"].(string) _, ok = data["id"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -104,7 +104,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
handleCreate(w, r, data) handleCreate(w, r, data)
default: default:
log.Warn().Str("object-type", objectType).Msg("Unknown message type") log.Warn().Str("object-type", objectType).Msg("Unknown message type")
webutils.ProblemDetailsStatusOnly(w, 500) _ = webutils.ProblemDetailsStatusOnly(w, 500)
} }
} }
@ -113,7 +113,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
activityId := object["id"].(string) activityId := object["id"].(string)
likerUrl, ok := object["actor"].(string) likerUrl, ok := object["actor"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -126,7 +126,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
// TODO: Account for case where object is embedded in like // TODO: Account for case where object is embedded in like
targetUrl, ok := object["object"].(string) targetUrl, ok := object["object"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -142,7 +142,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Strs("match-results", targetIdMatches). Strs("match-results", targetIdMatches).
Str("url", targetUrl). Str("url", targetUrl).
Msg("Url didn't match id extractor regex") Msg("Url didn't match id extractor regex")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
targetId := targetIdMatches[1] targetId := targetIdMatches[1]
@ -152,7 +152,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
switch err { switch err {
case nil: case nil:
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -163,7 +163,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
return return
default: default:
log.Error().Err(err).Str("note-id", targetId).Msg("Failed to get note from db") log.Error().Err(err).Str("note-id", targetId).Msg("Failed to get note from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
// Import liker after verifying that target note is correct // Import liker after verifying that target note is correct
@ -173,7 +173,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Err(err). Err(err).
Str("liker-url", likerUrl). Str("liker-url", likerUrl).
Msg("Failed to import liking remote account") Msg("Failed to import liking remote account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
reaction := models.Reaction{ reaction := models.Reaction{
@ -190,7 +190,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db") log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
// TODO: Create corresponding activity too // TODO: Create corresponding activity too
activity := models.Activity{ activity := models.Activity{
@ -203,12 +203,12 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db") log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to commit reaction transaction to db") log.Error().Err(err).Msg("Failed to commit reaction transaction to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }
@ -217,7 +217,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
log.Debug().Msg("Received follow request") log.Debug().Msg("Received follow request")
objectId, ok := object["id"].(string) objectId, ok := object["id"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -229,7 +229,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
actorApId, ok := object["actor"].(string) actorApId, ok := object["actor"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -241,7 +241,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
targetUrl, ok := object["object"].(string) targetUrl, ok := object["object"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -253,7 +253,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
followedMatch := objectIdRegex.FindStringSubmatch(targetUrl) followedMatch := objectIdRegex.FindStringSubmatch(targetUrl)
if len(followedMatch) != 2 { if len(followedMatch) != 2 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -267,18 +267,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
followed, err := dbgen.User.Where(dbgen.User.ID.Eq(followedId)).First() followed, err := dbgen.User.Where(dbgen.User.ID.Eq(followedId)).First()
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
log.Error().Err(err).Str("target-id", followedId).Msg("Failed to get account from db") log.Error().Err(err).Str("target-id", followedId).Msg("Failed to get account from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId) follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to import following account") log.Error().Err(err).Msg("Failed to import following account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
u2u := dbgen.UserToUserRelation u2u := dbgen.UserToUserRelation
@ -296,7 +296,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
Str("follower", follower.ID). Str("follower", follower.ID).
Str("followed", followedId). Str("followed", followedId).
Msg("Failed to count follow relations") Msg("Failed to count follow relations")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if followRelations > 0 { if followRelations > 0 {
@ -312,7 +312,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request") log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
activity := models.Activity{ activity := models.Activity{
@ -325,13 +325,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity") log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to commit follow activity transaction") log.Error().Err(err).Msg("Failed to commit follow activity transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if !followed.RestrictedFollow { if !followed.RestrictedFollow {
@ -340,7 +340,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Msg("Failed to update follow to confirmed") log.Error().Err(err).Msg("Failed to update follow to confirmed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
acceptActivity := models.Activity{ acceptActivity := models.Activity{
@ -353,13 +353,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Msg("Failed to store accept activity in db") log.Error().Err(err).Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to commit follow accept to db") log.Error().Err(err).Msg("Failed to commit follow accept to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
go func() { go func() {
@ -402,7 +402,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r) log := hlog.FromRequest(r)
rawTarget, ok := object["object"] rawTarget, ok := object["object"]
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -422,7 +422,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string) objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows // TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" { if !ok || objType != "Follow" {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -434,7 +434,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
targetObjectId, ok = target["id"].(string) targetObjectId, ok = target["id"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -445,7 +445,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
return return
} }
default: default:
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -457,7 +457,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId) internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 { if len(internalIdMatch) != 2 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -471,7 +471,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First() followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
@ -479,7 +479,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to get target follow activity from db") Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64)) relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -490,7 +490,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done // No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
@ -499,7 +499,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to update follow status to confirmed follow") Msg("Failed to update follow status to confirmed follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
activity := models.Activity{ activity := models.Activity{
@ -515,7 +515,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to store accept activity in db") Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
@ -524,7 +524,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to commit accept transaction") Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} }
@ -534,7 +534,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r) log := hlog.FromRequest(r)
rawTarget, ok := object["object"] rawTarget, ok := object["object"]
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -554,7 +554,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string) objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows // TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" { if !ok || objType != "Follow" {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -566,7 +566,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
targetObjectId, ok = target["id"].(string) targetObjectId, ok = target["id"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -577,7 +577,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
return return
} }
default: default:
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -589,7 +589,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
} }
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId) internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 { if len(internalIdMatch) != 2 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -603,7 +603,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First() followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
@ -611,7 +611,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to get target follow activity from db") Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64)) relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -621,7 +621,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done // No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
@ -630,7 +630,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to delete follow status") Msg("Failed to delete follow status")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
_, err = tx.Activity.Where( _, err = tx.Activity.Where(
@ -641,7 +641,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Msg("Failed to delete accept for later rejected follow") log.Error().Err(err).Msg("Failed to delete accept for later rejected follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
activity := models.Activity{ activity := models.Activity{
@ -657,7 +657,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to store accept activity in db") Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
@ -666,7 +666,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("target-id", internalId). Str("target-id", internalId).
Msg("Failed to commit accept transaction") Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} }
@ -680,7 +680,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Any("raw", object). Any("raw", object).
Msg("Failed to marshal create activity to proper type") Msg("Failed to marshal create activity to proper type")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
actingUser, err := activitypub.ImportRemoteAccountByAPUrl(activity.Actor) actingUser, err := activitypub.ImportRemoteAccountByAPUrl(activity.Actor)
@ -689,7 +689,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Str("actor", activity.Actor). Str("actor", activity.Actor).
Msg("Failed to import remote actor for note") Msg("Failed to import remote actor for note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
switch val := activity.Object.(type) { switch val := activity.Object.(type) {
@ -697,18 +697,18 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
actor, err := dbgen.User.GetById(r.PathValue("id")) actor, err := dbgen.User.GetById(r.PathValue("id"))
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to get local actor for importing targeted note") log.Error().Err(err).Msg("Failed to get local actor for importing targeted note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
_, err = activitypub.ImportRemoteNote(val, actor) _, err = activitypub.ImportRemoteNote(val, actor)
if err != nil { if err != nil {
log.Error().Err(err).Str("note-url", val).Msg("Failed to import remote note that landed as id in the inbox") log.Error().Err(err).Str("note-url", val).Msg("Failed to import remote note that landed as id in the inbox")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
return return
case map[string]any: case map[string]any:
default: default:
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -733,11 +733,11 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err). Err(err).
Any("raw", activity.Object). Any("raw", activity.Object).
Msg("Failed to unmarshal create object into note") Msg("Failed to unmarshal create object into note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if objectNote.Type != "Note" { if objectNote.Type != "Note" {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -774,7 +774,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note in db") log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
createActivity := models.Activity{ createActivity := models.Activity{
@ -787,13 +787,13 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note create activity in db") log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note create activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Any("note", dbNote).Msg("Failed to submit note creation in db") log.Error().Err(err).Any("note", dbNote).Msg("Failed to submit note creation in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} }

View file

@ -17,7 +17,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
_ = object["id"].(string) _ = object["id"].(string)
_, ok := object["actor"].(string) _, ok := object["actor"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -29,7 +29,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
} }
rawTarget, ok := object["object"] rawTarget, ok := object["object"]
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -49,7 +49,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
case map[string]any: case map[string]any:
objType, ok := target["type"].(string) objType, ok := target["type"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -62,7 +62,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
targetObjectType = objType targetObjectType = objType
targetObjectId, ok = target["id"].(string) targetObjectId, ok = target["id"].(string)
if !ok { if !ok {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -73,7 +73,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
return return
} }
default: default:
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-request-data", "/errors/bad-request-data",
@ -92,7 +92,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
log.Error(). log.Error().
Str("undo-target-type", targetObjectType). Str("undo-target-type", targetObjectType).
Msg("Unknown/unimplemented undo target type") Msg("Unknown/unimplemented undo target type")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }
@ -109,7 +109,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err). Err(err).
Str("activity-id", targetId). Str("activity-id", targetId).
Msg("Error while looking for like activity") Msg("Error while looking for like activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
reactionId := uint(other.Must(strconv.ParseUint(act.ObjectId, 10, 64))) reactionId := uint(other.Must(strconv.ParseUint(act.ObjectId, 10, 64)))
@ -123,7 +123,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err). Err(err).
Str("activity-id", targetId). Str("activity-id", targetId).
Msg("Error while looking for find activity") Msg("Error while looking for find activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
tx := dbgen.Q.Begin() tx := dbgen.Q.Begin()
@ -131,7 +131,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
if err != nil { if err != nil {
_ = tx.Rollback() _ = tx.Rollback()
log.Error().Err(err).Str("activity-id", act.Id).Msg("Failed to delete activity on undo") log.Error().Err(err).Str("activity-id", act.Id).Msg("Failed to delete activity on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
_, err = tx.Reaction.Where(dbgen.Reaction.ID.Eq(reaction.ID)).Delete() _, err = tx.Reaction.Where(dbgen.Reaction.ID.Eq(reaction.ID)).Delete()
@ -141,13 +141,13 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
Err(err). Err(err).
Uint("reaction-id", reaction.ID). Uint("reaction-id", reaction.ID).
Msg("Failed to delete reaction on undo") Msg("Failed to delete reaction on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to delete reaction and activity") log.Error().Err(err).Msg("Failed to delete reaction and activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }
@ -164,7 +164,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err). Err(err).
Str("activity-id", targetId). Str("activity-id", targetId).
Msg("Error while looking for follow activity") Msg("Error while looking for follow activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
relationId := other.Must(strconv.ParseUint(act.ObjectId, 10, 64)) relationId := other.Must(strconv.ParseUint(act.ObjectId, 10, 64))
@ -176,7 +176,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err). Err(err).
Str("activity-id", act.Id). Str("activity-id", act.Id).
Msg("Failed to delete follow activity on undo") Msg("Failed to delete follow activity on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
// Delete all activities that reference the follow activity (so accept/reject if exists) // Delete all activities that reference the follow activity (so accept/reject if exists)
@ -187,7 +187,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Err(err). Err(err).
Str("activity-id", act.Id). Str("activity-id", act.Id).
Msg("Failed to delete accept/reject activity for follow on undo") Msg("Failed to delete accept/reject activity for follow on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
_, err = tx.UserToUserRelation.Where(dbgen.UserToUserRelation.ID.Eq(relationId)).Delete() _, err = tx.UserToUserRelation.Where(dbgen.UserToUserRelation.ID.Eq(relationId)).Delete()
@ -198,12 +198,12 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
Str("activity-id", act.Id). Str("activity-id", act.Id).
Uint64("relation-id", relationId). Uint64("relation-id", relationId).
Msg("Failed to delete user-to-user relation for follow on undo") Msg("Failed to delete user-to-user relation for follow on undo")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to delete reaction and activity") log.Error().Err(err).Msg("Failed to delete reaction and activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }

View file

@ -51,25 +51,25 @@ func objectNote(w http.ResponseWriter, r *http.Request) {
note, err := NoteFromStorage(r.Context(), id) note, err := NoteFromStorage(r.Context(), id)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
note.Context = activitypub.BaseLdContext note.Context = activitypub.BaseLdContext
data, err := json.Marshal(note) data, err := json.Marshal(note)
if err != nil { if err != nil {
log.Error().Err(err).Any("activity", note).Msg("Failed to marshal create activity") log.Error().Err(err).Any("activity", note).Msg("Failed to marshal create activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
default: default:
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Error().Err(err).Msg("Connection failed, restart attempt started") log.Error().Err(err).Msg("Connection failed, restart attempt started")
} else { } else {
log.Error().Err(err).Msg("Failed to get create activity from db") log.Error().Err(err).Msg("Failed to get create activity from db")
} }
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
} }
} }

View file

@ -63,7 +63,14 @@ func users(w http.ResponseWriter, r *http.Request) {
Preload(dbgen.User.BeingTypes). Preload(dbgen.User.BeingTypes).
First() First()
if err != nil { if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -146,11 +153,11 @@ func users(w http.ResponseWriter, r *http.Request) {
encoded, err := json.Marshal(data) encoded, err := json.Marshal(data)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to marshal response") log.Error().Err(err).Msg("Failed to marshal response")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(encoded)) _, _ = fmt.Fprint(w, string(encoded))
} }
func userFollowing(w http.ResponseWriter, r *http.Request) { func userFollowing(w http.ResponseWriter, r *http.Request) {
@ -160,11 +167,11 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId) exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil { if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists") log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if !exists { if !exists {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
} }
apUrl := activitypub.UserIdToApUrl(userId) apUrl := activitypub.UserIdToApUrl(userId)
@ -172,7 +179,7 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
followingCount, err := dbgen.UserToUserRelation.CountFollowingForId(userId) followingCount, err := dbgen.UserToUserRelation.CountFollowingForId(userId)
if err != nil { if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get following count") log.Error().Err(err).Str("id", userId).Msg("Failed to get following count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if pageNrStr == "" { if pageNrStr == "" {
@ -186,13 +193,13 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col) data, err = json.Marshal(col)
if err != nil { if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal following collection page") log.Error().Err(err).Any("raw", data).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} else { } else {
pageNr, err := strconv.Atoi(pageNrStr) pageNr, err := strconv.Atoi(pageNrStr)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-page", "/errors/bad-page",
@ -207,12 +214,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
links, err := dbgen.UserToUserRelation.GetFollowingApLinksPagedForId(userId, pageNr) links, err := dbgen.UserToUserRelation.GetFollowingApLinksPagedForId(userId, pageNr)
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id") log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
page := collectionPageOut{ page := collectionPageOut{
@ -231,12 +238,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page) data, err = json.Marshal(page)
if err != nil { if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal following collection page") log.Error().Err(err).Any("raw", page).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} }
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
} }
func userFollowers(w http.ResponseWriter, r *http.Request) { func userFollowers(w http.ResponseWriter, r *http.Request) {
@ -246,12 +253,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId) exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil { if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists") log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if !exists { if !exists {
log.Debug().Str("id", userId).Msg("user not found") log.Debug().Str("id", userId).Msg("user not found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
} }
apUrl := activitypub.UserIdToApUrl(userId) apUrl := activitypub.UserIdToApUrl(userId)
@ -259,7 +266,7 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
followersCount, err := dbgen.UserToUserRelation.CountFollowersForId(userId) followersCount, err := dbgen.UserToUserRelation.CountFollowersForId(userId)
if err != nil { if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get followers count") log.Error().Err(err).Str("id", userId).Msg("Failed to get followers count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
if pageNrStr == "" { if pageNrStr == "" {
@ -273,13 +280,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col) data, err = json.Marshal(col)
if err != nil { if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal followers collection page") log.Error().Err(err).Any("raw", data).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} else { } else {
pageNr, err := strconv.Atoi(pageNrStr) pageNr, err := strconv.Atoi(pageNrStr)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-page", "/errors/bad-page",
@ -295,12 +302,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
switch err { switch err {
case gorm.ErrRecordNotFound: case gorm.ErrRecordNotFound:
log.Debug().Msg("No followers found") log.Debug().Msg("No followers found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return return
case nil: case nil:
default: default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id") log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
page := collectionPageOut{ page := collectionPageOut{
@ -319,13 +326,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page) data, err = json.Marshal(page)
if err != nil { if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal followers collection page") log.Error().Err(err).Any("raw", page).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) _ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return return
} }
} }
log.Debug().Bytes("body", data).Msg("Sending collection(page) out") log.Debug().Bytes("body", data).Msg("Sending collection(page) out")
w.Header().Add("Content-Type", "application/activity+json") w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data)) _, _ = fmt.Fprint(w, string(data))
} }
/* /*
@ -354,7 +361,7 @@ var chain goap.BaseApChain = &goap.EmptyBaseObject{}
// data, err := goap.Compact(chain, baseLdContext) // data, err := goap.Compact(chain, baseLdContext)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to marshal ap chain") log.Error().Err(err).Msg("Failed to marshal ap chain")
webutils.ProblemDetailsStatusOnly(w, 500) _ = webutils.ProblemDetailsStatusOnly(w, 500)
return return
} }
*/ */

View file

@ -27,7 +27,7 @@ func BuildApiRouter() http.Handler {
), ),
) )
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "in api") _, _ = fmt.Fprint(w, "in api")
}) })
return router return router
} }

View file

@ -35,7 +35,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
requestedResource := r.FormValue("resource") requestedResource := r.FormValue("resource")
matches := webfingerResourceRegex.FindStringSubmatch(requestedResource) matches := webfingerResourceRegex.FindStringSubmatch(requestedResource)
if len(matches) == 0 { if len(matches) == 0 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/webfinger-bad-resource", "/errors/webfinger-bad-resource",
@ -56,16 +56,16 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
// Fail if requested user is a different domain // Fail if requested user is a different domain
// TODO: Decide whether to include the info that it's a different domain // TODO: Decide whether to include the info that it's a different domain
if domain != config.GlobalConfig.General.GetFullDomain() { if domain != config.GlobalConfig.General.GetFullDomain() {
webutils.ProblemDetailsStatusOnly(w, 404) _ = webutils.ProblemDetailsStatusOnly(w, 404)
return return
} }
user, err := dbgen.User.GetByUsername(username) user, err := dbgen.User.GetByUsername(username)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
webutils.ProblemDetailsStatusOnly(w, 404) _ = webutils.ProblemDetailsStatusOnly(w, 404)
} else { } else {
// Fail the request, then attempt to reconnect // Fail the request, then attempt to reconnect
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -101,7 +101,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
}, },
}, },
} }
webutils.SendJson(w, &data) _ = webutils.SendJson(w, &data)
} }
func NodeInfoOverview(w http.ResponseWriter, r *http.Request) { func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
@ -117,7 +117,7 @@ func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
}, },
}, },
} }
webutils.SendJson(w, data) _ = webutils.SendJson(w, data)
} }
func NodeInfo21(w http.ResponseWriter, r *http.Request) { func NodeInfo21(w http.ResponseWriter, r *http.Request) {
@ -125,7 +125,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
log := hlog.FromRequest(r) log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true), u.ServerId.Eq(1)).Count() userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true), u.ServerId.Eq(1)).Count()
if err != nil { if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -136,7 +143,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
n := dbgen.Note n := dbgen.Note
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count() noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
if err != nil { if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -169,7 +183,7 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
LocalComments: 0}, LocalComments: 0},
Metadata: map[string]any{}, Metadata: map[string]any{},
} }
webutils.SendJson(w, data) _ = webutils.SendJson(w, data)
} }
func NodeInfo20(w http.ResponseWriter, r *http.Request) { func NodeInfo20(w http.ResponseWriter, r *http.Request) {
@ -177,7 +191,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
log := hlog.FromRequest(r) log := hlog.FromRequest(r)
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).Count() userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).Count()
if err != nil { if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -188,7 +209,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
n := dbgen.Note n := dbgen.Note
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count() noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
if err != nil { if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil) _ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) { if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started") log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else { } else {
@ -221,5 +249,5 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
Metadata: map[string]any{}, Metadata: map[string]any{},
} }
webutils.SendJson(w, data) _ = webutils.SendJson(w, data)
} }

View file

@ -21,6 +21,6 @@ func errorTypeHandler(w http.ResponseWriter, r *http.Request) {
if description, ok := errorDescriptions[errName]; ok { if description, ok := errorDescriptions[errName]; ok {
_, _ = fmt.Fprint(w, description) _, _ = fmt.Fprint(w, description)
} else { } else {
webutils.ProblemDetailsStatusOnly(w, 404) _ = webutils.ProblemDetailsStatusOnly(w, 404)
} }
} }

View file

@ -80,7 +80,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawDate := r.Header.Get("Date") rawDate := r.Header.Get("Date")
date, err := http.ParseTime(rawDate) date, err := http.ParseTime(rawDate)
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusBadRequest, http.StatusBadRequest,
"/errors/bad-date", "/errors/bad-date",
@ -91,7 +91,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
return return
} }
if time.Since(date) > time.Hour+time.Minute*5 { if time.Since(date) > time.Hour+time.Minute*5 {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -105,7 +105,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
if signatureHeader == "" { if signatureHeader == "" {
log.Debug(). log.Debug().
Msg("Received AP request without signature header where one is required") Msg("Received AP request without signature header where one is required")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -123,7 +123,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
log.Debug(). log.Debug().
Str("header", signatureHeader). Str("header", signatureHeader).
Msg("Received signature with invalid pattern") Msg("Received signature with invalid pattern")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -143,7 +143,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawAlgorithm2 := match[4] rawAlgorithm2 := match[4]
signature, err := base64.StdEncoding.DecodeString(match[5]) signature, err := base64.StdEncoding.DecodeString(match[5])
if err != nil { if err != nil {
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -167,7 +167,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
_, err = url.Parse(rawKeyId) _, err = url.Parse(rawKeyId)
if err != nil { if err != nil {
log.Debug().Err(err).Msg("Key id is not an url") log.Debug().Err(err).Msg("Key id is not an url")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -184,7 +184,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
requestingActor, err := getRequestingActor(rawKeyId) requestingActor, err := getRequestingActor(rawKeyId)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to get requesting actor") log.Error().Err(err).Msg("Failed to get requesting actor")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -206,7 +206,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
rawKey, err := x509.ParsePKIXPublicKey(requestingActor.PublicKeyRsa) rawKey, err := x509.ParsePKIXPublicKey(requestingActor.PublicKeyRsa)
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Failed to parse public key of requesting actor") log.Warn().Err(err).Msg("Failed to parse public key of requesting actor")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -220,7 +220,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
key, ok = rawKey.(*rsa.PublicKey) key, ok = rawKey.(*rsa.PublicKey)
if !ok { if !ok {
log.Warn().Msg("Received public key is not rsa") log.Warn().Msg("Received public key is not rsa")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",
@ -235,7 +235,7 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
err = rsa.VerifyPKCS1v15(key, crypto.SHA256, hash[:], []byte(signature)) err = rsa.VerifyPKCS1v15(key, crypto.SHA256, hash[:], []byte(signature))
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Signature verification failed") log.Warn().Err(err).Msg("Signature verification failed")
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnauthorized, http.StatusUnauthorized,
"/errors/invalid-auth-signature", "/errors/invalid-auth-signature",

View file

@ -19,7 +19,7 @@ func BuildMimetypeCheck(acceptedMimetypes []string) webutils.HandlerBuilder {
} }
} }
// Requested mimtype not in list of accepted ones, failing request with note // Requested mimtype not in list of accepted ones, failing request with note
webutils.ProblemDetails( _ = webutils.ProblemDetails(
w, w,
http.StatusUnsupportedMediaType, http.StatusUnsupportedMediaType,
"/errors/bad-accept-mime-type", "/errors/bad-accept-mime-type",

View file

@ -24,7 +24,7 @@ func SignRequest(r *http.Request, keyId string, privateKeyBytes, postBody []byte
} else { } else {
headers.Set("Date", time.Now().UTC().Format(http.TimeFormat)) headers.Set("Date", time.Now().UTC().Format(http.TimeFormat))
} }
applyBodyHash(headers, postBody) _ = applyBodyHash(headers, postBody)
// Filter for only the date, host, digest and request-target headers // Filter for only the date, host, digest and request-target headers
var signedString string var signedString string
var usedHeaders []string var usedHeaders []string

View file

@ -21,7 +21,7 @@ func TestSignRequest(t *testing.T) {
func Test_applyBodyHash_WithBody(t *testing.T) { func Test_applyBodyHash_WithBody(t *testing.T) {
var headers = make(http.Header, 0) var headers = make(http.Header, 0)
digest := "SHA-256=" + string(testBodyHash) digest := "SHA-256=" + string(testBodyHash)
applyBodyHash(headers, []byte(testBody)) _ = applyBodyHash(headers, []byte(testBody))
headerDigest := headers.Get("Digest") headerDigest := headers.Get("Digest")
if headerDigest != digest { if headerDigest != digest {
t.Fatalf("digests didn't match: header \"%v\" != precalc \"%v\"", headerDigest, digest) t.Fatalf("digests didn't match: header \"%v\" != precalc \"%v\"", headerDigest, digest)