mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-20 19:20:14 +00:00
fix: avoid o(2n) complexity in acl lookup
This commit is contained in:
@@ -30,27 +30,21 @@ func NewAccessControlsService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (service *AccessControlsService) lookupStaticACLs(domain string) *model.App {
|
func (service *AccessControlsService) lookupStaticACLs(domain string) *model.App {
|
||||||
var appAcls *model.App
|
var nameMatch *model.App
|
||||||
|
|
||||||
// first pass - try to find an exact match for the domain
|
// First try to find a matching app by domain, then fallback to matching by app name (subdomain)
|
||||||
for app, config := range service.config.Apps {
|
for app, config := range service.config.Apps {
|
||||||
if config.Config.Domain == domain {
|
if config.Config.Domain == domain {
|
||||||
service.log.App.Debug().Str("name", app).Msg("Found matching container by domain")
|
service.log.App.Debug().Str("name", app).Msg("Found matching container by domain")
|
||||||
appAcls = &config
|
return &config
|
||||||
break // If we find a match by domain, we can stop searching
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// second pass - if we didn't find a match by domain, try to find a match by app name (subdomain)
|
|
||||||
for app, config := range service.config.Apps {
|
|
||||||
if strings.SplitN(domain, ".", 2)[0] == app {
|
if strings.SplitN(domain, ".", 2)[0] == app {
|
||||||
service.log.App.Debug().Str("name", app).Msg("Found matching container by app name")
|
service.log.App.Debug().Str("name", app).Msg("Found matching container by app name")
|
||||||
appAcls = &config
|
nameMatch = &config
|
||||||
break // If we find a match by app name, we can stop searching
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return appAcls
|
return nameMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *AccessControlsService) GetAccessControls(domain string) (*model.App, error) {
|
func (service *AccessControlsService) GetAccessControls(domain string) (*model.App, error) {
|
||||||
|
|||||||
@@ -85,21 +85,23 @@ func (docker *DockerService) GetLabels(appDomain string) (*model.App, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// fist pass - try to find an exact match for the domain
|
var nameMatch *model.App
|
||||||
for _, appLabels := range labels.Apps {
|
|
||||||
|
// First try to find a matching app by domain, then fallback to matching by app name (subdomain)
|
||||||
|
for appName, appLabels := range labels.Apps {
|
||||||
if appLabels.Config.Domain == appDomain {
|
if appLabels.Config.Domain == appDomain {
|
||||||
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by domain")
|
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by domain")
|
||||||
return &appLabels, nil
|
return &appLabels, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// second pass - if we didn't find a match by domain, try to find a match by app name (subdomain)
|
|
||||||
for appName, appLabels := range labels.Apps {
|
|
||||||
if strings.SplitN(appDomain, ".", 2)[0] == appName {
|
if strings.SplitN(appDomain, ".", 2)[0] == appName {
|
||||||
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by app name")
|
docker.log.App.Debug().Str("id", inspect.ID).Str("name", inspect.Name).Msg("Found matching container by app name")
|
||||||
return &appLabels, nil
|
nameMatch = &appLabels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nameMatch != nil {
|
||||||
|
return nameMatch, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
docker.log.App.Debug().Str("domain", appDomain).Msg("No matching container found for domain")
|
docker.log.App.Debug().Str("domain", appDomain).Msg("No matching container found for domain")
|
||||||
|
|||||||
Reference in New Issue
Block a user