werckerclient

package module
v0.0.0-...-7842356 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2018 License: MIT Imports: 12 Imported by: 0

README

wercker api client

wercker status

werckerclient is the official wercker client for the wercker API.

Caution: Both the API and this client are under active development. This client may introduce breaking changes, so be sure to vendor in this client.

Usage

To start using this client, import this package and create a new client:

import "github.com/wercker/werckerclient"

client := werckerclient.NewClient(nil)

This will create a new client with the default config. If you want to override the default config, then you need to create a wercker.Config object and pass this wercker.NewClient:

import "github.com/wercker/werckerclient"

options := &werckerclient.Config{}
client := werckerclient.NewClient(options)

Authentication

The client uses a Provider to get the credentials for the user. By default it uses the following strategy:

  • Retrieve the token from the environment variable$WERCKER_TOKEN
  • Retrieve the token from file ~/.wercker/credentials
  • Fallback to anonymous user

If you retrieved your wercker token through other means, then you can use the credentials.Token method to create a static Provider:

import "github.com/wercker/werckerclient"
import "github.com/wercker/werckerclient/credentials"

token := "... your token ..."
options := &werckerclient.Config{Credentials: credentials.Token(token)}
client := werckerclient.NewClient(options)

More information

FAQ

...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Message    string `json:"message"`
	StatusCode int    `json:"statusCode"`
}

APIError represents a wercker error.

func (*APIError) Error

func (e *APIError) Error() string

Error returns the message and status code.

type Application

type Application struct {
	ID        string       `json:"id"`
	URL       string       `json:"url"`
	Name      string       `json:"name"`
	Owner     *UnifiedUser `json:"owner"`
	Builds    string       `json:"builds"`
	Deploys   string       `json:"deploys"`
	SCM       *SCM         `json:"scm"`
	CreatedAt time.Time    `json:"createdAt"`
	UpdatedAt time.Time    `json:"updatedAt"`
	Privacy   string       `json:"privacy"`
	Stack     int          `json:"stack"`
}

Application is a detailed api representation

type ApplicationService

type ApplicationService interface {
	GetApplication(*GetApplicationOptions) (*Application, error)
}

type ApplicationSummary

type ApplicationSummary struct {
	ID        string       `json:"id"`
	URL       string       `json:"url"`
	Name      string       `json:"name"`
	Owner     *UnifiedUser `json:"owner"`
	CreatedAt time.Time    `json:"createdAt"`
	UpdatedAt time.Time    `json:"updatedAt"`
	Privacy   string       `json:"privacy"`
	Stack     int          `json:"stack"`
}

ApplicationSummary is a summary api representation

type Build

type Build struct {
	ID          string              `json:"id"`
	URL         string              `json:"url"`
	Application *ApplicationSummary `json:"application"`
	Branch      string              `json:"branch"`
	CommitHash  string              `json:"commitHash"`
	CreatedAt   time.Time           `json:"createdAt"`
	EnvVars     []EnvVar            `json:"envVars"`
	FinishedAt  time.Time           `json:"finishedAt"`
	Message     string              `json:"message"`
	Progress    int                 `json:"progress"`
	Result      string              `json:"result"`
	StartedAt   time.Time           `json:"startedAt"`
	Status      string              `json:"status"`
}

Build is a detailed api representation

type BuildSummary

type BuildSummary struct {
	ID         string    `json:"id"`
	URL        string    `json:"url"`
	Branch     string    `json:"branch"`
	CommitHash string    `json:"commitHash"`
	CreatedAt  time.Time `json:"createdAt"`
	FinishedAt time.Time `json:"finishedAt"`
	Message    string    `json:"message"`
	Progress   int       `json:"progress"`
	Result     string    `json:"result"`
	StartedAt  time.Time `json:"startedAt"`
	Status     string    `json:"status"`
}

BuildSummary is a summary api representation

type Client

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

Client is the wercker api client.

func NewClient

func NewClient(config *Config) *Client

NewClient creates a new Client. It merges the default Config together with config.

