github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/internal/volumes/parser/linux_parser.go (about)

     1  package parser
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"gitlab.com/gitlab-org/gitlab-runner/helpers/path"
     7  )
     8  
     9  const (
    10  	linuxDir        = `/(?:[^\\/:*?"<>|\r\n ]+/?)*`
    11  	linuxVolumeName = `[^\\/:*?"<>|\r\n]+`
    12  
    13  	linuxSource = `((?P<source>((` + linuxDir + `)|(` + linuxVolumeName + `))):)?`
    14  
    15  	linuxDestination     = `(?P<destination>(?:` + linuxDir + `))`
    16  	linuxMode            = `(:(?P<mode>(?i)ro|rw|z))?`
    17  	linuxBindPropagation = `((:|,)(?P<bindPropagation>(?i)shared|slave|private|rshared|rslave|rprivate))?`
    18  )
    19  
    20  type linuxParser struct {
    21  	baseParser
    22  }
    23  
    24  func NewLinuxParser() Parser {
    25  	return &linuxParser{
    26  		baseParser: baseParser{
    27  			path: path.NewUnixPath(),
    28  		},
    29  	}
    30  }
    31  
    32  func (p *linuxParser) ParseVolume(spec string) (*Volume, error) {
    33  	specExp := regexp.MustCompile(`^` + linuxSource + linuxDestination + linuxMode + linuxBindPropagation + `$`)
    34  
    35  	parts, err := p.matchesToVolumeSpecParts(spec, specExp)
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	return newVolume(parts["source"], parts["destination"], parts["mode"], parts["bindPropagation"]), nil
    41  }