move load restrictions

This commit is contained in:
Jeffrey Regan
2019-11-01 17:20:50 -07:00
committed by jregan
parent 79c5f8a977
commit a45eca7e22
18 changed files with 243 additions and 139 deletions

View File

@@ -0,0 +1,32 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
"github.com/pkg/errors"
)
type errOnlyBuiltinPluginsAllowed struct {
name string
}
func (e *errOnlyBuiltinPluginsAllowed) Error() string {
return fmt.Sprintf(
"external plugins disabled; unable to load external plugin '%s'",
e.name)
}
func NewErrOnlyBuiltinPluginsAllowed(n string) *errOnlyBuiltinPluginsAllowed {
return &errOnlyBuiltinPluginsAllowed{name: n}
}
func IsErrOnlyBuiltinPluginsAllowed(err error) bool {
_, ok := err.(*errOnlyBuiltinPluginsAllowed)
if ok {
return true
}
_, ok = errors.Cause(err).(*errOnlyBuiltinPluginsAllowed)
return ok
}

View File

@@ -0,0 +1,24 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types
// Restrictions on what things can be referred to
// in a kustomization file.
//
//go:generate stringer -type=LoadRestrictions
type LoadRestrictions int
const (
LoadRestrictionsUnknown LoadRestrictions = iota
// Files referenced by a kustomization file must be in
// or under the directory holding the kustomization
// file itself.
LoadRestrictionsRootOnly
// The kustomization file may specify absolute or
// relative paths to patch or resources files outside
// its own tree.
LoadRestrictionsNone
)

View File

@@ -0,0 +1,25 @@
// Code generated by "stringer -type=LoadRestrictions"; DO NOT EDIT.
package types
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[LoadRestrictionsUnknown-0]
_ = x[LoadRestrictionsRootOnly-1]
_ = x[LoadRestrictionsNone-2]
}
const _LoadRestrictions_name = "LoadRestrictionsUnknownLoadRestrictionsRootOnlyLoadRestrictionsNone"
var _LoadRestrictions_index = [...]uint8{0, 23, 47, 67}
func (i LoadRestrictions) String() string {
if i < 0 || i >= LoadRestrictions(len(_LoadRestrictions_index)-1) {
return "LoadRestrictions(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _LoadRestrictions_name[_LoadRestrictions_index[i]:_LoadRestrictions_index[i+1]]
}

View File

@@ -11,6 +11,7 @@ type PluginConfig struct {
// further categorizing plugins.
DirectoryPath string
// Enabled is true if plugins are enabled.
Enabled bool
// PluginRestrictions defines the plugin restriction state.
// See type for more information.
PluginRestrictions PluginRestrictions
}

View File

@@ -0,0 +1,28 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types
// Some plugin classes
// - builtin: plugins defined in the kustomize repo.
// May be freely used and re-configured.
// - local: plugins that aren't builtin but are
// locally defined (presumably by the user), meaning
// the kustomization refers to them via a relative
// file path, not a URL.
// - remote: require a build-time download to obtain.
// Unadvised, unless one controls the
// serving site.
//
//go:generate stringer -type=PluginRestrictions
type PluginRestrictions int
const (
PluginRestrictionsUnknown PluginRestrictions = iota
// Non-builtin plugins completely disabled.
PluginRestrictionsBuiltinsOnly
// No restrictions, do whatever you want.
PluginRestrictionsNone
)

View File

@@ -0,0 +1,25 @@
// Code generated by "stringer -type=PluginRestrictions"; DO NOT EDIT.
package types
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[PluginRestrictionsUnknown-0]
_ = x[PluginRestrictionsBuiltinsOnly-1]
_ = x[PluginRestrictionsNone-2]
}
const _PluginRestrictions_name = "PluginRestrictionsUnknownPluginRestrictionsBuiltinsOnlyPluginRestrictionsNone"
var _PluginRestrictions_index = [...]uint8{0, 25, 55, 77}
func (i PluginRestrictions) String() string {
if i < 0 || i >= PluginRestrictions(len(_PluginRestrictions_index)-1) {
return "PluginRestrictions(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _PluginRestrictions_name[_PluginRestrictions_index[i]:_PluginRestrictions_index[i+1]]
}