github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/pkg/capabilities/caps.go (about)

     1  // Package capabilities allows to generically handle capabilities.
     2  package capabilities // import "github.com/docker/docker/pkg/capabilities"
     3  
     4  // Set represents a set of capabilities.
     5  type Set map[string]struct{}
     6  
     7  // Match tries to match set with caps, which is an OR list of AND lists of capabilities.
     8  // The matched AND list of capabilities is returned; or nil if none are matched.
     9  func (set Set) Match(caps [][]string) []string {
    10  	if set == nil {
    11  		return nil
    12  	}
    13  anyof:
    14  	for _, andList := range caps {
    15  		for _, cap := range andList {
    16  			if _, ok := set[cap]; !ok {
    17  				continue anyof
    18  			}
    19  		}
    20  		return andList
    21  	}
    22  	// match anything
    23  	return nil
    24  }