db

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2018 License: GPL-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SuperAdminRoleName      = "SuperAdministrator"
	CommunityAdminRoleName  = "Administrator"
	CommunityMemberRoleName = "Member"
)

Functions

func IsNoResultsError

func IsNoResultsError(e error) bool

IsNoResultsError means no rows found

Types

type Bind

type Bind struct {
	IOPort   IOPort
	VolumeID string
}

Bind describes the binding between an IOPort and a docker volume

type Build

type Build struct {
	ID           string
	ServiceID    ServiceID
	ConnectionID ConnectionID
	Started      time.Time
	Duration     int64
	State        *BuildState
}

Build describes status information about an image being built for a GEF service

type BuildState

type BuildState struct {
	Status string
	Error  string
	Code   int // 0 - finished successfully, -1 - build in progress, 1 - there is an error
}

BuildState keeps information about a build state

func NewBuildStateError

func NewBuildStateError(err string, code int) BuildState

NewBuildStateError creates a new BuildState with specified error

func NewBuildStateOk

func NewBuildStateOk(status string, code int) BuildState

NewBuildStateOk creates a new BuildState with no error

type BuildTable

type BuildTable struct {
	ID           string
	ServiceID    string
	ConnectionID int
	Started      time.Time
	Duration     int64 // duration time in seconds
	Error        string
	Status       string
	Code         int
	Revision     int
}

BuildTable stores the information about an image build process

type Community

type Community struct {
	ID          int64
	Name        string
	Description string
}

Community information

type CommunityTable

type CommunityTable struct {
	ID          int64
	Name        string
	Description string
	Revision    int
}

CommunityTable stores the communities in the db

type ConnectionID

type ConnectionID int

ConnectionID is the type used to identify a docker connection

type ConnectionTable

type ConnectionTable struct {
	ID          int
	Endpoint    string // unique key
	Description string
	TLSVerify   bool
	CertPath    string
	KeyPath     string
	CAPath      string
	Revision    int
}

ConnectionTable stores the information about a docker connection (used to store data in a database)

type ContainerID

type ContainerID string

ContainerID exported

type Db

type Db struct {
	// contains filtered or unexported fields
}

Db is used to keep DbMap

func InitDb

func InitDb() (Db, error)

InitDb initializes the database engine

func InitDbForTesting

func InitDbForTesting() (Db, string, error)

InitDbForTesting must only be used for tests

func (*Db) AddBuild

func (d *Db) AddBuild(newBuild Build) error

AddBuild adds a new build

func (*Db) AddCmd

func (d *Db) AddCmd(service Service) error

AddCmd adds an array of cmd options to the specified service

func (*Db) AddCommunity

func (d *Db) AddCommunity(name, description string, addDefaultRoles bool) (Community, error)

AddCommunity adds a community to the database, with checks

func (*Db) AddConnection

func (d *Db) AddConnection(userID int64, connection def.DockerConfig) (ConnectionID, error)

AddConnection adds a connection to the database

func (*Db) AddIOPort

func (d *Db) AddIOPort(service Service) error

AddIOPort adds input and output ports to the database

func (*Db) AddJob

func (d *Db) AddJob(userID int64, job Job) error

AddJob adds a job to the database

func (*Db) AddJobTask

func (d *Db) AddJobTask(id JobID, taskName string, taskContainer string, taskSwarmService string,
	taskError string, taskExitCode int, taskConsoleOutput *bytes.Buffer) error

AddJobTask adds a task to a job

func (*Db) AddJobVolume

func (d *Db) AddJobVolume(id JobID, volume VolumeID, isInput bool, portName string, content string) error

AddJobVolume sets a job input/output volume

func (*Db) AddRole

func (d *Db) AddRole(name string, communityID int64, description string) (Role, error)

AddRole adds a role to the database, but only if it's not already present For roles that have no associated community use communityID: 0

func (*Db) AddRoleToUser

func (d *Db) AddRoleToUser(userID, roleID int64) error

AddRoleToUser

func (*Db) AddService

func (d *Db) AddService(userID int64, service Service) error

AddService creates a new service in the database

func (*Db) AddUser

func (d *Db) AddUser(user User) (User, error)

AddUser adds a user to the database

func (*Db) Close

func (d *Db) Close()

Close closes the db connections

func (*Db) CountRunningJobs

func (d *Db) CountRunningJobs() int64

CountRunningJobs returns a number of jobs currently running

func (*Db) CountUserRunningJobs

func (d *Db) CountUserRunningJobs(userID int64) int64

CountUserRunningJobs returns a number of running jobs owned by a specific user

func (*Db) DeleteRoleFromUser

func (d *Db) DeleteRoleFromUser(userID, roleID int64) error

DeleteRoleFromUser

func (*Db) DeleteUserToken

func (d *Db) DeleteUserToken(userID, tokenID int64) error

DeleteUserToken deletes the token from the database

func (*Db) GetBuild

func (d *Db) GetBuild(id string) (Build, error)

GetBuild returns a build ready to be converted into JSON

func (*Db) GetCommunityByID

func (d *Db) GetCommunityByID(communityID int64) (Community, error)