func (*Client) CreateBuild

func (c *Client) CreateBuild(options *CreateBuildOptions) (*Build, error)

CreateBuild will trigger a new build.

func (*Client) CreateChainRun

func (c *Client) CreateChainRun(options *CreateChainRunOptions) (*Run, error)

CreateChainRun will trigger a new run.

func (*Client) CreateRun

func (c *Client) CreateRun(options *CreateRunOptions) (*Run, error)

CreateRun will trigger a new run.

func (*Client) CreateToken

func (c *Client) CreateToken(options *CreateTokenOptions) (*Token, error)

CreateToken creates a new Token.

func (*Client) DeleteToken

func (c *Client) DeleteToken(options *DeleteTokenOptions) error

DeleteToken deletes a token

func (*Client) Do

func (c *Client) Do(method string, urlTemplate *uritemplates.UriTemplate, urlModel interface{}, payload interface{}, result interface{}) error

Do makes a request to the wercker api servers.

func (*Client) DoRaw

func (c *Client) DoRaw(method string, urlTemplate *uritemplates.UriTemplate, urlModel interface{}, payload interface{}) ([]byte, error)

DoRaw makes a full request but returns the result as a byte array

func (*Client) GetApplication

func (c *Client) GetApplication(o *GetApplicationOptions) (*Application, error)

GetApplication will retrieve a single Application

func (*Client) GetApplicationPipelines

func (c *Client) GetApplicationPipelines(o *GetApplicationPipelinesOptions) ([]PipelineSummary, error)

GetApplicationPipelines will retrieve a list of of an Application's pipelines

func (*Client) GetApplications

func (c *Client) GetApplications(options *GetApplicationsOptions) ([]Application, error)

GetApplications will retrieve a list of Applications

func (*Client) GetBuild

func (c *Client) GetBuild(options *GetBuildOptions) (*Build, error)

GetBuild will retrieve a single Build

func (*Client) GetBuilds

func (c *Client) GetBuilds(o *GetBuildsOptions) ([]*BuildSummary, error)

GetBuilds fetches all builds for a certain application and optional filters.

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() (*User, error)

func (*Client) GetDeploy

func (c *Client) GetDeploy(options *GetDeployOptions) (*Deploy, error)

GetDeploy will retrieve a single Deploy

func (*Client) GetDeploys

func (c *Client) GetDeploys(o *GetDeploysOptions) ([]*DeploySummary, error)

GetDeploys fetches all deploys for a certain application and optional filters.

func (*Client) GetRun

func (c *Client) GetRun(options *GetRunOptions) (*Run, error)

GetRun will retrieve a single Run

func (*Client) GetRunStep

func (c *Client) GetRunStep(options *GetRunStepOptions) (*RunStep, error)

GetRunStep will retrieve a single RunStep

func (*Client) GetRunStepLog

func (c *Client) GetRunStepLog(options *GetRunStepLogOptions) ([]byte, error)

GetRunStepLog will retreive a single RunStepLog

func (*Client) GetRuns

func (c *Client) GetRuns(options *GetRunsOptions) ([]*RunSummary, error)

GetRuns fetches all runs for a certain application and optional filters.

func (*Client) GetStepVersion

func (c *Client) GetStepVersion(options *GetStepVersionOptions) (*Step, error)

GetStepVersion will retrieve a single Step

func (*Client) GetToken

func (c *Client) GetToken(options *GetTokenOptions) (*Token, error)

GetToken retrieves a single Token.

func (*Client) GetTokens

func (c *Client) GetTokens(options *GetTokensOptions) ([]*TokenSummary, error)

GetTokens gets all tokens for the current user.

func (*Client) UpdateToken

func (c *Client) UpdateToken(options *UpdateTokenOptions) (*Token, error)

UpdateToken updates a Token.

type Config

type Config struct {
	Credentials credentials.Provider
	Endpoint    string
	HTTPClient  *http.Client
}

Config contains all configurable settings which will be used when making requests

func (*Config) Copy

func (o *Config) Copy() *Config

Copy will create a shallow copy of the Copy object

func (*Config) Merge

func (o *Config) Merge(config *Config) *Config

Merge creates a new shallow copy of o, and copies all non empty values from config to the copy. If config is nil, than o will be returned.

type CreateBuildOptions

type CreateBuildOptions struct {
	// Required
	ApplicationID string `json:"applicationId,omitempty"`

	// Optional
	Branch     string   `json:"branch,omitempty"`
	CommitHash string   `json:"commitHash,omitempty"`
	Message    string   `json:"message,omitempty"`
	EnvVars    []EnvVar `json:"envVars,omitempty"`
}

CreateBuildOptions are the options associated with Client.CreateBuild.

type CreateChainRunOptions

type CreateChainRunOptions struct {
	// Required
	SourceRunID string `json:"sourceRunId,omitempty"`
	PipelineID  string `json:"pipelineId,omitempty"`

	Message string   `json:"message,omitempty"`
	EnvVars []EnvVar `json:"envVars,omitempty"`
}

CreateChainRunOptions are the options associated with Client.CreateChainRun.

type CreateRunOptions

type CreateRunOptions struct {
	// Required
	PipelineID string `json:"pipelineId,omitempty"`

	// Optional
	Branch     string   `json:"branch,omitempty"`
	Tag        string   `json:"tag,omitempty"`
	CommitHash string   `json:"commitHash,omitempty"`
	Message    string   `json:"message,omitempty"`
	EnvVars    []EnvVar `json:"envVars,omitempty"`
}

CreateRunOptions are the options associated with Client.CreateRun.

type CreateTokenOptions

type CreateTokenOptions struct {
	Name string `json:"name"`
}

CreateTokenOptions are the options associated with Client.CreateToken

type DeleteTokenOptions

type DeleteTokenOptions struct {
	TokenID string `map:"tokenId"`
}

DeleteTokenOptions are the options associated with Client.DeleteToken

type Deploy

type Deploy struct {
	ID          string              `json:"id"`
	URL         string              `json:"url"`
	Status      string              `json:"status"`
	Result      string              `json:"result"`
	CreatedAt   time.Time           `json:"createdAt"`
	FinishedAt  time.Time           `json:"finishedAt"`
	Progress    int                 `json:"progress"`
	Application *ApplicationSummary `json:"application"`
	Build       *BuildSummary       `json:"build"`
}

Deploy is a detailed api representation

type DeploySummary

type DeploySummary struct {
	ID         string    `json:"id"`
	URL        string    `json:"url"`
	Status     string    `json:"status"`
	Result     string    `json:"result"`
	CreatedAt  time.Time `json:"createdAt"`
	FinishedAt time.Time `json:"finishedAt"`
	Progress   int       `json:"progress"`
}

DeploySummary is a summary api representation

type EnvVar

type EnvVar struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

EnvVar represents a environment variable key value pair

func EnvVarFromMap

func EnvVarFromMap(envmap map[string]string) []EnvVar

type ErrResponse

type ErrResponse struct {
	StatusCode    int    `json:"statusCode"`
	StatusMessage string `json:"error"`
	Message       string `json:"message"`
}

ErrResponse is a generic error object using wercker api conventions.

func (*ErrResponse) Error

func (e *ErrResponse) Error() string

Error returns the wercker error message

type GetApplicationOptions

type GetApplicationOptions struct {
	// Required
	Owner string `map:"owner"`
	Name  string `map:"name"`

	// ApplicationName will override Owner and Name
	ApplicationName string `map:"applicationName"`
}

GetApplicationOptions are the options associated with Client.GetApplication

type GetApplicationPipelinesOptions

type GetApplicationPipelinesOptions struct {
	// Required
	Name  string `map:"name"`
	Owner string `map:"owner"`

	// Optional
	Limit string `map:"limit,omitempty"`
	Skip  int    `map:"skip,omitempty"`

	// ApplicationName will override Owner and Name
	ApplicationName string `map:"-"`
}

