...

Source file src/edge-infra.dev/pkg/f8n/warehouse/release/repository.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/release

     1  package release
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gopkg.in/yaml.v3"
     7  )
     8  
     9  type Repo interface {
    10  	String() string
    11  	Registry() string
    12  	Name() string
    13  }
    14  
    15  type Repository struct {
    16  	Repo
    17  }
    18  
    19  func (rr *Repository) UnmarshalYAML(rootNode *yaml.Node) error {
    20  	gcpRep := &GCPRepository{}
    21  	gcpRepErr := rootNode.Decode(gcpRep)
    22  	if gcpRepErr == nil {
    23  		rr.Repo = gcpRep
    24  		return nil
    25  	}
    26  
    27  	rawRep := &RawRepository{}
    28  	rawRepErr := rootNode.Decode(rawRep)
    29  	if rawRepErr == nil {
    30  		rr.Repo = rawRep
    31  		return nil
    32  	}
    33  
    34  	return fmt.Errorf("could not unmarshal ReleaseRepository")
    35  }
    36  
    37  type GCPRepository struct {
    38  	Location string `yaml:"location"`
    39  	Project  string `yaml:"project"`
    40  	RepoName string `yaml:"name"`
    41  }
    42  
    43  func (gcpr GCPRepository) String() string {
    44  	return fmt.Sprintf("%s-docker.pkg.dev/%s/%s", gcpr.Location, gcpr.Project, gcpr.Name())
    45  }
    46  
    47  func (gcpr GCPRepository) Name() string {
    48  	return gcpr.RepoName
    49  }
    50  
    51  func (gcpr GCPRepository) Registry() string {
    52  	return fmt.Sprintf("%s-docker.pkg.dev/%s", gcpr.Location, gcpr.Project)
    53  }
    54  
    55  type RawRepository struct {
    56  	RawRegistry string `yaml:"registry"`
    57  	RepoName    string `yaml:"repo"`
    58  }
    59  
    60  func (rr RawRepository) String() string {
    61  	return fmt.Sprintf("%s/%s", rr.Registry(), rr.Name())
    62  }
    63  
    64  func (rr RawRepository) Registry() string {
    65  	return rr.RawRegistry
    66  }
    67  
    68  func (rr RawRepository) Name() string {
    69  	return rr.RepoName
    70  }
    71  

View as plain text