Skip to content

Commit

Permalink
update #103
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed May 29, 2020
1 parent 116b7c4 commit 97adcc5
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pull_request_rules:
-
actions:
comment:
message: "Nice! PR merged successfully."
message: "Nice! PR successfully merged."
conditions:
- merged
name: "Merge Done 🚀"
8 changes: 4 additions & 4 deletions internal/app/controller/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Application(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Cluster not found %s: %s`, cn, err.Error()))

c.Status(http.StatusNotFound)
Expand All @@ -39,7 +39,7 @@ func Application(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Warn(fmt.Sprintf(`Error while fetching beetle configMap for cluster %s namespace %s: %s`, cn, ns, err.Error()))
}

Expand All @@ -55,7 +55,7 @@ func Application(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Warn(fmt.Sprintf(`Error while fetching application %s current version cluster %s namespace %s: %s`, id, cn, ns, err.Error()))
}

Expand All @@ -70,7 +70,7 @@ func Application(c *gin.Context) {
}

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Application %s not found for cluster %s namespace %s`, id, cn, ns))

c.Status(http.StatusNotFound)
Expand Down
6 changes: 3 additions & 3 deletions internal/app/controller/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Applications(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Cluster not found %s: %s`, cn, err.Error()))

c.Status(http.StatusNotFound)
Expand All @@ -37,7 +37,7 @@ func Applications(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Warn(fmt.Sprintf(`Error while fetching beetle configMap for cluster %s namespace %s: %s`, cn, ns, err.Error()))
}

Expand All @@ -54,7 +54,7 @@ func Applications(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Warn(fmt.Sprintf(`Error while fetching application %s current version cluster %s namespace %s: %s`, app.ID, cn, ns, err.Error()))
continue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Cluster(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Cluster not found %s: %s`, cn, err.Error()))

c.Status(http.StatusNotFound)
Expand All @@ -36,7 +36,7 @@ func Cluster(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))
}

Expand Down
4 changes: 2 additions & 2 deletions internal/app/controller/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Clusters(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand All @@ -38,7 +38,7 @@ func Clusters(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))
}

Expand Down
8 changes: 4 additions & 4 deletions internal/app/controller/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CreateDeployment(c *gin.Context, messages chan<- string) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Invalid request: %s`, err.Error()))

c.JSON(http.StatusBadRequest, gin.H{
Expand All @@ -48,7 +48,7 @@ func CreateDeployment(c *gin.Context, messages chan<- string) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Invalid request: %s`, err.Error()))

c.JSON(http.StatusBadRequest, gin.H{
Expand All @@ -61,7 +61,7 @@ func CreateDeployment(c *gin.Context, messages chan<- string) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Invalid request: %s`, err.Error()))

c.JSON(http.StatusBadRequest, gin.H{
Expand All @@ -76,7 +76,7 @@ func CreateDeployment(c *gin.Context, messages chan<- string) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error while connecting to database: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand Down
6 changes: 3 additions & 3 deletions internal/app/controller/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package controller

import (
"fmt"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -17,8 +16,9 @@ func HealthCheck(c *gin.Context) {
status := "ok"

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Health Status: %s`, status))
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
"status": status,
}).Info(`Health check`)