GetCommunityByID gets a community from the database

func (*Db) GetCommunityByName

func (d *Db) GetCommunityByName(name string) (Community, error)

GetCommunityByName gets a community from the database

func (*Db) GetConnectionOwners

func (d *Db) GetConnectionOwners(connectionID ConnectionID) ([]int64, error)

GetConnectionOwners does what it says

func (*Db) GetConnections

func (d *Db) GetConnections() (map[ConnectionID]def.DockerConfig, error)

GetConnections returns a map of all connections ready to be converted into JSON

func (*Db) GetFirstConnectionID

func (d *Db) GetFirstConnectionID() (ConnectionID, error)

GetFirstConnectionID returns the default (first) connection id

func (*Db) GetJob

func (d *Db) GetJob(id JobID) (Job, error)

GetJob returns a JSON ready representation of a job

func (*Db) GetJobOwningVolume

func (d *Db) GetJobOwningVolume(volumeID string) (Job, error)

GetJobOwningVolume returns a service ready to be converted into JSON

func (*Db) GetRoleByName

func (d *Db) GetRoleByName(name string, communityID int64) (Role, error)

GetRoleByName gets a named role from the database

func (*Db) GetRoleUsers

func (d *Db) GetRoleUsers(roleID int64) ([]User, error)

GetRoleByID gets a role from the database

func (*Db) GetService

func (d *Db) GetService(id ServiceID) (Service, error)

GetService returns a service ready to be converted into JSON

func (*Db) GetTokenByID

func (d *Db) GetTokenByID(tokenID int64) (Token, error)

GetTokenByID returns a token by its ID

func (*Db) GetTokenBySecret

func (d *Db) GetTokenBySecret(accessToken string) (Token, error)

GetTokenBySecret returns a token by its Secret

func (*Db) GetUserByEmail

func (d *Db) GetUserByEmail(email string) (*User, error)

GetUserByEmail searches for a user in the database

func (*Db) GetUserByID

func (d *Db) GetUserByID(id int64) (*User, error)

GetUserByID searches for a user in the database

func (*Db) GetUserRoles

func (d *Db) GetUserRoles(userID int64) ([]Role, error)

GetUserRoles

func (*Db) GetUserTokens

func (d *Db) GetUserTokens(userID int64) ([]Token, error)

GetUserTokens returns the user's tokens

func (*Db) HasSuperAdminRole

func (d *Db) HasSuperAdminRole(userID int64) bool

HasSuperAdminRole checks if a a user has super admin privileges

func (*Db) IsConnectionOwner

func (d *Db) IsConnectionOwner(userID int64, connectionID ConnectionID) bool

IsConnectionOwner checks if a certain user owns a certain connection

func (*Db) IsJobOwner

func (d *Db) IsJobOwner(userID int64, jobID JobID) bool

IsJobOwner checks if a certain user owns a certain job

func (*Db) IsServiceOwner

func (d *Db) IsServiceOwner(userID int64, serviceID ServiceID) bool

IsServiceOwner checks if a certain user owns a certain service

func (*Db) ListCommunities

func (d *Db) ListCommunities() ([]Community, error)

ListCommunities gets the list of all the communities

func (*Db) ListJobs

func (d *Db) ListJobs() ([]Job, error)

ListJobs returns a list of all jobs ready to be converted into JSON

func (*Db) ListRoles

func (d *Db) ListRoles() ([]Role, error)

ListRoles returns the list of all roles

func (*Db) ListServices

func (d *Db) ListServices() ([]Service, error)

ListServices produces a list of all services ready to be converted into JSON

func (*Db) NewUserToken

func (d *Db) NewUserToken(userID int64, name string, expire time.Time) (Token, error)

NewUserToken creates a new user access token

func (*Db) RemoveBuild

func (d *Db) RemoveBuild(id string) error

RemoveBuild removes a build from the database

func (*Db) RemoveConnection

func (d *Db) RemoveConnection(connectionID ConnectionID) error

RemoveConnection removes a connection to the database

func (*Db) RemoveJob

func (d *Db) RemoveJob(id JobID) error

RemoveJob removes a job and all corresponding tasks from the database

func (*Db) RemoveJobTask

func (d *Db) RemoveJobTask(taskID string) error

RemoveJobTask removes a task from the database

func (*Db) RemoveService

func (d *Db) RemoveService(id ServiceID) error

RemoveService removes a service and the corresponding IOPorts from the database

func (*Db) SetBuildServiceID

func (d *Db) SetBuildServiceID(id string, serviceID ServiceID) error

SetBuildServiceID sets a service ID for a given build

func (*Db) SetBuildState

func (d *Db) SetBuildState(id string, state BuildState) error

SetBuildState sets a build state

func (*Db) SetJobDurationTime

func (d *Db) SetJobDurationTime(id JobID, duration int64) error

SetJobDurationTime sets job finish time

func (*Db) SetJobState

func (d *Db) SetJobState(id JobID, state JobState) error

SetJobState sets a job state

func (*Db) UpdateUser

func (d *Db) UpdateUser(user User) error

