...

Source file src/edge-infra.dev/pkg/f8n/warehouse/oci/layer/types.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/oci/layer

     1  package layer
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/google/go-containerregistry/pkg/v1/types"
     7  )
     8  
     9  // YAML is the OCI media type of all Warehouse layers.
    10  const YAML types.MediaType = "yaml"
    11  
    12  // Type is a reliable way to identify distinct kinds of Layers that Warehouse
    13  // supports.
    14  type Type string
    15  
    16  // Supported Layer types.
    17  const (
    18  	Infra   Type = "infrastructure"
    19  	Runtime Type = "runtime"
    20  	Config  Type = "config"
    21  )
    22  
    23  func (t Type) String() string {
    24  	return string(t)
    25  }
    26  
    27  // IsValid returns an error if the Type t is not a valid Warehouse layer type.
    28  func (t Type) IsValid() error {
    29  	if IsType(t.String()) {
    30  		return nil
    31  	}
    32  	return fmt.Errorf("invalid warehouse layer type %s: expected one of %s",
    33  		t, []Type{Infra, Runtime, Config})
    34  }
    35  
    36  // IsType returns true if the input string is a valid Warehouse layer type.
    37  func IsType(s string) bool {
    38  	switch Type(s) {
    39  	case Infra, Runtime, Config:
    40  		return true
    41  	default:
    42  		return false
    43  	}
    44  }
    45  

View as plain text