mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-28 06:14:32 +00:00
refactor
This commit is contained in:
parent
939b44e3ca
commit
1bc9283240
15 changed files with 241 additions and 458 deletions
|
|
@ -22,7 +22,7 @@ func newDownloadError(err error, isRetryable bool) *downloadError {
|
|||
func (e *downloadError) IsRetryable() bool { return e.isRetryable }
|
||||
func (e *downloadError) Error() string { return e.err.Error() }
|
||||
|
||||
func NewHTTPRegistry(schemaPathTemplate string, strict bool) *KubernetesRegistry {
|
||||
func newHTTPRegistry(schemaPathTemplate string, strict bool) *KubernetesRegistry {
|
||||
return &KubernetesRegistry{
|
||||
schemaPathTemplate: schemaPathTemplate,
|
||||
strict: strict,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func (e *fileNotFoundError) IsRetryable() bool { return e.isRetryable }
|
|||
func (e *fileNotFoundError) Error() string { return e.err.Error() }
|
||||
|
||||
// NewLocalSchemas creates a new "registry", that will serve schemas from files, given a list of schema filenames
|
||||
func NewLocalRegistry(pathTemplate string, strict bool) *LocalRegistry {
|
||||
func newLocalRegistry(pathTemplate string, strict bool) *LocalRegistry {
|
||||
return &LocalRegistry{
|
||||
pathTemplate,
|
||||
strict,
|
||||
|
|
|
|||
|
|
@ -64,3 +64,15 @@ func schemaPath(tpl, resourceKind, resourceAPIVersion, k8sVersion string, strict
|
|||
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func New(schemaLocation string, strict bool) Registry {
|
||||
if !strings.HasSuffix(schemaLocation, "json") { // If we dont specify a full templated path, we assume the paths of kubernetesjsonschema.dev
|
||||
schemaLocation += "/{{ .NormalizedVersion }}-standalone{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(schemaLocation, "http") {
|
||||
return newHTTPRegistry(schemaLocation, strict)
|
||||
} else {
|
||||
return newLocalRegistry(schemaLocation, strict)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue