Skip to content

Commit

Permalink
Merge pull request #113 from Revolyssup/master
Browse files Browse the repository at this point in the history
Adding few extra checks in component generation
  • Loading branch information
tangledbytes committed Oct 7, 2021
2 parents f0e5782 + 0378821 commit 7e6ee2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/manifests/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
ErrGetAPIVersionCode = "1003"
ErrGetAPIGroupCode = "1004"
ErrPopulatingYamlCode = "1005"
ErrAbsentFilterCode = "1006"
)

func ErrGetCrdNames(err error) error {
Expand All @@ -27,3 +28,6 @@ func ErrGetAPIGroup(err error) error {
func ErrPopulatingYaml(err error) error {
return errors.New(ErrPopulatingYamlCode, errors.Alert, []string{"Error populating yaml"}, []string{err.Error()}, []string{"Yaml could not be populated with the returned manifests"}, []string{""})
}
func ErrAbsentFilter(err error) error {
return errors.New(ErrAbsentFilterCode, errors.Alert, []string{"Error with passed filters"}, []string{err.Error()}, []string{"ItrFilter or ItrSpecFilter is either not passed or empty"}, []string{"Pass the correct ItrFilter and ItrSpecFilter"})
}
14 changes: 14 additions & 0 deletions utils/manifests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manifests
import (
"bytes"
"encoding/json"
"errors"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -63,6 +64,10 @@ func getDefinitions(crd string, resource int, cfg Config, filepath string, binPa
}

func getSchema(crd string, fp string, binPath string, cfg Config) (string, error) {
//few checks to avoid index out of bound panic
if len(cfg.Filter.ItrSpecFilter) == 0 {
return "", ErrAbsentFilter(errors.New("Empty ItrSpecFilter"))
}
inputFormat := "yaml"
if cfg.Filter.IsJson {
inputFormat = "json"
Expand Down Expand Up @@ -165,6 +170,11 @@ func getCrdnames(s string) []string {
}

func getApiVersion(binPath string, fp string, crd string, inputFormat string, cfg Config) (string, error) {
//few checks to avoid index out of bound panic
if len(cfg.Filter.ItrFilter) == 0 {
return "", ErrAbsentFilter(errors.New("Empty ItrFilter"))
}

var (
out bytes.Buffer
er bytes.Buffer
Expand Down Expand Up @@ -199,6 +209,10 @@ func getApiVersion(binPath string, fp string, crd string, inputFormat string, cf
return s, nil
}
func getApiGrp(binPath string, fp string, crd string, inputFormat string, cfg Config) (string, error) {
//few checks to avoid index out of bound panic
if len(cfg.Filter.ItrFilter) == 0 {
return "", ErrAbsentFilter(errors.New("Empty ItrFilter"))
}
var (
out bytes.Buffer
er bytes.Buffer
Expand Down

0 comments on commit 7e6ee2e

Please sign in to comment.