db

package
v0.2.54 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessKeyRoleAnsibleUser = iota
	AccessKeyRoleAnsibleBecomeUser
	AccessKeyRoleAnsiblePasswordVault
	AccessKeyRoleGit
)
View Source
const (
	InventoryStatic     = "static"
	InventoryStaticYaml = "static-yaml"
	InventoryFile       = "file"
)

Variables

View Source
var AccessKeyProps = ObjectProps{
	TableName:             "access_key",
	Type:                  reflect.TypeOf(AccessKey{}),
	PrimaryColumnName:     "id",
	ReferringColumnSuffix: "key_id",
	SortableColumns:       []string{"name", "type"},
	DefaultSortingColumn:  "name",
}
View Source
var EnvironmentProps = ObjectProps{
	TableName:             "project__environment",
	Type:                  reflect.TypeOf(Environment{}),
	PrimaryColumnName:     "id",
	ReferringColumnSuffix: "environment_id",
	SortableColumns:       []string{"name"},
	DefaultSortingColumn:  "name",
}
View Source
var ErrInvalidOperation = errors.New("invalid operation")
View Source
var ErrNotFound = errors.New("no rows in result set")
View Source
var GlobalRunnerProps = ObjectProps{
	TableName:         "runner",
	Type:              reflect.TypeOf(Runner{}),
	PrimaryColumnName: "id",
	IsGlobal:          true,
}
View Source
var InventoryProps = ObjectProps{
	TableName:             "project__inventory",
	Type:                  reflect.TypeOf(Inventory{}),
	PrimaryColumnName:     "id",
	ReferringColumnSuffix: "inventory_id",
	SortableColumns:       []string{"name"},
	DefaultSortingColumn:  "name",
}
View Source
var ProjectProps = ObjectProps{
	TableName:            "project",
	Type:                 reflect.TypeOf(Project{}),
	PrimaryColumnName:    "id",
	DefaultSortingColumn: "name",
	IsGlobal:             true,
}
View Source
var ProjectUserProps = ObjectProps{
	TableName:         "project__user",
	Type:              reflect.TypeOf(ProjectUser{}),
	PrimaryColumnName: "user_id",
}
View Source
var RepositoryProps = ObjectProps{
	TableName:             "project__repository",
	Type:                  reflect.TypeOf(Repository{}),
	PrimaryColumnName:     "id",
	ReferringColumnSuffix: "repository_id",
	DefaultSortingColumn:  "name",
}
View Source
var ScheduleProps = ObjectProps{
	TableName:         "project__schedule",
	Type:              reflect.TypeOf(Schedule{}),
	PrimaryColumnName: "id",
}
View Source
var SessionProps = ObjectProps{
	TableName:         "session",
	Type:              reflect.TypeOf(Session{}),
	PrimaryColumnName: "id",
}
View Source
var TaskOutputProps = ObjectProps{
	TableName: "task__output",
	Type:      reflect.TypeOf(TaskOutput{}),
}
View Source
var TaskProps = ObjectProps{
	TableName:         "task",
	Type:              reflect.TypeOf(Task{}),
	PrimaryColumnName: "id",
	IsGlobal:          true,
	SortInverted:      true,
}
View Source
var TemplateProps = ObjectProps{
	TableName:             "project__template",
	Type:                  reflect.TypeOf(Template{}),
	PrimaryColumnName:     "id",
	ReferringColumnSuffix: "template_id",
	SortableColumns:       []string{"name"},
	DefaultSortingColumn:  "name",
}
View Source
var TokenProps = ObjectProps{
	TableName:         "user__token",
	Type:              reflect.TypeOf(APIToken{}),
	PrimaryColumnName: "id",
}
View Source
var UserProps = ObjectProps{
	TableName:         "user",
	Type:              reflect.TypeOf(User{}),
	PrimaryColumnName: "id",
	IsGlobal:          true,
}
View Source
var ViewProps = ObjectProps{
	TableName:            "project__view",
	Type:                 reflect.TypeOf(View{}),
	PrimaryColumnName:    "id",
	DefaultSortingColumn: "position",
}

