1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

oci/caps: simplify, and remove types that were not needed

The `CapabilityMapping` and `Capabilities` types appeared to be only
used locally, and added unneeded complexity.

This patch removes those types, and simplifies the logic to use a
map that maps names to `capability.Cap`s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-09-19 14:52:32 +02:00
parent fc3f98848a
commit 58c4c120a8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -9,15 +9,22 @@ import (
)
var (
allCaps []string
capabilityList Capabilities
allCaps []string
// capabilityList maps linux capability name to its value of capability.Cap
// type. This list contains nil entries for capabilities that are known, but
// not supported by the current kernel.
// Capabilities is one of the security systems in Linux Security Module (LSM)
// framework provided by the kernel.
// For more details on capabilities, see http://man7.org/linux/man-pages/man7/capabilities.7.html
capabilityList map[string]*capability.Cap
)
func init() {
last := capability.CAP_LAST_CAP
rawCaps := capability.List()
allCaps = make([]string, min(int(last+1), len(rawCaps)))
capabilityList = make(Capabilities, min(int(last+1), len(rawCaps)))
capabilityList = make(map[string]*capability.Cap, len(rawCaps))
for i, c := range rawCaps {
capName := "CAP_" + strings.ToUpper(c.String())
if c > last {
@ -25,10 +32,7 @@ func init() {
continue
}
allCaps[i] = capName
capabilityList[capName] = &CapabilityMapping{
Key: capName,
Value: c,
}
capabilityList[capName] = &c
}
}
@ -39,24 +43,6 @@ func min(a, b int) int {
return b
}
type (
// CapabilityMapping maps linux capability name to its value of capability.Cap type
// Capabilities is one of the security systems in Linux Security Module (LSM)
// framework provided by the kernel.
// For more details on capabilities, see http://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityMapping struct {
Key string `json:"key,omitempty"`
Value capability.Cap `json:"value,omitempty"`
}
// Capabilities contains all CapabilityMapping
Capabilities map[string]*CapabilityMapping
)
// String returns <key> of CapabilityMapping
func (c *CapabilityMapping) String() string {
return c.Key
}
// GetAllCapabilities returns all of the capabilities
func GetAllCapabilities() []string {
return allCaps