c.JSON(http.StatusOK, gin.H{
"status": status,
Expand Down
12 changes: 6 additions & 6 deletions internal/app/controller/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func GetJob(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand All @@ -37,15 +37,15 @@ func GetJob(c *gin.Context) {

if job.ID < 1 {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Job with UUID %s not found`, uuid))

c.Status(http.StatusNotFound)
return
}

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Retrieve a job with UUID %s`, uuid))

c.JSON(http.StatusOK, gin.H{
Expand All @@ -69,7 +69,7 @@ func DeleteJob(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand All @@ -82,15 +82,15 @@ func DeleteJob(c *gin.Context) {

if job.ID < 1 {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Job with UUID %s not found`, uuid))

c.Status(http.StatusNotFound)
return
}

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Deleting a job with UUID %s`, uuid))

db.DeleteJobByID(job.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Jobs(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand Down
4 changes: 2 additions & 2 deletions internal/app/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Namespace(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand All @@ -43,7 +43,7 @@ func Namespace(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/controller/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Namespaces(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

c.Status(http.StatusInternalServerError)
Expand All @@ -41,7 +41,7 @@ func Namespaces(c *gin.Context) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/app/controller/ready_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func ReadyCheck(c *gin.Context) {
status = "down"

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Ready Status: %s`, status))

c.Status(http.StatusInternalServerError)
Expand All @@ -43,11 +43,11 @@ func ReadyCheck(c *gin.Context) {
status = "down"

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Ready Status: %s`, status))

c.Status(http.StatusInternalServerError)
Expand All @@ -57,7 +57,7 @@ func ReadyCheck(c *gin.Context) {
defer db.Close()

log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Ready Status: %s`, status))

c.JSON(http.StatusOK, gin.H{
Expand Down
18 changes: 9 additions & 9 deletions internal/app/controller/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ func Worker(id int, messages <-chan string) {
deploymentRequest := model.DeploymentRequest{}

log.WithFields(log.Fields{
"CorrelationId": util.GenerateUUID4(),
"correlation_id": util.GenerateUUID4(),
}).Info(fmt.Sprintf(`Worker [%d] started`, id))

for message := range messages {
ok, err = messageObj.LoadFromJSON([]byte(message))

if !ok || err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Warn(fmt.Sprintf(`Worker [%d] received invalid message: %s`, id, message))
continue
}

log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Info(fmt.Sprintf(`Worker [%d] received: %d`, id, messageObj.Job))

db = module.Database{}
Expand All @@ -52,7 +52,7 @@ func Worker(id int, messages <-chan string) {

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Error(fmt.Sprintf(`Worker [%d] unable to connect to database: %s`, id, err.Error()))
continue
}
Expand All @@ -67,20 +67,20 @@ func Worker(id int, messages <-chan string) {

if !ok || err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Error(fmt.Sprintf(`Worker [%d] failure while executing async job [id=%d] [uuid=%s]: %s`, id, messageObj.Job, job.UUID, err.Error()))
continue
} else {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Info(fmt.Sprintf(`Worker [%d] processed async job [id=%d] [uuid=%s]`, id, messageObj.Job, job.UUID))
}

cluster, err = kubernetes.GetCluster(deploymentRequest.Cluster)

if err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Info(fmt.Sprintf(`Worker [%d] Cluster not found %s: %s`, id, deploymentRequest.Cluster, err.Error()))
continue
}
Expand All @@ -89,15 +89,15 @@ func Worker(id int, messages <-chan string) {

if !ok || err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Error(fmt.Sprintf(`Worker [%d] Unable to connect to cluster %s error: %s`, id, deploymentRequest.Cluster, err.Error()))
}

ok, err = cluster.Deploy(deploymentRequest)

if !ok || err != nil {
log.WithFields(log.Fields{
"CorrelationId": messageObj.UUID,
"correlation_id": messageObj.UUID,
}).Error(fmt.Sprintf(`Worker [%d] Unable to connect to cluster %s error: %s`, id, deploymentRequest.Cluster, err.Error()))
continue
}
Expand Down
9 changes: 6 additions & 3 deletions internal/app/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package middleware

import (
"fmt"
"net/http"
"strings"

Expand All @@ -24,8 +23,12 @@ func Auth() gin.HandlerFunc {
authToken := c.GetHeader("X-AUTH-TOKEN")
if viper.GetString("app.api.token") != "" && authToken != viper.GetString("app.api.token") {
log.WithFields(log.Fields{
"CorrelationId": c.Request.Header.Get("X-Correlation-ID"),
}).Info(fmt.Sprintf(`Unauthorized access to %s:%s with token %s`, method, path, authToken))
"correlation_id": c.Request.Header.Get("X-Correlation-ID"),
"http_method": method,
"http_path": path,
"auth_token": authToken,
}).Info(`Unauthorized access`)

c.AbortWithStatus(http.StatusUnauthorized)
}
}
Expand Down
Loading

0 comments on commit 97adcc5

Please sign in to comment.