db

package
v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DatabaseTimeFormat = "2006-01-02T15:04:05:99Z"

DatabaseTimeFormat represents the format that dredd uses to validate the datetime. This is not the same as the raw value we pass to a new object so we need to use this to coerce raw values to meet the API standard /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}T\d{2}:\d{2}:\d{2}Z$/

Variables

View Source
var Mysql *gorp.DbMap

Mysql is the gorp database map db.Connect must be called to set this up correctly

View Source
var Versions []*Version

Versions holds all sql schema version references

Functions

func Close

func Close()

Close closes the mysql connection and reports any errors called from main with a defer

func Connect

func Connect() error

Connect ensures that the db is connected and mapped properly with gorp

func GetParsedTime

func GetParsedTime(t time.Time) time.Time

GetParsedTime returns the timestamp as it will retrieved from the database This allows us to create timestamp consistency on return values from create requests

func MigrateAll

func MigrateAll() error

MigrateAll checks for db migrations and executes them

func SetupDBLink()

SetupDBLink is called by main after initialization of the Mysql object to create or return an existing table map

Types

type APIToken

type APIToken struct {
	ID      string    `db:"id" json:"id"`
	Created time.Time `db:"created" json:"created"`
	Expired bool      `db:"expired" json:"expired"`
	UserID  int       `db:"user_id" json:"user_id"`
}

APIToken is given to a user to allow API access

type AccessKey

type AccessKey struct {
	ID   int    `db:"id" json:"id"`
	Name string `db:"name" json:"name" binding:"required"`
	// 'aws/do/gcloud/ssh'
	Type string `db:"type" json:"type" binding:"required"`

	ProjectID *int    `db:"project_id" json:"project_id"`
	Key       *string `db:"key" json:"key"`
	Secret    *string `db:"secret" json:"secret"`

	Removed bool `db:"removed" json:"removed"`
}

AccessKey represents a key used to access a machine with ansible from semaphore

func (AccessKey) GetPath

func (key AccessKey) GetPath() string

GetPath returns the location of the access key once written to disk

type Environment

type Environment struct {
	ID        int     `db:"id" json:"id"`
	Name      string  `db:"name" json:"name" binding:"required"`
	ProjectID int     `db:"project_id" json:"project_id"`
	Password  *string `db:"password" json:"password"`
	JSON      string  `db:"json" json:"json" binding:"required"`
	Removed   bool    `db:"removed" json:"removed"`
}

Environment is used to pass additional arguments, in json form to ansible

type Event

type Event struct {
	ProjectID   *int      `db:"project_id" json:"project_id"`
	ObjectID    *int      `db:"object_id" json:"object_id"`
	ObjectType  *string   `db:"object_type" json:"object_type"`
	Description *string   `db:"description" json:"description"`
	Created     time.Time `db:"created" json:"created"`

	ObjectName  string  `db:"-" json:"object_name"`
	ProjectName *string `db:"project_name" json:"project_name"`
}

Event represents information generated by ansible or api action captured to the database during execution

func (Event) Insert

func (evt Event) Insert() error

Insert writes the event to the database

type Inventory

type Inventory struct {
	ID        int    `db:"id" json:"id"`
	Name      string `db:"name" json:"name" binding:"required"`
	ProjectID int    `db:"project_id" json:"project_id"`
	Inventory string `db:"inventory" json:"inventory"`

	// accesses dynamic inventory
	KeyID *int      `db:"key_id" json:"key_id"`
	Key   AccessKey `db:"-" json:"-"`
	// accesses hosts in inventory
	SSHKeyID *int      `db:"ssh_key_id" json:"ssh_key_id"`
	SSHKey   AccessKey `db:"-" json:"-"`

	// static/aws/do/gcloud
	Type string `db:"type" json:"type"`

	Removed bool `db:"removed" json:"removed"`
}

Inventory is the model of an ansible inventory file

type Project

type Project struct {
	ID        int       `db:"id" json:"id"`
	Name      string    `db:"name" json:"name" binding:"required"`
	Created   time.Time `db:"created" json:"created"`
	Alert     bool      `db:"alert" json:"alert"`
	AlertChat string    `db:"alert_chat" json:"alert_chat"`
}

Project is the top level structure in Semaphore

func (*Project) CreateProject

func (project *Project) CreateProject() error

CreateProject writes a project to the database

type Repository

type Repository struct {
	ID        int    `db:"id" json:"id"`
	Name      string `db:"name" json:"name" binding:"required"`
	ProjectID int    `db:"project_id" json:"project_id"`
	GitURL    string `db:"git_url" json:"git_url" binding:"required"`
	SSHKeyID  int    `db:"ssh_key_id" json:"ssh_key_id" binding:"required"`
	Removed   bool   `db:"removed" json:"removed"`

	SSHKey AccessKey `db:"-" json:"-"`
}