UpdateUser updates user information in the database

type IOPort

type IOPort struct {
	ID       string
	Name     string
	Path     string
	Type     string
	FileName string
}

IOPort is an i/o specification for a service The service can only read data from volumes and write to a single volume Path specifies where the volumes are mounted

type IOPortTable

type IOPortTable struct {
	ID        string
	Name      string
	Path      string
	IsInput   bool
	ServiceID string
	Type      string
	FileName  string
	Revision  int
}

IOPortTable is used to store info about service inputs and outputs in a database

type ImageID

type ImageID string

ImageID exported

type Job

type Job struct {
	ID           JobID
	ConnectionID ConnectionID
	ServiceID    ServiceID
	Created      time.Time
	Duration     int64
	State        *JobState
	InputVolume  []JobVolume
	OutputVolume []JobVolume
	Tasks        []Task
}

Job stores the information about a service execution (used to serialize JSON)

type JobID

type JobID string

JobID exported

type JobState

type JobState struct {
	Status string
	Error  string
	Code   int
}

JobState keeps information about a job state

func NewJobStateError

func NewJobStateError(err string, code int) JobState

NewJobStateError creates a new JobState with specified error

func NewJobStateOk

func NewJobStateOk(status string, code int) JobState

NewJobStateOk creates a new JobState with no error

type JobTable

type JobTable struct {
	ID           string
	ConnectionID int
	ServiceID    string
	Created      time.Time
	Duration     int64 // duration time in seconds
	Error        string
	Status       string
	Code         int
	Revision     int
}

JobTable stores the information about a service execution (used to store data in a database)

type JobVolume

type JobVolume struct {
	VolumeID VolumeID
	Name     string
}

JobVolume points to volumes bound to a particular job

type LatestOutput

type LatestOutput struct {
	Name          string
	ConsoleOutput string
}

LatestOutput used to serialize console output to JSON

type OwnerTable

type OwnerTable struct {
	UserID     int64
	ObjectType string
	ObjectID   string
	Revision   int
}

OwnerTable stores object ownerships

type Role

type Role struct {
	ID            int64
	Name          string
	Description   string
	CommunityID   int64
	CommunityName string
}

type RoleTable

type RoleTable struct {
	ID          int64
	Name        string
	CommunityID int64 // most roles are per community
	Description string
	Revision    int
}

RoleTable stores user roles in the db

type Service

type Service struct {
	ID           ServiceID
	ConnectionID ConnectionID
	ImageID      ImageID
	Name         string
	RepoTag      string
	Description  string
	Version      string
	Cmd          []string
	Created      time.Time
	Deleted      bool
	Size         int64
	Input        []IOPort
	Output       []IOPort
}

Service describes metadata for a GEF service (used to serialize JSON)

type ServiceCmdTable

type ServiceCmdTable struct {
	ID        int
	Cmd       string
	Index     int
	ServiceID string
	Revision  int
}

ServiceCmdTable stores CMD options for services

type ServiceID

type ServiceID string

ServiceID exported

type ServiceTable

type ServiceTable struct {
	ID           string
	ConnectionID int
	ImageID      string
	Name         string
	RepoTag      string
	Description  string
	Version      string
	Created      time.Time
	Deleted      bool
	Size         int64
	Revision     int
}

ServiceTable describes metadata for a GEF service (used to store data in a database)

type Task

type Task struct {
	ID             string
	Name           string
	ContainerID    ContainerID
	SwarmServiceID string
	Error          string
	ExitCode       int
	ConsoleOutput  string
}

Task contains tasks related to a specific job (used to serialize JSON)

type TaskTable

type TaskTable struct {
	ID             string
	Name           string
	ContainerID    string
	SwarmServiceID string
	Error          string
	ExitCode       int
	ConsoleOutput  string
	JobID          string
	Revision       int
}

TaskTable contains tasks related to a specific job (used to store data in a database)

type Token

type Token struct {
	ID     int64
	Name   string
	Secret string
	UserID int64
	Expire time.Time
}

Token struct, also used to serialize JSON

type TokenTable

type TokenTable struct {
	ID       int64
	Name     string // token name, user defined
	Secret   string // token secret, a random string
	UserID   int64
	Expire   time.Time
	Revision int
}

TokenTable stores user tokens in the db

type User

type User struct {
	ID      int64
	Name    string
	Email   string
	Created time.Time
	Updated time.Time
}

User struct, also used to serialize JSON

type UserRoleTable

type UserRoleTable struct {
	UserID   int64
	RoleID   int64
	Revision int
}

UserRoleTable stores user mapping to roles in the db

type UserTable

type UserTable struct {
	ID       int64
	Name     string
	Email    string
	Created  time.Time
	Updated  time.Time
	Revision int
}

UserTable stores the users in the db

type VolumeID

type VolumeID string

VolumeID contains a docker volume ID

type VolumeTable

type VolumeTable struct {
	ID         string
	IsInput    bool
	JobID      string
	IOPortName string
	Content    string
	Revision   int
}

VolumeTable contains information about input and output volumes for jobs

Jump to

Keyboard shortcuts

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