mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
add container name and path check.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<v-text-field
|
||||
label="Name"
|
||||
v-model="data.name"
|
||||
:rules="[ rules.slug ]"
|
||||
:rules="[ rules.containerNameStart, rules.containerName ]"
|
||||
autocomplete="off"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
@@ -218,7 +218,7 @@
|
||||
label="Host path"
|
||||
:value="host_path"
|
||||
@input="$set(data.mounts, index, { host_path: $event, container_path })"
|
||||
:rules="[ rules.absolutePath ]"
|
||||
:rules="[ rules.absolutePath, rules.withoutColon ]"
|
||||
autocomplete="off"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
@@ -228,7 +228,7 @@
|
||||
label="Container path"
|
||||
:value="container_path"
|
||||
@input="$set(data.mounts, index, { host_path, container_path: $event})"
|
||||
:rules="[ rules.absolutePath ]"
|
||||
:rules="[ rules.absolutePath, rules.withoutColon ]"
|
||||
autocomplete="off"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
@@ -307,11 +307,17 @@ export default class RoomsCreate extends Vue {
|
||||
nonZero(val: string) {
|
||||
return val === "0" ? 'Value cannot be zero.' : true
|
||||
},
|
||||
slug(val: string) {
|
||||
return val && !/^[A-Za-z0-9-_.]+$/.test(val) ? 'Should only contain A-Z a-z 0-9 - _ .' : true
|
||||
containerName(val: string) {
|
||||
return val && !/^[a-zA-Z0-9][a-zA-Z0-9_.-]+$/.test(val) ? 'Must only contain a-z A-Z 0-9 _ . -' : true
|
||||
},
|
||||
containerNameStart(val: string) {
|
||||
return val && /^[_.-]/.test(val) ? 'Cannot start with _ . -' : true
|
||||
},
|
||||
absolutePath(val: string) {
|
||||
return val[0] !== "/" ? 'Must be absolute path, starting with /.' : true
|
||||
},
|
||||
withoutColon(val: string) {
|
||||
return val && /:$/.test(val) ? 'Cannnot contain : character.' : true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
dockerNames "github.com/docker/docker/daemon/names"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -127,8 +128,23 @@ func (s *Room) Set() {
|
||||
s.NekoImages = viper.GetStringSlice("neko_images")
|
||||
|
||||
s.InstanceName = viper.GetString("instance.name")
|
||||
if !dockerNames.RestrictedNamePattern.MatchString(s.InstanceName) {
|
||||
log.Panic().Msg("invalid `instance.name`, must match " + dockerNames.RestrictedNameChars)
|
||||
}
|
||||
|
||||
s.InstanceUrl = viper.GetString("instance.url")
|
||||
s.InstanceData = viper.GetString("instance.data")
|
||||
if s.InstanceData != "" {
|
||||
if !strings.HasPrefix(s.InstanceData, "/") {
|
||||
log.Panic().Msg("invalid `instance.data`, must be absolute path starting with /.")
|
||||
}
|
||||
|
||||
if strings.Contains(s.InstanceData, ":") {
|
||||
log.Panic().Msg("invalid `instance.data`, cannot contain : character")
|
||||
}
|
||||
} else {
|
||||
log.Warn().Msg("missing `instance.data`, container mounts are unavailable")
|
||||
}
|
||||
|
||||
s.TraefikDomain = viper.GetString("traefik.domain")
|
||||
s.TraefikEntrypoint = viper.GetString("traefik.entrypoint")
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
network "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/strslice"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
dockerNames "github.com/docker/docker/daemon/names"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -84,6 +85,14 @@ func (manager *RoomManagerCtx) FindByName(name string) (*types.RoomEntry, error)
|
||||
}
|
||||
|
||||
func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, error) {
|
||||
if settings.Name != "" && dockerNames.RestrictedNamePattern.MatchString(settings.Name) {
|
||||
return "", fmt.Errorf("invalid container name, must match " + dockerNames.RestrictedNameChars)
|
||||
}
|
||||
|
||||
if manager.config.InstanceData == "" && len(settings.Mounts) > 0 {
|
||||
return "", fmt.Errorf("mounts cannot be specified, because `instance.data` config value is not set")
|
||||
}
|
||||
|
||||
if in, _ := utils.ArrayIn(settings.NekoImage, manager.config.NekoImages); !in {
|
||||
return "", fmt.Errorf("invalid neko image")
|
||||
}
|
||||
@@ -180,9 +189,12 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
||||
|
||||
binds := []string{}
|
||||
for _, mount := range settings.Mounts {
|
||||
if strings.Contains(mount.HostPath, ":") || strings.Contains(mount.ContainerPath, ":") {
|
||||
return "", fmt.Errorf("mount paths cannot contain : character")
|
||||
}
|
||||
|
||||
binds = append(
|
||||
binds,
|
||||
// TODO: Check for invalid paths.
|
||||
path.Join(manager.config.InstanceData, roomName, mount.HostPath)+":"+mount.ContainerPath,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user