From 67969981241f43002ab343659e355d897dbe3e15 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Fri, 25 Feb 2022 15:22:52 -0800 Subject: [PATCH] Remove unnecessary var data in log messages. Closes #1640 --- activitypub/controllers/webfinger.go | 2 +- controllers/controllers.go | 2 -- controllers/logo.go | 2 +- core/data/webhooks.go | 8 ++++---- core/storageproviders/s3Storage.go | 5 +---- core/user/externalAPIUser.go | 17 ++++++----------- router/middleware/auth.go | 2 +- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/activitypub/controllers/webfinger.go b/activitypub/controllers/webfinger.go index 04e18fd65..30a4bb6a7 100644 --- a/activitypub/controllers/webfinger.go +++ b/activitypub/controllers/webfinger.go @@ -38,7 +38,7 @@ func WebfingerHandler(w http.ResponseWriter, r *http.Request) { if _, valid := data.GetFederatedInboxMap()[user]; !valid { // User is not valid w.WriteHeader(http.StatusNotFound) - log.Debugln("webfinger request rejected for user:", user) + log.Debugln("webfinger request rejected") return } diff --git a/controllers/controllers.go b/controllers/controllers.go index 4d5e26b3a..fea119656 100644 --- a/controllers/controllers.go +++ b/controllers/controllers.go @@ -16,8 +16,6 @@ func InternalErrorHandler(w http.ResponseWriter, err error) { return } - log.Errorln(err) - w.WriteHeader(http.StatusInternalServerError) if err := json.NewEncoder(w).Encode(j{"error": err.Error()}); err != nil { InternalErrorHandler(w, err) diff --git a/controllers/logo.go b/controllers/logo.go index 149c8dc98..6d4cd0bef 100644 --- a/controllers/logo.go +++ b/controllers/logo.go @@ -72,7 +72,7 @@ func GetCompatibleLogo(w http.ResponseWriter, r *http.Request) { referrer = "an external site" } if !_hasWarnedSVGLogo { - log.Warnf("%s requested your logo. because many social networks do not support SVGs we returned a placeholder instead. change your current logo to a png or jpeg to be most compatible with external social networking sites.", referrer) + log.Warnf("an external site requested your logo. because many social networks do not support SVGs we returned a placeholder instead. change your current logo to a png or jpeg to be most compatible with external social networking sites.") _hasWarnedSVGLogo = true } } diff --git a/core/data/webhooks.go b/core/data/webhooks.go index 53a2fc9e0..2ae09885b 100644 --- a/core/data/webhooks.go +++ b/core/data/webhooks.go @@ -18,7 +18,7 @@ func createWebhooksTable() { "url" string NOT NULL, "events" TEXT NOT NULL, "timestamp" DATETIME DEFAULT CURRENT_TIMESTAMP, - "last_used" DATETIME + "last_used" DATETIME );` stmt, err := _db.Prepare(createTableSQL) @@ -33,7 +33,7 @@ func createWebhooksTable() { // InsertWebhook will add a new webhook to the database. func InsertWebhook(url string, events []models.EventType) (int, error) { - log.Traceln("Adding new webhook:", url) + log.Traceln("Adding new webhook") eventsString := strings.Join(events, ",") @@ -66,7 +66,7 @@ func InsertWebhook(url string, events []models.EventType) (int, error) { // DeleteWebhook will delete a webhook from the database. func DeleteWebhook(id int) error { - log.Traceln("Deleting webhook:", id) + log.Traceln("Deleting webhook") tx, err := _db.Begin() if err != nil { @@ -109,7 +109,7 @@ func GetWebhooksForEvent(event models.EventType) []models.Webhook { FROM split WHERE rest <> '') SELECT id, url, event - FROM split + FROM split WHERE event <> '' ) AS webhook WHERE event IS "` + event + `"` diff --git a/core/storageproviders/s3Storage.go b/core/storageproviders/s3Storage.go index 251ee2e21..269dfdecd 100644 --- a/core/storageproviders/s3Storage.go +++ b/core/storageproviders/s3Storage.go @@ -162,15 +162,13 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) { } response, err := s.uploader.Upload(uploadInput) - if err != nil { - log.Traceln("error uploading:", filePath, err.Error()) + log.Traceln("error uploading segment", err.Error()) if retryCount < 4 { log.Traceln("Retrying...") return s.Save(filePath, retryCount+1) } - log.Warnln("Giving up on", filePath, err) return "", fmt.Errorf("Giving up on %s", filePath) } @@ -192,7 +190,6 @@ func (s *S3Storage) connectAWS() *session.Session { S3ForcePathStyle: aws.Bool(s.s3ForcePathStyle), }, ) - if err != nil { log.Panicln(err) } diff --git a/core/user/externalAPIUser.go b/core/user/externalAPIUser.go index 20f3732b8..f4323232e 100644 --- a/core/user/externalAPIUser.go +++ b/core/user/externalAPIUser.go @@ -42,7 +42,7 @@ var validAccessTokenScopes = []string{ // InsertExternalAPIUser will add a new API user to the database. func InsertExternalAPIUser(token string, name string, color int, scopes []string) error { - log.Traceln("Adding new API user:", name) + log.Traceln("Adding new API user") _datastore.DbLock.Lock() defer _datastore.DbLock.Unlock() @@ -55,7 +55,6 @@ func InsertExternalAPIUser(token string, name string, color int, scopes []string return err } stmt, err := tx.Prepare("INSERT INTO users(id, access_token, display_name, display_color, scopes, type, previous_names) values(?, ?, ?, ?, ?, ?, ?)") - if err != nil { return err } @@ -74,7 +73,7 @@ func InsertExternalAPIUser(token string, name string, color int, scopes []string // DeleteExternalAPIUser will delete a token from the database. func DeleteExternalAPIUser(token string) error { - log.Traceln("Deleting access token:", token) + log.Traceln("Deleting access token") _datastore.DbLock.Lock() defer _datastore.DbLock.Unlock() @@ -84,7 +83,6 @@ func DeleteExternalAPIUser(token string) error { return err } stmt, err := tx.Prepare("UPDATE users SET disabled_at = ? WHERE access_token = ?") - if err != nil { return err } @@ -113,7 +111,7 @@ func GetExternalAPIUserForAccessTokenAndScope(token string, scope string) (*Exte // so we can efficiently find if a token supports a single scope. // This is SQLite specific, so if we ever support other database // backends we need to support other methods. - var query = `SELECT id, access_token, scopes, display_name, display_color, created_at, last_used FROM ( + query := `SELECT id, access_token, scopes, display_name, display_color, created_at, last_used FROM ( WITH RECURSIVE split(id, access_token, scopes, display_name, display_color, created_at, last_used, disabled_at, scope, rest) AS ( SELECT id, access_token, scopes, display_name, display_color, created_at, last_used, disabled_at, '', scopes || ',' FROM users UNION ALL @@ -122,8 +120,8 @@ func GetExternalAPIUserForAccessTokenAndScope(token string, scope string) (*Exte substr(rest, instr(rest, ',')+1) FROM split WHERE rest <> '') - SELECT id, access_token, scopes, display_name, display_color, created_at, last_used, disabled_at, scope - FROM split + SELECT id, access_token, scopes, display_name, display_color, created_at, last_used, disabled_at, scope + FROM split WHERE scope <> '' ORDER BY access_token, scope ) AS token WHERE token.access_token = ? AND token.scope = ?` @@ -141,7 +139,6 @@ func GetIntegrationNameForAccessToken(token string) *string { var name string err := row.Scan(&name) - if err != nil { log.Warnln(err) return nil @@ -153,7 +150,7 @@ func GetIntegrationNameForAccessToken(token string) *string { // GetExternalAPIUser will return all access tokens. func GetExternalAPIUser() ([]ExternalAPIUser, error) { //nolint // Get all messages sent within the past day - var query = "SELECT id, access_token, display_name, display_color, scopes, created_at, last_used FROM users WHERE type IS 'API' AND disabled_at IS NULL" + query := "SELECT id, access_token, display_name, display_color, scopes, created_at, last_used FROM users WHERE type IS 'API' AND disabled_at IS NULL" rows, err := _datastore.DB.Query(query) if err != nil { @@ -173,7 +170,6 @@ func SetExternalAPIUserAccessTokenAsUsed(token string) error { return err } stmt, err := tx.Prepare("UPDATE users SET last_used = CURRENT_TIMESTAMP WHERE access_token = ?") - if err != nil { return err } @@ -256,7 +252,6 @@ func HasValidScopes(scopes []string) bool { for _, scope := range scopes { _, foundInSlice := utils.FindInSlice(validAccessTokenScopes, scope) if !foundInSlice { - log.Errorln("Invalid scope", scope) return false } } diff --git a/router/middleware/auth.go b/router/middleware/auth.go index 7f1a10832..96a8af61f 100644 --- a/router/middleware/auth.go +++ b/router/middleware/auth.go @@ -41,7 +41,7 @@ func RequireAdminAuth(handler http.HandlerFunc) http.HandlerFunc { if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(username)) != 1 || subtle.ConstantTimeCompare([]byte(pass), []byte(password)) != 1 { w.Header().Set("WWW-Authenticate", `Basic realm="`+realm+`"`) http.Error(w, "Unauthorized", http.StatusUnauthorized) - log.Debugln("Failed authentication for", r.URL.Path, "from", r.RemoteAddr, r.UserAgent()) + log.Debugln("Failed admin authentication") return }