func TweakCapabilities(basics, adds, drops []string) ([]string, error) {
	var (
		newCaps []string
		allCaps = GetAllCapabilities()
	)

	// look for invalid cap in the drop list
	for _, cap := range drops {
		if strings.ToLower(cap) == "all" {
			continue
		}
		if !stringutils.InSlice(allCaps, cap) {
			return nil, fmt.Errorf("Unknown capability drop: %q", cap)
		}
	}

	// handle --cap-add=all
	if stringutils.InSlice(adds, "all") {
		basics = allCaps
	}

	if !stringutils.InSlice(drops, "all") {
		for _, cap := range basics {
			// skip `all` already handled above
			if strings.ToLower(cap) == "all" {
				continue
			}

			// if we don't drop `all`, add back all the non-dropped caps
			if !stringutils.InSlice(drops, cap) {
				newCaps = append(newCaps, strings.ToUpper(cap))
			}
		}
	}

	for _, cap := range adds {
		// skip `all` already handled above
		if strings.ToLower(cap) == "all" {
			continue
		}

		if !stringutils.InSlice(allCaps, cap) {
			return nil, fmt.Errorf("Unknown capability to add: %q", cap)
		}

		// add cap if not already in the list
		if !stringutils.InSlice(newCaps, cap) {
			newCaps = append(newCaps, strings.ToUpper(cap))
		}
	}
	return newCaps, nil
}
// TweakCapabilities can tweak capabilities by adding or dropping capabilities
// based on the basics capabilities.
TweakCapabilities can tweak capabilities by adding or dropping capabilities
based on the basics capabilities.
// TweakCapabilities can tweak capabilities by adding or dropping capabilities // based on the basics capabilities .
func TweakCapabilities(basics, adds, drops []string) ([]string, error) {
	var (
		newCaps []string
		allCaps = GetAllCapabilities()
	)
	for _, cap := range drops {
		if strings.ToLower(cap) == "all" {
			continue
		}
		if !stringutils.InSlice(allCaps, cap) {
			return nil, fmt.Errorf("Unknown capability drop: %q", cap)
		}
	}
	if stringutils.InSlice(adds, "all") {
		basics = allCaps
	}
	if !stringutils.InSlice(drops, "all") {
		for _, cap := range basics {
			if strings.ToLower(cap) == "all" {
				continue
			}
			if !stringutils.InSlice(drops, cap) {
				newCaps = append(newCaps, strings.ToUpper(cap))
			}
		}
	}
	for _, cap := range adds {
		if strings.ToLower(cap) == "all" {
			continue
		}
		if !stringutils.InSlice(allCaps, cap) {
			return nil, fmt.Errorf("Unknown capability to add: %q", cap)
		}
		if !stringutils.InSlice(newCaps, cap) {
			newCaps = append(newCaps, strings.ToUpper(cap))
		}
	}
	return newCaps, nil
}
func TweakCapabilities ( basics , adds , drops [ ] string ) ( [ ] string , error ) { var ( newCaps [ ] string allCaps = GetAllCapabilities ( ) ) for _ , cap := range drops { if strings . ToLower ( cap ) == " " { continue } if ! stringutils . InSlice ( allCaps , cap ) { return nil , fmt . Errorf ( " " , cap ) } } if stringutils . InSlice ( adds , " " ) { basics = allCaps } if ! stringutils . InSlice ( drops , " " ) { for _ , cap := range basics { if strings . ToLower ( cap ) == " " { continue } if ! stringutils . InSlice ( drops , cap ) { newCaps = append ( newCaps , strings . ToUpper ( cap ) ) } } } for _ , cap := range adds { if strings . ToLower ( cap ) == " " { continue } if ! stringutils . InSlice ( allCaps , cap ) { return nil , fmt . Errorf ( " " , cap ) } if ! stringutils . InSlice ( newCaps , cap ) { newCaps = append ( newCaps , strings . ToUpper ( cap ) ) } } return newCaps , nil }
TweakCapabilities can tweak capabilities by adding or dropping capabilities
based on the basics capabilities.
TweakCapabilities can tweak capabilities by adding or dropping capabilities based on the basics capabilities .
// look for invalid cap in the drop list // handle --cap-add=all // skip `all` already handled above // if we don't drop `all`, add back all the non-dropped caps // skip `all` already handled above // add cap if not already in the list