29 lines
1.0 KiB
Go
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
|
|
}
|