publish

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(ctx context.Context, req *CopyReq) error

Copy will copy the artifact from source to destination S3 bucket.

Types

type Archive

type Archive struct {
	Hashes    []string `json:"hashes"` // the hash of the zip file
	URL       string   `json:"url"`    // path to the zipfile relative to root
	SHA256Sum string   // The s3 mirror doesn't need this so there's no JSON tag
}

Archive is a zip archive of a binary.

type Artifacts

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

Artifacts is a collection of all the artifacts in the repository.

func NewArtifacts

func NewArtifacts(name string) *Artifacts

NewArtifacts takes the name of the terraform provider and returns a new Artifacts.

func (*Artifacts) AddBinary

func (a *Artifacts) AddBinary(version, platform, arch, binaryPath string) error

AddBinary takes version, platform, arch, and path of a binary and adds it to the mirror. It does this by creating a zip archive of the binary, hashing it and adding it to the artifacts collection.

func (*Artifacts) AddReleaseManifest

func (a *Artifacts) AddReleaseManifest(ctx context.Context, path, version string) error

Add the base release manifest into the artifacts.

func (*Artifacts) AddReleaseVersionToIndex

func (a *Artifacts) AddReleaseVersionToIndex(version string)

AddReleaseVersionToIndex adds the release version to the mirror index.

func (*Artifacts) CopyReleaseArtifactsBetweenRemoteBucketsForVersion

func (a *Artifacts) CopyReleaseArtifactsBetweenRemoteBucketsForVersion(ctx context.Context, srcBucketName string, destS3Client *s3.Client, destBucketName, providerName, providerID, version string) error

CopyReleaseArtifactsBetweenRemoteBucketsForVersion copies artifacts from a remote s3 mirror to another remote mirror.

func (*Artifacts) CreateVersionedRegistryManifest

func (a *Artifacts) CreateVersionedRegistryManifest(ctx context.Context) error

func (*Artifacts) CreateZipArchive

func (a *Artifacts) CreateZipArchive(sourceBinaryPath, zipFilePath string) error

CreateZipArchive takes a source binary and a destination path and creates a zip archive of the binary.

func (*Artifacts) DownloadFromTFC

func (a *Artifacts) DownloadFromTFC(ctx context.Context, tfcreq *TFCDownloadReq) error

DownloadFromTFC downloads the artifacts for a given version to a directory.

func (*Artifacts) ExtractProviderBinaries

func (a *Artifacts) ExtractProviderBinaries(ctx context.Context, tfcreq *TFCPromoteReq) error

ExtractProviderBinaries extracts the downloaded artifacts to an output directory.

func (*Artifacts) HasVersion

func (a *Artifacts) HasVersion(ctx context.Context, version string) (bool, error)

HasVersion checks if the artifact version exists in the loaded index.json of the remote mirror.

func (*Artifacts) HashZipArchive

func (a *Artifacts) HashZipArchive(path string) (string, error)

HashZipArchive returns the h1 style Terraform hash of the zip archive.

func (*Artifacts) Insert

func (a *Artifacts) Insert(version, platform, arch string, archive *Archive)

Insert takes a version, platform, arch, and archive and inserts it into the archive collection.

func (*Artifacts) InsertTFCRelease

func (a *Artifacts) InsertTFCRelease(version string, release *TFCRelease)

InsertTFCRelease takes a version, and release and inserts it into the tfcMetadata.

func (*Artifacts) LoadRemoteIndex

func (a *Artifacts) LoadRemoteIndex(ctx context.Context, s3Client *s3.Client, bucket, providerID string) error

LoadRemoteIndex fetches the existing index.json from the remote bucket and loads it. This way we can merge new builds with those in existing remote mirror.

func (*Artifacts) LoadRemoteReleaseMetedataForVersion

func (a *Artifacts) LoadRemoteReleaseMetedataForVersion(ctx context.Context, s3Client *s3.Client, bucket, providerID, version string) error

LoadRemoteReleaseMetedataForVersion fetches the version.json for a given release from the remote bucket and loads it. We need this information to known what and where release artifacts for the release are.

func (*Artifacts) PublishToGithubRelease

func (a *Artifacts) PublishToGithubRelease(ctx context.Context, req *GithubReleaseCreateReq) error

PublishToGithubReleases publishes the local mirror artifacts to Github Releases in a manner that is compatible with the public Github registry.

func (*Artifacts) PublishToRemoteBucket

func (a *Artifacts) PublishToRemoteBucket(ctx context.Context, s3Client *s3.Client, bucket, providerID string) error

