tool

package
v0.0.0-...-2bbe97e Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HubHost is the main URL for the repository
	HubHost = "https://index.docker.io/v1/"
	// HubLoginURL is the URL were we can login into the repository
	HubLoginURL = "https://hub.docker.com/v2/users/login/"
	// HubTagsURL is the url where we can fetch the tags of an image
	HubTagsURL = "https://hub.docker.com/v2/repositories/%s/tags/?page=%d&page_size=%d"
)
View Source
var (
	// ErrorToolNotFound will be thrown when the tool was not found
	ErrorToolNotFound = errors.New("Tool not found")
	// ErrorRegistryEmpty will be thrown when the registry is empty
	ErrorRegistryEmpty = errors.New("Registry cannot be empty")
	// ErrorNameEmpty will be thrown if the name of the tool is empty
	ErrorNameEmpty = errors.New("Name cannot be empty")
	// ErrorNameInvalid will be thrown if the name of the tool is inavlid
	ErrorNameInvalid = errors.New("Name is not valid")
	// ErrorTypeInvalid will be thrown if the Type of the tool is inavlid
	ErrorTypeInvalid = errors.New("Type is not valid")
	// NameRegex is the pattern that all tool names must match
	NameRegex = "^[a-zA-Z0-9-_]+$"
)
View Source
var (
	// BucketKey is the key under which all tools are stored in the database
	BucketKey = "tools"
	// Types define the possible types of a tool
	Types = map[string]Factory{
		"local": &LocalFactory{},
		"hub":   &HubFactory{},
		"jfrog": &JFrogFactory{},
		"":      &HubFactory{},
	}
)
View Source
var (
	// JFrogTagsURL is the URL that will return all tags for a given image
	JFrogTagsURL = "%s/artifactory/v2/%s/tags/list"
)

Functions

func Execute

func Execute(containerID string, opt *ExecutionOptions) (int, error)

Execute will execute the given command in an already running container.

func Exists

func Exists(tools []Tool, tool Tool) bool

Exists will check if a given tool exists in the collection of tools

func FullImage

func FullImage(tool Tool, version string) string

FullImage will return the full name of the image including repository and version if possible

func HasValidName

func HasValidName(name string) bool

HasValidName will check if the name of the tool is valid according to the regex

func Pull

func Pull(client config.Docker, to Tool, tag string, timeout time.Duration) error

Pull will try to pull the given tool with the given version from the remote repository

func StartAndExecute

func StartAndExecute(opt *ExecutionOptions) (int, error)

StartAndExecute will start a container and execute the given command. When this method is called, the tool is not a daemon tool

func StartIfDaemon

func StartIfDaemon(opt *ExecutionOptions) (string, error)

StartIfDaemon will start the given tool if it is a daemon and will return the id of the prepared container. If no id is returned, then the tool is no daemon

func StopDaemons

func StopDaemons()

StopDaemons will stop all tool daeomons if possible

func Versions

func Versions(client config.Docker, to Tool) ([]string, error)

Versions will get all local version that are available for the given tool

Types

type Daemon

type Daemon struct {
	Entry []string `json:"entry,omitempty"`
}

Daemon defines the entry point when the container should be started as a daemon

type Data

type Data struct {
	Name          string    `json:"name"`
	Description   string    `json:"description"`
	Registry      string    `json:"registry"`
	ImageRegistry string    `json:"imageRegistry,omitempty"`
	Image         string    `json:"image"`
	Default       bool      `json:"default"`
	Type          string    `json:"type,omitempty"`
	Entry         []string  `json:"entry,omitempty"`
	Added         time.Time `json:"added"`
	Versions      []string  `json:"versions,omitempty"`
	Daemon        *Daemon   `json:"daemon,omitempty"`
}

Data is the data each tool contains

type ExecutionOptions

type ExecutionOptions struct {
	Tool      Tool
	Version   string
	IO        *config.IO
	Docker    *config.Docker
	Arguments []string
	Mounts    []string
}

ExecutionOptions are used to execute commands on a container

type Factory

type Factory interface {
	Raw() Tool
	Create(Data) Tool
}

Factory is a factory to create tools from the db and from user input

type HubFactory

type HubFactory struct{}

HubFactory is the factory for the HubTool

func (*HubFactory) Create

func (g *HubFactory) Create(dt Data) Tool

Create will take data and return a HubFactory from the given arguments

func (*HubFactory) Raw

func (g *HubFactory) Raw() Tool

Raw will return a raw HubFactory struct for populating from the db

