@@ -14,7 +14,8 @@ import (
14
14
"github.com/religiosa1/git-webhook-receiver/internal/ActionRunner"
15
15
actiondb "github.com/religiosa1/git-webhook-receiver/internal/actionDb"
16
16
"github.com/religiosa1/git-webhook-receiver/internal/config"
17
- "github.com/religiosa1/git-webhook-receiver/internal/http/handlers"
17
+ "github.com/religiosa1/git-webhook-receiver/internal/http/admin"
18
+ handlers "github.com/religiosa1/git-webhook-receiver/internal/http/webhook_handlers"
18
19
"github.com/religiosa1/git-webhook-receiver/internal/logger"
19
20
"github.com/religiosa1/git-webhook-receiver/internal/logsDb"
20
21
"github.com/religiosa1/git-webhook-receiver/internal/whreceiver"
@@ -60,11 +61,28 @@ func Serve(cfg config.Config) {
60
61
61
62
//==========================================================================
62
63
// HTTP-Server
63
- srv , err := createServer (actionRunner .Chan (), cfg , logger )
64
+ mux , err := createProjectsMux (actionRunner .Chan (), cfg , logger )
64
65
if err != nil {
65
66
logger .Error ("Error creating the server" , slog .Any ("error" , err ))
66
67
os .Exit (ExitReadConfig )
67
68
}
69
+ if cfg .WebAdmin {
70
+ if dbActions != nil {
71
+ logger .Debug ("Web admin enabled for pipelines" )
72
+ mux .HandleFunc ("GET /pipelines" , admin .ListPipelines (dbActions , logger ))
73
+ mux .HandleFunc ("GET /pipelines/{pipeId}" , admin .GetPipeline (dbActions , logger ))
74
+ mux .HandleFunc ("GET /pipelines/{pipeId}/output" , admin .GetPipelineOutput (dbActions , logger ))
75
+ }
76
+ if dbLogs != nil {
77
+ logger .Debug ("Web admin enabled for logs" )
78
+ mux .HandleFunc ("GET /logs" , admin .GetLogs (dbLogs , logger ))
79
+ }
80
+ }
81
+
82
+ srv := & http.Server {
83
+ Addr : fmt .Sprintf ("%s:%d" , cfg .Host , cfg .Port ),
84
+ Handler : mux ,
85
+ }
68
86
69
87
srvCtx , srcCancel := context .WithCancel (context .Background ())
70
88
defer srcCancel ()
@@ -140,7 +158,7 @@ func runServer(ctx context.Context, srv *http.Server, sslConfig config.SslConfig
140
158
return err
141
159
}
142
160
143
- func createServer (actionsCh chan ActionRunner.ActionArgs , cfg config.Config , logger * slog.Logger ) (* http.Server , error ) {
161
+ func createProjectsMux (actionsCh chan ActionRunner.ActionArgs , cfg config.Config , logger * slog.Logger ) (* http.ServeMux , error ) {
144
162
mux := http .NewServeMux ()
145
163
for projectName , project := range cfg .Projects {
146
164
receiver := whreceiver .New (project )
@@ -158,7 +176,7 @@ func createServer(actionsCh chan ActionRunner.ActionArgs, cfg config.Config, log
158
176
159
177
projectLogger := logger .With (slog .String ("project" , projectName ))
160
178
mux .HandleFunc (
161
- fmt .Sprintf ("POST /%s" , projectName ),
179
+ fmt .Sprintf ("POST /projects/ %s" , projectName ),
162
180
handlers .HandleWebhookPost (actionsCh , projectLogger , cfg , projectName , project , receiver ),
163
181
)
164
182
logger .Debug ("Registered project" ,
@@ -167,11 +185,7 @@ func createServer(actionsCh chan ActionRunner.ActionArgs, cfg config.Config, log
167
185
slog .String ("repo" , project .Repo ),
168
186
)
169
187
}
170
- srv := & http.Server {
171
- Addr : fmt .Sprintf ("%s:%d" , cfg .Host , cfg .Port ),
172
- Handler : mux ,
173
- }
174
- return srv , nil
188
+ return mux , nil
175
189
}
176
190
177
191
type ErrShutdown struct {
0 commit comments