Documentation
¶
Index ¶
- Variables
- func Execute(containerID string, opt *ExecutionOptions) (int, error)
- func Exists(tools []Tool, tool Tool) bool
- func FullImage(tool Tool, version string) string
- func HasValidName(name string) bool
- func Pull(client config.Docker, to Tool, tag string, timeout time.Duration) error
- func StartAndExecute(opt *ExecutionOptions) (int, error)
- func StartIfDaemon(opt *ExecutionOptions) (string, error)
- func StopDaemons()
- func Versions(client config.Docker, to Tool) ([]string, error)
- type Daemon
- type Data
- type ExecutionOptions
- type Factory
- type HubFactory
- type HubTagResponse
- type HubTagResult
- type HubTokenResponse
- type HubTool
- type JFrogFactory
- type JFrogTagResponse
- type JFrogTool
- type JSON
- type LocalFactory
- type LocalTool
- type Tool
- type Tools
- func (t *Tools) Add(toolsToAdd ...Tool) error
- func (t *Tools) From(registry string) ([]Tool, error)
- func (t *Tools) Get(registry string, name string) (Tool, error)
- func (t *Tools) List() ([]string, map[string][]Tool, error)
- func (t *Tools) Remove(registry string, tool string) error
- func (t *Tools) Search(search string) ([]string, map[string][]Tool, error)
Constants ¶
This section is empty.
Variables ¶
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" )
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-_]+$" )
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{}, } )
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 FullImage ¶
FullImage will return the full name of the image including repository and version if possible
func HasValidName ¶
HasValidName will check if the name of the tool is valid according to the regex
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
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 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
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 ¶
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
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
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 ¶
Tools is the struct that has access to all tools in the database
func New ¶
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) List ¶
List will list all tools currently stored in the database and returns a sorted list of toolnames and the tools