Functions

func FillEvents

func FillEvents(d Store, events []Event) (err error)

func FillInventory

func FillInventory(d Store, inventory *Inventory) (err error)

func FillTemplate

func FillTemplate(d Store, template *Template) (err error)

func FillTemplates

func FillTemplates(d Store, templates []Template) (err error)

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 Migrate

func Migrate(d Store) error

func ObjectToJSON

func ObjectToJSON(obj interface{}) *string

func StoreSession

func StoreSession(store Store, token string, callback func())

func ValidateUser

func ValidateUser(user User) error

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"`
	// 'ssh/login_password/none'
	Type AccessKeyType `db:"type" json:"type" binding:"required"`

	ProjectID *int `db:"project_id" json:"project_id"`

	// Secret used internally, do not assign this field.
	// You should use methods SerializeSecret to fill this field.
	Secret *string `db:"secret" json:"-"`

	LoginPassword  LoginPassword `db:"-" json:"login_password"`
	SshKey         SshKey        `db:"-" json:"ssh"`
	OverrideSecret bool          `db:"-" json:"override_secret"`
}

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

func (*AccessKey) DeserializeSecret

func (key *AccessKey) DeserializeSecret() error

func (*AccessKey) DeserializeSecret2

func (key *AccessKey) DeserializeSecret2(encryptionString string) error

func (*AccessKey) Install

func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installation AccessKeyInstallation, err error)

func (*AccessKey) SerializeSecret

func (key *AccessKey) SerializeSecret() error

func (*AccessKey) Validate

func (key *AccessKey) Validate(validateSecretFields bool) error

type AccessKeyInstallation

type AccessKeyInstallation struct {
	InstallationKey int64
	SshAgent        *lib.SshAgent
}

func (AccessKeyInstallation) Destroy

func (key AccessKeyInstallation) Destroy() error

func (AccessKeyInstallation) GetPath

func (key AccessKeyInstallation) GetPath() string

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

type AccessKeyRole

type AccessKeyRole int

type AccessKeyType

type AccessKeyType string
const (
	AccessKeySSH           AccessKeyType = "ssh"
	AccessKeyNone          AccessKeyType = "none"
	AccessKeyLoginPassword AccessKeyType = "login_password"
)

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"`
	ENV       *string `db:"env" json:"env" binding:"required"`
}

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

func (*Environment) Validate

func (env *Environment) Validate() error

type Event

type Event struct {
	ID          int              `db:"id" json:"-"`
	UserID      *int             `db:"user_id" json:"user_id"`
	ProjectID   *int             `db:"project_id" json:"project_id"`
	ObjectID    *int             `db:"object_id" json:"object_id"`
	ObjectType  *EventObjectType `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"`
	Username    *string `db:"-" json:"username"`
}

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

type EventObjectType

type EventObjectType string
const (
	EventTask        EventObjectType = "task"
	EventEnvironment EventObjectType = "environment"
	EventInventory   EventObjectType = "inventory"
	EventKey         EventObjectType = "key"
	EventProject     EventObjectType = "project"
	EventRepository  EventObjectType = "repository"
	EventSchedule    EventObjectType = "schedule"
	EventTemplate    EventObjectType = "template"
	EventUser        EventObjectType = "user"
	EventView        EventObjectType = "view"
)

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 hosts in inventory
	SSHKeyID *int      `db:"ssh_key_id" json:"ssh_key_id"`
	SSHKey   AccessKey `db:"-" json:"-"`

	BecomeKeyID *int      `db:"become_key_id" json:"become_key_id"`
	BecomeKey   AccessKey `db:"-" json:"-"`

	// static/file
	Type string `db:"type" json:"type"`
}

Inventory is the model of an ansible inventory file

type LoginPassword

type LoginPassword struct {
	Login    string `json:"login"`
	Password string `json:"password"`
}

type Migration

type Migration struct {
	Version      string     `db:"version" json:"version"`
	UpgradedDate *time.Time `db:"upgraded_date" json:"upgraded_date"`
	Notes        *string    `db:"notes" json:"notes"`
}

