-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from intelops/jfrogcontainer
Jfrogcontainer-registry
- Loading branch information
Showing
10 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/intelops/kubviz/model" | ||
) | ||
|
||
var ErrInvalidPayloads = errors.New("invalid or malformed jfrog Container Registry webhook payload") | ||
|
||
func (ah *APIHandler) PostEventJfrogContainer(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.JfrogContainerPushEventPayload | ||
err = json.Unmarshal(payload, &pushEvent) | ||
if err != nil { | ||
log.Printf("%v: %v", ErrInvalidPayloads, err) | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "Bad Request"}) | ||
return | ||
} | ||
|
||
log.Printf("Received event from jfrog Container Registry: %v", pushEvent) | ||
|
||
err = ah.conn.Publish(payload, "Jfrog_Container_Registry") | ||
if err != nil { | ||
log.Printf("%v: %v", ErrPublishToNats, err) | ||
c.Status(http.StatusInternalServerError) | ||
return | ||
} | ||
c.Status(http.StatusOK) | ||
} |
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
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,18 @@ | ||
package model | ||
|
||
type JfrogContainerPushEventPayload struct { | ||
Domain string `json:"domain"` | ||
EventType string `json:"event_type"` | ||
Data struct { | ||
RepoKey string `json:"repo_key"` | ||
Path string `json:"path"` | ||
Name string `json:"name"` | ||
SHA256 string `json:"sha256"` | ||
Size int32 `json:"size"` | ||
ImageName string `json:"image_name"` | ||
Tag string `json:"tag"` | ||
} `json:"data"` | ||
SubscriptionKey string `json:"subscription_key"` | ||
JPDOrigin string `json:"jpd_origin"` | ||
Source string `json:"source"` | ||
} |