mediatype

package
v0.105.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// BlueprintType is the name of the blueprint type in a component descriptor.
	BlueprintType = "landscaper.gardener.cloud/blueprint"

	// OldBlueprintType is the old name of the blueprint type in a component descriptor.
	OldBlueprintType = "blueprint"

	// BlueprintArtifactsMediaTypeV0 is the reserved media type for a blueprint that is stored as its own artifact.
	// This is the legacy deprecated artifact media type that was used for the layer and the config type.
	// Use BlueprintArtifactsConfigMediaTypeV1 or BlueprintArtifactsLayerMediaTypeV1 instead.
	// DEPRECATED
	BlueprintArtifactsMediaTypeV0 = "application/vnd.gardener.landscaper.blueprint.v1+tar+gzip"

	// BlueprintArtifactsConfigMediaTypeV1 is the config reserved media type for a blueprint that is stored as its own artifact.
	// This describes the config media type of the blueprint artifact.
	// The suffix can be yaml or json whereas yaml is the default.
	BlueprintArtifactsConfigMediaTypeV1 = "application/vnd.gardener.landscaper.blueprint.config.v1"

	// BlueprintArtifactsLayerMediaTypeV1 is the reserved layer media type for a blueprint that is stored as its own artifact.
	// This describes the layer media type of the blueprint artifact as well as the media type of a localOciBlob.
	// Optionally the compression can be added as "+gzip"
	BlueprintArtifactsLayerMediaTypeV1 = "application/vnd.gardener.landscaper.blueprint.layer.v1.tar"

	// JSONSchemaType is the name of json schema type in a component descriptor.
	// Although it is not a media or MIME type, this currently seems like the best place to put it.
	JSONSchemaType = "landscaper.gardener.cloud/jsonschema"

	// JSONSchemaArtifactsMediaTypeV0 is the reserved media type for a jsonschema that is stored as layer in an oci artifact.
	// This is the legacy deprecated artifact media type use JSONSchemaArtifactsMediaTypeV1 instead.
	// DEPRECATED
	JSONSchemaArtifactsMediaTypeV0 = "application/vnd.gardener.landscaper.jsonscheme.v1+json"

	// JSONSchemaArtifactsMediaTypeV1 is the reserved media type for a jsonschema that is stored as layer in an oci artifact.
	// This is the legacy deprecated artifact media type.
	JSONSchemaArtifactsMediaTypeV1 = "application/vnd.gardener.landscaper.jsonschema.layer.v1.json"

	// GZipCompression is the identifier for a gzip compressed file.
	GZipCompression = "gzip"

	// MediaTypeGZip defines the media type for a gzipped file
	MediaTypeGZip = "application/gzip"
)

Variables

View Source
var InvalidTypeError = errors.New("INVALID_MEDIA_TYPE")

Functions

func DefaultMediaTypeConversions

func DefaultMediaTypeConversions(mediaType string) (convertedType string, converted bool, err error)

DefaultMediaTypeConversions defines the default conversions for landscaper media types.

Types

type Builder

type Builder struct {
	Type MediaType
}

Builder is a media type builder

func NewBuilder

func NewBuilder(t string) *Builder

NewBuilder creates a new media type builder.

func (*Builder) Build

func (b *Builder) Build() MediaType

Build builds the mediatype

func (*Builder) Compression

func (b *Builder) Compression(comp string) *Builder

Compression sets the compression format

func (*Builder) FileFormat

func (b *Builder) FileFormat(format string) *Builder

FileFormat sets the file format of the media type. Will be automatically parsed from the type if it is not a config type.

func (*Builder) IsConfigType

func (b *Builder) IsConfigType() *Builder

IsConfigType configures the media type as oci config.

func (*Builder) IsLayerType

func (b *Builder) IsLayerType() *Builder

IsLayerType configures the media type as oci layer.

func (*Builder) String

func (b *Builder) String() string

String returns the media type as string

type ConversionFunc

type ConversionFunc func(mediaType string) (convertedType string, converted bool, err error)

ConversionFunc describes a conversion func for a media type

type MediaType

type MediaType struct {
	// Orig contains the complete original type
	Orig string
	// Format describes the specific format of the media type
	Format MediaTypeFormat
	// Type contain the parsed type without suffix.
	Type string
	// Suffix contains the suffix of a media that is given after the "+"-char
	Suffix *string

	// Version describes the config or layer version.
	Version *string
	// FileFormat contains only the file format.
	// This is part of the Type if the mediatype is not a ConfigType.
	// If it is a ConfigType the FileFormat is not part of the type.
	FileFormat *string
	// CompressionFormat contains the optional compression format.
	CompressionFormat *string
}

MediaType describes a media type (formerly known as MIME type) defined by the IANA in THE RFC 2045. In addition oci specific media types as defined in https://github.com/opencontainers/artifacts/blob/master/artifact-authors.md#defining-layermediatypes are parsed.

func Parse

func Parse(mediaType string, conversions ...ConversionFunc) (MediaType, error)

Parse parses a config and layer media type according to the oci spec. Config: [registration-tree].[org|company|entity].[objectType].[optional-subType].config.[version]+[optional-configFormat] Layers: [registration-tree].[org|company|entity].[layerType].[optional-layerSubType].layer.[version].[fileFormat]+[optional-compressionFormat] Layers also allow any IANA media type

https://github.com/opencontainers/artifacts/blob/master/artifact-authors.md#defining-layermediatypes

This method is highly landscaper specific and can also handle legacy types that are automatically converted.

func (MediaType) HasFileFormat

func (t MediaType) HasFileFormat(format string) bool

HasFileFormat checks if the media type contains the given file format. if the given format is empty this functions only validates if a format is given

func (MediaType) HasSuffix

func (t MediaType) HasSuffix(suffix string) bool

HasSuffix checks if the media type contains the given suffix. if the given format is empty this functions only validates if a format is given

func (MediaType) IsCompressed

func (t MediaType) IsCompressed(format string) bool

IsCompressed checks if the media type is compressed with the given format. if the given format is empty this functions only validates if a compression is given

func (MediaType) String

func (t MediaType) String() string

String returns the string using the parsed type file and compression.

type MediaTypeFormat

type MediaTypeFormat string
const (
	DefaultFormat   MediaTypeFormat = ""
	OCIConfigFormat MediaTypeFormat = "ociConfig"
	OCILayerFormat  MediaTypeFormat = "ociLayer"
)

Jump to

Keyboard shortcuts

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