type GetApplicationsOptions

type GetApplicationsOptions struct {
	Limit string `map:"limit,omitempty"`
	Skip  int    `map:"skip,omitempty"`
	Sort  int    `map:"sort,omitempty"`
	Stack string `map:"stack,omitempty"`
}

GetApplicationsOptions are the options associated with Client.GetApplications

type GetBuildOptions

type GetBuildOptions struct {
	BuildID string `map:"buildId"`
}

GetBuildOptions are the options associated with Client.GetBuild

type GetBuildsOptions

type GetBuildsOptions struct {
	// Required
	Owner string `map:"owner"`
	Name  string `map:"name"`

	// Optional
	Branch string `map:"branch,omitempty"`
	Commit string `map:"commit,omitempty"`
	Limit  int    `map:"limit,omitempty"`
	Result string `map:"result,omitempty"`
	Skip   int    `map:"skip,omitempty"`
	Sort   string `map:"sort,omitempty"`
	Stack  string `map:"stack,omitempty"`
	Status string `map:"status,omitempty"`

	// ApplicationName will override Owner and Name
	ApplicationName string `map:"-"`
}

GetBuildsOptions are the options associated with Client.GetBuilds.

type GetDeployOptions

type GetDeployOptions struct {
	DeployID string `map:"deployId"`
}

GetDeployOptions are the options associated with Client.GetDeploy

type GetDeploysOptions

type GetDeploysOptions struct {
	// Required
	Owner string `map:"owner"`
	Name  string `map:"name"`

	// Optional
	BuildID string `map:"buildId,omitempty"`
	Limit   int    `map:"limit,omitempty"`
	Result  string `map:"result,omitempty"`
	Skip    int    `map:"skip,omitempty"`
	Sort    string `map:"sort,omitempty"`
	Stack   string `map:"stack,omitempty"`
	Status  string `map:"status,omitempty"`

	// ApplicationName will override Owner and Name
	ApplicationName string `map:"-"`
}

GetDeploysOptions are the options associated with Client.GetDeploys.

type GetRunOptions

type GetRunOptions struct {
	RunID string `map:"runId"`
}

GetRunOptions are the options associated with Client.GetRun

type GetRunStepLogOptions

type GetRunStepLogOptions struct {
	RunStepID string `map:"runStepId"`
}

GetRunStepLogOptions are the options associated with Client.GetRunStep

type GetRunStepOptions

type GetRunStepOptions struct {
	RunStepID string `map:"runStepId"`
}

GetRunStepOptions are the options associated with Client.GetRunStep

type GetRunsOptions

type GetRunsOptions struct {
	// Required (one or the other)
	ApplicationID string `map:"owner"`
	PipelineID    string `map:"name"`

	// Optional
	Limit     int    `map:"limit,omitempty"`
	Skip      int    `map:"skip,omitempty"`
	Sort      string `map:"sort,omitempty"`
	Status    string `map:"status,omitempty"`
	Result    string `map:"result,omitempty"`
	Branch    string `map:"branch,omitempty"`
	Tag       string `map:"tag,omitempty"`
	Commit    string `map:"commit,omitempty"`
	SourceRun string `map:"sourceRun,omitempty"`
	Author    string `map:"author,omitempty"`
}

GetRunsOptions are the options associated with Client.GetRuns. Options defined here: http://devcenter.wercker.com/api/endpoints/runs.html#get-all-runs

type GetStepVersionOptions

type GetStepVersionOptions struct {
	Owner   string `map:"owner"`
	Name    string `map:"name"`
	Version string `map:"version"`
}

GetStepVersionOptions are the options associated with Client.GetStepVersion

type GetTokenOptions

type GetTokenOptions struct {
	TokenID string `map:"tokenId"`
}

GetTokenOptions are the options associated with Client.GetToken

type GetTokensOptions

type GetTokensOptions struct {
}

GetTokensOptions are the options associated with Client.GetTokens

type Pipeline

