-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9397799
commit b92aab5
Showing
26 changed files
with
409 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/deepfence/ThreatMapper/deepfence_server/model" | ||
"github.com/deepfence/ThreatMapper/deepfence_utils/directory" | ||
"github.com/deepfence/ThreatMapper/deepfence_utils/log" | ||
"github.com/go-chi/chi/v5" | ||
httpext "github.com/go-playground/pkg/v5/net/http" | ||
) | ||
|
||
func (h *Handler) GetDeepfenceCommunication(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
pgClient, err := directory.PostgresClient(ctx) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(&InternalServerError{err}, w) | ||
return | ||
} | ||
|
||
messages := []model.DeepfenceCommunication{} | ||
deepfenceCommunication, err := pgClient.GetUnreadDeepfenceCommunication(ctx) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(&InternalServerError{err}, w) | ||
return | ||
} | ||
for _, m := range deepfenceCommunication { | ||
messages = append(messages, model.DeepfenceCommunication{ | ||
ID: m.ID, | ||
Title: m.Title, | ||
Content: m.Content, | ||
Link: m.Link, | ||
LinkTitle: m.LinkTitle, | ||
ButtonContent: m.ButtonContent, | ||
Read: m.Read, | ||
CreatedAt: m.CreatedAt, | ||
UpdatedAt: m.UpdatedAt, | ||
}) | ||
} | ||
err = httpext.JSON(w, http.StatusOK, messages) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
} | ||
} | ||
|
||
func (h *Handler) MarkDeepfenceCommunicationAsRead(w http.ResponseWriter, r *http.Request) { | ||
defer r.Body.Close() | ||
messageID, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(&BadDecoding{err}, w) | ||
return | ||
} | ||
req := model.DeepfenceCommunicationID{ | ||
ID: messageID, | ||
} | ||
err = h.Validator.Struct(req) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(&ValidatorError{err: err}, w) | ||
return | ||
} | ||
|
||
ctx := r.Context() | ||
pgClient, err := directory.PostgresClient(ctx) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(&InternalServerError{err}, w) | ||
return | ||
} | ||
err = pgClient.MarkDeepfenceCommunicationRead(ctx, req.ID) | ||
if err != nil { | ||
log.Error().Msgf("%v", err) | ||
h.respondError(err, w) | ||
return | ||
} | ||
w.WriteHeader(http.StatusNoContent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
deepfence_utils/postgresql/migrate/0008_create_deepfence_communication_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- +goose Up | ||
|
||
-- +goose StatementBegin | ||
CREATE TABLE public.deepfence_communication | ||
( | ||
id bigint PRIMARY KEY, | ||
title text NOT NULL, | ||
content text NOT NULL, | ||
link text NOT NULL, | ||
link_title text NOT NULL, | ||
button_content text NOT NULL, | ||
read bool DEFAULT FALSE NOT NULL, | ||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
); | ||
|
||
CREATE TRIGGER deepfence_communication_updated_at | ||
BEFORE UPDATE | ||
ON deepfence_communication | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE update_modified_column(); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
|
||
-- +goose StatementBegin | ||
DROP TABLE IF EXISTS deepfence_communication; | ||
-- +goose StatementEnd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.