Remove UsecaseDependancies service locator pattern
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Replace the UsecaseDependancies interface with plain Dependencies structs defined locally in each route package. DeclareRoutes acts as the sole composition root where use cases are resolved; sub-route functions and controllers receive only the specific interfaces they need.
This commit is contained in:
parent
570d3d16dd
commit
c9552fa9b2
27 changed files with 174 additions and 240 deletions
|
|
@ -26,11 +26,10 @@ import (
|
||||||
|
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareUserAuthsRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareUserAuthsRoutes(router *gin.RouterGroup, dep Dependencies, store storage.Storage) {
|
||||||
ac := controller.NewAuthUserController(dependancies.AuthUserUsecase(), store)
|
ac := controller.NewAuthUserController(dep.AuthUser, store)
|
||||||
|
|
||||||
router.GET("/auth", ac.GetAuthUsers)
|
router.GET("/auth", ac.GetAuthUsers)
|
||||||
router.POST("/auth", ac.NewAuthUser)
|
router.POST("/auth", ac.NewAuthUser)
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,13 @@ import (
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/api/middleware"
|
"git.happydns.org/happyDomain/internal/api/middleware"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareDomainRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareDomainRoutes(router *gin.RouterGroup, dep Dependencies, store storage.Storage) {
|
||||||
dc := controller.NewDomainController(
|
dc := controller.NewDomainController(
|
||||||
dependancies.DomainUsecase(),
|
dep.Domain,
|
||||||
dependancies.RemoteZoneImporterUsecase(),
|
dep.RemoteZoneImporter,
|
||||||
dependancies.ZoneImporterUsecase(),
|
dep.ZoneImporter,
|
||||||
store,
|
store,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -45,11 +44,11 @@ func declareDomainRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseD
|
||||||
router.DELETE("/domains/:domain", dc.DeleteDomain)
|
router.DELETE("/domains/:domain", dc.DeleteDomain)
|
||||||
|
|
||||||
apiDomainsRoutes := router.Group("/domains/:domain")
|
apiDomainsRoutes := router.Group("/domains/:domain")
|
||||||
apiDomainsRoutes.Use(middleware.DomainHandler(dependancies.DomainUsecase(), true))
|
apiDomainsRoutes.Use(middleware.DomainHandler(dep.Domain, true))
|
||||||
|
|
||||||
apiDomainsRoutes.GET("", dc.GetDomain)
|
apiDomainsRoutes.GET("", dc.GetDomain)
|
||||||
apiDomainsRoutes.PUT("", dc.UpdateDomain)
|
apiDomainsRoutes.PUT("", dc.UpdateDomain)
|
||||||
|
|
||||||
apiDomainsRoutes.PUT("/zones", dc.UpdateZones)
|
apiDomainsRoutes.PUT("/zones", dc.UpdateZones)
|
||||||
declareZoneRoutes(apiDomainsRoutes, dependancies, store)
|
declareZoneRoutes(apiDomainsRoutes, dep, store)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,26 +27,25 @@ import (
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/api/middleware"
|
"git.happydns.org/happyDomain/internal/api/middleware"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareProviderRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareProviderRoutes(router *gin.RouterGroup, dep Dependencies, store storage.Storage) {
|
||||||
pc := controller.NewProviderController(dependancies.ProviderUsecase(false), store)
|
pc := controller.NewProviderController(dep.Provider, store)
|
||||||
|
|
||||||
router.GET("/providers", pc.ListProviders)
|
router.GET("/providers", pc.ListProviders)
|
||||||
router.POST("/providers", pc.AddProvider)
|
router.POST("/providers", pc.AddProvider)
|
||||||
router.DELETE("/providers", pc.ClearProviders)
|
router.DELETE("/providers", pc.ClearProviders)
|
||||||
|
|
||||||
apiProvidersMetaRoutes := router.Group("/providers/:pid")
|
apiProvidersMetaRoutes := router.Group("/providers/:pid")
|
||||||
apiProvidersMetaRoutes.Use(middleware.ProviderMetaHandler(dependancies.ProviderUsecase(false)))
|
apiProvidersMetaRoutes.Use(middleware.ProviderMetaHandler(dep.Provider))
|
||||||
|
|
||||||
apiProvidersMetaRoutes.DELETE("", pc.DeleteProvider)
|
apiProvidersMetaRoutes.DELETE("", pc.DeleteProvider)
|
||||||
|
|
||||||
apiProvidersRoutes := router.Group("/providers/:pid")
|
apiProvidersRoutes := router.Group("/providers/:pid")
|
||||||
apiProvidersRoutes.Use(middleware.ProviderHandler(dependancies.ProviderUsecase(false)))
|
apiProvidersRoutes.Use(middleware.ProviderHandler(dep.Provider))
|
||||||
|
|
||||||
apiProvidersRoutes.GET("", pc.GetProvider)
|
apiProvidersRoutes.GET("", pc.GetProvider)
|
||||||
apiProvidersRoutes.PUT("", pc.UpdateProvider)
|
apiProvidersRoutes.PUT("", pc.UpdateProvider)
|
||||||
|
|
||||||
declareDomainRoutes(apiProvidersRoutes, dependancies, store)
|
declareDomainRoutes(apiProvidersRoutes, dep, store)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,18 +26,32 @@ import (
|
||||||
|
|
||||||
api "git.happydns.org/happyDomain/internal/api/route"
|
api "git.happydns.org/happyDomain/internal/api/route"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
happydns "git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareRoutes(cfg *happydns.Options, router *gin.Engine, s storage.Storage, dependancies happydns.UsecaseDependancies) {
|
// Dependencies holds all use cases required to register the admin API routes.
|
||||||
|
type Dependencies struct {
|
||||||
|
AuthUser happydns.AuthUserUsecase
|
||||||
|
Domain happydns.DomainUsecase
|
||||||
|
Provider happydns.ProviderUsecase
|
||||||
|
RemoteZoneImporter happydns.RemoteZoneImporterUsecase
|
||||||
|
Service happydns.ServiceUsecase
|
||||||
|
User happydns.UserUsecase
|
||||||
|
Zone happydns.ZoneUsecase
|
||||||
|
ZoneCorrectionApplier happydns.ZoneCorrectionApplierUsecase
|
||||||
|
ZoneImporter happydns.ZoneImporterUsecase
|
||||||
|
ZoneService happydns.ZoneServiceUsecase
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeclareRoutes(cfg *happydns.Options, router *gin.Engine, s storage.Storage, dep Dependencies) {
|
||||||
apiRoutes := router.Group("/api")
|
apiRoutes := router.Group("/api")
|
||||||
|
|
||||||
declareBackupRoutes(cfg, apiRoutes, s)
|
declareBackupRoutes(cfg, apiRoutes, s)
|
||||||
declareDomainRoutes(apiRoutes, dependancies, s)
|
declareDomainRoutes(apiRoutes, dep, s)
|
||||||
declareProviderRoutes(apiRoutes, dependancies, s)
|
declareProviderRoutes(apiRoutes, dep, s)
|
||||||
declareSessionsRoutes(cfg, apiRoutes, s)
|
declareSessionsRoutes(cfg, apiRoutes, s)
|
||||||
declareUserAuthsRoutes(apiRoutes, dependancies, s)
|
declareUserAuthsRoutes(apiRoutes, dep, s)
|
||||||
declareUsersRoutes(apiRoutes, dependancies, s)
|
declareUsersRoutes(apiRoutes, dep, s)
|
||||||
declareTidyRoutes(apiRoutes, s)
|
declareTidyRoutes(apiRoutes, s)
|
||||||
api.DeclareVersionRoutes(apiRoutes)
|
api.DeclareVersionRoutes(apiRoutes)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,16 @@ import (
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/api/middleware"
|
"git.happydns.org/happyDomain/internal/api/middleware"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareZoneServiceRoutes(apiZonesRoutes *gin.RouterGroup, zc *controller.ZoneController, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareZoneServiceRoutes(apiZonesRoutes *gin.RouterGroup, zc *controller.ZoneController, dep Dependencies, store storage.Storage) {
|
||||||
sc := controller.NewServiceController(
|
sc := controller.NewServiceController(
|
||||||
dependancies.ServiceUsecase(),
|
dep.Service,
|
||||||
dependancies.ZoneServiceUsecase(),
|
dep.ZoneService,
|
||||||
)
|
)
|
||||||
|
|
||||||
apiZonesServiceIdRoutes := apiZonesRoutes.Group("/services/:serviceid")
|
apiZonesServiceIdRoutes := apiZonesRoutes.Group("/services/:serviceid")
|
||||||
apiZonesServiceIdRoutes.Use(middleware.ServiceIdHandler(dependancies.ServiceUsecase()))
|
apiZonesServiceIdRoutes.Use(middleware.ServiceIdHandler(dep.Service))
|
||||||
apiZonesServiceIdRoutes.GET("", sc.GetZoneService)
|
apiZonesServiceIdRoutes.GET("", sc.GetZoneService)
|
||||||
apiZonesServiceIdRoutes.PUT("", sc.UpdateZoneService)
|
apiZonesServiceIdRoutes.PUT("", sc.UpdateZoneService)
|
||||||
apiZonesServiceIdRoutes.DELETE("", sc.DeleteZoneService)
|
apiZonesServiceIdRoutes.DELETE("", sc.DeleteZoneService)
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,10 @@ import (
|
||||||
|
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareUsersRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareUsersRoutes(router *gin.RouterGroup, dep Dependencies, store storage.Storage) {
|
||||||
sc := controller.NewUserController(store, dependancies.UserUsecase())
|
sc := controller.NewUserController(store, dep.User)
|
||||||
|
|
||||||
router.GET("/users", sc.GetUsers)
|
router.GET("/users", sc.GetUsers)
|
||||||
router.POST("/users", sc.NewUser)
|
router.POST("/users", sc.NewUser)
|
||||||
|
|
@ -43,6 +42,6 @@ func declareUsersRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDe
|
||||||
apiUsersRoutes.PUT("", sc.UpdateUser)
|
apiUsersRoutes.PUT("", sc.UpdateUser)
|
||||||
apiUsersRoutes.DELETE("", sc.DeleteUser)
|
apiUsersRoutes.DELETE("", sc.DeleteUser)
|
||||||
|
|
||||||
declareDomainRoutes(apiUsersRoutes, dependancies, store)
|
declareDomainRoutes(apiUsersRoutes, dep, store)
|
||||||
declareProviderRoutes(apiUsersRoutes, dependancies, store)
|
declareProviderRoutes(apiUsersRoutes, dep, store)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,13 @@ import (
|
||||||
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
"git.happydns.org/happyDomain/internal/api-admin/controller"
|
||||||
"git.happydns.org/happyDomain/internal/api/middleware"
|
"git.happydns.org/happyDomain/internal/api/middleware"
|
||||||
"git.happydns.org/happyDomain/internal/storage"
|
"git.happydns.org/happyDomain/internal/storage"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func declareZoneRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, store storage.Storage) {
|
func declareZoneRoutes(router *gin.RouterGroup, dep Dependencies, store storage.Storage) {
|
||||||
zc := controller.NewZoneController(
|
zc := controller.NewZoneController(
|
||||||
dependancies.DomainUsecase(),
|
dep.Domain,
|
||||||
dependancies.ZoneUsecase(),
|
dep.Zone,
|
||||||
dependancies.ZoneCorrectionApplierUsecase(),
|
dep.ZoneCorrectionApplier,
|
||||||
store,
|
store,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -45,10 +44,10 @@ func declareZoneRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDep
|
||||||
router.DELETE("/zones/:zoneid", zc.DeleteZone)
|
router.DELETE("/zones/:zoneid", zc.DeleteZone)
|
||||||
|
|
||||||
apiZonesRoutes := router.Group("/zones/:zoneid")
|
apiZonesRoutes := router.Group("/zones/:zoneid")
|
||||||
apiZonesRoutes.Use(middleware.ZoneHandler(dependancies.ZoneUsecase()))
|
apiZonesRoutes.Use(middleware.ZoneHandler(dep.Zone))
|
||||||
|
|
||||||
apiZonesRoutes.GET("", zc.GetZone)
|
apiZonesRoutes.GET("", zc.GetZone)
|
||||||
apiZonesRoutes.PUT("", zc.UpdateZone)
|
apiZonesRoutes.PUT("", zc.UpdateZone)
|
||||||
|
|
||||||
declareZoneServiceRoutes(apiZonesRoutes, zc, dependancies, store)
|
declareZoneServiceRoutes(apiZonesRoutes, zc, dep, store)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareAuthUserRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, lc *controller.LoginController) *controller.AuthUserController {
|
func DeclareAuthUserRoutes(router *gin.RouterGroup, authUserUC happydns.AuthUserUsecase, lc *controller.LoginController) *controller.AuthUserController {
|
||||||
ac := controller.NewAuthUserController(dependancies.AuthUserUsecase(), lc)
|
ac := controller.NewAuthUserController(authUserUC, lc)
|
||||||
|
|
||||||
apiUserAuthRoutes := router.Group("/users/:uid")
|
apiUserAuthRoutes := router.Group("/users/:uid")
|
||||||
apiUserAuthRoutes.Use(middleware.AuthUserHandler(dependancies.AuthUserUsecase()))
|
apiUserAuthRoutes.Use(middleware.AuthUserHandler(authUserUC))
|
||||||
apiUserAuthRoutes.GET("/is_auth_user", func(c *gin.Context) {
|
apiUserAuthRoutes.GET("/is_auth_user", func(c *gin.Context) {
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareAuthenticationRoutes(cfg *happydns.Options, baserouter, apirouter *gin.RouterGroup, dependancies happydns.UsecaseDependancies) *controller.LoginController {
|
func DeclareAuthenticationRoutes(cfg *happydns.Options, baserouter, apirouter *gin.RouterGroup, authUC happydns.AuthenticationUsecase, captchaVerifier happydns.CaptchaVerifier, failureTracker happydns.FailureTracker) *controller.LoginController {
|
||||||
lc := controller.NewLoginController(dependancies.AuthenticationUsecase(), dependancies.CaptchaVerifier(), dependancies.FailureTracker())
|
lc := controller.NewLoginController(authUC, captchaVerifier, failureTracker)
|
||||||
|
|
||||||
apirouter.POST("/auth", lc.Login)
|
apirouter.POST("/auth", lc.Login)
|
||||||
apirouter.POST("/auth/logout", lc.Logout)
|
apirouter.POST("/auth/logout", lc.Logout)
|
||||||
|
|
||||||
if localChallenge, ok := dependancies.CaptchaVerifier().(happydns.CaptchaLocalChallenge); ok {
|
if localChallenge, ok := captchaVerifier.(happydns.CaptchaLocalChallenge); ok {
|
||||||
apirouter.GET("/auth/challenge", func(c *gin.Context) {
|
apirouter.GET("/auth/challenge", func(c *gin.Context) {
|
||||||
challenge, err := localChallenge.NewChallenge()
|
challenge, err := localChallenge.NewChallenge()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -50,7 +50,7 @@ func DeclareAuthenticationRoutes(cfg *happydns.Options, baserouter, apirouter *g
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.OIDCClients) > 0 {
|
if len(cfg.OIDCClients) > 0 {
|
||||||
oidcp := controller.NewOIDCProvider(cfg, dependancies.AuthenticationUsecase())
|
oidcp := controller.NewOIDCProvider(cfg, authUC)
|
||||||
|
|
||||||
authRoutes := baserouter.Group("/auth")
|
authRoutes := baserouter.Group("/auth")
|
||||||
|
|
||||||
|
|
@ -71,6 +71,6 @@ func DeclareAuthenticationRoutes(cfg *happydns.Options, baserouter, apirouter *g
|
||||||
return lc
|
return lc
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeclareAuthenticationCheckRoutes(apiAuthRoutes *gin.RouterGroup, dependancies happydns.UsecaseDependancies, lc *controller.LoginController) {
|
func DeclareAuthenticationCheckRoutes(apiAuthRoutes *gin.RouterGroup, lc *controller.LoginController) {
|
||||||
apiAuthRoutes.GET("/auth", lc.GetLoggedUser)
|
apiAuthRoutes.GET("/auth", lc.GetLoggedUser)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,27 +29,27 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareDomainRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareDomainRoutes(router *gin.RouterGroup, domainUC happydns.DomainUsecase, domainLogUC happydns.DomainLogUsecase, remoteZoneImporter happydns.RemoteZoneImporterUsecase, zoneImporter happydns.ZoneImporterUsecase, zoneUC happydns.ZoneUsecase, zoneCorrApplier happydns.ZoneCorrectionApplierUsecase, zoneServiceUC happydns.ZoneServiceUsecase, serviceUC happydns.ServiceUsecase) {
|
||||||
dc := controller.NewDomainController(
|
dc := controller.NewDomainController(
|
||||||
dependancies.DomainUsecase(),
|
domainUC,
|
||||||
dependancies.RemoteZoneImporterUsecase(),
|
remoteZoneImporter,
|
||||||
dependancies.ZoneImporterUsecase(),
|
zoneImporter,
|
||||||
)
|
)
|
||||||
|
|
||||||
router.GET("/domains", dc.GetDomains)
|
router.GET("/domains", dc.GetDomains)
|
||||||
router.POST("/domains", dc.AddDomain)
|
router.POST("/domains", dc.AddDomain)
|
||||||
|
|
||||||
apiDomainsRoutes := router.Group("/domains/:domain")
|
apiDomainsRoutes := router.Group("/domains/:domain")
|
||||||
apiDomainsRoutes.Use(middleware.DomainHandler(dependancies.DomainUsecase(), false))
|
apiDomainsRoutes.Use(middleware.DomainHandler(domainUC, false))
|
||||||
|
|
||||||
apiDomainsRoutes.GET("", dc.GetDomain)
|
apiDomainsRoutes.GET("", dc.GetDomain)
|
||||||
apiDomainsRoutes.PUT("", dc.UpdateDomain)
|
apiDomainsRoutes.PUT("", dc.UpdateDomain)
|
||||||
apiDomainsRoutes.DELETE("", dc.DelDomain)
|
apiDomainsRoutes.DELETE("", dc.DelDomain)
|
||||||
|
|
||||||
DeclareDomainLogRoutes(apiDomainsRoutes, dependancies)
|
DeclareDomainLogRoutes(apiDomainsRoutes, domainLogUC)
|
||||||
|
|
||||||
apiDomainsRoutes.POST("/zone", dc.ImportZone)
|
apiDomainsRoutes.POST("/zone", dc.ImportZone)
|
||||||
apiDomainsRoutes.POST("/retrieve_zone", dc.RetrieveZone)
|
apiDomainsRoutes.POST("/retrieve_zone", dc.RetrieveZone)
|
||||||
|
|
||||||
DeclareZoneRoutes(apiDomainsRoutes, dependancies)
|
DeclareZoneRoutes(apiDomainsRoutes, zoneUC, domainUC, zoneCorrApplier, zoneServiceUC, serviceUC)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareDomainLogRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareDomainLogRoutes(router *gin.RouterGroup, domainLogUC happydns.DomainLogUsecase) {
|
||||||
dlc := controller.NewDomainLogController(dependancies.DomainLogUsecase())
|
dlc := controller.NewDomainLogController(domainLogUC)
|
||||||
|
|
||||||
router.GET("/logs", dlc.GetDomainLogs)
|
router.GET("/logs", dlc.GetDomainLogs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,19 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareProviderRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareProviderRoutes(router *gin.RouterGroup, providerUC happydns.ProviderUsecase) {
|
||||||
pc := controller.NewProviderController(dependancies.ProviderUsecase(true))
|
pc := controller.NewProviderController(providerUC)
|
||||||
|
|
||||||
router.GET("/providers", pc.ListProviders)
|
router.GET("/providers", pc.ListProviders)
|
||||||
router.POST("/providers", pc.AddProvider)
|
router.POST("/providers", pc.AddProvider)
|
||||||
|
|
||||||
apiProvidersMetaRoutes := router.Group("/providers/:pid")
|
apiProvidersMetaRoutes := router.Group("/providers/:pid")
|
||||||
apiProvidersMetaRoutes.Use(middleware.ProviderMetaHandler(dependancies.ProviderUsecase(true)))
|
apiProvidersMetaRoutes.Use(middleware.ProviderMetaHandler(providerUC))
|
||||||
|
|
||||||
apiProvidersMetaRoutes.DELETE("", pc.DeleteProvider)
|
apiProvidersMetaRoutes.DELETE("", pc.DeleteProvider)
|
||||||
|
|
||||||
apiProviderRoutes := router.Group("/providers/:pid")
|
apiProviderRoutes := router.Group("/providers/:pid")
|
||||||
apiProviderRoutes.Use(middleware.ProviderHandler(dependancies.ProviderUsecase(true)))
|
apiProviderRoutes.Use(middleware.ProviderHandler(providerUC))
|
||||||
|
|
||||||
apiProviderRoutes.GET("", pc.GetProvider)
|
apiProviderRoutes.GET("", pc.GetProvider)
|
||||||
apiProviderRoutes.PUT("", pc.UpdateProvider)
|
apiProviderRoutes.PUT("", pc.UpdateProvider)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareProviderSettingsRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareProviderSettingsRoutes(router *gin.RouterGroup, providerSettingsUC happydns.ProviderSettingsUsecase) {
|
||||||
psc := controller.NewProviderSettingsController(dependancies.ProviderSettingsUsecase())
|
psc := controller.NewProviderSettingsController(providerSettingsUC)
|
||||||
|
|
||||||
apiProviderSpecsRoutes := router.Group("/providers/_specs/:psid")
|
apiProviderSpecsRoutes := router.Group("/providers/_specs/:psid")
|
||||||
apiProviderSpecsRoutes.Use(middleware.ProviderSpecsHandler)
|
apiProviderSpecsRoutes.Use(middleware.ProviderSpecsHandler)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareProviderSpecsRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareProviderSpecsRoutes(router *gin.RouterGroup, providerSpecsUC happydns.ProviderSpecsUsecase) {
|
||||||
pc := controller.NewProviderSpecsController(dependancies.ProviderSpecsUsecase())
|
pc := controller.NewProviderSpecsController(providerSpecsUC)
|
||||||
|
|
||||||
router.GET("/providers/_specs", pc.ListProviders)
|
router.GET("/providers/_specs", pc.ListProviders)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,9 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"git.happydns.org/happyDomain/internal/api/controller"
|
"git.happydns.org/happyDomain/internal/api/controller"
|
||||||
"git.happydns.org/happyDomain/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareRecordRoutes(apiRoutes *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareRecordRoutes(apiRoutes *gin.RouterGroup) {
|
||||||
rc := controller.NewRecordController()
|
rc := controller.NewRecordController()
|
||||||
|
|
||||||
apiRoutes.POST("/records", rc.ParseRecords)
|
apiRoutes.POST("/records", rc.ParseRecords)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareResolverRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareResolverRoutes(router *gin.RouterGroup, resolverUC happydns.ResolverUsecase) {
|
||||||
rc := controller.NewResolverController(dependancies.ResolverUsecase())
|
rc := controller.NewResolverController(resolverUC)
|
||||||
|
|
||||||
router.POST("/resolver", rc.RunResolver)
|
router.POST("/resolver", rc.RunResolver)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,33 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"git.happydns.org/happyDomain/internal/api/middleware"
|
"git.happydns.org/happyDomain/internal/api/middleware"
|
||||||
"git.happydns.org/happyDomain/model"
|
happydns "git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Dependencies holds all use cases required to register the public API routes.
|
||||||
|
// It is a plain struct — no methods, no interface — constructed once in app.go.
|
||||||
|
type Dependencies struct {
|
||||||
|
Authentication happydns.AuthenticationUsecase
|
||||||
|
AuthUser happydns.AuthUserUsecase
|
||||||
|
CaptchaVerifier happydns.CaptchaVerifier
|
||||||
|
Domain happydns.DomainUsecase
|
||||||
|
DomainLog happydns.DomainLogUsecase
|
||||||
|
FailureTracker happydns.FailureTracker
|
||||||
|
Provider happydns.ProviderUsecase
|
||||||
|
ProviderSettings happydns.ProviderSettingsUsecase
|
||||||
|
ProviderSpecs happydns.ProviderSpecsUsecase
|
||||||
|
RemoteZoneImporter happydns.RemoteZoneImporterUsecase
|
||||||
|
Resolver happydns.ResolverUsecase
|
||||||
|
Service happydns.ServiceUsecase
|
||||||
|
ServiceSpecs happydns.ServiceSpecsUsecase
|
||||||
|
Session happydns.SessionUsecase
|
||||||
|
User happydns.UserUsecase
|
||||||
|
Zone happydns.ZoneUsecase
|
||||||
|
ZoneCorrectionApplier happydns.ZoneCorrectionApplierUsecase
|
||||||
|
ZoneImporter happydns.ZoneImporterUsecase
|
||||||
|
ZoneService happydns.ZoneServiceUsecase
|
||||||
|
}
|
||||||
|
|
||||||
// @title happyDomain API
|
// @title happyDomain API
|
||||||
// @version 0.1
|
// @version 0.1
|
||||||
// @description Finally a simple interface for domain names.
|
// @description Finally a simple interface for domain names.
|
||||||
|
|
@ -48,38 +72,37 @@ import (
|
||||||
// @name Authorization
|
// @name Authorization
|
||||||
// @description Description for what is this security definition being used
|
// @description Description for what is this security definition being used
|
||||||
|
|
||||||
func DeclareRoutes(cfg *happydns.Options, router *gin.Engine, dependancies happydns.UsecaseDependancies) {
|
func DeclareRoutes(cfg *happydns.Options, router *gin.Engine, dep Dependencies) {
|
||||||
// Declare routes
|
|
||||||
baseRoutes := router.Group("")
|
baseRoutes := router.Group("")
|
||||||
|
|
||||||
declareRouteSwagger(cfg, baseRoutes)
|
declareRouteSwagger(cfg, baseRoutes)
|
||||||
|
|
||||||
apiRoutes := router.Group("/api")
|
apiRoutes := router.Group("/api")
|
||||||
|
|
||||||
lc := DeclareAuthenticationRoutes(cfg, baseRoutes, apiRoutes, dependancies)
|
lc := DeclareAuthenticationRoutes(cfg, baseRoutes, apiRoutes, dep.Authentication, dep.CaptchaVerifier, dep.FailureTracker)
|
||||||
auc := DeclareAuthUserRoutes(apiRoutes, dependancies, lc)
|
auc := DeclareAuthUserRoutes(apiRoutes, dep.AuthUser, lc)
|
||||||
DeclareProviderSpecsRoutes(apiRoutes, dependancies)
|
DeclareProviderSpecsRoutes(apiRoutes, dep.ProviderSpecs)
|
||||||
DeclareRegistrationRoutes(apiRoutes, dependancies)
|
DeclareRegistrationRoutes(apiRoutes, dep.AuthUser, dep.CaptchaVerifier)
|
||||||
DeclareResolverRoutes(apiRoutes, dependancies)
|
DeclareResolverRoutes(apiRoutes, dep.Resolver)
|
||||||
DeclareServiceSpecsRoutes(apiRoutes, dependancies)
|
DeclareServiceSpecsRoutes(apiRoutes, dep.ServiceSpecs)
|
||||||
DeclareUserRecoveryRoutes(apiRoutes, dependancies, auc)
|
DeclareUserRecoveryRoutes(apiRoutes, dep.AuthUser, auc)
|
||||||
DeclareVersionRoutes(apiRoutes)
|
DeclareVersionRoutes(apiRoutes)
|
||||||
|
|
||||||
apiAuthRoutes := router.Group("/api")
|
apiAuthRoutes := router.Group("/api")
|
||||||
|
|
||||||
if cfg.NoAuth {
|
if cfg.NoAuth {
|
||||||
apiAuthRoutes.Use(middleware.NoAuthMiddleware(dependancies.AuthenticationUsecase()))
|
apiAuthRoutes.Use(middleware.NoAuthMiddleware(dep.Authentication))
|
||||||
} else {
|
} else {
|
||||||
apiAuthRoutes.Use(middleware.JwtAuthMiddleware(dependancies.AuthenticationUsecase(), cfg.JWTSigningMethod, cfg.JWTSecretKey))
|
apiAuthRoutes.Use(middleware.JwtAuthMiddleware(dep.Authentication, cfg.JWTSigningMethod, cfg.JWTSecretKey))
|
||||||
apiAuthRoutes.Use(middleware.SessionMiddleware(dependancies.AuthenticationUsecase()))
|
apiAuthRoutes.Use(middleware.SessionMiddleware(dep.Authentication))
|
||||||
}
|
}
|
||||||
apiAuthRoutes.Use(middleware.AuthRequired())
|
apiAuthRoutes.Use(middleware.AuthRequired())
|
||||||
|
|
||||||
DeclareAuthenticationCheckRoutes(apiAuthRoutes, dependancies, lc)
|
DeclareAuthenticationCheckRoutes(apiAuthRoutes, lc)
|
||||||
DeclareDomainRoutes(apiAuthRoutes, dependancies)
|
DeclareDomainRoutes(apiAuthRoutes, dep.Domain, dep.DomainLog, dep.RemoteZoneImporter, dep.ZoneImporter, dep.Zone, dep.ZoneCorrectionApplier, dep.ZoneService, dep.Service)
|
||||||
DeclareProviderRoutes(apiAuthRoutes, dependancies)
|
DeclareProviderRoutes(apiAuthRoutes, dep.Provider)
|
||||||
DeclareProviderSettingsRoutes(apiAuthRoutes, dependancies)
|
DeclareProviderSettingsRoutes(apiAuthRoutes, dep.ProviderSettings)
|
||||||
DeclareRecordRoutes(apiAuthRoutes, dependancies)
|
DeclareRecordRoutes(apiAuthRoutes)
|
||||||
DeclareUsersRoutes(apiAuthRoutes, dependancies, lc)
|
DeclareUsersRoutes(apiAuthRoutes, dep.User, lc)
|
||||||
DeclareSessionRoutes(apiAuthRoutes, dependancies)
|
DeclareSessionRoutes(apiAuthRoutes, dep.Session)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,15 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareZoneServiceRoutes(apiZonesRoutes, apiZonesSubdomainRoutes *gin.RouterGroup, zc *controller.ZoneController, dependancies happydns.UsecaseDependancies) {
|
func DeclareZoneServiceRoutes(apiZonesRoutes, apiZonesSubdomainRoutes *gin.RouterGroup, zc *controller.ZoneController, zoneServiceUC happydns.ZoneServiceUsecase, serviceUC happydns.ServiceUsecase, zoneUC happydns.ZoneUsecase) {
|
||||||
sc := controller.NewServiceController(dependancies.ZoneServiceUsecase(), dependancies.ServiceUsecase(), dependancies.ZoneUsecase())
|
sc := controller.NewServiceController(zoneServiceUC, serviceUC, zoneUC)
|
||||||
|
|
||||||
apiZonesRoutes.PATCH("", sc.UpdateZoneService)
|
apiZonesRoutes.PATCH("", sc.UpdateZoneService)
|
||||||
|
|
||||||
apiZonesSubdomainRoutes.POST("/services", sc.AddZoneService)
|
apiZonesSubdomainRoutes.POST("/services", sc.AddZoneService)
|
||||||
|
|
||||||
apiZonesSubdomainServiceIdRoutes := apiZonesSubdomainRoutes.Group("/services/:serviceid")
|
apiZonesSubdomainServiceIdRoutes := apiZonesSubdomainRoutes.Group("/services/:serviceid")
|
||||||
apiZonesSubdomainServiceIdRoutes.Use(middleware.ServiceIdHandler(dependancies.ServiceUsecase()))
|
apiZonesSubdomainServiceIdRoutes.Use(middleware.ServiceIdHandler(serviceUC))
|
||||||
apiZonesSubdomainServiceIdRoutes.GET("", sc.GetZoneService)
|
apiZonesSubdomainServiceIdRoutes.GET("", sc.GetZoneService)
|
||||||
apiZonesSubdomainServiceIdRoutes.DELETE("", sc.DeleteZoneService)
|
apiZonesSubdomainServiceIdRoutes.DELETE("", sc.DeleteZoneService)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareServiceSpecsRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareServiceSpecsRoutes(router *gin.RouterGroup, serviceSpecsUC happydns.ServiceSpecsUsecase) {
|
||||||
ssc := controller.NewServiceSpecsController(dependancies.ServiceSpecsUsecase())
|
ssc := controller.NewServiceSpecsController(serviceSpecsUC)
|
||||||
|
|
||||||
router.GET("/service_specs", ssc.ListServiceSpecs)
|
router.GET("/service_specs", ssc.ListServiceSpecs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareSessionRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareSessionRoutes(router *gin.RouterGroup, sessionUC happydns.SessionUsecase) {
|
||||||
sc := controller.NewSessionController(dependancies.SessionUsecase())
|
sc := controller.NewSessionController(sessionUC)
|
||||||
|
|
||||||
router.GET("/session", sc.GetSession)
|
router.GET("/session", sc.GetSession)
|
||||||
router.DELETE("/session", sc.ClearSession)
|
router.DELETE("/session", sc.ClearSession)
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,17 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareUsersRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, lc *controller.LoginController) *controller.UserController {
|
func DeclareUsersRoutes(router *gin.RouterGroup, userUC happydns.UserUsecase, lc *controller.LoginController) *controller.UserController {
|
||||||
uc := controller.NewUserController(dependancies.UserUsecase(), lc)
|
uc := controller.NewUserController(userUC, lc)
|
||||||
|
|
||||||
apiUserRoutes := router.Group("/users/:uid")
|
apiUserRoutes := router.Group("/users/:uid")
|
||||||
apiUserRoutes.Use(middleware.UserHandler(dependancies.UserUsecase()))
|
apiUserRoutes.Use(middleware.UserHandler(userUC))
|
||||||
|
|
||||||
apiUserRoutes.GET("", uc.GetUser)
|
apiUserRoutes.GET("", uc.GetUser)
|
||||||
apiUserRoutes.GET("/avatar.png", uc.GetUserAvatar)
|
apiUserRoutes.GET("/avatar.png", uc.GetUserAvatar)
|
||||||
|
|
||||||
apiSameUserRoutes := router.Group("/users/:uid")
|
apiSameUserRoutes := router.Group("/users/:uid")
|
||||||
apiSameUserRoutes.Use(middleware.UserHandler(dependancies.UserUsecase()))
|
apiSameUserRoutes.Use(middleware.UserHandler(userUC))
|
||||||
apiSameUserRoutes.Use(middleware.SameUserHandler)
|
apiSameUserRoutes.Use(middleware.SameUserHandler)
|
||||||
|
|
||||||
apiSameUserRoutes.DELETE("", uc.DeleteMyUser)
|
apiSameUserRoutes.DELETE("", uc.DeleteMyUser)
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareUserRecoveryRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies, auc *controller.AuthUserController) *controller.UserRecoveryController {
|
func DeclareUserRecoveryRoutes(router *gin.RouterGroup, authUserUC happydns.AuthUserUsecase, auc *controller.AuthUserController) *controller.UserRecoveryController {
|
||||||
urc := controller.NewUserRecoveryController(dependancies.AuthUserUsecase())
|
urc := controller.NewUserRecoveryController(authUserUC)
|
||||||
|
|
||||||
router.PATCH("/users", urc.UserRecoveryOperations)
|
router.PATCH("/users", urc.UserRecoveryOperations)
|
||||||
|
|
||||||
apiUserRoutes := router.Group("/users/:uid")
|
apiUserRoutes := router.Group("/users/:uid")
|
||||||
apiUserRoutes.Use(middleware.AuthUserHandler(dependancies.AuthUserUsecase()))
|
apiUserRoutes.Use(middleware.AuthUserHandler(authUserUC))
|
||||||
|
|
||||||
apiUserRoutes.POST("/email", urc.ValidateUserAddress)
|
apiUserRoutes.POST("/email", urc.ValidateUserAddress)
|
||||||
apiUserRoutes.POST("/recovery", urc.RecoverUserAccount)
|
apiUserRoutes.POST("/recovery", urc.RecoverUserAccount)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"git.happydns.org/happyDomain/model"
|
"git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareRegistrationRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) *controller.RegistrationController {
|
func DeclareRegistrationRoutes(router *gin.RouterGroup, authUserUC happydns.AuthUserUsecase, captchaVerifier happydns.CaptchaVerifier) *controller.RegistrationController {
|
||||||
rc := controller.NewRegistrationController(dependancies.AuthUserUsecase(), dependancies.CaptchaVerifier())
|
rc := controller.NewRegistrationController(authUserUC, captchaVerifier)
|
||||||
|
|
||||||
router.POST("/users", rc.RegisterNewUser)
|
router.POST("/users", rc.RegisterNewUser)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,15 @@ import (
|
||||||
happydns "git.happydns.org/happyDomain/model"
|
happydns "git.happydns.org/happyDomain/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeclareZoneRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDependancies) {
|
func DeclareZoneRoutes(router *gin.RouterGroup, zoneUC happydns.ZoneUsecase, domainUC happydns.DomainUsecase, zoneCorrApplier happydns.ZoneCorrectionApplierUsecase, zoneServiceUC happydns.ZoneServiceUsecase, serviceUC happydns.ServiceUsecase) {
|
||||||
zc := controller.NewZoneController(
|
zc := controller.NewZoneController(
|
||||||
dependancies.ZoneUsecase(),
|
zoneUC,
|
||||||
dependancies.DomainUsecase(),
|
domainUC,
|
||||||
dependancies.ZoneCorrectionApplierUsecase(),
|
zoneCorrApplier,
|
||||||
)
|
)
|
||||||
|
|
||||||
apiZonesRoutes := router.Group("/zone/:zoneid")
|
apiZonesRoutes := router.Group("/zone/:zoneid")
|
||||||
apiZonesRoutes.Use(middleware.ZoneHandler(dependancies.ZoneUsecase()))
|
apiZonesRoutes.Use(middleware.ZoneHandler(zoneUC))
|
||||||
|
|
||||||
apiZonesRoutes.GET("", zc.GetZone)
|
apiZonesRoutes.GET("", zc.GetZone)
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ func DeclareZoneRoutes(router *gin.RouterGroup, dependancies happydns.UsecaseDep
|
||||||
apiZonesSubdomainRoutes.Use(middleware.SubdomainHandler)
|
apiZonesSubdomainRoutes.Use(middleware.SubdomainHandler)
|
||||||
apiZonesSubdomainRoutes.GET("", zc.GetZoneSubdomain)
|
apiZonesSubdomainRoutes.GET("", zc.GetZoneSubdomain)
|
||||||
|
|
||||||
DeclareZoneServiceRoutes(apiZonesRoutes, apiZonesSubdomainRoutes, zc, dependancies)
|
DeclareZoneServiceRoutes(apiZonesRoutes, apiZonesSubdomainRoutes, zc, zoneServiceUC, serviceUC, zoneUC)
|
||||||
|
|
||||||
apiZonesRoutes.POST("/records", zc.AddRecords)
|
apiZonesRoutes.POST("/records", zc.AddRecords)
|
||||||
apiZonesRoutes.POST("/records/delete", zc.DeleteRecords)
|
apiZonesRoutes.POST("/records/delete", zc.DeleteRecords)
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,21 @@ func NewAdmin(app *App) *Admin {
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.Use(gin.Logger(), gin.Recovery())
|
router.Use(gin.Logger(), gin.Recovery())
|
||||||
|
|
||||||
// Prepare usecases
|
// Prepare usecases (admin uses unrestricted provider access)
|
||||||
app.usecases.providerAdmin = providerUC.NewService(app.store)
|
app.usecases.providerAdmin = providerUC.NewService(app.store)
|
||||||
|
|
||||||
admin.DeclareRoutes(app.cfg, router, app.store, app)
|
admin.DeclareRoutes(app.cfg, router, app.store, admin.Dependencies{
|
||||||
|
AuthUser: app.usecases.authUser,
|
||||||
|
Domain: app.usecases.domain,
|
||||||
|
Provider: app.usecases.providerAdmin,
|
||||||
|
RemoteZoneImporter: app.usecases.orchestrator.RemoteZoneImporter,
|
||||||
|
Service: app.usecases.service,
|
||||||
|
User: app.usecases.user,
|
||||||
|
Zone: app.usecases.zone,
|
||||||
|
ZoneCorrectionApplier: app.usecases.orchestrator.ZoneCorrectionApplier,
|
||||||
|
ZoneImporter: app.usecases.orchestrator.ZoneImporter,
|
||||||
|
ZoneService: app.usecases.zoneService,
|
||||||
|
})
|
||||||
web.DeclareRoutes(app.cfg, router)
|
web.DeclareRoutes(app.cfg, router)
|
||||||
|
|
||||||
return &Admin{
|
return &Admin{
|
||||||
|
|
|
||||||
|
|
@ -84,89 +84,6 @@ type App struct {
|
||||||
usecases Usecases
|
usecases Usecases
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) AuthenticationUsecase() happydns.AuthenticationUsecase {
|
|
||||||
return a.usecases.authentication
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) AuthUserUsecase() happydns.AuthUserUsecase {
|
|
||||||
return a.usecases.authUser
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) CaptchaVerifier() happydns.CaptchaVerifier {
|
|
||||||
return a.captchaVerifier
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) DomainUsecase() happydns.DomainUsecase {
|
|
||||||
return a.usecases.domain
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) DomainLogUsecase() happydns.DomainLogUsecase {
|
|
||||||
return a.usecases.domainLog
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) FailureTracker() happydns.FailureTracker {
|
|
||||||
return a.failureTracker
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) Orchestrator() *orchestrator.Orchestrator {
|
|
||||||
return a.usecases.orchestrator
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ProviderUsecase(secure bool) happydns.ProviderUsecase {
|
|
||||||
if secure {
|
|
||||||
return a.usecases.provider
|
|
||||||
} else {
|
|
||||||
return a.usecases.providerAdmin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ProviderSettingsUsecase() happydns.ProviderSettingsUsecase {
|
|
||||||
return a.usecases.providerSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ProviderSpecsUsecase() happydns.ProviderSpecsUsecase {
|
|
||||||
return a.usecases.providerSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ResolverUsecase() happydns.ResolverUsecase {
|
|
||||||
return a.usecases.resolver
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) RemoteZoneImporterUsecase() happydns.RemoteZoneImporterUsecase {
|
|
||||||
return a.usecases.orchestrator.RemoteZoneImporter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ServiceUsecase() happydns.ServiceUsecase {
|
|
||||||
return a.usecases.service
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ServiceSpecsUsecase() happydns.ServiceSpecsUsecase {
|
|
||||||
return a.usecases.serviceSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) SessionUsecase() happydns.SessionUsecase {
|
|
||||||
return a.usecases.session
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) UserUsecase() happydns.UserUsecase {
|
|
||||||
return a.usecases.user
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ZoneCorrectionApplierUsecase() happydns.ZoneCorrectionApplierUsecase {
|
|
||||||
return a.usecases.orchestrator.ZoneCorrectionApplier
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ZoneImporterUsecase() happydns.ZoneImporterUsecase {
|
|
||||||
return a.usecases.orchestrator.ZoneImporter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ZoneUsecase() happydns.ZoneUsecase {
|
|
||||||
return a.usecases.zone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ZoneServiceUsecase() happydns.ZoneServiceUsecase {
|
|
||||||
return a.usecases.zoneService
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewApp(cfg *happydns.Options) *App {
|
func NewApp(cfg *happydns.Options) *App {
|
||||||
app := &App{
|
app := &App{
|
||||||
|
|
@ -319,7 +236,27 @@ func (app *App) setupRouter() {
|
||||||
session.NewSessionStore(app.cfg, app.store, []byte(app.cfg.JWTSecretKey)),
|
session.NewSessionStore(app.cfg, app.store, []byte(app.cfg.JWTSecretKey)),
|
||||||
))
|
))
|
||||||
|
|
||||||
api.DeclareRoutes(app.cfg, app.router, app)
|
api.DeclareRoutes(app.cfg, app.router, api.Dependencies{
|
||||||
|
Authentication: app.usecases.authentication,
|
||||||
|
AuthUser: app.usecases.authUser,
|
||||||
|
CaptchaVerifier: app.captchaVerifier,
|
||||||
|
Domain: app.usecases.domain,
|
||||||
|
DomainLog: app.usecases.domainLog,
|
||||||
|
FailureTracker: app.failureTracker,
|
||||||
|
Provider: app.usecases.provider,
|
||||||
|
ProviderSettings: app.usecases.providerSettings,
|
||||||
|
ProviderSpecs: app.usecases.providerSpecs,
|
||||||
|
RemoteZoneImporter: app.usecases.orchestrator.RemoteZoneImporter,
|
||||||
|
Resolver: app.usecases.resolver,
|
||||||
|
Service: app.usecases.service,
|
||||||
|
ServiceSpecs: app.usecases.serviceSpecs,
|
||||||
|
Session: app.usecases.session,
|
||||||
|
User: app.usecases.user,
|
||||||
|
Zone: app.usecases.zone,
|
||||||
|
ZoneCorrectionApplier: app.usecases.orchestrator.ZoneCorrectionApplier,
|
||||||
|
ZoneImporter: app.usecases.orchestrator.ZoneImporter,
|
||||||
|
ZoneService: app.usecases.zoneService,
|
||||||
|
})
|
||||||
web.DeclareRoutes(app.cfg, app.router, app.captchaVerifier)
|
web.DeclareRoutes(app.cfg, app.router, app.captchaVerifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
// This file is part of the happyDomain (R) project.
|
|
||||||
// Copyright (c) 2020-2024 happyDomain
|
|
||||||
// Authors: Pierre-Olivier Mercier, et al.
|
|
||||||
//
|
|
||||||
// This program is offered under a commercial and under the AGPL license.
|
|
||||||
// For commercial licensing, contact us at <contact@happydomain.org>.
|
|
||||||
//
|
|
||||||
// For AGPL licensing:
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package happydns
|
|
||||||
|
|
||||||
type UsecaseDependancies interface {
|
|
||||||
AuthenticationUsecase() AuthenticationUsecase
|
|
||||||
AuthUserUsecase() AuthUserUsecase
|
|
||||||
CaptchaVerifier() CaptchaVerifier
|
|
||||||
DomainUsecase() DomainUsecase
|
|
||||||
DomainLogUsecase() DomainLogUsecase
|
|
||||||
FailureTracker() FailureTracker
|
|
||||||
ProviderUsecase(secure bool) ProviderUsecase
|
|
||||||
ProviderSettingsUsecase() ProviderSettingsUsecase
|
|
||||||
ProviderSpecsUsecase() ProviderSpecsUsecase
|
|
||||||
RemoteZoneImporterUsecase() RemoteZoneImporterUsecase
|
|
||||||
ResolverUsecase() ResolverUsecase
|
|
||||||
ServiceUsecase() ServiceUsecase
|
|
||||||
ServiceSpecsUsecase() ServiceSpecsUsecase
|
|
||||||
SessionUsecase() SessionUsecase
|
|
||||||
UserUsecase() UserUsecase
|
|
||||||
ZoneCorrectionApplierUsecase() ZoneCorrectionApplierUsecase
|
|
||||||
ZoneImporterUsecase() ZoneImporterUsecase
|
|
||||||
ZoneServiceUsecase() ZoneServiceUsecase
|
|
||||||
ZoneUsecase() ZoneUsecase
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue