Debian Codegraph @

api/internal/loader/loader.go

raw
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Package loader has a data loading interface and various implementations.
5 package loader
6
7 import (
8 "sigs.k8s.io/kustomize/api/ifc"
9 "sigs.k8s.io/kustomize/api/internal/git"
10 "sigs.k8s.io/kustomize/kyaml/errors"
11 "sigs.k8s.io/kustomize/kyaml/filesys"
12 )
13
14 // NewLoader returns a Loader pointed at the given target.
15 // If the target is remote, the loader will be restricted
16 // to the root and below only. If the target is local, the
17 // loader will have the restrictions passed in. Regardless,
18 // if a local target attempts to transitively load remote bases,
19 // the remote bases will all be root-only restricted.
20 func NewLoader(
21 lr LoadRestrictorFunc,
22 target string, fSys filesys.FileSystem) (ifc.Loader, error) {
23 repoSpec, err := git.NewRepoSpecFromURL(target)
24 if err == nil {
25 // The target qualifies as a remote git target.
26 return newLoaderAtGitClone(
27 repoSpec, fSys, nil, git.ClonerUsingGitExec)
28 }
29 root, err := filesys.ConfirmDir(fSys, target)
30 if err != nil {
31 return nil, errors.WrapPrefixf(err, "%s", ErrRtNotDir.Error())
32 }
33 return newLoaderAtConfirmedDir(
34 lr, root, fSys, nil, git.ClonerUsingGitExec), nil
35 }