Migration represents sql schema version

func GetMigrations

func GetMigrations() []Migration

func (Migration) HumanoidVersion

func (m Migration) HumanoidVersion() string

HumanoidVersion adds a v to the VersionString

type ObjectProps

type ObjectProps struct {
	TableName             string
	Type                  reflect.Type // to which type the table bust be mapped.
	IsGlobal              bool         // doesn't belong to other table, for example to project or user.
	ReferringColumnSuffix string
	PrimaryColumnName     string
	SortableColumns       []string
	DefaultSortingColumn  string
	SortInverted          bool // sort from high to low object ID by default. It is useful for some NoSQL implementations.
}

ObjectProps describe database entities. It mainly used for NoSQL implementations (currently BoltDB) to preserve same data structure of different implementations and easy change it if required.

func (ObjectProps) GetReferringFieldsFrom

func (p ObjectProps) GetReferringFieldsFrom(t reflect.Type) (fields []string, err error)

type ObjectReferrer

type ObjectReferrer struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type ObjectReferrers

type ObjectReferrers struct {
	Templates    []ObjectReferrer `json:"templates"`
	Inventories  []ObjectReferrer `json:"inventories"`
	Repositories []ObjectReferrer `json:"repositories"`
}

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"`
	MaxParallelTasks int       `db:"max_parallel_tasks" json:"max_parallel_tasks"`
}

Project is the top level structure in Distro

type ProjectUser

type ProjectUser struct {
	ID        int             `db:"id" json:"-"`
	ProjectID int             `db:"project_id" json:"project_id"`
	UserID    int             `db:"user_id" json:"user_id"`
	Role      ProjectUserRole `db:"role" json:"role"`
}

type ProjectUserPermission

type ProjectUserPermission int
const (
	CanRunProjectTasks ProjectUserPermission = 1 << iota
	CanUpdateProject
	CanManageProjectResources
	CanManageProjectUsers
)

type ProjectUserRole

type ProjectUserRole string
const (
	ProjectOwner      ProjectUserRole = "owner"
	ProjectManager    ProjectUserRole = "manager"
	ProjectTaskRunner ProjectUserRole = "task_runner"
	ProjectGuest      ProjectUserRole = "guest"
	ProjectNone       ProjectUserRole = ""
)

func (ProjectUserRole) Can

func (r ProjectUserRole) Can(permissions ProjectUserPermission) bool

func (ProjectUserRole) GetPermissions

func (r ProjectUserRole) GetPermissions() ProjectUserPermission

func (ProjectUserRole) IsValid

func (r ProjectUserRole) IsValid() bool

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"`
	GitBranch string `db:"git_branch" json:"git_branch" binding:"required"`
	SSHKeyID  int    `db:"ssh_key_id" json:"ssh_key_id" binding:"required"`

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

Repository is the model for code stored in a git repository

func (Repository) ClearCache

func (r Repository) ClearCache() error

func (Repository) GetDirName

func (r Repository) GetDirName(templateID int) string

func (Repository) GetFullPath

func (r Repository) GetFullPath(templateID int) string

func (Repository) GetGitURL

func (r Repository) GetGitURL() string

func (Repository) GetType

func (r Repository) GetType() RepositoryType

func (Repository) Validate

func (r Repository) Validate() error

type RepositoryType

type RepositoryType string
const (
	RepositoryGit   RepositoryType = "git"
	RepositorySSH   RepositoryType = "ssh"
	RepositoryHTTPS RepositoryType = "https"
	RepositoryFile  RepositoryType = "file"
	RepositoryLocal RepositoryType = "local"
)

type RetrieveQueryParams

type RetrieveQueryParams struct {
	Offset       int
	Count        int
	SortBy       string
	SortInverted bool
}

type Runner

type Runner struct {
	ID        int    `db:"id" json:"-"`
	Token     string `db:"token" json:"-"`
	ProjectID *int   `db:"project_id" json:"project_id"`
	//State            RunnerState `db:"state" json:"state"`
	Webhook          string `db:"webhook" json:"webhook"`
	MaxParallelTasks int    `db:"max_parallel_tasks" json:"max_parallel_tasks"`
}

type RunnerState

type RunnerState string

type Schedule

type Schedule struct {
	ID             int     `db:"id" json:"id"`
	ProjectID      int     `db:"project_id" json:"project_id"`
	TemplateID     int     `db:"template_id" json:"template_id"`
	CronFormat     string  `db:"cron_format" json:"cron_format"`
	RepositoryID   *int    `db:"repository_id" json:"repository_id"`
	LastCommitHash *string `db:"last_commit_hash" json:"-"`
}

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 SshKey

type SshKey struct {
	Login      string `json:"login"`
	Passphrase string `json:"passphrase"`
	PrivateKey string `json:"private_key"`
}

type Store

type Store interface {
	// Connect connects to the database.
	// Token parameter used if PermanentConnection returns false.
	// Token used for debugging of session connections.
	Connect(token string)
	Close(token string)

	// PermanentConnection returns true if connection should be kept from start to finish of the app.
	// This mode is suitable for MySQL and Postgres but not for BoltDB.
	// For BoltDB we should reconnect for each request because BoltDB support only one connection at time.
	PermanentConnection() bool

	// IsInitialized indicates is database already initialized, or it is empty.
	// The method is useful for creating required entities in database during first run.
	IsInitialized() (bool, error)
	// IsMigrationApplied queries the database to see if a migration table with
	// this version id exists already
	IsMigrationApplied(version Migration) (bool, error)
	// ApplyMigration runs executes a database migration
	ApplyMigration(version Migration) error
	// TryRollbackMigration attempts to roll back the database to an earlier version
	// if a rollback exists
	TryRollbackMigration(version Migration)

	GetEnvironment(projectID int, environmentID int) (Environment, error)
	GetEnvironmentRefs(projectID int, environmentID int) (ObjectReferrers, error)
	GetEnvironments(projectID int, params RetrieveQueryParams) ([]Environment, error)
	UpdateEnvironment(env Environment) error
	CreateEnvironment(env Environment) (Environment, error)
	DeleteEnvironment(projectID int, templateID int) error

	GetInventory(projectID int, inventoryID int) (Inventory, error)
	GetInventoryRefs(projectID int, inventoryID int) (ObjectReferrers, error)
	GetInventories(projectID int, params RetrieveQueryParams) ([]Inventory, error)
	UpdateInventory(inventory Inventory) error
	CreateInventory(inventory Inventory) (Inventory, error)
	DeleteInventory(projectID int, inventoryID int) error

	GetRepository(projectID int, repositoryID int) (Repository, error)
	GetRepositoryRefs(projectID int, repositoryID int) (ObjectReferrers, error)
	GetRepositories(projectID int, params RetrieveQueryParams) ([]Repository, error)
	UpdateRepository(repository Repository) error
	CreateRepository(repository Repository) (Repository, error)
	DeleteRepository(projectID int, repositoryID int) error

	GetAccessKey(projectID int, accessKeyID int) (AccessKey, error)
	GetAccessKeyRefs(projectID int, accessKeyID int) (ObjectReferrers, error)
	GetAccessKeys(projectID int, params RetrieveQueryParams) ([]AccessKey, error)
	RekeyAccessKeys(oldKey string) error

	UpdateAccessKey(accessKey AccessKey) error
	CreateAccessKey(accessKey AccessKey) (AccessKey, error)
	DeleteAccessKey(projectID int, accessKeyID int) error

	GetUsers(params RetrieveQueryParams) ([]User, error)
	CreateUserWithoutPassword(user User) (User, error)
	CreateUser(user UserWithPwd) (User, error)
	DeleteUser(userID int) error

	// UpdateUser updates all fields of the entity except Pwd.
	// Pwd should be present of you want update user password. Empty Pwd ignored.
	UpdateUser(user UserWithPwd) error
	SetUserPassword(userID int, password string) error
	GetUser(userID int) (User, error)
	GetUserByLoginOrEmail(login string, email string) (User, error)

	GetProject(projectID int) (Project, error)
	GetAllProjects() ([]Project, error)
	GetProjects(userID int) ([]Project, error)
	CreateProject(project Project) (Project, error)
	DeleteProject(projectID int) error
	UpdateProject(project Project) error

	GetTemplates(projectID int, filter TemplateFilter, params RetrieveQueryParams) ([]Template, error)
	GetTemplateRefs(projectID int, templateID int) (ObjectReferrers, error)
	CreateTemplate(template Template) (Template, error)
	UpdateTemplate(template Template) error
	GetTemplate(projectID int, templateID int) (Template, error)
	DeleteTemplate(projectID int, templateID int) error

	GetSchedules() ([]Schedule, error)
	GetTemplateSchedules(projectID int, templateID int) ([]Schedule, error)
	CreateSchedule(schedule Schedule) (Schedule, error)
	UpdateSchedule(schedule Schedule) error
	SetScheduleCommitHash(projectID int, scheduleID int, hash string) error
	GetSchedule(projectID int, scheduleID int) (Schedule, error)
	DeleteSchedule(projectID int, scheduleID int) error

	GetProjectUsers(projectID int, params RetrieveQueryParams) ([]UserWithProjectRole, error)
	CreateProjectUser(projectUser ProjectUser) (ProjectUser, error)
	DeleteProjectUser(projectID int, userID int) error
	GetProjectUser(projectID int, userID int) (ProjectUser, error)
	UpdateProjectUser(projectUser ProjectUser) error

	CreateEvent(event Event) (Event, error)
	GetUserEvents(userID int, params RetrieveQueryParams) ([]Event, error)
	GetEvents(projectID int, params RetrieveQueryParams) ([]Event, error)

	GetAPITokens(userID int) ([]APIToken, error)
	CreateAPIToken(token APIToken) (APIToken, error)
	GetAPIToken(tokenID string) (APIToken, error)
	ExpireAPIToken(userID int, tokenID string) error
	DeleteAPIToken(userID int, tokenID string) error

	GetSession(userID int, sessionID int) (Session, error)
	CreateSession(session Session) (Session, error)
	ExpireSession(userID int, sessionID int) error
	TouchSession(userID int, sessionID int) error

	CreateTask(task Task) (Task, error)
	UpdateTask(task Task) error

	GetTemplateTasks(projectID int, templateID int, params RetrieveQueryParams) ([]TaskWithTpl, error)
	GetProjectTasks(projectID int, params RetrieveQueryParams) ([]TaskWithTpl, error)
	GetTask(projectID int, taskID int) (Task, error)
	DeleteTaskWithOutputs(projectID int, taskID int) error
	GetTaskOutputs(projectID int, taskID int) ([]TaskOutput, error)
	CreateTaskOutput(output TaskOutput) (TaskOutput, error)

	GetView(projectID int, viewID int) (View, error)
	GetViews(projectID int) ([]View, error)
	UpdateView(view View) error
	CreateView(view View) (View, error)
	DeleteView(projectID int, viewID int) error
	SetViewPositions(projectID int, viewPositions map[int]int) error

	GetRunner(projectID int, runnerID int) (Runner, error)
	GetRunners(projectID int) ([]Runner, error)
	DeleteRunner(projectID int, runnerID int) error
	GetGlobalRunner(runnerID int) (Runner, error)
	GetGlobalRunners() ([]Runner, error)
	DeleteGlobalRunner(runnerID int) error
	UpdateRunner(runner Runner) error
	CreateRunner(runner Runner) (Runner, error)
}

