gomason

package
v0.0.0-...-8a89c22 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 32 Imported by: 1

Documentation

Index

Constants

View Source
const AWS_ID_ENV_VAR = "AWS_ACCESS_KEY_ID"

AWS_ID_ENV_VAR Default env var for AWS access key

View Source
const AWS_REGION_ENV_VAR = "AWS_DEFAULT_REGION"

AWS_REGION_ENV_VAR Default env var for AWS region.

View Source
const AWS_SECRET_ENV_VAR = "AWS_SECRET_ACCESS_KEY"

AWS_SECRET_ENV_VAR Default env var for AWS secret key

View Source
const (
	// LanguageGolang a canonical string representation of the golang language
	LanguageGolang = "golang"
)
View Source
const METADATA_FILENAME = "metadata.json"

METADATA_FILENAME The default gomason metadata file name

View Source
const VERSION = "2.13.1"

VERSION is the current gomason version

Variables

This section is empty.

Functions

func AllChecksumsForBytes

func AllChecksumsForBytes(input []byte) (md5sum, sha1sum, sha256sum string, err error)

AllChecksumsForBytes is a convenience method for returning the md5, sha1, sha256 checksums for a byte array.

func AllChecksumsForFile

func AllChecksumsForFile(filename string) (md5sum, sha1sum, sha256sum string, err error)

AllChecksumsForFile is a convenience method that generates and returns md5, sha1, and sha256 checksums for a given file

func BuildExtras

func BuildExtras(meta Metadata, workdir string) (err error)

BuildExtras builds the extra artifacts specified in the metadata file

func BytesMd5

func BytesMd5(input []byte) (checksum string, err error)

BytesMd5 generates the md5sum for a byte array

func BytesSha1

func BytesSha1(input []byte) (checksum string, err error)

BytesSha1 generates the sha1sum for a byte array

func BytesSha256

func BytesSha256(input []byte) (checksum string, err error)

BytesSha256 generates the sha256sum for a byte array

func CollectFileAndSignature

func CollectFileAndSignature(cwd string, filename string) (err error)

CollectFileAndSignature grabs a file and the signature if it exists and copies it from the temp workspace into the CWD where gomason was called. Does nothing at all if the file is currently in cwd.

func DebugPrint

func DebugPrint(filename, tag string)

func DefaultSession

func DefaultSession() (awssession *session.Session, err error)

DefaultSession creates a default AWS session from local config path. Hooks directly into credentials if present, or Credentials Provider if configured.

func DirsForURL

func DirsForURL(uri string) (dirs []string, err error)

DirsForURL given a URL, return a list of path elements suitable for creating directories/ folders

func FileMd5

func FileMd5(filename string) (checksum string, err error)

FileMd5 generates the md5sum for a file.

func FileSha1

func FileSha1(filename string) (checksum string, err error)

FileSha1 generates the sha1sum for a file.

func FileSha256

func FileSha256(filename string) (checksum string, err error)

FileSha256 generates the Sha256 sum for a file.

func GetFunc

func GetFunc(shellCommand string) (result string, err error)

GetFunc runs a shell command that is a getter function. This could certainly be dangerous, so be careful how you use it.

func GitSSHUrlFromPackage

func GitSSHUrlFromPackage(packageName string) (gitpath string)

GitSSHUrlFromPackage Turns a go package name into a ssh git url.

func GoxInstall

func GoxInstall(gopath string) (err error)

GoxInstall Installs github.com/mitchellh/gox, the go cross compiler.

func ParseTemplateForMetadata

func ParseTemplateForMetadata(templateText string, metadata Metadata) (outputText string, err error)

ParseTemplateForMetadata parses a raw string as if it was a text/template template and uses the Metadata from metadata file as it's data source. e.g. injecting Version into upload targets (PUT url) when publishing.

func SignGPG

func SignGPG(binary string, signingEntity string, meta Metadata) (err error)

SignGPG signs a given binary with GPG using the given signing entity.

func TestMetadata_GetLanguage

func TestMetadata_GetLanguage(t *testing.T)

func Upload

func Upload(client *http.Client, url string, data io.Reader, md5sum string, sha1sum string, sha256sum string, username string, password string) (err error)

Upload actually does the upload. It uploads pure data.

func UploadChecksum

func UploadChecksum(parsedDestination, checksum, sumtype string, client *http.Client, username, password string) (err error)

UploadChecksum uploads the checksum of the given type for the given file

func UploadChecksums

func UploadChecksums(client *http.Client, destination, filename string, meta Metadata, username string, password string) (err error)

UploadChecksums uploads the checksums for a file. This is useful if the repository is not configured to do so automatically.

