Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debug-logs in "send-notification" #15

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/model/host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
Expand All @@ -21,3 +22,17 @@ type HostRequest struct {
Host string `json:"host"`
Stage string `json:"stage"`
}

func (h *Host) String() string {
return fmt.Sprintf(
fmt.Sprintf("Id: %s", h.Id.String()),
fmt.Sprintf("ProjectId: %s", h.ProjectId),
fmt.Sprintf("Host: %s", h.Host),
fmt.Sprintf("Stage: %s", h.Stage),
fmt.Sprintf("Verified: %s", h.VerifyToken),
fmt.Sprintf("VerifyToken: %s", h.VerifyToken),
fmt.Sprintf("UpdatedAt: %s", h.UpdatedAt),
fmt.Sprintf("CreatedAt: %s", h.CreatedAt),
fmt.Sprintf("DeletedAt: %s", h.DeletedAt),
)
}
12 changes: 12 additions & 0 deletions internal/service/domain_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,43 @@ const (
func (c *Client) SendNotification(host string, notification model.Notification) (*model.SuccessMessage, error) {
err := validateNotificationRequest(notification)
if err != nil {
log.Debug("notification-request-validation is failed; ", err.Error())
return nil, err
}

validatedHost, err := url.Parse(host)
if err != nil {
log.Debug("parse host is failed; ", err.Error())
return nil, fmt.Errorf("failed to parse host")
}

hosts, err := c.db.ListHosts(model.Host{ProjectId: notification.ProjectId})
if err != nil {
log.Error(err)
log.Debug("failed to list hosts; ", err.Error())
return nil, fmt.Errorf("failed to verify host")
}

if index := ifHostInHosts(validatedHost.Host, hosts); hosts == nil || index == -1 || !hosts[index].Verified {
log.Debug(
"failed to verify hosts; ",
fmt.Sprintf("host: %s; ", validatedHost.Host),
fmt.Sprintf("index: %d; ", index),
fmt.Sprintf("length: %d; ", len(hosts)),
fmt.Sprintf("hosts: %v", hosts),
)
return nil, fmt.Errorf("failed to verify host")
}

flows, err := c.db.ListFlows(model.Flow{ProjectId: notification.ProjectId})
if err != nil {
log.Error(err)
log.Debug("failed to list flows; ", err.Error())
return nil, fmt.Errorf("failed to list flows")
}

if flows == nil || len(flows) == 0 {
log.Debug("failed to list flows; ", "there are no flows; ", flows)
return nil, fmt.Errorf("failed to list flows")
}

Expand Down