type SurveyVar

type SurveyVar struct {
	Name        string        `json:"name"`
	Title       string        `json:"title"`
	Required    bool          `json:"required"`
	Type        SurveyVarType `json:"type"`
	Description string        `json:"description"`
}

type SurveyVarType

type SurveyVarType string

type Task

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

	Status lib.TaskStatus `db:"status" json:"status"`

	Debug  bool `db:"debug" json:"debug"`
	DryRun bool `db:"dry_run" json:"dry_run"`
	Diff   bool `db:"diff" json:"diff"`

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

	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"`

	Message string `db:"message" json:"message"`

	// CommitMessage is a git commit hash of playbook repository which
	// was active when task was created.
	CommitHash *string `db:"commit_hash" json:"commit_hash"`
	// CommitMessage contains message retrieved from git repository after checkout to CommitHash.
	// It is readonly by API.
	CommitMessage string `db:"commit_message" json:"commit_message"`

	BuildTaskID *int `db:"build_task_id" json:"build_task_id"`

	// Version is a build version.
	// This field available only for Build tasks.
	Version *string `db:"version" json:"version"`

	Arguments *string `db:"arguments" json:"arguments"`
}

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

func (*Task) GetIncomingVersion

func (task *Task) GetIncomingVersion(d Store) *string