Repository is the model for code stored in a git repository

type Session

type Session struct {
	ID         int       `db:"id" json:"id"`
	UserID     int       `db:"user_id" json:"user_id"`
	Created    time.Time `db:"created" json:"created"`
	LastActive time.Time `db:"last_active" json:"last_active"`
	IP         string    `db:"ip" json:"ip"`
	UserAgent  string    `db:"user_agent" json:"user_agent"`
	Expired    bool      `db:"expired" json:"expired"`
}

Session is a connection to the API

type Task

type Task struct {
	ID         int `db:"id" json:"id"`
	TemplateID int `db:"template_id" json:"template_id" binding:"required"`

	Status string `db:"status" json:"status"`
	Debug  bool   `db:"debug" json:"debug"`

	DryRun bool `db:"dry_run" json:"dry_run"`

	// override variables
	Playbook    string `db:"playbook" json:"playbook"`
	Environment string `db:"environment" json:"environment"`

	UserID *int `db:"user_id" json:"user_id"`

	Created time.Time  `db:"created" json:"created"`
	Start   *time.Time `db:"start" json:"start"`
	End     *time.Time `db:"end" json:"end"`
}

Task is a model of a task which will be executed by the runner

type TaskOutput

type TaskOutput struct {
	TaskID int       `db:"task_id" json:"task_id"`
	Task   string    `db:"task" json:"task"`
	Time   time.Time `db:"time" json:"time"`
	Output string    `db:"output" json:"output"`
}

TaskOutput is the ansible log output from the task

type Template

type Template struct {
	ID int `db:"id" json:"id"`

	SSHKeyID      int  `db:"ssh_key_id" json:"ssh_key_id"`
	ProjectID     int  `db:"project_id" json:"project_id"`
	InventoryID   int  `db:"inventory_id" json:"inventory_id"`
	RepositoryID  int  `db:"repository_id" json:"repository_id"`
	EnvironmentID *int `db:"environment_id" json:"environment_id"`

	// Alias as described in https://github.com/ansible-semaphore/semaphore/issues/188
	Alias string `db:"alias" json:"alias"`
	// playbook name in the form of "some_play.yml"
	Playbook string `db:"playbook" json:"playbook"`
	// to fit into []string
	Arguments *string `db:"arguments" json:"arguments"`
	// if true, semaphore will not prepend any arguments to `arguments` like inventory, etc
	OverrideArguments bool `db:"override_args" json:"override_args"`
}

Template is a user defined model that is used to run a task

type User

type User struct {
	ID       int       `db:"id" json:"id"`
	Created  time.Time `db:"created" json:"created"`
	Username string    `db:"username" json:"username" binding:"required"`
	Name     string    `db:"name" json:"name" binding:"required"`
	Email    string    `db:"email" json:"email" binding:"required"`
	Password string    `db:"password" json:"-"`
	Admin    bool      `db:"admin" json:"admin"`
	External bool      `db:"external" json:"external"`
	Alert    bool      `db:"alert" json:"alert"`
}

User is the model for an entity which has access to the API

func FetchUser

func FetchUser(userID int) (*User, error)

FetchUser retrieves a user from the database by ID

type Version

type Version struct {
	Major int
	Minor int
	Patch int
	Build string

	UpgradedDate *time.Time
	Notes        *string
}

Version represents an sql schema version

func (*Version) CheckExists

func (version *Version) CheckExists() (bool, error)

CheckExists queries the database to see if a migration table with this version id exists already

func (*Version) GetErrPath

func (version *Version) GetErrPath() string

GetErrPath is the humanoid version with '.err' and file format appended

func (*Version) GetPath

func (version *Version) GetPath() string

GetPath is the humanoid version with the file format appended

func (*Version) GetSQL

func (version *Version) GetSQL(path string) []string

GetSQL takes a path to an SQL file and returns it from packr as a slice of strings separated by newlines

func (*Version) HumanoidVersion

func (version *Version) HumanoidVersion() string

HumanoidVersion adds a v to the VersionString

func (*Version) Run

func (version *Version) Run() error

Run executes a database migration

func (*Version) TryRollback

func (version *Version) TryRollback()

TryRollback attempts to rollback the database to an earlier version if a rollback exists

func (*Version) VersionString

func (version *Version) VersionString() string

VersionString returns a well formatted string of the current Version

Jump to

Keyboard shortcuts

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