github.com/wolfi-dev/wolfictl@v0.16.11/pkg/distro/distro.go (about)

     1  package distro
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // Distro represents a wolfictl-compatible distro, along with important
     8  // properties discovered about how the user interacts with the distro.
     9  type Distro struct {
    10  	Local    LocalProperties
    11  	Absolute AbsoluteProperties
    12  }
    13  
    14  // LocalProperties describe the aspects of the distro that are specific to the
    15  // context of the user's local environment.
    16  type LocalProperties struct {
    17  	// PackagesRepo is the context about the user's local clone of the distro's
    18  	// packages repo.
    19  	PackagesRepo LocalRepo
    20  
    21  	// AdvisoriesRepo is the context about the user's local clone of the distro's
    22  	// advisories repo.
    23  	AdvisoriesRepo LocalRepo
    24  }
    25  
    26  // LocalRepo stores the context about a local git repository that is needed for
    27  // interacting with this distro.
    28  type LocalRepo struct {
    29  	// Dir is the path to the directory containing the user's clone of the repo.
    30  	Dir string
    31  
    32  	// UpstreamName is the name of the locally configured git remote that the
    33  	// user's clone of the repo uses to reference the upstream repo.
    34  	UpstreamName string
    35  
    36  	// ForkPoint is the commit hash of the latest commit had in common between the
    37  	// local repo and the upstream repo main branch.
    38  	ForkPoint string
    39  }
    40  
    41  // AbsoluteProperties describe the aspects of the distro that are constant and
    42  // not a function of any user's local environment.
    43  type AbsoluteProperties struct {
    44  	// The Name of the distro, e.g. "Wolfi".
    45  	Name string
    46  
    47  	// DistroRepoOwner is the GitHub organization name that owns the packages repo.
    48  	DistroRepoOwner string
    49  
    50  	// DistroPackagesRepo is the name of the distro's packages repo.
    51  	DistroPackagesRepo string
    52  
    53  	// DistroAdvisoriesRepo is the name of the distro's advisories repo.
    54  	DistroAdvisoriesRepo string
    55  
    56  	// APKRepositoryURL is the URL to the distro's package repository (e.g.
    57  	// "https://packages.wolfi.dev/os").
    58  	APKRepositoryURL string
    59  
    60  	// SupportedArchitectures is a list of architectures supported by the distro.
    61  	SupportedArchitectures []string
    62  }
    63  
    64  const (
    65  	githubURLFormatGit   = "git@github.com:%s/%s"
    66  	githubURLFormatHTTPS = "https://github.com/%s/%s"
    67  	gitSuffix            = ".git"
    68  )
    69  
    70  // DistroRemoteURLs is the known set of possible git remote URLs of the distro
    71  // repo.
    72  func (ap AbsoluteProperties) DistroRemoteURLs() []string {
    73  	return githubRemoteURLs(ap.DistroRepoOwner, ap.DistroPackagesRepo)
    74  }
    75  
    76  // AdvisoriesRemoteURLs is the known set of possible git remote URLs of the
    77  // advisories repo.
    78  func (ap AbsoluteProperties) AdvisoriesRemoteURLs() []string {
    79  	return githubRemoteURLs(ap.DistroRepoOwner, ap.DistroAdvisoriesRepo)
    80  }
    81  
    82  func githubRemoteURLs(owner, repo string) []string {
    83  	formats := []string{
    84  		githubURLFormatGit,
    85  		githubURLFormatHTTPS,
    86  	}
    87  
    88  	suffixes := []string{
    89  		gitSuffix,
    90  		"",
    91  	}
    92  
    93  	var urls []string
    94  	for _, format := range formats {
    95  		for _, suffix := range suffixes {
    96  			urls = append(urls, fmt.Sprintf(format, owner, repo)+suffix)
    97  		}
    98  	}
    99  	return urls
   100  }
   101  
   102  func (ap AbsoluteProperties) AdvisoriesHTTPSCloneURL() string {
   103  	return fmt.Sprintf(githubURLFormatHTTPS, ap.DistroRepoOwner, ap.DistroAdvisoriesRepo) + gitSuffix
   104  }
   105  
   106  var (
   107  	wolfiDistro = AbsoluteProperties{
   108  		Name:                 "Wolfi",
   109  		DistroRepoOwner:      "wolfi-dev",
   110  		DistroPackagesRepo:   "os",
   111  		DistroAdvisoriesRepo: "advisories",
   112  		APKRepositoryURL:     "https://packages.wolfi.dev/os",
   113  		SupportedArchitectures: []string{
   114  			"x86_64",
   115  			"aarch64",
   116  		},
   117  	}
   118  
   119  	chainguardDistro = AbsoluteProperties{
   120  		Name:                 "Enterprise Packages",
   121  		DistroRepoOwner:      "chainguard-dev",
   122  		DistroPackagesRepo:   "enterprise-packages",
   123  		DistroAdvisoriesRepo: "enterprise-advisories",
   124  		APKRepositoryURL:     "https://packages.cgr.dev/os",
   125  		SupportedArchitectures: []string{
   126  			"x86_64",
   127  			"aarch64",
   128  		},
   129  	}
   130  
   131  	extraPackagesDistro = AbsoluteProperties{
   132  		Name:                 "Extra Packages",
   133  		DistroRepoOwner:      "chainguard-dev",
   134  		DistroPackagesRepo:   "extra-packages",
   135  		DistroAdvisoriesRepo: "extra-advisories",
   136  		APKRepositoryURL:     "https://packages.cgr.dev/extras",
   137  		SupportedArchitectures: []string{
   138  			"x86_64",
   139  			"aarch64",
   140  		},
   141  	}
   142  )