func UploadFile

func UploadFile(client *http.Client, destination string, filename string, meta Metadata, username string, password string) (err error)

UploadFile uploads a file off the filesystem

func UploadSignature

func UploadSignature(client *http.Client, destination string, filename string, meta Metadata, username string, password string) (err error)

UploadSignature uploads the detached signature for a file

func VerifyBinary

func VerifyBinary(binary string, meta Metadata) (ok bool, err error)

VerifyBinary will verify the signature of a signed binary.

func VerifyGPG

func VerifyGPG(binary string, meta Metadata) (ok bool, err error)

VerifyGPG Verifies signatures with gpg.

Types

type BuildInfo

type BuildInfo struct {
	PrepCommands []string        `json:"prepcommands,omitempty"`
	Targets      []BuildTarget   `json:"targets,omitempty"`
	Extras       []ExtraArtifact `json:"extras,omitempty"`
}

BuildInfo stores information used for building the code.

type BuildTarget

type BuildTarget struct {
	Name    string            `json:"name"`
	Cgo     bool              `json:"cgo,omitempty"`
	Flags   map[string]string `json:"flags,omitempty"`
	Ldflags string            `json:"ldflags,omitempty"`
	Legacy  bool              `json:"legacy,omitempty"`
}

BuildTarget contains information on each build target

type ExtraArtifact

type ExtraArtifact struct {
	Template   string `json:"template"`
	FileName   string `json:"filename"`
	Executable bool   `json:"executable"`
}

ExtraArtifact is an extra file built from a template at build time

type Golang

type Golang struct{}

Golang struct. For golang, workdir is GOPATH

func (Golang) Build

func (g Golang) Build(gopath string, meta Metadata, skipTargets string, local bool) (err error)

Build uses `gox` to build binaries per metadata file

func (Golang) Checkout

func (Golang) Checkout(gopath string, meta Metadata, branch string) (err error)

Checkout Actually checks out the code you're trying to test into your temporary GOPATH

func (Golang) CreateWorkDir

func (Golang) CreateWorkDir(workDir string) (gopath string, err error)

CreateWorkDir Creates an empty but workable GOPATH in the directory specified. Returns the full GOPATH

func (Golang) Prep

func (Golang) Prep(gopath string, meta Metadata, local bool) (err error)

Prep Commands run pre-build/ pre-test the checked out code in your temporary GOPATH

func (Golang) Test

func (Golang) Test(gopath string, gomodule string, timeout string, local bool) (err error)

Test Runs 'go test -v ./...' in the checked out code directory

type Gomason

type Gomason struct {
	Config UserConfig
}

Gomason Object that does all the building

func NewGomason

func NewGomason() (g *Gomason, err error)

NewGomason creates a new Gomason object for the current user

func (*Gomason) GetCredentials

func (g *Gomason) GetCredentials(meta Metadata) (username, password string, err error)

GetCredentials gets credentials, first from the metadata file, and then from the user config in ~/.gomason if it exists. If no credentials are found in any of the places, it returns the empty stings for usernames and passwords. This is not recommended, but it might be useful in some cases. Who knows? We makes the tools, we don't tell you how to use them. (we do, however make suggestions.) :D

func (*Gomason) HandleArtifacts

func (g *Gomason) HandleArtifacts(meta Metadata, gopath string, cwd string, sign bool, publish bool, collect bool, skipTargets string, local bool) (err error)

HandleArtifacts loops over the expected files built by Build() and optionally signs them and publishes them along with their signatures (if signing).

If not publishing, the binaries (and their optional signatures) are collected and dumped into the directory where gomason was called. (Typically the root of a go project).

func (*Gomason) HandleExtras

func (g *Gomason) HandleExtras(meta Metadata, gopath string, cwd string, sign bool, publish bool, collect bool, local bool) (err error)

HandleExtras loops over the expected files built by Build() and optionally signs them and publishes them along with their signatures (if signing).

If not publishing, the binaries (and their optional signatures) are collected and dumped into the directory where gomason was called. (Typically the root of a go project).

func (*Gomason) PublishFile

func (g *Gomason) PublishFile(meta Metadata, filePath string) (err error)

PublishFile publishes the binary to wherever you have it configured to go

func (*Gomason) SignBinary

func (g *Gomason) SignBinary(meta Metadata, binary string) (err error)

SignBinary signs the given binary based on the entity and program given in metadata file, possibly overridden by information in ~/.gomason

type Language

type Language interface {
	CreateWorkDir(string) (string, error)
	Checkout(workdir string, meta Metadata, branch string) error
	Prep(workdir string, meta Metadata, local bool) error
	Test(workdir string, module string, timeout string, local bool) error
	Build(workdir string, meta Metadata, skipTargets string, local bool) error
}

