Skip to content

Commit

Permalink
quay agent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vijeyash1 committed Aug 26, 2023
1 parent a3fbfe1 commit 618b85c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
30 changes: 23 additions & 7 deletions agent/container/api/agent.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/container/cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ generate:
gin-server: true
models: true
embedded-spec: true
output: agent/container/api/agent.gen.go
output: api/agent.gen.go
9 changes: 9 additions & 0 deletions agent/container/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ paths:
'200':
description: OK

/event/quay/container:
post:
tags:
- public
summary: Post quay Container Registry webhook events
responses:
'200':
description: OK

# oapi-codegen -config ./cfg.yaml ./openapi.yaml
1 change: 1 addition & 0 deletions agent/container/pkg/handler/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (ah *APIHandler) BindRequest(r *gin.Engine) {
apiGroup.GET("/status", ah.GetStatus)
apiGroup.POST("/event/docker/hub", ah.PostEventDockerHub)
apiGroup.POST("/event/azure/container", ah.PostEventAzureContainer)
apiGroup.POST("/event/quay/container", ah.PostEventQuayContainer)
}
}

Expand Down
40 changes: 40 additions & 0 deletions agent/container/pkg/handler/quay_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package handler

import (
"encoding/json"
"io"
"log"
"net/http"

"github.com/gin-gonic/gin"
"github.com/intelops/kubviz/model"
)

func (ah *APIHandler) PostEventQuayContainer(c *gin.Context) {
defer func() {
_, _ = io.Copy(io.Discard, c.Request.Body)
_ = c.Request.Body.Close()
}()
payload, err := io.ReadAll(c.Request.Body)
if err != nil || len(payload) == 0 {
log.Printf("%v: %v", ErrReadingBody, err)
c.Status(http.StatusBadRequest)
return
}
var pushEvent model.QuayImagePushPayload
err = json.Unmarshal(payload, &pushEvent)
if err != nil {
log.Printf("%v: %v", ErrInvalidPayload, err)
c.JSON(http.StatusBadRequest, gin.H{"error": "Bad Request"})
return
}
log.Printf("Received event from Quay Container Registry: %v", pushEvent)

err = ah.conn.Publish(payload, "Quay_Container_Registry")
if err != nil {
log.Printf("%v: %v", ErrPublishToNats, err)
c.Status(http.StatusInternalServerError)
return
}
c.Status(http.StatusOK)
}
10 changes: 10 additions & 0 deletions model/quay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package model

type QuayImagePushPayload struct {
Name string `json:"name"`
Repository string `json:"repository"`
Namespace string `json:"namespace"`
DockerURL string `json:"docker_url"`
Homepage string `json:"homepage"`
UpdatedTags []string `json:"updated_tags"`
}

0 comments on commit 618b85c

Please sign in to comment.