PublishToRemoteBucket publishes the artifacts in the local mirror to the remote S3 Bucket.

func (*Artifacts) PublishToTFC

func (a *Artifacts) PublishToTFC(ctx context.Context, tfcreq *TFCUploadReq) error

PublishToTFC publishes the artifact version to TFC org.

func (*Artifacts) SHA256Sum

func (a *Artifacts) SHA256Sum(path string) (string, error)

SHA256Sum returns the SHA256 sum of a file for a given path.

func (*Artifacts) WriteDetachedSignature

func (a *Artifacts) WriteDetachedSignature(ctx context.Context, source, out, name string) error

WriteDetachedSignature takes a context, source file path, outfile path, and the GPG entity name and writes a signed version of the source file to the outfile.

func (*Artifacts) WriteMetadata

func (a *Artifacts) WriteMetadata() error

WriteMetadata writes the artifact collection as JSON metadata into the local mirror.

func (*Artifacts) WriteSHA256SUMS

func (a *Artifacts) WriteSHA256SUMS(
	ctx context.Context,
	regType RegistryType,
	gpgIdentityName string,
	gpgDetachSign bool,
) error

WriteSHA256SUMS writes the release SHA256SUMS file as required by TFC or the public registry.

type CopyReq

type CopyReq struct {
	Version          string
	SrcBucketName    string
	DestBucketName   string
	SrcProviderName  string
	SrcBinaryName    string
	SrcProviderID    string
	DestProviderName string
	DestBinaryName   string
	DestProviderID   string
	SrcS3Client      *s3.Client
	DestS3Client     *s3.Client
	// contains filtered or unexported fields
}

CopyReq to be copied.

type GithubReleaseCreateReq

type GithubReleaseCreateReq struct {
	// Local artifacts
	DistDir         string
	BinaryName      string
	ProviderName    string
	GPGKeyID        string
	GPGIdentityName string
	Version         string
	ManifestPath    string
	// Github release
	GithubRelease       *github.RepositoryRelease
	GithubToken         string
	GithubRepoNameOwner string // owner/repo
}

func (*GithubReleaseCreateReq) OwnerRepo

func (r *GithubReleaseCreateReq) OwnerRepo() (string, string)

type Index

type Index struct {
	Versions map[string]*IndexValue `json:"versions"`
	// contains filtered or unexported fields
}

Index is our root index.json which tracks which versions are available in the mirror.

func NewIndex

func NewIndex() *Index

NewIndex returns a new Index.

func (*Index) AsJSON

func (i *Index) AsJSON(to io.Writer) error

AsJSON takes an io.Writes and writes itself as JSON to it.

type IndexValue

type IndexValue struct{}

IndexValue is the value of Version in the Index. Currently it is a blank object.

type Local

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

Local is a local provider artifact mirror.

func NewLocal

func NewLocal(name, binname string, opts ...NewLocalOpt) *Local

NewLocal takes a terraform provider name and returns a new local mirror.

func (*Local) AddGoBinariesFrom

func (l *Local) AddGoBinariesFrom(binPath string) error

AddGoBinariesFrom takes a directory path to the go builds, walks it, finds any providers binaries, creates an archive of them and adds them to the artifacts and index.

func (*Local) AddReleaseManifest

func (l *Local) AddReleaseManifest(ctx context.Context, path, version string) error

Add public registry manifest path to the local mirror. If present we'll inject in into the provider binary archives.

func (*Local) AddReleaseVersionToIndex

func (l *Local) AddReleaseVersionToIndex(ctx context.Context, version string)

AddReleaseVersionToIndex adds a version to the release index.

func (*Local) Close

func (l *Local) Close() error

Close removes all of the mirrors files.

func (*Local) CopyReleaseArtifactsBetweenRemoteBucketsForVersion

func (l *Local) CopyReleaseArtifactsBetweenRemoteBucketsForVersion(ctx context.Context, srcBucketName string, destS3Client *s3.Client, destBucketName, binaryName, providerID, version string) error

CopyReleaseArtifactsBetweenRemoteBucketsForVersion copies release artifacts from source bucket to the destination bucket.

func (*Local) CreateVersionedRegistryManifest

func (l *Local) CreateVersionedRegistryManifest(ctx context.Context) error

Create a versions registry manifest.

func (*Local) DownloadFromTFC

func (l *Local) DownloadFromTFC(ctx context.Context, tfcreq *TFCDownloadReq) error

DownloadFromTFC downloads the artifacts for a given version to a directory.

func (*Local) ExtractProviderBinaries

func (l *Local) ExtractProviderBinaries(ctx context.Context, tfcreq *TFCPromoteReq) error

ExtractProviderBinaries extracts the artifacts to an output directory.

func (*Local) HasVersion

func (l *Local) HasVersion(ctx context.Context, version string) (bool, error)

HasVersion checks if t the version exists in the bucket.

func (*Local) Initialize

func (l *Local) Initialize() error

Initialize initializes the mirror.

func (*Local) LoadRemoteIndex

func (l *Local) LoadRemoteIndex(ctx context.Context, s3Client *s3.Client, bucket, providerID string) error

LoadRemoteIndex fetches a remote index and loads it.

func (*Local) PublishToGithubReleases

func (l *Local) PublishToGithubReleases(ctx context.Context, req *GithubReleaseCreateReq) error

PublishToGithubReleases publishes the local mirror artifacts to Github Releases in a manner that is compatible with the public Github registry.

func (*Local) PublishToRemoteBucket

func (l *Local) PublishToRemoteBucket(ctx context.Context, s3Client *s3.Client, bucket, providerID string) error

PublishToRemoteBucket publishes the local mirror artifacts into the remote bucket.

func (*Local) PublishToTFC

func (l *Local) PublishToTFC(ctx context.Context, tfcreq *TFCUploadReq) error

PublishToTFC publishes artifact version to TFC org.

func (*Local) SetLogLevel

func (l *Local) SetLogLevel(level zapcore.Level) error

SetLogLevel sets the log level.

func (*Local) WriteMetadata

func (l *Local) WriteMetadata() error

WriteMetadata writes metadata JSON files of the mirror artifacts.

func (*Local) WriteSHA256Sums

func (l *Local) WriteSHA256Sums(ctx context.Context, regType RegistryType, name string, sign bool) error

WriteSHA256Sums writes a detached signature of the source file to the outfile.

type NewLocalOpt

type NewLocalOpt func(*Local) *Local

NewLocalOpt accepts optional arguments for Local.

func WithLocalBinaryRename

func WithLocalBinaryRename(name string) NewLocalOpt

WithLocalBinaryRename renames the binary during creation.

type RegistryManifest

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

RegistryManifest is the public registry manifest.

type RegistryType

type RegistryType string
const (
	RegistryTypePrivate RegistryType = "private"
	RegistryTypePublic  RegistryType = "public"
)

type Release

type Release struct {
	Archives map[string]*Archive `json:"archives"` // key is the platform_arch
	// contains filtered or unexported fields
}

Release is a version collection of archives.

func NewRelease

func NewRelease() *Release

NewRelease returns a new Release.

func (*Release) AddArchive

func (r *Release) AddArchive(platform, arch string, archive *Archive)

AddArchive takes a platform, arch and archive and adds it to the releases archives.

func (*Release) AsJSON

func (r *Release) AsJSON(to io.Writer) error

AsJSON writes the release as JSON to the io.Writer.

type TFCClient

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

TFCClient is a collection of http client request params.

func NewTFCClient

func NewTFCClient(opts ...TFCClientOpt) (*TFCClient, error)

NewTFCClient creates and returns a new instance of TFCClient.

func (*TFCClient) CreatePrivateProvider

func (c *TFCClient) CreatePrivateProvider(
	ctx context.Context,
	namespace string,
	providerName string,
) error

CreatePrivateProvider creates a private provider.

func (*TFCClient) CreateProviderPlatforms

func (c *TFCClient) CreateProviderPlatforms(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
	releases []*TFCRelease,
) error

CreateProviderPlatforms creates platforms for a provider version.

func (*TFCClient) CreateProviderVersion

func (c *TFCClient) CreateProviderVersion(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
	gpgKeyID string,
	sha256sumsPath string,
) error

CreateProviderVersion creates a private provider version.

func (*TFCClient) DoRequest

func (c *TFCClient) DoRequest(ctx context.Context, tfcReq *TFCRequest) (*http.Response, error)

DoRequest takes a context, http request params with an optional data body and returns an http response.

func (*TFCClient) FindOrCreatePlatform

func (c *TFCClient) FindOrCreatePlatform(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
	release []*TFCRelease,
) error

FindOrCreatePlatform - FindProviderPlatform - CreateProviderPlatforms.

func (*TFCClient) FindOrCreateProvider