Language is a generic interface for doing what gomason does - abstracting build, test, signing, and publishing of binaries

func GetByName

func GetByName(lang string) (Language, error)

GetByName Gets a specific Language interface by name.

type Metadata

type Metadata struct {
	Name           string                 `json:"name"`
	Version        string                 `json:"version"`
	Package        string                 `json:"package"`
	Description    string                 `json:"description"`
	Repository     string                 `json:"repository"`
	ToolRepository string                 `json:"tool-repository"`
	InsecureGet    bool                   `json:"insecure_get"`
	Language       string                 `json:"language,omitempty"`
	BuildInfo      BuildInfo              `json:"building,omitempty"`
	SignInfo       SignInfo               `json:"signing,omitempty"`
	PublishInfo    PublishInfo            `json:"publishing,omitempty"`
	Options        map[string]interface{} `json:"options,omitempty"`
}

Metadata type to represent the metadata file

func ReadMetadata

func ReadMetadata(filename string) (metadata Metadata, err error)

ReadMetadata Reads a metadata file and returns the Metadata object thus described

func (Metadata) GetLanguage

func (m Metadata) GetLanguage() (lang string)

GetLanguage returns the language set in metadata, or the default 'golang'.

type NoLanguage

type NoLanguage struct{}

NoLanguage essentially an abstract class for the Language interface

func (NoLanguage) Build

func (NoLanguage) Build(workdor string, meta Metadata, skipTargets string, localBuild bool) error

Build Stub for the Build Action

func (NoLanguage) Checkout

func (NoLanguage) Checkout(workdir string, meta Metadata, branch string) error

Checkout Stub for the Checkout action

func (NoLanguage) CreateWorkDir

func (NoLanguage) CreateWorkDir(string) (workdir string, err error)

CreateWorkDir Stub for the CreateWorkDir action

func (NoLanguage) Prep

func (NoLanguage) Prep(workdir string, meta Metadata, local bool) error

Prep stub for the Prep action

func (NoLanguage) Test

func (NoLanguage) Test(workdir string, module string, timeout string, localTest bool) error

Test Stub for the Test action

type PublishInfo

type PublishInfo struct {
	Targets      []PublishTarget          `json:"targets"`
	TargetsMap   map[string]PublishTarget `json:"-"`
	Username     string                   `json:"username"`
	Password     string                   `json:"password"`
	UsernameFunc string                   `json:"usernamefunc"`
	PasswordFunc string                   `json:"passwordfunc"`
	SkipSigning  bool                     `json:"skip-signing"`
}

PublishInfo holds information for publishing

type PublishTarget

type PublishTarget struct {
	Source      string `json:"src"`
	Destination string `json:"dst"`
	Signature   bool   `json:"sig"`
	Checksums   bool   `json:"checksums"`
}

PublishTarget a struct representing an individual file to upload

type S3Meta

type S3Meta struct {
	Bucket string
	Region string
	Key    string
	Url    string
}

S3Meta a struct for holding metadata for S3 Objects. There's probably already a struct that holds this, but this is all I need.

func S3Url

func S3Url(url string) (ok bool, meta S3Meta)

S3Url returns true, and a metadata struct if the url given appears to be in s3

type SignInfo

type SignInfo struct {
	Program string `json:"program"`
	Email   string `json:"email"`
}

SignInfo holds information used for signing your binaries.

type TestRepo

type TestRepo struct{}

TestRepo a fake repository server. Basically an in-memory http server that can be used as a test fixture for testing the internal API. Cool huh?

func (*TestRepo) HandlerTool

func (tr *TestRepo) HandlerTool(w http.ResponseWriter, r *http.Request)

HandlerTool handles requests publishing a tool in the test repo

func (*TestRepo) Run

func (tr *TestRepo) Run(port int) (err error)

Run runs the test repository server.

type UserConfig

type UserConfig struct {
	User    UserInfo
	Signing UserSignInfo
}

UserConfig a struct representing the information stored in ~/.gomason

func GetUserConfig

func GetUserConfig(homedir string) (config UserConfig, err error)

GetUserConfig reads ~/.gomason if present, and returns a struct with its data.

type UserInfo

type UserInfo struct {
	Email        string
	Username     string
	Password     string
	UsernameFunc string
	PasswordFunc string
}

UserInfo information from the user section in ~/.gomason

type UserSignInfo

type UserSignInfo struct {
	Program string
}

UserSignInfo information from the signing section in ~/.gomason

Jump to

Keyboard shortcuts

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