jsonapihelper

package
v0.0.0-...-7c77b90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateModifiedConfigFile

func GenerateModifiedConfigFile(dataFiles [][]byte, patchData []byte, fns []string, rsName string, rsKind string) ([]byte, error)

GenerateModifiedConfigFile takes in two JSON bytes arrays. First JSON byte array consists of data which the generated configMap shall contain or the raw data that the files contain. Second JSON byte array consists of the patch JSON. Example of both JSONs configMap.json

[{
    "scenario": "traffic",
    "address": "Dawson Creek",
    "location": {
        "lat": 45.539626,
        "lon": -122.929569
    },
    "sensors": [{
        "address": "Shute & Dawson Creek",
        "location": {
            "lat": 45.544223,
            "lon": -122.926128
        },
        "algorithm": "object-detection",
        "mnth": 75.0,
        "alpha": 45.0,
        "fovh": 90.0,
        "fovv": 68.0,
        "theta": 0.0,
        "simsn": "cams1o1c0",
        "simfile": "_traffic.mp4$"
    }]
}]

PatchJSON: [

{
    "op": "replace",
    "path": "/data/config.json",
    "value":  "1"
}

]

func GenerateModifiedYamlFileForExistingResources

func GenerateModifiedYamlFileForExistingResources(patchData []byte, existingResData []byte, resName string) ([]byte, error)

GenerateModifiedYamlFileForExistingResources takes in the patchData and the existing resource's yaml file and returns the modified yaml file for the resource

func GetPatchFromFile

func GetPatchFromFile(fns []string) ([]byte, error)

GetPatchFromFile generates patch files. Patch files are array of JSON, eg:

	[
    	{
        	"op": "replace",
        	"path": "/Data/config1.json",
        	"value":  "1"
		},
		{
        	"op": "replace",
        	"path": "/Data/config2.json",
        	"value":  "1"
    	}
	]
	Here "config.json" shall be replaced by the fileNames.

func GetPatchFromPatchJSON

func GetPatchFromPatchJSON(p []map[string]interface{}) ([]byte, error)

GetPatchFromPatchJSON generates patch files in bytes. This is used when the user requests

 the patchType as "json" and patchJSON as below:

	"patchType": "json",
    "patchJson": [
      {
        "op": "replace",
        "path": "/spec/replicas",
        "value": "1"
      }
    ]

func SetBaseConfigMap

func SetBaseConfigMap(fns []string, cmName string) ([]byte, error)

SetBaseConfigMap returns a base configMap JSON in form of bytes

func SetBaseSecret

func SetBaseSecret(fns []string, cmName string) ([]byte, error)

SetBaseSecret returns a base secret resource in bytes format

Types

type ConfigMapResource

type ConfigMapResource struct {
	APIVersion string            `yaml:"apiVersion"`
	Kind       string            `yaml:"kind"`
	MetaData   MetaDataStr       `yaml:"metadata"`
	Data       map[string]string `yaml:"data"`
}

ConfigMapResource consists of ApiVersion, Kind, MetaData and Data map

type MetaDataStr

type MetaDataStr struct {
	Name      string `yaml:"name"`
	Namespace string `yaml:"namespace,omitempty"`
}

MetaDataStr consists of Name and Namespace. Namespace is optional

type SecretResource

type SecretResource struct {
	APIVersion string            `yaml:"apiVersion"`
	Kind       string            `yaml:"kind"`
	MetaData   MetaDataStr       `yaml:"metadata"`
	Type       string            `yaml:"type"`
	Data       map[string]string `yaml:"data"`
}

SecretResource consists of ApiVersion, Kind, MetaData, type and Data map

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL