1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00

Revert "Adding HTTP(git raw or any public url ) URL applying functionality to kyverno cli (#1527)" (#1548)

This reverts commit 0487330b33.
This commit is contained in:
shuting 2021-02-05 19:34:15 -08:00 committed by GitHub
parent 0487330b33
commit c42d545c20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 77 deletions

View file

@ -7,9 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"path/filepath"
"strings"
"sigs.k8s.io/controller-runtime/pkg/log"
@ -53,25 +51,14 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, errors []error)
for _, path := range paths {
log.Log.V(5).Info("reading policies", "path", path)
var (
fileDesc os.FileInfo
err error
)
isHttpPath := strings.Contains(path, "http")
// path clean and retrieving file info can be possible if it's not an HTTP URL
if !isHttpPath {
path = filepath.Clean(path)
fileDesc, err = os.Stat(path)
if err != nil {
errors = append(errors, err)
continue
}
path = filepath.Clean(path)
fileDesc, err := os.Stat(path)
if err != nil {
errors = append(errors, err)
continue
}
// apply file from a directory is possible only if the path is not HTTP URL
if !isHttpPath && fileDesc.IsDir() {
if fileDesc.IsDir() {
files, err := ioutil.ReadDir(path)
if err != nil {
errors = append(errors, fmt.Errorf("failed to read %v: %v", path, err.Error()))
@ -91,34 +78,10 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, errors []error)
policies = append(policies, policiesFromDir...)
} else {
var fileBytes []byte
if isHttpPath {
resp, err := http.Get(path)
if err != nil {
fmt.Errorf("failed to process %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
errors = append(errors, fmt.Errorf("failed to process %v: %v", path, err.Error()))
continue
}
fileBytes, err = ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Errorf("failed to process %s", err)
}
if err != nil {
errors = append(errors, fmt.Errorf("failed to read %v: %v", path, err.Error()))
continue
}
} else {
fileBytes, err = ioutil.ReadFile(path)
if err != nil {
errors = append(errors, fmt.Errorf("failed to read %v: %v", path, err.Error()))
continue
}
fileBytes, err := ioutil.ReadFile(path)
if err != nil {
errors = append(errors, fmt.Errorf("failed to read %v: %v", path, err.Error()))
continue
}
policiesFromFile, errFromFile := utils.GetPolicy(fileBytes)
@ -129,7 +92,6 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, errors []error)
}
policies = append(policies, policiesFromFile...)
}
}

View file

@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
v1 "github.com/kyverno/kyverno/pkg/api/kyverno/v1"
client "github.com/kyverno/kyverno/pkg/dclient"
@ -198,34 +196,10 @@ func getResourcesOfTypeFromCluster(resourceTypes []string, dClient *client.Clien
}
func getFileBytes(path string) ([]byte, error) {
var (
file []byte
err error
)
if strings.Contains(path, "http") {
resp, err := http.Get(path)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, err
}
file, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
} else {
file, err = ioutil.ReadFile(path)
if err != nil {
return nil, err
}
file, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return file, err
}