From 809c433a309640e8eee1ae964a27fdb75115a283 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Wed, 29 May 2024 10:10:01 -0500 Subject: [PATCH] [logs] added some log tags and removed unneeded logs (#1674) * logs: removed auth logs since they crowded logs * logs: removed feed logs * logs: added log tags for workspace logs * logs: added feed tag to feed.go file * logs: added auth tag to handlers/auth.go * logs: added bounty tag to logs in handlers/bounty.go --- auth/auth.go | 7 ---- feeds/podcastindex.go | 2 -- handlers/auth.go | 14 ++++---- handlers/bounty.go | 66 +++++++++++++++++++------------------- handlers/feed.go | 26 +++++++-------- handlers/workspaces.go | 72 +++++++++++++++++++++--------------------- 6 files changed, 89 insertions(+), 98 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index b41708b28..7a80df7fc 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -39,8 +39,6 @@ func PubKeyContext(next http.Handler) http.Handler { if token == "" { token = r.Header.Get("x-jwt") } - fmt.Println("PubKeyContext Token:") - fmt.Println(token) if token == "" { fmt.Println("[auth] no token") @@ -50,8 +48,6 @@ func PubKeyContext(next http.Handler) http.Handler { isJwt := strings.Contains(token, ".") && !strings.HasPrefix(token, ".") - fmt.Println("Checking if JWT: ") - fmt.Println(isJwt) if isJwt { claims, err := DecodeJwt(token) @@ -67,14 +63,11 @@ func PubKeyContext(next http.Handler) http.Handler { return } - fmt.Println("Passed jwt check") ctx := context.WithValue(r.Context(), ContextKey, claims["pubkey"]) next.ServeHTTP(w, r.WithContext(ctx)) } else { pubkey, err := VerifyTribeUUID(token, true) - fmt.Println("Checking pubkey and error: ") - fmt.Println(pubkey) if pubkey == "" || err != nil { fmt.Println("[auth] no pubkey || err != nil") if err != nil { diff --git a/feeds/podcastindex.go b/feeds/podcastindex.go index 0f0eedcc5..a0ceeddc0 100644 --- a/feeds/podcastindex.go +++ b/feeds/podcastindex.go @@ -40,7 +40,6 @@ func EpisodeToGeneric(ep Episode, includeFeedStuff bool) Item { func PodcastToGeneric(url string, p *Podcast) (Feed, error) { items := []Item{} - // fmt.Println("P EPISODES", len(p.Episodes), p) for _, ep := range p.Episodes { items = append(items, EpisodeToGeneric(ep, false)) } @@ -80,7 +79,6 @@ func PodcastIndexHeaders() map[string]string { func ParsePodcastFeed(url string, fulltext bool) (*Feed, error) { pod, err := PodcastFeed(url, fulltext) - fmt.Println("GOT A POD!", pod) if err != nil || pod == nil { return nil, err } diff --git a/handlers/auth.go b/handlers/auth.go index 858f680a4..15f987eae 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -70,7 +70,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque } if err != nil { - fmt.Println(err) + fmt.Println("[auth]", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -78,7 +78,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque _, err = ah.db.CreateConnectionCode(codeArr) if err != nil { - fmt.Println("=> ERR create connection code", err) + fmt.Println("[auth] => ERR create connection code", err) w.WriteHeader(http.StatusBadRequest) return } @@ -131,7 +131,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { exVerify, err := auth.VerifyDerSig(sig, k1, userKey) if err != nil || !exVerify { - fmt.Println("Error signing signature") + fmt.Println("[auth] Error signing signature") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(err.Error()) return @@ -150,7 +150,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { tokenString, err := auth.EncodeJwt(userKey) if err != nil { - fmt.Println("error creating LNAUTH JWT") + fmt.Println("[auth] error creating LNAUTH JWT") w.WriteHeader(http.StatusNotAcceptable) json.NewEncoder(w).Encode(err.Error()) return @@ -174,7 +174,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { socket.Conn.WriteJSON(socketMsg) db.Store.DeleteCache(k1[0:20]) } else { - fmt.Println("Socket Error", err) + fmt.Println("[auth] Socket Error", err) } responseMsg["status"] = "OK" @@ -194,7 +194,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) { claims, err := ah.decodeJwt(token) if err != nil { - fmt.Println("Failed to parse JWT") + fmt.Println("[auth] Failed to parse JWT") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(err.Error()) return @@ -209,7 +209,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) { tokenString, err := ah.encodeJwt(pubkey) if err != nil { - fmt.Println("error creating refresh JWT") + fmt.Println("[auth] error creating refresh JWT") w.WriteHeader(http.StatusNotAcceptable) json.NewEncoder(w).Encode(err.Error()) return diff --git a/handlers/bounty.go b/handlers/bounty.go index 27e93d200..d0dc996a8 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -57,7 +57,7 @@ func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) { bounties, err := h.db.GetBountyById(bountyId) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -69,7 +69,7 @@ func (h *bountyHandler) GetNextBountyByCreated(w http.ResponseWriter, r *http.Re bounties, err := h.db.GetNextBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -80,7 +80,7 @@ func (h *bountyHandler) GetPreviousBountyByCreated(w http.ResponseWriter, r *htt bounties, err := h.db.GetPreviousBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -91,7 +91,7 @@ func (h *bountyHandler) GetWorkspaceNextBountyByCreated(w http.ResponseWriter, r bounties, err := h.db.GetNextWorkspaceBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -102,7 +102,7 @@ func (h *bountyHandler) GetWorkspacePreviousBountyByCreated(w http.ResponseWrite bounties, err := h.db.GetPreviousWorkspaceBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -127,7 +127,7 @@ func (h *bountyHandler) GetBountyByCreated(w http.ResponseWriter, r *http.Reques bounties, err := h.db.GetBountyDataByCreated(created) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) @@ -159,7 +159,7 @@ func (h *bountyHandler) GetPersonCreatedBounties(w http.ResponseWriter, r *http. bounties, err := h.db.GetCreatedBounties(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -171,7 +171,7 @@ func (h *bountyHandler) GetPersonAssignedBounties(w http.ResponseWriter, r *http bounties, err := h.db.GetAssignedBounties(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("Error", err) + fmt.Println("[bounty] Error", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -189,7 +189,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques r.Body.Close() err = json.Unmarshal(body, &bounty) if err != nil { - fmt.Println(err) + fmt.Println("[bounty]", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -253,14 +253,14 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques hasBountyRoles := h.userHasManageBountyRoles(pubKeyFromAuth, bounty.WorkspaceUuid) if !hasBountyRoles { msg := "You don't have a=the right permission ton update bounty" - fmt.Println(msg) + fmt.Println("[bounty]", msg) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(msg) return } } else { msg := "Cannot edit another user's bounty" - fmt.Println(msg) + fmt.Println("[bounty]", msg) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(msg) return @@ -284,7 +284,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques b, err := h.db.CreateOrEditBounty(bounty) if err != nil { - fmt.Println(err) + fmt.Println("[bounty]", err) w.WriteHeader(http.StatusBadRequest) return } @@ -298,7 +298,7 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -307,19 +307,19 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { pubkey := chi.URLParam(r, "pubkey") if pubkey == "" { - fmt.Println("no pubkey from route") + fmt.Println("[bounty] no pubkey from route") w.WriteHeader(http.StatusUnauthorized) return } if created == "" { - fmt.Println("no created timestamp from route") + fmt.Println("[bounty] no created timestamp from route") w.WriteHeader(http.StatusUnauthorized) return } b, err := h.db.DeleteBounty(pubkey, created) if err != nil { - fmt.Println("failed to delete bounty", err.Error()) + fmt.Println("[bounty] failed to delete bounty", err.Error()) w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode("failed to delete bounty") return @@ -470,14 +470,14 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request id, err := utils.ConvertStringToUint(idParam) if err != nil { - fmt.Println("could not parse id") + fmt.Println("[bounty] could not parse id") w.WriteHeader(http.StatusForbidden) h.m.Unlock() return } if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) h.m.Unlock() return @@ -530,7 +530,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request err = json.Unmarshal(body, &request) if err != nil { - fmt.Println(err) + fmt.Println("[bounty]", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -546,11 +546,11 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody)) req.Header.Set("x-user-token", config.RelayAuthKey) req.Header.Set("Content-Type", "application/json") - log.Printf("Making Bounty Payment: amount: %d, pubkey: %s, route_hint: %s", amount, assignee.OwnerPubKey, assignee.OwnerRouteHint) + log.Printf("[bounty] Making Bounty Payment: amount: %d, pubkey: %s, route_hint: %s", amount, assignee.OwnerPubKey, assignee.OwnerRouteHint) res, err := h.httpClient.Do(req) if err != nil { - log.Printf("Request Failed: %s", err) + log.Printf("[bounty] Request Failed: %s", err) h.m.Unlock() return } @@ -613,7 +613,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) h.m.Unlock() return @@ -630,7 +630,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ return } - log.Printf("[BountyBudgetWithdraw] Logging body: orguuid: %s, pubkey: %s, invoice: %s", request.OrgUuid, pubKeyFromAuth, request.PaymentRequest) + log.Printf("[bounty] [BountyBudgetWithdraw] Logging body: orguuid: %s, pubkey: %s, invoice: %s", request.OrgUuid, pubKeyFromAuth, request.PaymentRequest) // check if user is the admin of the workspace // or has a withdraw bounty budget role @@ -683,7 +683,7 @@ func (h *bountyHandler) NewBountyBudgetWithdraw(w http.ResponseWriter, r *http.R pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) h.m.Unlock() return @@ -760,7 +760,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR res, _ := h.httpClient.Do(req) if err != nil { - log.Printf("Request Failed: %s", err) + log.Printf("[bounty] Request Failed: %s", err) return db.InvoiceResult{}, db.InvoiceError{} } @@ -774,7 +774,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR err = json.Unmarshal(body, &invoiceErr) if err != nil { - log.Printf("Reading Invoice body failed: %s", err) + log.Printf("[bounty] Reading Invoice body failed: %s", err) return db.InvoiceResult{}, invoiceErr } @@ -785,7 +785,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR err = json.Unmarshal(body, &invoiceRes) if err != nil { - log.Printf("Reading Invoice body failed: %s", err) + log.Printf("[bounty] Reading Invoice body failed: %s", err) return invoiceRes, db.InvoiceError{} } @@ -805,7 +805,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP res, err := h.httpClient.Do(req) if err != nil { - log.Printf("Request Failed: %s", err) + log.Printf("[bounty] Request Failed: %s", err) return db.InvoicePaySuccess{}, db.InvoicePayError{} } @@ -818,7 +818,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP err = json.Unmarshal(body, &invoiceError) if err != nil { - log.Printf("Reading Invoice pay error body failed: %s", err) + log.Printf("[bounty] Reading Invoice pay error body failed: %s", err) return db.InvoicePaySuccess{}, db.InvoicePayError{} } @@ -828,7 +828,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP err = json.Unmarshal(body, &invoiceSuccess) if err != nil { - log.Printf("Reading Invoice pay success body failed: %s", err) + log.Printf("[bounty] Reading Invoice pay success body failed: %s", err) return db.InvoicePaySuccess{}, db.InvoicePayError{} } @@ -857,7 +857,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { var err error if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -896,7 +896,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { res, _ := h.httpClient.Do(req) if err != nil { - log.Printf("Request Failed: %s", err) + log.Printf("[bounty] Request Failed: %s", err) return } @@ -925,7 +925,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { // Unmarshal result keysendError := db.KeysendError{} err = json.Unmarshal(body, &keysendError) - log.Printf("Keysend Payment to %s Failed, with Error: %s", invData.UserPubkey, keysendError.Error) + log.Printf("[bounty] Keysend Payment to %s Failed, with Error: %s", invData.UserPubkey, keysendError.Error) } } // Update the invoice status diff --git a/handlers/feed.go b/handlers/feed.go index 9507c2e38..253d7c5ba 100644 --- a/handlers/feed.go +++ b/handlers/feed.go @@ -58,7 +58,7 @@ func DownloadYoutubeFeed(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &youtube_download) if err != nil { - fmt.Println(err) + fmt.Println("[feed] ", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -94,7 +94,7 @@ func DownloadYoutubeFeed(w http.ResponseWriter, r *http.Request) { func processYoutubeDownload(data []string) { stakworkKey := fmt.Sprintf("Token token=%s", os.Getenv("STAKWORK_KEY")) if stakworkKey == "" { - fmt.Println("Youtube Download Error: Stakwork key not found") + fmt.Println("[feed] Youtube Download Error: Stakwork key not found") } else { type Vars struct { YoutubeContent []string `json:"youtube_content"` @@ -128,7 +128,7 @@ func processYoutubeDownload(data []string) { buf, err := json.Marshal(body) if err != nil { - fmt.Println("Youtube error: Unable to parse message into byte buffer", err) + fmt.Println("[feed] Youtube error: Unable to parse message into byte buffer", err) return } @@ -140,14 +140,14 @@ func processYoutubeDownload(data []string) { client := &http.Client{} response, err := client.Do(request) if err != nil { - fmt.Println("Youtube Download Request Error ===", err) + fmt.Println("[feed] Youtube Download Request Error ===", err) } defer response.Body.Close() res, err := io.ReadAll(response.Body) if err != nil { - fmt.Println("Youtube Download Request Error ==", err) + fmt.Println("[feed] Youtube Download Request Error ==", err) } - fmt.Println("Youtube Download Succces ==", string(res)) + fmt.Println("[feed] Youtube Download Succces ==", string(res)) } } @@ -166,7 +166,7 @@ func GetPodcast(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) err = json.NewEncoder(w).Encode(podcast) if err != nil { - fmt.Println(err) + fmt.Println("[feed]", err) } } @@ -266,7 +266,7 @@ func getFeed(feedURL string, feedID string) (*feeds.Podcast, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("GET error:", err) + fmt.Println("[feed] GET error:", err) return nil, err } defer resp.Body.Close() @@ -275,7 +275,7 @@ func getFeed(feedURL string, feedID string) (*feeds.Podcast, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("json unmarshall error", err) + fmt.Println("[feed] json unmarshall error", err) return nil, err } @@ -308,7 +308,7 @@ func getEpisodes(feedURL string, feedID string) ([]feeds.Episode, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("GET error:", err) + fmt.Println("[feed] GET error:", err) return nil, err } defer resp.Body.Close() @@ -317,7 +317,7 @@ func getEpisodes(feedURL string, feedID string) ([]feeds.Episode, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("json unmarshall error", err) + fmt.Println("[feed] json unmarshall error", err) return nil, err } @@ -342,7 +342,7 @@ func searchPodcastIndex(term string) ([]feeds.Podcast, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("GET error:", err) + fmt.Println("[feed] GET error:", err) return nil, err } defer resp.Body.Close() @@ -351,7 +351,7 @@ func searchPodcastIndex(term string) ([]feeds.Podcast, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("json unmarshall error", err) + fmt.Println("[feed] json unmarshall error", err) return nil, err } diff --git a/handlers/workspaces.go b/handlers/workspaces.go index e6b4795dd..3c7c44e7e 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -40,7 +40,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -52,7 +52,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http err := json.Unmarshal(body, &workspace) if err != nil { - fmt.Println(err) + fmt.Println("[workspaces] ", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -60,14 +60,14 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http workspace.Name = strings.TrimSpace(workspace.Name) if len(workspace.Name) == 0 || len(workspace.Name) > 20 { - fmt.Printf("invalid workspace name %s\n", workspace.Name) + fmt.Printf("[workspaces] invalid workspace name %s\n", workspace.Name) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode("Error: workspace name must be present and should not exceed 20 character") return } if len(workspace.Description) > 120 { - fmt.Printf("invalid workspace name %s\n", workspace.Description) + fmt.Printf("[workspaces] invalid workspace name %s\n", workspace.Description) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode("Error: workspace description should not exceed 120 character") return @@ -76,9 +76,9 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http if pubKeyFromAuth != workspace.OwnerPubKey { hasRole := db.UserHasAccess(pubKeyFromAuth, workspace.Uuid, db.EditOrg) if !hasRole { - fmt.Println(pubKeyFromAuth) - fmt.Println(workspace.OwnerPubKey) - fmt.Println("mismatched pubkey") + fmt.Println("[workspaces] mismatched pubkey") + fmt.Println("[workspaces] Auth pubkey:", pubKeyFromAuth) + fmt.Println("[workspaces] OwnerPubKey:", workspace.OwnerPubKey) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode("Don't have access to Edit workspace") return @@ -104,7 +104,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http existing := oh.db.GetWorkspaceByUuid(workspace.Uuid) if existing.ID == 0 { // new! if workspace.ID != 0 { // can't try to "edit" if it does not exist already - fmt.Println("cant edit non existing") + fmt.Println("[workspaces] cant edit non existing") w.WriteHeader(http.StatusUnauthorized) return } @@ -178,13 +178,13 @@ func CreateWorkspaceUser(w http.ResponseWriter, r *http.Request) { workspace := db.DB.GetWorkspaceByUuid(workspaceUser.WorkspaceUuid) if err != nil { - fmt.Println(err) + fmt.Println("[workspaces] ", err) w.WriteHeader(http.StatusNotAcceptable) return } if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -250,7 +250,7 @@ func GetWorkspaceUser(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -284,13 +284,13 @@ func DeleteWorkspaceUser(w http.ResponseWriter, r *http.Request) { } if err != nil { - fmt.Println(err) + fmt.Println("[workspaces]", err) w.WriteHeader(http.StatusNotAcceptable) return } if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -342,7 +342,7 @@ func AddUserRoles(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(body, &roles) if err != nil { - fmt.Println(err) + fmt.Println("[workspaces]:", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -437,7 +437,7 @@ func GetUserWorkspaces(w http.ResponseWriter, r *http.Request) { userId, _ := utils.ConvertStringToUint(userIdParam) if userId == 0 { - fmt.Println("provide user id") + fmt.Println("[workspaces] provide user id") w.WriteHeader(http.StatusNotAcceptable) return } @@ -478,7 +478,7 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * userId, _ := utils.ConvertStringToUint(userIdParam) if userId == 0 { - fmt.Println("provide user id") + fmt.Println("[workspaces] provide user id") w.WriteHeader(http.StatusNotAcceptable) return } @@ -560,7 +560,7 @@ func (oh *workspaceHandler) GetWorkspaceBudget(w http.ResponseWriter, r *http.Re uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -606,7 +606,7 @@ func GetPaymentHistory(w http.ResponseWriter, r *http.Request) { uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -646,7 +646,7 @@ func (oh *workspaceHandler) PollBudgetInvoices(w http.ResponseWriter, r *http.Re uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -681,7 +681,7 @@ func GetInvoicesCount(w http.ResponseWriter, r *http.Request) { uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -697,7 +697,7 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -706,7 +706,7 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque if pubKeyFromAuth != workspace.OwnerPubKey { msg := "only workspace admin can delete an workspace" - fmt.Println(msg) + fmt.Println("[workspaces]", msg) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(msg) return @@ -714,14 +714,14 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque // Update workspace to hide and clear certain fields if err := oh.db.UpdateWorkspaceForDeletion(uuid); err != nil { - fmt.Println("Error updating workspace:", err) + fmt.Println("[workspaces] Error updating workspace:", err) w.WriteHeader(http.StatusInternalServerError) return } // Delete all users from the workspace if err := oh.db.DeleteAllUsersFromWorkspace(uuid); err != nil { - fmt.Println("Error removing users from workspace:", err) + fmt.Println("[workspaces] Error removing users from workspace:", err) w.WriteHeader(http.StatusInternalServerError) return } @@ -736,7 +736,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -747,7 +747,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque err := json.Unmarshal(body, &workspace) if err != nil { - fmt.Println(err) + fmt.Println("[workspaces]", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -755,9 +755,9 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque if pubKeyFromAuth != workspace.OwnerPubKey { hasRole := db.UserHasAccess(pubKeyFromAuth, workspace.Uuid, db.EditOrg) if !hasRole { - fmt.Println(pubKeyFromAuth) - fmt.Println(workspace.OwnerPubKey) - fmt.Println("mismatched pubkey") + fmt.Println("[workspaces] mismatched pubkey") + fmt.Println("Auth Pubkey:", pubKeyFromAuth) + fmt.Println("OwnerPubKey:", workspace.OwnerPubKey) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode("Don't have access to Edit workspace") return @@ -787,7 +787,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceRepository(w http.ResponseWrite ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -798,7 +798,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceRepository(w http.ResponseWrite err := json.Unmarshal(body, &workspaceRepo) if err != nil { - fmt.Println(err) + fmt.Println("[workspaces]", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -847,7 +847,7 @@ func (oh *workspaceHandler) GetWorkspaceRepositorByWorkspaceUuid(w http.Response ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -863,7 +863,7 @@ func (oh *workspaceHandler) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(w http.Re ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -872,7 +872,7 @@ func (oh *workspaceHandler) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(w http.Re uuid := chi.URLParam(r, "uuid") WorkspaceRepository, err := oh.db.GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(workspace_uuid, uuid) if err != nil { - fmt.Println("workspace repository not found:", err) + fmt.Println("[workspaces] workspace repository not found:", err) w.WriteHeader(http.StatusNotFound) json.NewEncoder(w).Encode(map[string]string{"error": "Repository not found"}) return @@ -888,7 +888,7 @@ func (oh *workspaceHandler) DeleteWorkspaceRepository(w http.ResponseWriter, r * pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -906,7 +906,7 @@ func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + fmt.Println("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return }