-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/handle-webhook-notifications (#33)
* feat: start implementing webhook WIP * feat: start implementing web server which will receive webhooks * feat: WIP implement webhook handler * feat: make cmd start server instead of webhook * improvement(webhook): webhook is now handled by the server * chore: catch webhook init error * chore: update default server port * feat: rename annotations methods * chore: use log instead of logs * chore(webhook): add some logs just to see where's it crashing * chore: update log method * chore: add sshUrls listing * feat: handle webhook annotation in state machine * fix: change condition values --------- Co-authored-by: Alan <alanl@padok.fr>
- Loading branch information
Showing
17 changed files
with
348 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/padok-team/burrito/internal/burrito" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func BuildServerCmd(app *burrito.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "server", | ||
Short: "cmd to use burrito's server", | ||
} | ||
cmd.AddCommand(buildServerStartCmd(app)) | ||
return cmd | ||
} |
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,21 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/padok-team/burrito/internal/burrito" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildServerStartCmd(app *burrito.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "start", | ||
Short: "Start burrito's server", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
app.StartServer() | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&app.Config.Server.Port, "port", "8080", "port the server listens on") | ||
|
||
return cmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,5 @@ | ||
package burrito | ||
|
||
func (app *App) StartServer() { | ||
app.Server.Exec() | ||
} |
This file was deleted.
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
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,48 @@ | ||
package server | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/padok-team/burrito/internal/burrito/config" | ||
"github.com/padok-team/burrito/internal/webhook" | ||
) | ||
|
||
type Server struct { | ||
config *config.Config | ||
Webhook *webhook.Webhook | ||
} | ||
|
||
func New(c *config.Config) *Server { | ||
webhook := webhook.New(c) | ||
err := webhook.Init() | ||
if err != nil { | ||
log.Printf("error initializing webhook: %s", err) | ||
} | ||
return &Server{ | ||
config: c, | ||
Webhook: webhook, | ||
} | ||
} | ||
|
||
func (s *Server) Exec() { | ||
http.HandleFunc("/healthz", handleHealthz) | ||
http.HandleFunc("/webhook", s.Webhook.GetHttpHandler()) | ||
|
||
err := http.ListenAndServe(fmt.Sprintf(":%s", s.config.Server.Port), nil) | ||
if errors.Is(err, http.ErrServerClosed) { | ||
log.Println("server is closed") | ||
} | ||
if err != nil { | ||
log.Printf("error starting server, exiting: %s", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func handleHealthz(w http.ResponseWriter, r *http.Request) { | ||
// The HTTP server is always healthy. | ||
// TODO: check it can get terraformlayers and/or repositories | ||
} |
Oops, something went wrong.