This commit is contained in:
Stavros
2025-01-29 22:06:52 +02:00
parent 2385599c80
commit 6602e8140b
7 changed files with 186 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
package constants
var TinyauthLabels = []string{
"tinyauth.oauth.whitelist",
"tinyauth.users",
}

51
internal/docker/docker.go Normal file
View File

@@ -0,0 +1,51 @@
package docker
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)
func NewDocker() *Docker {
return &Docker{}
}
type Docker struct {
Client *client.Client
Context context.Context
}
func (docker *Docker) Init() error {
apiClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return err
}
docker.Context = context.Background()
docker.Client = apiClient
return nil
}
func (docker *Docker) GetContainers() ([]types.Container, error) {
containers, err := docker.Client.ContainerList(docker.Context, container.ListOptions{})
if err != nil {
return nil, err
}
return containers, nil
}
func (docker *Docker) InspectContainer(containerId string) (types.ContainerJSON, error) {
inspect, err := docker.Client.ContainerInspect(docker.Context, containerId)
if err != nil {
return types.ContainerJSON{}, err
}
return inspect, nil
}

View File

@@ -95,3 +95,8 @@ type SessionCookie struct {
Username string
Provider string
}
type TinyauthLabels struct {
OAuthWhitelist []string
Users []string
}

View File

@@ -4,7 +4,9 @@ import (
"errors"
"net/url"
"os"
"slices"
"strings"
"tinyauth/internal/constants"
"tinyauth/internal/types"
"github.com/rs/zerolog/log"
@@ -128,3 +130,19 @@ func GetUsers(conf string, file string) (types.Users, error) {
func OAuthConfigured(config types.Config) bool {
return (config.GithubClientId != "" && config.GithubClientSecret != "") || (config.GoogleClientId != "" && config.GoogleClientSecret != "") || (config.GenericClientId != "" && config.GenericClientSecret != "")
}
func GetTinyauthLabels(labels map[string]string) types.TinyauthLabels {
var tinyauthLabels types.TinyauthLabels
for label, value := range labels {
if slices.Contains(constants.TinyauthLabels, label) {
log.Debug().Str("label", label).Str("value", value).Msg("Found label")
switch label {
case "tinyauth.oauth.whitelist":
tinyauthLabels.OAuthWhitelist = strings.Split(value, ",")
case "tinyauth.users":
tinyauthLabels.Users = strings.Split(value, ",")
}
}
}
return tinyauthLabels
}