type HubTagResponse

type HubTagResponse struct {
	Next    string         `json:"next"`
	Results []HubTagResult `json:"results"`
}

HubTagResponse is the response the repository returns when asked for tags

type HubTagResult

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

HubTagResult is the tag name and part of the TagResult

type HubTokenResponse

type HubTokenResponse struct {
	Token string `json:"token"`
}

HubTokenResponse is the response for a login request

type HubTool

type HubTool struct {
	Core Data `json:"code"`
}

HubTool represents a sledgehammer tool which is stored in the official docker hub repository

func (*HubTool) Data

func (t *HubTool) Data() *Data

Data will return the inner data for the tool

func (*HubTool) Versions

func (t *HubTool) Versions() ([]string, error)

Versions returns the version of the tool while it fetches them from the official docker repository

type JFrogFactory

type JFrogFactory struct{}

JFrogFactory is the factory for the JFrogTool

func (*JFrogFactory) Create

func (g *JFrogFactory) Create(dt Data) Tool

Create will take data and return a JFrogTool from the given arguments

func (*JFrogFactory) Raw

func (g *JFrogFactory) Raw() Tool

Raw will return a raw JFrogFactory struct for populating from the db

type JFrogTagResponse

type JFrogTagResponse struct {
	Name string   `json:"name"`
	Tags []string `json:"tags"`
}

JFrogTagResponse is the response the repository returns when asked for tags

type JFrogTool

type JFrogTool struct {
	Core Data `json:"code"`
}

JFrogTool represents a sledgehammer tool which is stored in any JFrog artifacory repository

func (*JFrogTool) Data

func (t *JFrogTool) Data() *Data

Data will return the inner data for the tool

func (*JFrogTool) Versions

func (t *JFrogTool) Versions() ([]string, error)

Versions returns the version of the tool while it fetches them from the official docker repository

type JSON

type JSON struct {
	Type string          `json:"type"`
	Tool json.RawMessage `json:"tool"`
}

JSON is the structure that will be stored in the database

type LocalFactory

type LocalFactory struct{}

LocalFactory is the factory for the LocalRegistry

func (*LocalFactory) Create

func (g *LocalFactory) Create(dt Data) Tool

Create will take data and return a LocalRegistry from the given arguments

func (*LocalFactory) Raw

func (g *LocalFactory) Raw() Tool

Raw will return a raw LocalRepository struct for populating from the db

type LocalTool

type LocalTool struct {
	Core Data `json:"code"`
}

LocalTool represents a tool that can only be found on the local computer, this should not be used in prodution It is mainly used for local development

func (*LocalTool) Data

func (t *LocalTool) Data() *Data

Data will return the inner data for the tool

func (*LocalTool) Versions

func (t *LocalTool) Versions() ([]string, error)

Versions will return all available remote versions, in this case none

type Tool

type Tool interface {
	// Versions will return all version that are currently available for the given tool
	Versions() ([]string, error)
	Data() *Data
}

Tool is the base interface for a tool and can be used to support multiple tools

type Tools

type Tools struct {
	config.Database
}

Tools is the struct that has access to all tools in the database

func New

func New(db config.Database) *Tools

New will instantiate a new Tools struct that can be used to access all tools registered with Sledgehammer7 The structure of the tool will look like this: tools |- foo | |- default (foo tool in the default registry) | |- other (foo tool in the other registry) |- bar

|- default/bar (bar tool in the default registry)

For a registry only unique tools are allowed. In the case that there are multiple entries with the same name in the same registry it is up to the registry to select the one with the highest priority.

func (*Tools) Add

func (t *Tools) Add(toolsToAdd ...Tool) error

Add will add the given tool to Sledgehammer

func (*Tools) From

func (t *Tools) From(registry string) ([]Tool, error)

From will return all tools from a given registry name

func (*Tools) Get

func (t *Tools) Get(registry string, name string) (Tool, error)

Get will return a single tool from a registry

func (*Tools) List

func (t *Tools) List() ([]string, map[string][]Tool, error)

List will list all tools currently stored in the database and returns a sorted list of toolnames and the tools

func (*Tools) Remove

func (t *Tools) Remove(registry string, tool string) error

Remove will remove the given tool from the list of tools registered with Sledgehammer

func (*Tools) Search

func (t *Tools) Search(search string) ([]string, map[string][]Tool, error)

Search will return a list filtered by the search term. A simple contains is supported, nothing else.

Jump to

Keyboard shortcuts

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