atlas

package
v0.0.0-...-bd9d91d Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataAnyValue = "943febbf-589f-401b-8f25-58f6d8786848"

This is the value that should be used for metadata in ArtifactSearchOpts if you don't care what the value is.

Variables

View Source
var ErrAuth = fmt.Errorf("authentication failed")

ErrAuth is the error returned if a 401 is returned by an API request.

View Source
var ErrNotFound = fmt.Errorf("resource not found")

ErrNotFound is the error returned if a 404 is returned by an API request.

Functions

func ParseSlug

func ParseSlug(slug string) (string, string, error)

ParseSlug parses a slug of the format (x/y) into the x and y components. It accepts a string of the format "x/y" ("user/name" for example). If an empty string is given, an error is returned. If the given string is not a valid slug format, an error is returned.

Types

type App

type App struct {
	// User is the namespace (username or organization) under which the
	// Atlas application resides
	User string `json:"username"`

	// Name is the name of the application
	Name string `json:"name"`
}

App represents a single instance of an application on the Atlas server.

func (*App) Slug

func (a *App) Slug() string

Slug returns the slug format for this App (User/Name)

type Artifact

type Artifact struct {
	// User and name are self-explanatory. Tag is the combination
	// of both into "username/name"
	User string `json:"username"`
	Name string `json:"name"`
	Tag  string `json:",omitempty"`
}

Artifact represents a single instance of an artifact.

type ArtifactSearchOpts

type ArtifactSearchOpts struct {
	User string
	Name string
	Type string

	Build    string
	Version  string
	Metadata map[string]string
}

ArtifactSearchOpts are the options used to search for an artifact.

type ArtifactVersion

type ArtifactVersion struct {
	User     string            `json:"username"`
	Name     string            `json:"name"`
	Tag      string            `json:",omitempty"`
	Type     string            `json:"artifact_type"`
	ID       string            `json:"id"`
	Version  int               `json:"version"`
	Metadata map[string]string `json:"metadata"`
	File     bool              `json:"file"`
	Slug     string            `json:"slug"`

	UploadPath  string `json:"upload_path"`
	UploadToken string `json:"upload_token"`
}

ArtifactVersion represents a single version of an artifact.

type BuildConfig

type BuildConfig struct {
	// User is the namespace under which the build config lives
	User string `json:"username"`

	// Name is the actual name of the build config, unique in the scope
	// of the username.
	Name string `json:"name"`
}

BuildConfig represents a Packer build configuration.

func (*BuildConfig) Slug

func (b *BuildConfig) Slug() string

Slug returns the slug format for this BuildConfig (User/Name)

type BuildConfigBuild

type BuildConfigBuild struct {
	// Name is a unique name for this build
	Name string `json:"name"`

	// Type is the type of builder that this build needs to run on,
	// such as "amazon-ebs" or "qemu".
	Type string `json:"type"`

	// Artifact is true if this build results in one or more artifacts
	// being sent to Atlas
	Artifact bool `json:"artifact"`
}

BuildConfigBuild is a single build that is present in an uploaded build configuration.

type BuildConfigVersion

type BuildConfigVersion struct {
	// The fields below are the username/name combo to uniquely identify
	// a build config.
	User string `json:"username"`
	Name string `json:"name"`

	// Builds is the list of builds that this version supports.
	Builds []BuildConfigBuild
}

BuildConfigVersion represents a single uploaded (or uploadable) version of a build configuration.

func (*BuildConfigVersion) Slug

func (bv *BuildConfigVersion) Slug() string

Slug returns the slug format for this BuildConfigVersion (User/Name)

type BuildVar

type BuildVar struct {
	Key       string `json:"key"`
	Value     string `json:"value"`
	Sensitive bool   `json:"sensitive"`
}

Atlas expects a list of key/value vars

type BuildVars

type BuildVars []BuildVar

type Client

type Client struct {
	// URL is the full endpoint address to the Atlas server including the
	// protocol, port, and path.
	URL *url.URL

	// Token is the Atlas authentication token
	Token string

	// HTTPClient is the underlying http client with which to make requests.
	HTTPClient *http.Client

	// DefaultHeaders is a set of headers that will be added to every request.
	// This minimally includes the atlas user-agent string.
	DefaultHeader http.Header
}

Client represents a single connection to a Atlas API endpoint.

func DefaultClient

func DefaultClient() *Client

DefaultClient returns a client that connects to the Atlas API.

func NewClient

func NewClient(urlString string) (*Client, error)

NewClient creates a new Atlas Client from the given URL (as a string). If the URL cannot be parsed, an error is returned. The HTTPClient is set to an empty http.Client, but this can be changed programmatically by setting client.HTTPClient. The user can also programmatically set the URL as a *url.URL.

func (*Client) App

func (c *Client) App(user, name string) (*App, error)

App gets the App by the given user space and name. In the event the App is not found (404), or for any other non-200 responses, an error is returned.

func (*Client) Artifact

func (c *Client) Artifact(user, name string) (*Artifact, error)

Artifact finds the Atlas artifact by the given name and returns it. Any errors that occur are returned, including ErrAuth and ErrNotFound special exceptions which the user may want to handle separately.

func (*Client) ArtifactFileURL