type Pipeline struct {
	ID                   string    `json:"id"`
	Url                  string    `json:"url"`
	CreatedAt            time.Time `json:"createdAt"`
	Name                 string    `json:"name"`
	Permissions          string    `json:"permissions"`
	PipelineName         string    `json:"pipelineName"`
	SetSCMProviderStatus bool      `json:"setScmProviderStatus"`
	Type                 string    `json:"type"`
}

Pipeline is a detailed api representation

type PipelineSummary

type PipelineSummary struct {
	ID                   string    `json:"id"`
	CreatedAt            time.Time `json:"createdAt"`
	Name                 string    `json:"name"`
	Permissions          string    `json:"permissions"`
	PipelineName         string    `json:"pipelineName"`
	SetSCMProviderStatus bool      `json:"setScmProviderStatus"`
	Type                 string    `json:"type"`
}

PipelineSummary is a summary api representation

type Run

type Run struct {
	ID          string              `json:"id"`
	URL         string              `json:"url"`
	Application *ApplicationSummary `json:"application"`
	Branch      string              `json:"branch"`
	Tag         string              `json:"tag"`
	CommitHash  string              `json:"commitHash"`
	CreatedAt   time.Time           `json:"createdAt"`
	EnvVars     []EnvVar            `json:"envVars"`
	FinishedAt  time.Time           `json:"finishedAt"`
	Message     string              `json:"message"`
	Progress    int                 `json:"progress"`
	Result      string              `json:"result"`
	StartedAt   time.Time           `json:"startedAt"`
	SourceRun   *RunSummary         `json:"sourceRun"`
	Pipeline    *PipelineSummary    `json:"pipeline"`
	Status      string              `json:"status"`
}

Run is a detailed api representation

type RunService

type RunService interface {
	GetRun(options *GetRunOptions) (*Run, error)
	GetRuns(options *GetRunsOptions) ([]*RunSummary, error)
	CreateRun(options *CreateRunOptions) (*Run, error)
	CreateChainRun(options *CreateChainRunOptions) (*Run, error)
}

RunService holds all run specific methods

type RunStep

type RunStep struct {
	ID           string              `json:"id"`
	URL          string              `json:"url"`
	ArtifactsURL string              `json:"artifactsUrl"`
	CreatedAt    time.Time           `json:"createdAt"`
	FinishedAt   time.Time           `json:"finishedAt"`
	Message      string              `json:"message"`
	LogURL       string              `json:"logUrl"`
	Order        int                 `json:"order"`
	Application  *ApplicationSummary `json:"project"`
	Phase        string              `json:"phase"`
	Result       string              `json:"result"`
	Run          *RunSummary         `json:"run"`
	StartedAt    time.Time           `json:"startedAt"`
	Status       string              `json:"status"`
	Step         string              `json:"step"`
}

RunStep is a detailed api representation

type RunStepService

type RunStepService interface {
	GetRunStep(options *GetRunStepOptions) (*RunStep, error)
	GetRunStepLog(options *GetRunStepLogOptions) ([]byte, error)
}

RunStepService holds all runStep specific methods

type RunSummary

type RunSummary struct {
	ID         string    `json:"id"`
	URL        string    `json:"url"`
	Branch     string    `json:"branch"`
	Tag        string    `json:"tag"`
	CommitHash string    `json:"commitHash"`
	CreatedAt  time.Time `json:"createdAt"`
	FinishedAt time.Time `json:"finishedAt"`
	Message    string    `json:"message"`
	Progress   int       `json:"progress"`
	Result     string    `json:"result"`
	StartedAt  time.Time `json:"startedAt"`
	Status     string    `json:"status"`
}

RunSummary is a summary api representation

type SCM

type SCM struct {
	Type       string `json:"type"`
	Owner      string `json:"owner"`
	Repository string `json:"repository"`
}

SCM is a detailed source control manager api representation

type Step

