Files
DoGaMa-serv/internal/instance/runtime_user.go
T
codex 368ae918a8
CI / validate (pull_request) Successful in 26m27s
feat(runtime): add configurable game server uid gid
2026-08-25 22:57:23 +02:00

29 lines
1.0 KiB
Go

package instance
import (
"fmt"
"strconv"
"git.zaynet.fr/DoGaMa/DoGaMa-serv/internal/catalog"
)
// RuntimeUserEnvironment maps the global managed identity through the
// template-declared environment contract. It deliberately does not know any
// game-specific variable names.
func RuntimeUserEnvironment(template catalog.Template, identity RuntimeIdentity) (map[string]string, error) {
result := map[string]string{}
runtimeUser := template.Container.RuntimeUser
if runtimeUser.Mode == "" || runtimeUser.Mode == "docker" {
return result, nil
}
if runtimeUser.Mode != "environment" || template.Container.UserMode != DockerUserImage {
return nil, fmt.Errorf("invalid runtime user policy")
}
if runtimeUser.UIDEnv == "" || runtimeUser.GIDEnv == "" || runtimeUser.UIDEnv == runtimeUser.GIDEnv {
return nil, fmt.Errorf("invalid runtime user environment mapping")
}
result[runtimeUser.UIDEnv] = strconv.FormatUint(uint64(identity.UID), 10)
result[runtimeUser.GIDEnv] = strconv.FormatUint(uint64(identity.GID), 10)
return result, nil
}