utils/buildflags: ParseEntitlements(): use BuildKit's parsing

Use buildkit's parsing of entitlements to make sure that accepted
values match what's accepted by BuildKit.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-06-23 10:44:30 +02:00
parent bd672eaf5b
commit 399beb53d9
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 5 additions and 11 deletions

View File

@ -1,21 +1,15 @@
package buildflags package buildflags
import ( import "github.com/moby/buildkit/util/entitlements"
"github.com/moby/buildkit/util/entitlements"
"github.com/pkg/errors"
)
func ParseEntitlements(in []string) ([]entitlements.Entitlement, error) { func ParseEntitlements(in []string) ([]entitlements.Entitlement, error) {
out := make([]entitlements.Entitlement, 0, len(in)) out := make([]entitlements.Entitlement, 0, len(in))
for _, v := range in { for _, v := range in {
switch v { e, err := entitlements.Parse(v)
case "security.insecure": if err != nil {
out = append(out, entitlements.EntitlementSecurityInsecure) return nil, err
case "network.host":
out = append(out, entitlements.EntitlementNetworkHost)
default:
return nil, errors.Errorf("invalid entitlement: %v", v)
} }
out = append(out, e)
} }
return out, nil return out, nil
} }