type Step struct {
	Deploy           string     `json:"deploy"`
	ApplicationOwner *StepUser  `json:"applicationOwner"`
	Application      string     `json:application"`
	CreatedOn        *time.Time `json:"createdOn"`
	Name             string     `json:"name"`
	Fullname         string     `json:"fullname"`
	Owner            string     `json:"owner"`
	Version          string     `json:"version"`
	Description      string     `json:"description"`
	License          string     `json:"license"`
	WerckerURL       string     `json:"werckerUrl"`
	CodeURL          string     `json:"codeUrl"`
	TarballURL       string     `json:"tarballUrl"`
	TarballSize      int        `json:"tarballSize"`
	Shasum           string     `json:"shasum"`
	Readme           string     `json:"readMe"`
	Keywords         []string   `json:"keywords"`

	Properties     map[string]*StepProperty `json:"properties"`
	Main           string                   `json:"main"`
	ViewCount      int                      `json:"viewCount"`
	PackageVersion string                   `json:"packageVersion"`
	ReleasedBy     *StepUser                `json:"releasedBy"`
}

type StepProperty

type StepProperty struct {
	Default  string `json:"default"`
	Required bool   `json:"required"`
	Type     string `json:"type"`
}

type StepService

type StepService interface {
	GetStepVersion(options *GetStepVersionOptions) (*Step, error)
}

StepService holds all run specific methods

type StepUser

type StepUser struct {
	Name     string `json:"name"`
	Gravatar string `json:"gravatar"`
	Username string `json:"username"`
}

StepUser is the user representation used by the step detail

type Token

type Token struct {
	ID             string     `json:"id"`
	URL            string     `json:"url"`
	Name           string     `json:"name"`
	Token          string     `json:"token"`
	HashedToken    string     `json:"hashedToken"`
	LastCharacters string     `json:"lastCharacters"`
	CreatedAt      *time.Time `json:"createdAt"`
	LastUsedAt     *time.Time `json:"lastUsedAt"`
}

Token is a detailed api representation

type TokenSummary

type TokenSummary struct {
	ID             string     `json:"id"`
	URL            string     `json:"url"`
	Name           string     `json:"name"`
	HashedToken    string     `json:"hashedToken"`
	LastCharacters string     `json:"lastCharacters"`
	CreatedAt      *time.Time `json:"createdAt"`
	LastUsedAt     *time.Time `json:"lastUsedAt"`
}

TokenSummary is a summary api representation

type UnifiedUser

type UnifiedUser struct {
	Type   string             `json:"type"`
	Name   string             `json:"name"`
	Avatar *UnifiedUserAvatar `json:"avatar"`
	UserID string             `json:"userId"`
	Meta   *UnifiedUserMeta   `json:"meta"`
}

UnifiedUser is a flexible user representation. Not all fields have to be set

type UnifiedUserAvatar

type UnifiedUserAvatar struct {
	Gravatar string `json:"gravatar"`
}

UnifiedUserAvatar is the avatar property of the UnifiedUser

type UnifiedUserMeta

type UnifiedUserMeta struct {
	Username        string `json:"username"`
	WerckerEmployee bool   `json:"werckerEmployee"`
}

UnifiedUserMeta is the meta property of the UnifiedUser

type UpdateTokenOptions

type UpdateTokenOptions struct {
	// Required
	TokenID string `map:"tokenId"`

	// Optional
	Name string `json:"name,omitempty"`
}

UpdateTokenOptions are the options associated with Client.UpdateToken

type User

type User struct {
	ID                string `json:"id"`
	FirstName         string `json:"name"`
	LastName          string `json:"lastName"`
	Username          string `json:"username"`
	Email             string `json:"email"`
	GravatarHash      string `json:"gravatarHash"`
	Organization      string `json:"organisation"`
	URL               string `json:"url"`
	Twitter           string `json:"twitter"`
	HasGithubToken    bool   `json:"hasGithubToken"`
	HasBitbucketToken bool   `json:"hasBitbucketToken"`
}

func (User) String

func (u User) String() string

type UserService

type UserService interface {
	GetCurrentUser() (*User, error)
}

Directories

Path Synopsis
cmd
explorer command

Jump to

Keyboard shortcuts

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