-
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.
- Loading branch information
Showing
8 changed files
with
269 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
package handler | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
// parse errors | ||
var ( | ||
ErrReadingBody = errors.New("error reading the request body") | ||
ErrPublishToNats = errors.New("error while publishing to nats") | ||
) | ||
|
||
func (ah *APIHandler) PostEventDockerHub(w http.ResponseWriter, r *http.Request) { | ||
event, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
log.Printf("Event body read failed: %v", err) | ||
defer func() { | ||
_, _ = io.Copy(io.Discard, r.Body) | ||
_ = r.Body.Close() | ||
}() | ||
payload, err := io.ReadAll(r.Body) | ||
if err != nil || len(payload) == 0 { | ||
log.Printf("%v: %v", ErrReadingBody, err) | ||
return | ||
} | ||
|
||
log.Printf("Received event from docker artifactory: %v", string(event)) | ||
err = ah.conn.Publish(event, "docker registry") | ||
log.Printf("Received event from docker artifactory: %v", string(payload)) | ||
err = ah.conn.Publish(payload, "Dockerhub_Registry") | ||
if err != nil { | ||
log.Printf("Publish failed for event: %v, reason: %v", string(event), err) | ||
log.Printf("%v: %v", ErrPublishToNats, err) | ||
return | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,37 @@ | ||
package handler | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
var ( | ||
ErrMissingGithubEventHeader = errors.New("missing X-GitHub-Event Header") | ||
) | ||
|
||
func (ah *APIHandler) PostEventDockerGithub(w http.ResponseWriter, r *http.Request) { | ||
event, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
log.Printf("Event body read failed: %v", err) | ||
defer func() { | ||
_, _ = io.Copy(io.Discard, r.Body) | ||
_ = r.Body.Close() | ||
}() | ||
event := r.Header.Get("X-GitHub-Event") | ||
if event == "" { | ||
log.Printf("%v", ErrMissingGithubEventHeader) | ||
return | ||
} | ||
|
||
payload, err := io.ReadAll(r.Body) | ||
if err != nil || len(payload) == 0 { | ||
log.Printf("%v: %v", ErrReadingBody, err) | ||
return | ||
} | ||
|
||
log.Printf("Received docker event from github artifactory: %v", string(event)) | ||
err = ah.conn.Publish(event, "Github_Registory") | ||
log.Printf("Received docker event from github artifactory: %v", string(payload)) | ||
err = ah.conn.Publish(payload, "Github_Registry") | ||
if err != nil { | ||
log.Printf("Publish failed for event: %v, reason: %v", string(event), err) | ||
log.Printf("%v: %v", ErrPublishToNats, err) | ||
return | ||
} | ||
} |
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,37 @@ | ||
package model | ||
|
||
type BuildPayload struct { | ||
CallbackURL string `json:"callback_url"` | ||
PushData struct { | ||
Images []string `json:"images"` | ||
PushedAt float32 `json:"pushed_at"` | ||
Pusher string `json:"pusher"` | ||
Tag string `json:"tag"` | ||
} `json:"push_data"` | ||
Repository struct { | ||
CommentCount int `json:"comment_count"` | ||
DateCreated float32 `json:"date_created"` | ||
Description string `json:"description"` | ||
Dockerfile string `json:"dockerfile"` | ||
FullDescription string `json:"full_description"` | ||
IsOfficial bool `json:"is_official"` | ||
IsPrivate bool `json:"is_private"` | ||
IsTrusted bool `json:"is_trusted"` | ||
Name string `json:"name"` | ||
Namespace string `json:"namespace"` | ||
Owner string `json:"owner"` | ||
RepoName string `json:"repo_name"` | ||
RepoURL string `json:"repo_url"` | ||
StarCount int `json:"star_count"` | ||
Status string `json:"status"` | ||
} `json:"repository"` | ||
} | ||
|
||
type DockerHubBuild struct { | ||
PushedBy string | ||
ImageTag string | ||
RepositoryName string | ||
DateCreated string | ||
Owner string | ||
Event string | ||
} |
Oops, something went wrong.