github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/internal/volumes/parser/base_parser.go (about) 1 package parser 2 3 import ( 4 "regexp" 5 6 "gitlab.com/gitlab-org/gitlab-runner/helpers/path" 7 ) 8 9 type baseParser struct { 10 path path.Path 11 } 12 13 // The way how matchesToVolumeSpecParts parses the volume mount specification and assigns 14 // parts was inspired by how Docker Engine's `windowsParser` is created. The original sources 15 // can be found at: 16 // 17 // https://github.com/docker/engine/blob/a79fabbfe84117696a19671f4aa88b82d0f64fc1/volume/mounts/windows_parser.go 18 // 19 // The original source is licensed under Apache License 2.0 and the copyright for it 20 // goes to Docker, Inc. 21 func (p *baseParser) matchesToVolumeSpecParts(spec string, specExp *regexp.Regexp) (map[string]string, error) { 22 match := specExp.FindStringSubmatch(spec) 23 24 if len(match) == 0 { 25 return nil, NewInvalidVolumeSpecErr(spec) 26 } 27 28 matchgroups := make(map[string]string) 29 for i, name := range specExp.SubexpNames() { 30 matchgroups[name] = match[i] 31 } 32 33 parts := map[string]string{ 34 "source": "", 35 "destination": "", 36 "mode": "", 37 "bindPropagation": "", 38 } 39 40 for group := range parts { 41 content, ok := matchgroups[group] 42 if ok { 43 parts[group] = content 44 } 45 } 46 47 return parts, nil 48 } 49 50 func (p *baseParser) Path() path.Path { 51 return p.path 52 }