add general shizzle
(cherry picked from commit 72d164f3960436093d01d00d5ed6d43bc2e4e256)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package helmunit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/Jeffail/gabs"
|
||||
)
|
||||
|
||||
type manifestCollection map[string]map[string]gabs.Container
|
||||
|
||||
func (c *manifestCollection) Initialize() {
|
||||
*c = make(manifestCollection)
|
||||
}
|
||||
|
||||
func (c *manifestCollection) Add(yamlInput []byte) error {
|
||||
collection := *c
|
||||
jsonManifest, err := yamlToJson(yamlInput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kind := strings.ToLower(jsonManifest.Path("kind").Data().(string))
|
||||
name := strings.ToLower(jsonManifest.Path("metadata.name").Data().(string))
|
||||
|
||||
if kind == "" || name == "" {
|
||||
return errors.New("invalid manifest")
|
||||
}
|
||||
|
||||
data, ok := collection[kind]
|
||||
if !ok {
|
||||
data = make(map[string]gabs.Container)
|
||||
collection[kind] = data
|
||||
}
|
||||
data[name] = *jsonManifest
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *manifestCollection) Get(kind string, name string) *gabs.Container {
|
||||
collection := *c
|
||||
manifest, ok := collection[strings.ToLower(kind)][strings.ToLower(name)]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return &manifest
|
||||
}
|
||||
Reference in New Issue
Block a user