sctl

package module
v0.0.0-...-27420d4 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: MIT Imports: 14 Imported by: 0

README

sctl-common

Common types and functions for sctl

go get github.com/CzarSimon/sctl-common

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectTokenDB

func ConnectTokenDB(path string) *sql.DB

ConnectTokenDB Connects to a token db and returns the handler

func GenerateToken

func GenerateToken(length int) string

GenerateToken Creates a random token consiting of aspecified number of sha256 hashes

func GetActiveProject

func GetActiveProject(db *sql.DB) (string, error)

GetActiveProject Fetches the name of the current active project

func NodeSchema

func NodeSchema() string

NodeSchema Returns the database schema for nodes

func ProjectSchema

func ProjectSchema() string

ProjectSchema Returns the database schema for projects

func TokenPart

func TokenPart() string

TokenPart Generates a random sha256 hash and returns as a string

func TokenSchema

func TokenSchema() string

TokenSchema Returns the token schema

Types

type Command

type Command struct {
	Main string   `json:"main"`
	Args []string `json:"args"`
}

Command Holds the main command and argument to be executed against os/exec

func DockerCommand

func DockerCommand(args []string) Command

DockerCommand creates a general docker command

func (Command) Execute

func (command Command) Execute() (string, error)

Execute Executes a given command against os/exec and return the output and potential errors

func (Command) ToString

func (command Command) ToString() string

ToString returns the string representation of the command

type Init

type Init struct {
	Project Project `json:"project"`
	Master  Node    `json:"master"`
}

Init Struct for initializing a project

type MinionCommand

type MinionCommand struct {
	Minion  Node    `json:"node"`
	Command Command `json:"command"`
}

MinionCommand Holds a command and the minon it should be sent to

type Node

type Node struct {
	Project  string `json:"project"`
	IP       string `json:"ip"`
	OS       string `json:"os"`
	IsMaster bool   `json:"isMaster"`
	User     string `json:"user"`
}

Node contains node metadata

func (Node) IsLocal

func (node Node) IsLocal() bool

IsLocal Checks if node is localhost

func (Node) Remote

func (node Node) Remote() string

Remote Creates a remote node adress such as user@hostname

func (Node) RsyncFileCMD

func (node Node) RsyncFileCMD(filePath, targetFolder string) Command

RsyncFileCMD Creates a command to rsync a file to the node

func (Node) RsyncFolderCMD

func (node Node) RsyncFolderCMD(execFolder, targetFolder string) Command

RsyncFolderCMD Creates a command to rsync minion executables to the node

func (Node) RsyncTarget

func (node Node) RsyncTarget(targetFolder string) string

RsyncTarget Prepends user@hostname: to target folder if node is not local

func (Node) SSHCommand

func (node Node) SSHCommand(args ...string) Command

SSHCommand Creates an ssh command to be executed on the node

func (*Node) SetToMinion

func (node *Node) SetToMinion(db *sql.DB) error

SetToMinion sets a node struct to hold values of a minion

func (Node) ToMinon

func (node Node) ToMinon() util.ServerConfig

ToMinon Turns a node into a minion server config

type Project

type Project struct {
	Name        string `json:"name"`
	Folder      string `json:"folder"`
	SwarmToken  string `json:"swarmToken"`
	IsActive    bool   `json:"isActive"`
	Network     string `json:"network"`
	MasterToken string `json:"masterToken"`
	Master      string `json:"master"`
}

Project holds metadata about a project

func NewProject

func NewProject(name, folder string) Project

NewProject generates a new project based on name an folder

func (Project) InactivateOthers

func (project Project) InactivateOthers(db *sql.DB) error

InactivateOthers Sets all other projects besides the supplied one to inactive

func (Project) Insert

func (project Project) Insert(db *sql.DB) error

Insert Inserts a new project into the database and sets it to active

func (Project) MakeMasterNode

func (project Project) MakeMasterNode() Node

MakeMasterNode creates node struct for a project master node

type Service

type Service struct {
	Name        string   `json:"name"`
	Image       string   `json:"image"`
	EnvVars     []string `json:"envVars"`
	KeywordArgs []string `json:"keywordArgs"`
}

Service Holds service configuration info

func (Service) GetEnvVars

func (service Service) GetEnvVars() []string

GetEnvVars Formats the environment arguments in a service definition to be runnable

func (Service) GetKeywordArgs

func (service Service) GetKeywordArgs() []string

GetKeywordArgs Formats the keyword arguments in a service definition to be runnable

func (*Service) GetServiceDef

func (service *Service) GetServiceDef(path string) error

GetServiceDef reads a given service definition file and stores the content in the given service struct

func (Service) PullCommand

func (service Service) PullCommand() Command

PullCommand creates a command to pull a docker image

func (Service) PushCommand

func (service Service) PushCommand() Command

PushCommand creates a command to push a docker image

func (Service) RunCommand

func (service Service) RunCommand(network string) Command

RunCommand creates a command to start a servcie

func (Service) ServiceFilePath

func (service Service) ServiceFilePath(path string) string

ServiceFilePath Creates a file path to a service's definition file

func (Service) StopCommand

func (service Service) StopCommand() Command

StopCommand creates a command to pull a docker image

type Token

type Token struct {
	Data      string    `json:"data"`
	Timestamp time.Time `json:"timestamp"`
}

Token Struct to keep a token and its timestamp

func NewToken

func NewToken() Token

NewToken Return a new random token with timestamp set to the current UTC time

func (Token) ToBundle

func (token Token) ToBundle(masterToken string) TokenBundle

ToBundle Turns a token to a TokenBundle with a given master token

func (Token) Valid

func (token Token) Valid(maxAge float64) bool

Valid checks if a token in valid or out of date

type TokenBundle

type TokenBundle struct {
	Auth   Token
	Master string
}

TokenBundle Struct to keep all project tokens

func GetTokenBundle

func GetTokenBundle(path string) TokenBundle

GetTokenBundle Retrives tokens from the token-db

func (TokenBundle) Print

func (tokens TokenBundle) Print()

Print Prints the content of the token bundle in a formated way

Jump to

Keyboard shortcuts

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