func (c *TFCClient) FindOrCreateProvider(ctx context.Context, namespace, providerName string) error

FindOrCreateProvider - FindProvider - CreateProvider.

func (*TFCClient) FindOrCreateVersion

func (c *TFCClient) FindOrCreateVersion(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
	gpgKeyID string,
	sha256sumsPath string,
) error

FindOrCreateVersion - FindProviderVersion - CreateProviderVersion.

func (*TFCClient) FindPrivateProvider

func (c *TFCClient) FindPrivateProvider(
	ctx context.Context,
	namespace string,
	providerName string,
) (*TFCProvider, error)

FindPrivateProvider searches for existing private provider.

func (*TFCClient) FindProviderPlatform

func (c *TFCClient) FindProviderPlatform(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
) ([]*TFCProviderPlatform, error)

FindProviderPlatform searches for platforms supported by a private provider version.

func (*TFCClient) FindProviderVersion

func (c *TFCClient) FindProviderVersion(
	ctx context.Context,
	namespace string,
	providerName string,
	providerVersion string,
	sha256sumsPath string,
) (*TFCProviderVersion, error)

FindProviderVersion searches for existing private provider version.

type TFCClientOpt

type TFCClientOpt func(*TFCClient)

TFCClientOpt takes TFC client options.

func WithTFCLog

func WithTFCLog(log *zap.SugaredLogger) TFCClientOpt

WithTFCLog sets the logging.

func WithTFCOrg

func WithTFCOrg(org string) TFCClientOpt

WithTFCOrg sets the base url.

func WithTFCToken

func WithTFCToken(token string) TFCClientOpt

WithTFCToken sets the TFC token.

type TFCDownloadReq

type TFCDownloadReq struct {
	DownloadDir     string
	ProviderVersion string
	BinaryName      string
	ProviderName    string
	TFCOrg          string
	TFCToken        string
}

TFCDownloadReq is a collection of provider download request.

type TFCPromoteReq

type TFCPromoteReq struct {
	ProviderVersion  string
	DownloadsDir     string
	PromoteDir       string
	SrcProviderName  string
	DestProviderName string
	SrcBinaryName    string
	DestBinaryName   string
	GPGKeyID         string
	GPGIdentityName  string
	TFCOrg           string
	TFCToken         string
}

TFCPromoteReq is a collection of provider promote request.

type TFCProvider

type TFCProvider struct {
	Name         string
	Namespace    string
	RegistryType string
	Org          string
	URL          string
}

TFCProvider is a collection of TFC provider registry namespace.

type TFCProviderPlatform

type TFCProviderPlatform struct {
	PlatformID             string
	Version                string
	RegistryType           string
	Org                    string
	OS                     string
	Arch                   string
	Filename               string
	Filepath               string
	SHAsum                 string
	PlatformBinaryUploaded bool
	PlatformBinaryURL      string
}

TFCProviderPlatform struct is a collection of provider platform data.

type TFCProviderVersion

type TFCProviderVersion struct {
	Version        string
	RegistryType   string
	KeyID          string
	Org            string
	SHAUploaded    bool
	SHASigUploaded bool
	SHASumsURL     string
	SHASumsSigURL  string
}

TFCProviderVersion is a collection of TFC provider's version.

type TFCRelease

type TFCRelease struct {
	Platform    string
	Arch        string
	ZipFilePath string
	SHA256Sum   string
}

TFCRelease is a collection of TFC release zip binary, platform, architecture, and sha256sum.

type TFCRequest

type TFCRequest struct {
	Scheme     string // "https"
	Host       string // "app.terraform.io"
	ReqPath    string
	HTTPMethod string
	Body       io.Reader
}

TFCRequest is a TFC API request.

func NewTFCRequest

func NewTFCRequest(opts ...TFCRequestOpt) (*TFCRequest, error)

NewTFCRequest takes TFCRequestOpt args and returns a new TFC API request.

type TFCRequestOpt

type TFCRequestOpt func(*TFCRequest) (*TFCRequest, error)

TFCRequestOpt are functional options for a new Request.

func WithRequestBody

func WithRequestBody(body io.Reader) TFCRequestOpt

WithRequestBody sets the request body.

type TFCUploadReq

type TFCUploadReq struct {
	DistDir         string
	BinaryRename    string
	BinaryName      string
	ProviderName    string
	GPGKeyID        string
	GPGIdentityName string
	TFCOrg          string
	TFCToken        string
}

TFCUploadReq is a collection of provider upload request.

Jump to

Keyboard shortcuts

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