func (c *Client) ArtifactFileURL(av *ArtifactVersion) (*url.URL, error)

ArtifactFileURL is a helper method for getting the URL for an ArtifactVersion from the Client.

func (*Client) ArtifactSearch

func (c *Client) ArtifactSearch(opts *ArtifactSearchOpts) ([]*ArtifactVersion, error)

ArtifactSearch searches Atlas for the given ArtifactSearchOpts and returns a slice of ArtifactVersions.

func (*Client) BuildConfig

func (c *Client) BuildConfig(user, name string) (*BuildConfig, error)

BuildConfig gets a single build configuration by user and name.

func (*Client) CreateApp

func (c *Client) CreateApp(user, name string) (*App, error)

CreateApp creates a new App under the given user with the given name. If the App is created successfully, it is returned. If the server returns any errors, an error is returned.

func (*Client) CreateArtifact

func (c *Client) CreateArtifact(user, name string) (*Artifact, error)

CreateArtifact creates and returns a new Artifact in Atlas. Any errors that occurr are returned.

func (*Client) CreateBuildConfig

func (c *Client) CreateBuildConfig(user, name string) (*BuildConfig, error)

CreateBuildConfig creates a new build configuration.

func (*Client) CreateTerraformConfigVersion

func (c *Client) CreateTerraformConfigVersion(
	user string, name string,
	version *TerraformConfigVersion,
	data io.Reader, size int64) (int, error)

CreateTerraformConfigVersion creatse a new Terraform configuration versions and uploads a slug with it.

func (*Client) Login

func (c *Client) Login(username, password string) (string, error)

Login accepts a username and password as string arguments. Both username and password must be non-nil, non-empty values. Atlas does not permit passwordless authentication.

If authentication is unsuccessful, an error is returned with the body of the error containing the server's response.

If authentication is successful, this method sets the Token value on the Client and returns the Token as a string.

func (*Client) Request

func (c *Client) Request(verb, spath string, ro *RequestOptions) (*http.Request, error)

Request creates a new HTTP request using the given verb and sub path.

func (*Client) TerraformConfigLatest

func (c *Client) TerraformConfigLatest(user, name string) (*TerraformConfigVersion, error)

TerraformConfigLatest returns the latest Terraform configuration version.

func (*Client) UploadApp

func (c *Client) UploadApp(app *App, metadata map[string]interface{},
	data io.Reader, size int64) (uint64, error)

UploadApp creates and uploads a new version for the App. If the server does not find the application, an error is returned. If the server does not accept the data, an error is returned.

It is the responsibility of the caller to create a properly-formed data object; this method blindly passes along the contents of the io.Reader.

func (*Client) UploadArtifact

func (c *Client) UploadArtifact(opts *UploadArtifactOpts) (*ArtifactVersion, error)

UploadArtifact streams the upload of a file on disk using the given UploadArtifactOpts. Any errors that occur are returned.

func (*Client) UploadBuildConfigVersion

func (c *Client) UploadBuildConfigVersion(v *BuildConfigVersion, metadata map[string]interface{},
	vars BuildVars, data io.Reader, size int64) error

UploadBuildConfigVersion creates a single build configuration version and uploads the template associated with it.

Actual API: "Create Build Config Version"

func (*Client) Verify

func (c *Client) Verify() error

Verify verifies that authentication and communication with Atlas is properly functioning.

type RailsError

type RailsError struct {
	Errors []string `json:"errors"`
}

RailsError represents an error that was returned from the Rails server.

func (*RailsError) Error

func (re *RailsError) Error() string

Error collects all of the errors in the RailsError and returns a comma- separated list of the errors that were returned from the server.

type RequestOptions

type RequestOptions struct {
	// Params is a map of key-value pairs that will be added to the Request.
	Params map[string]string

	// Headers is a map of key-value pairs that will be added to the Request.
	Headers map[string]string

	// Body is an io.Reader object that will be streamed or uploaded with the
	// Request. BodyLength is the final size of the Body.
	Body       io.Reader
	BodyLength int64
}

RequestOptions is the list of options to pass to the request.

type TFVar

type TFVar struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	IsHCL bool   `json:"hcl"`
}

TFVar is used to serialize a single Terraform variable sent by the manager as a collection of Variables in a Job payload.

type TerraformConfigVersion

type TerraformConfigVersion struct {
	Version   int
	Remotes   []string          `json:"remotes"`
	Metadata  map[string]string `json:"metadata"`
	Variables map[string]string `json:"variables,omitempty"`
	TFVars    []TFVar           `json:"tf_vars"`
}

TerraformConfigVersion represents a single uploaded version of a Terraform configuration.

type UploadArtifactOpts

type UploadArtifactOpts struct {
	User      string
	Name      string
	Type      string
	ID        string
	File      io.Reader
	FileSize  int64
	Metadata  map[string]string
	BuildID   int
	CompileID int
}

UploadArtifactOpts are the options used to upload an artifact.

func (*UploadArtifactOpts) MarshalJSON

func (o *UploadArtifactOpts) MarshalJSON() ([]byte, error)

MarshalJSON converts the UploadArtifactOpts into a JSON struct.

Jump to

Keyboard shortcuts

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