converter

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package converter provides utilities for converting between various types. For example, one should expect to see the following conversions:

TextProto <-> Protos
JSON      <-> Protos
YAML      <-> Protos

Index

Constants

This section is empty.

Variables

View Source
var (
	// Bundle is a converter for ClusterBundles
	Bundle = &Converter{&bpb.ClusterBundle{}}

	// ComponentPackage is a converter for ComponentPackage protos.
	ComponentPackage = &Converter{&bpb.ComponentPackage{}}

	// NodeConfig is a converter for NodeConfig protos.
	NodeConfig = &Converter{&bextpb.NodeConfig{}}

	// ObjectMeta is a converter for NodeConfig protos.
	ObjectMeta = &Converter{&bpb.ObjectMeta{}}

	// Struct is a converter for Struct protos.
	Struct = &Converter{&structpb.Struct{}}
)

Functions

func CloneBundle

func CloneBundle(b *bpb.ClusterBundle) *bpb.ClusterBundle

CloneBundle creates a copy of a cluster bundle proto.

func CloneComponentPackage added in v0.4.0

func CloneComponentPackage(b *bpb.ComponentPackage) *bpb.ComponentPackage

CloneComponentPackage creates a copy of a object collection proto.

func CloneFile

func CloneFile(b *bpb.File) *bpb.File

CloneFile creates a copy of a file proto **but not the actual file**.

func CloneStruct

func CloneStruct(b *structpb.Struct) *structpb.Struct

CloneStruct creates a copy of a struct proto.

func ObjectMetaFromStruct

func ObjectMetaFromStruct(obj *structpb.Struct) (*bpb.ObjectMeta, error)

ObjectMetaFromStruct converts to the ObjectMeta proto from a structpb's ObjectMeta.

func ProtoToJSON

func ProtoToJSON(b proto.Message) ([]byte, error)

ProtoToJSON converts a proto into a JSON encoded proto.

func ProtoToYAML

func ProtoToYAML(b proto.Message) ([]byte, error)

ProtoToYAML converts a proto into a YAML encoded proto.

func SanitizeName added in v0.4.1

func SanitizeName(name string) string

SanitizeName sanitizes a metadata.name field, replacing unsafe characters with _ and truncating if it's longer than 253 characters.

func ToBundle

func ToBundle(msg proto.Message) *bpb.ClusterBundle

ToBundle is a type converter for converting to and from a Bundle.

func ToComponentPackage added in v0.4.0

func ToComponentPackage(msg proto.Message) *bpb.ComponentPackage

ToComponentPackage is a type converter for converting to and from a ComponentPackage.

func ToNodeConfig

func ToNodeConfig(msg proto.Message) *bextpb.NodeConfig

ToNodeConfig is a type converter for converting to and from a NodeConfig.

func ToObjectMeta

func ToObjectMeta(msg proto.Message) *bpb.ObjectMeta

ToObjectMeta is a type converter for converting a proto to an ObjectMeta.

func ToStruct

func ToStruct(msg proto.Message) *structpb.Struct

ToStruct is a type converter for converting to and from a Struct.

Types

type BundleReaderWriter

type BundleReaderWriter struct {
	// RW is a FileReaderWriter instance.
	RW files.FileReaderWriter
}

BundleReaderWriter uses a file reader writer to read, write. and convert bundles.

func NewFileSystemBundleReaderWriter

func NewFileSystemBundleReaderWriter() *BundleReaderWriter

func (*BundleReaderWriter) ReadBundleFile

func (r *BundleReaderWriter) ReadBundleFile(ctx context.Context, path string) (*bpb.ClusterBundle, error)

ReadBundleFile reads in a ClusterBundle from a yaml file found at the given path.

func (*BundleReaderWriter) WriteBundleFile

func (r *BundleReaderWriter) WriteBundleFile(ctx context.Context, path string, bundle *bpb.ClusterBundle, permissions os.FileMode) error

WriteBundleFile writes a given ClusterBundle proto to a yaml file at the specified path with given permissions.

type Converter

type Converter struct {
	Msg proto.Message
}

Converter is a generic struct that knows how to convert between textpb, proto, and yamls, for a specific proto message.

func (*Converter) JSONToProto

func (b *Converter) JSONToProto(contents []byte) (proto.Message, error)

JSONToProto converts a json encoded bundle into a proto.

func (*Converter) ProtoToJSON

func (b *Converter) ProtoToJSON(bun proto.Message) ([]byte, error)

ProtoToJSON converts a bundle into a JSON encoded proto.

func (*Converter) ProtoToTextProto

func (b *Converter) ProtoToTextProto(msg proto.Message) ([]byte, error)

ProtoToTextProto converts a proto to a textformat proto.

func (*Converter) ProtoToYAML

func (b *Converter) ProtoToYAML(bun proto.Message) ([]byte, error)

ProtoToYAML converts a proto into a YAML encoded proto.

func (*Converter) TextProtoToProto

func (b *Converter) TextProtoToProto(textpb []byte) (proto.Message, error)

TextProtoToProto converts a textformat proto to a proto.

func (*Converter) YAMLToProto

func (b *Converter) YAMLToProto(contents []byte) (proto.Message, error)

YAMLToProto converts a yaml encoded bundle into a Proto

type KubeConverter

type KubeConverter struct {
	// contains filtered or unexported fields
}

KubeConverter converts structs to Kubernetes objects.

func FromStruct

func FromStruct(s *structpb.Struct) *KubeConverter

FromStruct creates a new KubeConverter.

func (*KubeConverter) ToConfigMap added in v0.4.1

func (k *KubeConverter) ToConfigMap() (*corev1.ConfigMap, error)

ToNodeConfig converts from a struct to a NodeConfig.

func (*KubeConverter) ToNodeConfig added in v0.4.0

func (k *KubeConverter) ToNodeConfig() (*bextpb.NodeConfig, error)

ToNodeConfig converts from a struct to a NodeConfig.

type ObjectExporter

type ObjectExporter struct {
	Objects []*structpb.Struct
}

ObjectExporter exports cluster objects

func (*ObjectExporter) ExportAsMultiYAML

func (e *ObjectExporter) ExportAsMultiYAML() ([]string, error)

ExportAsMultiYAML converts cluster objects into multiple YAML files.

func (*ObjectExporter) ExportAsYAML

func (e *ObjectExporter) ExportAsYAML() (string, error)

ExportAsYAML converts cluster objects into single YAML file.

Jump to

Keyboard shortcuts

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