@@ -18,7 +18,6 @@ import (
1818 "time"
1919
2020 "github.com/gin-gonic/gin"
21- "github.com/tinyauthapp/tinyauth/internal/controller"
2221 "github.com/tinyauthapp/tinyauth/internal/model"
2322 "github.com/tinyauthapp/tinyauth/internal/repository"
2423 "github.com/tinyauthapp/tinyauth/internal/service"
@@ -36,25 +35,9 @@ type Services struct {
3635 oidcService * service.OIDCService
3736}
3837
39- type RuntimeConfig struct {
40- appUrl string
41- uuid string
42- cookieDomain string
43- sessionCookieName string
44- csrfCookieName string
45- redirectCookieName string
46- oauthSessionCookieName string
47- localUsers []model.LocalUser
48- oauthProviders map [string ]model.OAuthServiceConfig
49- oauthWhitelist []string
50- configuredProviders []controller.Provider
51- oidcClients []model.OIDCClientConfig
52- labelProvider service.LabelProvider
53- }
54-
55- type App struct {
38+ type BootstrapApp struct {
5639 config model.Config
57- runtime RuntimeConfig
40+ runtime model. RuntimeConfig
5841 services Services
5942 log * logger.Logger
6043 ctx context.Context
@@ -64,13 +47,13 @@ type App struct {
6447 db * sql.DB
6548}
6649
67- func NewBootstrapApp (config model.Config ) * App {
68- return & App {
50+ func NewBootstrapApp (config model.Config ) * BootstrapApp {
51+ return & BootstrapApp {
6952 config : config ,
7053 }
7154}
7255
73- func (app * App ) Setup () error {
56+ func (app * BootstrapApp ) Setup () error {
7457 // create context
7558 ctx , cancel := signal .NotifyContext (context .Background (), os .Interrupt , syscall .SIGTERM )
7659 app .ctx = ctx
@@ -92,7 +75,7 @@ func (app *App) Setup() error {
9275 return fmt .Errorf ("failed to parse app url: %w" , err )
9376 }
9477
95- app .runtime .appUrl = appUrl .Scheme + "://" + appUrl .Host
78+ app .runtime .AppURL = appUrl .Scheme + "://" + appUrl .Host
9679
9780 // validate session config
9881 if app .config .Auth .SessionMaxLifetime != 0 && app .config .Auth .SessionMaxLifetime < app .config .Auth .SessionExpiry {
@@ -106,7 +89,7 @@ func (app *App) Setup() error {
10689 return fmt .Errorf ("failed to load users: %w" , err )
10790 }
10891
109- app .runtime .localUsers = * users
92+ app .runtime .LocalUsers = * users
11093
11194 // load oauth whitelist
11295 oauthWhitelist , err := utils .GetStringList (app .config .OAuth .Whitelist , app .config .OAuth .WhitelistFile )
@@ -115,39 +98,39 @@ func (app *App) Setup() error {
11598 return fmt .Errorf ("failed to load oauth whitelist: %w" , err )
11699 }
117100
118- app .runtime .oauthWhitelist = oauthWhitelist
101+ app .runtime .OAuthWhitelist = oauthWhitelist
119102
120103 // Setup oauth providers
121- app .runtime .oauthProviders = app .config .OAuth .Providers
104+ app .runtime .OAuthProviders = app .config .OAuth .Providers
122105
123- for id , provider := range app .runtime .oauthProviders {
106+ for id , provider := range app .runtime .OAuthProviders {
124107 secret := utils .GetSecret (provider .ClientSecret , provider .ClientSecretFile )
125108 provider .ClientSecret = secret
126109 provider .ClientSecretFile = ""
127110
128111 if provider .RedirectURL == "" {
129- provider .RedirectURL = app .runtime .appUrl + "/api/oauth/callback/" + id
112+ provider .RedirectURL = app .runtime .AppURL + "/api/oauth/callback/" + id
130113 }
131114
132- app .runtime .oauthProviders [id ] = provider
115+ app .runtime .OAuthProviders [id ] = provider
133116 }
134117
135118 // set presets for built-in providers
136- for id , provider := range app .runtime .oauthProviders {
119+ for id , provider := range app .runtime .OAuthProviders {
137120 if provider .Name == "" {
138121 if name , ok := model .OverrideProviders [id ]; ok {
139122 provider .Name = name
140123 } else {
141124 provider .Name = utils .Capitalize (id )
142125 }
143126 }
144- app .runtime .oauthProviders [id ] = provider
127+ app .runtime .OAuthProviders [id ] = provider
145128 }
146129
147130 // setup oidc clients
148131 for id , client := range app .config .OIDC .Clients {
149132 client .ID = id
150- app .runtime .oidcClients = append (app .runtime .oidcClients , client )
133+ app .runtime .OIDCClients = append (app .runtime .OIDCClients , client )
151134 }
152135
153136 // cookie domain
@@ -158,23 +141,23 @@ func (app *App) Setup() error {
158141 cookieDomainResolver = utils .GetStandaloneCookieDomain
159142 }
160143
161- cookieDomain , err := cookieDomainResolver (app .runtime .appUrl )
144+ cookieDomain , err := cookieDomainResolver (app .runtime .AppURL )
162145
163146 if err != nil {
164147 return fmt .Errorf ("failed to get cookie domain: %w" , err )
165148 }
166149
167- app .runtime .cookieDomain = cookieDomain
150+ app .runtime .CookieDomain = cookieDomain
168151
169152 // cookie names
170- app .runtime .uuid = utils .GenerateUUID (appUrl .Hostname ())
153+ app .runtime .UUID = utils .GenerateUUID (appUrl .Hostname ())
171154
172- cookieId := strings .Split (app .runtime .uuid , "-" )[0 ] // first 8 characters of the uuid should be good enough
155+ cookieId := strings .Split (app .runtime .UUID , "-" )[0 ] // first 8 characters of the uuid should be good enough
173156
174- app .runtime .sessionCookieName = fmt .Sprintf ("%s-%s" , model .SessionCookieName , cookieId )
175- app .runtime .csrfCookieName = fmt .Sprintf ("%s-%s" , model .CSRFCookieName , cookieId )
176- app .runtime .redirectCookieName = fmt .Sprintf ("%s-%s" , model .RedirectCookieName , cookieId )
177- app .runtime .oauthSessionCookieName = fmt .Sprintf ("%s-%s" , model .OAuthSessionCookieName , cookieId )
157+ app .runtime .SessionCookieName = fmt .Sprintf ("%s-%s" , model .SessionCookieName , cookieId )
158+ app .runtime .CSRFCookieName = fmt .Sprintf ("%s-%s" , model .CSRFCookieName , cookieId )
159+ app .runtime .RedirectCookieName = fmt .Sprintf ("%s-%s" , model .RedirectCookieName , cookieId )
160+ app .runtime .OAuthSessionCookieName = fmt .Sprintf ("%s-%s" , model .OAuthSessionCookieName , cookieId )
178161
179162 // database
180163 err = app .SetupDatabase ()
@@ -195,10 +178,10 @@ func (app *App) Setup() error {
195178 }
196179
197180 // configured providers
198- configuredProviders := make ([]controller .Provider , 0 )
181+ configuredProviders := make ([]model .Provider , 0 )
199182
200- for id , provider := range app .runtime .oauthProviders {
201- configuredProviders = append (configuredProviders , controller .Provider {
183+ for id , provider := range app .runtime .OAuthProviders {
184+ configuredProviders = append (configuredProviders , model .Provider {
202185 Name : provider .Name ,
203186 ID : id ,
204187 OAuth : true ,
@@ -210,15 +193,15 @@ func (app *App) Setup() error {
210193 })
211194
212195 if app .services .authService .LocalAuthConfigured () {
213- configuredProviders = append (configuredProviders , controller .Provider {
196+ configuredProviders = append (configuredProviders , model .Provider {
214197 Name : "Local" ,
215198 ID : "local" ,
216199 OAuth : false ,
217200 })
218201 }
219202
220203 if app .services .authService .LDAPAuthConfigured () {
221- configuredProviders = append (configuredProviders , controller .Provider {
204+ configuredProviders = append (configuredProviders , model .Provider {
222205 Name : "LDAP" ,
223206 ID : "ldap" ,
224207 OAuth : false ,
@@ -229,11 +212,11 @@ func (app *App) Setup() error {
229212 return errors .New ("no authentication providers configured" )
230213 }
231214
232- for _ , provider := range app .runtime .configuredProviders {
215+ for _ , provider := range app .runtime .ConfiguredProviders {
233216 app .log .App .Debug ().Str ("provider" , provider .Name ).Msg ("Configured authentication provider" )
234217 }
235218
236- app .runtime .configuredProviders = configuredProviders
219+ app .runtime .ConfiguredProviders = configuredProviders
237220
238221 // setup router
239222 err = app .setupRouter ()
@@ -279,7 +262,7 @@ func (app *App) Setup() error {
279262 return nil
280263}
281264
282- func (app * App ) serveHTTP () error {
265+ func (app * BootstrapApp ) serveHTTP () error {
283266 address := fmt .Sprintf ("%s:%d" , app .config .Server .Address , app .config .Server .Port )
284267
285268 app .log .App .Info ().Msgf ("Starting server on %s" , address )
@@ -304,7 +287,7 @@ func (app *App) serveHTTP() error {
304287 return nil
305288}
306289
307- func (app * App ) serveUnix () error {
290+ func (app * BootstrapApp ) serveUnix () error {
308291 if app .config .Server .SocketPath == "" {
309292 return nil
310293 }
@@ -351,7 +334,7 @@ func (app *App) serveUnix() error {
351334 return nil
352335}
353336
354- func (app * App ) heartbeatRoutine () {
337+ func (app * BootstrapApp ) heartbeatRoutine () {
355338 ticker := time .NewTicker (time .Duration (12 ) * time .Hour )
356339 defer ticker .Stop ()
357340
@@ -362,7 +345,7 @@ func (app *App) heartbeatRoutine() {
362345
363346 var body Heartbeat
364347
365- body .UUID = app .runtime .uuid
348+ body .UUID = app .runtime .UUID
366349 body .Version = model .Version
367350
368351 bodyJson , err := json .Marshal (body )
@@ -412,7 +395,7 @@ func (app *App) heartbeatRoutine() {
412395 }
413396}
414397
415- func (app * App ) dbCleanupRoutine () {
398+ func (app * BootstrapApp ) dbCleanupRoutine () {
416399 ticker := time .NewTicker (time .Duration (30 ) * time .Minute )
417400 defer ticker .Stop ()
418401
0 commit comments