func (*Task) ValidateNewTask

func (task *Task) ValidateNewTask(template Template) error

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 TaskWithTpl

type TaskWithTpl struct {
	Task
	TemplatePlaybook string       `db:"tpl_playbook" json:"tpl_playbook"`
	TemplateAlias    string       `db:"tpl_alias" json:"tpl_alias"`
	TemplateType     TemplateType `db:"tpl_type" json:"tpl_type"`
	UserName         *string      `db:"user_name" json:"user_name"`
	BuildTask        *Task        `db:"-" json:"build_task"`
}

TaskWithTpl is the task data with additional fields

func (*TaskWithTpl) Fill

func (task *TaskWithTpl) Fill(d Store) error

type Template

type Template struct {
	ID int `db:"id" json:"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"`

	// Name as described in https://github.com/khulnasoft-lab/distro/issues/188
	Name string `db:"name" json:"name"`
	// 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, distro will not prepend any arguments to `arguments` like inventory, etc
	AllowOverrideArgsInTask bool `db:"allow_override_args_in_task" json:"allow_override_args_in_task"`

	Description *string `db:"description" json:"description"`

	VaultKeyID *int      `db:"vault_key_id" json:"vault_key_id"`
	VaultKey   AccessKey `db:"-" json:"-"`

	Type            TemplateType `db:"type" json:"type"`
	StartVersion    *string      `db:"start_version" json:"start_version"`
	BuildTemplateID *int         `db:"build_template_id" json:"build_template_id"`

	ViewID *int `db:"view_id" json:"view_id"`

	LastTask *TaskWithTpl `db:"-" json:"last_task"`

	Autorun bool `db:"autorun" json:"autorun"`

	// SurveyVarsJSON used internally for read from database.
	// It is not used for store survey vars to database.
	// Do not use it in your code. Use SurveyVars instead.
	SurveyVarsJSON *string     `db:"survey_vars" json:"-"`
	SurveyVars     []SurveyVar `db:"-" json:"survey_vars"`

	SuppressSuccessAlerts bool `db:"suppress_success_alerts" json:"suppress_success_alerts"`
}

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

func (*Template) Validate

func (tpl *Template) Validate() error

type TemplateFilter

type TemplateFilter struct {
	ViewID          *int
	BuildTemplateID *int
	AutorunOnly     bool
}

type TemplateType

type TemplateType string
const (
	TemplateTask   TemplateType = ""
	TemplateBuild  TemplateType = "build"
	TemplateDeploy TemplateType = "deploy"
)
const (
	SurveyVarStr TemplateType = ""
	SurveyVarInt TemplateType = "int"
)

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:"-"` // password hash
	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

type UserWithProjectRole

type UserWithProjectRole struct {
	Role ProjectUserRole `db:"role" json:"role"`
	User
}

type UserWithPwd

type UserWithPwd struct {
	Pwd string `db:"-" json:"password"` // unhashed password from JSON
	User
}

UserWithPwd extends User structure with field for unhashed password received from JSON.

type ValidationError

type ValidationError struct {
	Message string
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

type View

type View struct {
	ID        int    `db:"id" json:"id"`
	ProjectID int    `db:"project_id" json:"project_id"`
	Title     string `db:"title" json:"title"`
	Position  int    `db:"position" json:"position"`
}

func (*View) Validate

func (view *View) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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