mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-12-31 04:22:28 +00:00
feat: add paerser as submodule and apply patch for nested maps
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "paerser"]
|
||||||
|
path = paerser
|
||||||
|
url = https://github.com/traefik/paerser
|
||||||
@@ -2,6 +2,8 @@ FROM golang:1.25-alpine3.21
|
|||||||
|
|
||||||
WORKDIR /tinyauth
|
WORKDIR /tinyauth
|
||||||
|
|
||||||
|
COPY ./paerser ./paerser
|
||||||
|
|
||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
COPY go.sum ./
|
COPY go.sum ./
|
||||||
|
|
||||||
@@ -20,4 +22,4 @@ ENV TINYAUTH_DATABASEPATH=/data/tinyauth.db
|
|||||||
|
|
||||||
ENV TINYAUTH_RESOURCESDIR=/data/resources
|
ENV TINYAUTH_RESOURCESDIR=/data/resources
|
||||||
|
|
||||||
ENTRYPOINT ["air", "-c", "air.toml"]
|
ENTRYPOINT ["air", "-c", "air.toml"]
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -4,6 +4,8 @@ go 1.24.0
|
|||||||
|
|
||||||
toolchain go1.24.3
|
toolchain go1.24.3
|
||||||
|
|
||||||
|
replace github.com/traefik/paerser v0.2.2 => ./paerser
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3
|
github.com/cenkalti/backoff/v5 v5.0.3
|
||||||
github.com/charmbracelet/huh v0.8.0
|
github.com/charmbracelet/huh v0.8.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -271,8 +271,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
|||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/traefik/paerser v0.2.2 h1:cpzW/ZrQrBh3mdwD/jnp6aXASiUFKOVr6ldP+keJTcQ=
|
|
||||||
github.com/traefik/paerser v0.2.2/go.mod h1:7BBDd4FANoVgaTZG+yh26jI6CA2nds7D/4VTEdIsh24=
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ var RedirectCookieName = "tinyauth-redirect"
|
|||||||
// Main app config
|
// Main app config
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Apps
|
|
||||||
AppURL string `description:"The base URL where the app is hosted." yaml:"appUrl"`
|
AppURL string `description:"The base URL where the app is hosted." yaml:"appUrl"`
|
||||||
LogLevel string `description:"Log level (trace, debug, info, warn, error)." yaml:"logLevel"`
|
LogLevel string `description:"Log level (trace, debug, info, warn, error)." yaml:"logLevel"`
|
||||||
ResourcesDir string `description:"The directory where resources are stored." yaml:"resourcesDir"`
|
ResourcesDir string `description:"The directory where resources are stored." yaml:"resourcesDir"`
|
||||||
@@ -26,6 +25,7 @@ type Config struct {
|
|||||||
LogJSON bool `description:"Enable JSON formatted logs." yaml:"logJSON"`
|
LogJSON bool `description:"Enable JSON formatted logs." yaml:"logJSON"`
|
||||||
Server ServerConfig `description:"Server configuration." yaml:"server"`
|
Server ServerConfig `description:"Server configuration." yaml:"server"`
|
||||||
Auth AuthConfig `description:"Authentication configuration." yaml:"auth"`
|
Auth AuthConfig `description:"Authentication configuration." yaml:"auth"`
|
||||||
|
Apps map[string]App `description:"Application ACLs configuration." yaml:"apps"`
|
||||||
OAuth OAuthConfig `description:"OAuth configuration." yaml:"oauth"`
|
OAuth OAuthConfig `description:"OAuth configuration." yaml:"oauth"`
|
||||||
UI UIConfig `description:"UI customization." yaml:"ui"`
|
UI UIConfig `description:"UI customization." yaml:"ui"`
|
||||||
Ldap LdapConfig `description:"LDAP configuration." yaml:"ldap"`
|
Ldap LdapConfig `description:"LDAP configuration." yaml:"ldap"`
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func setupProxyController(t *testing.T, middlewares *[]gin.HandlerFunc) (*gin.En
|
|||||||
assert.NilError(t, dockerService.Init())
|
assert.NilError(t, dockerService.Init())
|
||||||
|
|
||||||
// Access controls
|
// Access controls
|
||||||
accessControlsService := service.NewAccessControlsService(dockerService)
|
accessControlsService := service.NewAccessControlsService(dockerService, map[string]config.App{})
|
||||||
|
|
||||||
assert.NilError(t, accessControlsService.Init())
|
assert.NilError(t, accessControlsService.Init())
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import (
|
|||||||
|
|
||||||
type AccessControlsService struct {
|
type AccessControlsService struct {
|
||||||
docker *DockerService
|
docker *DockerService
|
||||||
config config.Apps
|
static map[string]config.App
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccessControlsService(docker *DockerService, config config.Apps) *AccessControlsService {
|
func NewAccessControlsService(docker *DockerService, static map[string]config.App) *AccessControlsService {
|
||||||
return &AccessControlsService{
|
return &AccessControlsService{
|
||||||
docker: docker,
|
docker: docker,
|
||||||
config: config,
|
static: static,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ func (acls *AccessControlsService) Init() error {
|
|||||||
return nil // No initialization needed
|
return nil // No initialization needed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acls *AccessControlsService) lookupConfigACLs(domain string) (config.App, error) {
|
func (acls *AccessControlsService) lookupStaticACLs(domain string) (config.App, error) {
|
||||||
for app, config := range acls.config.Apps {
|
for app, config := range acls.static {
|
||||||
if config.Config.Domain == domain {
|
if config.Config.Domain == domain {
|
||||||
log.Debug().Str("name", app).Msg("Found matching container by domain")
|
log.Debug().Str("name", app).Msg("Found matching container by domain")
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -41,7 +41,7 @@ func (acls *AccessControlsService) lookupConfigACLs(domain string) (config.App,
|
|||||||
|
|
||||||
func (acls *AccessControlsService) GetAccessControls(domain string) (config.App, error) {
|
func (acls *AccessControlsService) GetAccessControls(domain string) (config.App, error) {
|
||||||
// First check in the static config
|
// First check in the static config
|
||||||
app, err := acls.lookupConfigACLs(domain)
|
app, err := acls.lookupStaticACLs(domain)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Debug().Msg("Using ACls from static configuration")
|
log.Debug().Msg("Using ACls from static configuration")
|
||||||
|
|||||||
1
paerser
Submodule
1
paerser
Submodule
Submodule paerser added at 9364ccd8ba
95
patches/nested_maps.diff
Normal file
95
patches/nested_maps.diff
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
diff --git a/env/env_test.go b/env/env_test.go
|
||||||
|
index 7045569..365dc00 100644
|
||||||
|
--- a/env/env_test.go
|
||||||
|
+++ b/env/env_test.go
|
||||||
|
@@ -166,6 +166,38 @@ func TestDecode(t *testing.T) {
|
||||||
|
Foo: &struct{ Field string }{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
+ {
|
||||||
|
+ desc: "map under the root key",
|
||||||
|
+ environ: []string{"TRAEFIK_FOO_BAR_FOOBAR_BARFOO=foo"},
|
||||||
|
+ element: &struct {
|
||||||
|
+ Foo map[string]struct {
|
||||||
|
+ Foobar struct {
|
||||||
|
+ Barfoo string
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }{},
|
||||||
|
+ expected: &struct {
|
||||||
|
+ Foo map[string]struct {
|
||||||
|
+ Foobar struct {
|
||||||
|
+ Barfoo string
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }{
|
||||||
|
+ Foo: map[string]struct {
|
||||||
|
+ Foobar struct {
|
||||||
|
+ Barfoo string
|
||||||
|
+ }
|
||||||
|
+ }{
|
||||||
|
+ "bar": {
|
||||||
|
+ Foobar: struct {
|
||||||
|
+ Barfoo string
|
||||||
|
+ }{
|
||||||
|
+ Barfoo: "foo",
|
||||||
|
+ },
|
||||||
|
+ },
|
||||||
|
+ },
|
||||||
|
+ },
|
||||||
|
+ },
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
diff --git a/parser/nodes_metadata.go b/parser/nodes_metadata.go
|
||||||
|
index 36946c1..0279705 100644
|
||||||
|
--- a/parser/nodes_metadata.go
|
||||||
|
+++ b/parser/nodes_metadata.go
|
||||||
|
@@ -75,8 +75,13 @@ func (m metadata) add(rootType reflect.Type, node *Node) error {
|
||||||
|
node.Kind = fType.Kind()
|
||||||
|
node.Tag = field.Tag
|
||||||
|
|
||||||
|
- if fType.Kind() == reflect.Struct || fType.Kind() == reflect.Pointer && fType.Elem().Kind() == reflect.Struct ||
|
||||||
|
- fType.Kind() == reflect.Map {
|
||||||
|
+ if node.Kind == reflect.String && len(node.Children) > 0 {
|
||||||
|
+ fType = reflect.TypeOf(struct{}{})
|
||||||
|
+ node.Kind = reflect.Struct
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if node.Kind == reflect.Struct || node.Kind == reflect.Pointer && fType.Elem().Kind() == reflect.Struct ||
|
||||||
|
+ node.Kind == reflect.Map {
|
||||||
|
if len(node.Children) == 0 && !(field.Tag.Get(m.TagName) == TagLabelAllowEmpty || field.Tag.Get(m.TagName) == "-") {
|
||||||
|
return fmt.Errorf("%s cannot be a standalone element (type %s)", node.Name, fType)
|
||||||
|
}
|
||||||
|
@@ -90,11 +95,11 @@ func (m metadata) add(rootType reflect.Type, node *Node) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
- if fType.Kind() == reflect.Struct || fType.Kind() == reflect.Pointer && fType.Elem().Kind() == reflect.Struct {
|
||||||
|
+ if node.Kind == reflect.Struct || node.Kind == reflect.Pointer && fType.Elem().Kind() == reflect.Struct {
|
||||||
|
return m.browseChildren(fType, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
- if fType.Kind() == reflect.Map {
|
||||||
|
+ if node.Kind == reflect.Map {
|
||||||
|
if fType.Elem().Kind() == reflect.Interface {
|
||||||
|
addRawValue(node)
|
||||||
|
return nil
|
||||||
|
@@ -115,7 +120,7 @@ func (m metadata) add(rootType reflect.Type, node *Node) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
- if fType.Kind() == reflect.Slice {
|
||||||
|
+ if node.Kind == reflect.Slice {
|
||||||
|
if m.AllowSliceAsStruct && field.Tag.Get(TagLabelSliceAsStruct) != "" {
|
||||||
|
return m.browseChildren(fType.Elem(), node)
|
||||||
|
}
|
||||||
|
@@ -129,7 +134,7 @@ func (m metadata) add(rootType reflect.Type, node *Node) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
- return fmt.Errorf("invalid node %s: %v", node.Name, fType.Kind())
|
||||||
|
+ return fmt.Errorf("invalid node %s: %v", node.Name, node.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m metadata) findTypedField(rType reflect.Type, node *Node) (reflect.StructField, error) {
|
||||||
Reference in New Issue
Block a user