@@ -15,6 +15,8 @@ import (
1515 "github.com/jmpsec/mapctf/pkg/backend"
1616 "github.com/jmpsec/mapctf/pkg/cache"
1717 "github.com/jmpsec/mapctf/pkg/config"
18+ "github.com/jmpsec/mapctf/pkg/teams"
19+ "github.com/jmpsec/mapctf/pkg/users"
1820 "github.com/jmpsec/mapctf/pkg/version"
1921 "github.com/rs/zerolog"
2022 "github.com/rs/zerolog/log"
@@ -35,6 +37,8 @@ const (
3537 LoggerTimeFormat string = "2006-01-02T15:04:05.999Z07:00"
3638 // Default path used when generating example configs
3739 defaultExampleConfigPath = "config/mapctf.example.yaml"
40+ // Default path for service configuration file
41+ defaultConfigPath = "config/mapctf.yaml"
3842)
3943
4044// Paths
@@ -64,6 +68,8 @@ const (
6468 apiStatsPath = "/stats"
6569 // API teams path
6670 apiTeamsPath = "/teams"
71+ // API users path
72+ apiUsersPath = "/users"
6773 // API challenges path
6874 apiChallengesPath = "/challenges"
6975)
@@ -109,7 +115,7 @@ func configFileFromCommand(cmd *cli.Command) string {
109115 if flagParams .ConfigFile != "" {
110116 return flagParams .ConfigFile
111117 }
112- return "config/mapctf.yaml"
118+ return defaultConfigPath
113119}
114120
115121// Initialization code
@@ -135,7 +141,7 @@ DELETE /api/admin/challenges/:id - Delete challenge
135141
136142// Let's go!
137143func mapCTFService () {
138- // ////////////////////////////// Backend
144+ // Backend
139145 log .Info ().Msg ("Initializing backend..." )
140146 for {
141147 db , err = backend .CreateDBManager (flagParams .ConfigValues .DB )
@@ -152,7 +158,7 @@ func mapCTFService() {
152158 log .Debug ().Msgf ("Backend NOT ready! Retrying in %d seconds...\n " , flagParams .ConfigValues .DB .ConnRetry )
153159 time .Sleep (time .Duration (flagParams .ConfigValues .DB .ConnRetry ) * time .Second )
154160 }
155- // ////////////////////////////// Cache
161+ // Cache
156162 log .Info ().Msg ("Initializing cache..." )
157163 for {
158164 redis , err = cache .CreateRedisManager (flagParams .ConfigValues .Redis )
@@ -169,15 +175,23 @@ func mapCTFService() {
169175 log .Debug ().Msgf ("Cache NOT ready! Retrying in %d seconds...\n " , flagParams .ConfigValues .Redis .ConnRetry )
170176 time .Sleep (time .Duration (flagParams .ConfigValues .Redis .ConnRetry ) * time .Second )
171177 }
172- // ////////////////////////////// Handlers
178+ // Team Manager
179+ log .Info ().Msg ("Initialize teams" )
180+ teamsMgr := teams .CreateTeams (db .Conn )
181+ // User Manager
182+ log .Info ().Msg ("Initialize users" )
183+ usersMgr := users .CreateUserManager (db .Conn )
184+ // Handlers
173185 log .Info ().Msg ("Initializing handlers" )
174186 handlersCTF := handlers .CreateHandlersAPI (
175187 handlers .WithDB (db .Conn ),
176188 handlers .WithRedisCache (redis ),
177189 handlers .WithConfig (flagParams .ConfigValues ),
190+ handlers .WithTeams (teamsMgr ),
191+ handlers .WithUsers (usersMgr ), // User manager to be added
178192 handlers .WithDebugHTTP (& flagParams .ConfigValues .DebugHTTP ),
179193 )
180- // ////////////////////////////// Router
194+ // Router
181195 log .Info ().Msg ("Initializing router" )
182196 // Create router for API
183197 muxAPI := http .NewServeMux ()
0 commit comments