model

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermNone      = 0
	PermWrite     = 1
	PermReadWrite = 2
)

Perm control scope

View Source
const PageSize = 25

PageSize is default page size.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive struct {
	ID        string    `bson:"_id" json:"id,omitempty" bind:"id=path"`
	Name      string    `bson:"name" json:"name,omitempty"`
	Content   string    `bson:"content" json:"content,omitempty" bind:"content=form,content=file"`
	CreatedBy string    `bson:"created_by" json:"created_by,omitempty"`
	CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"`
	UpdatedBy string    `bson:"updated_by" json:"updated_by,omitempty"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

type ArchiveListArgs

type ArchiveListArgs struct {
	Name      string `bind:"name"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type AuthUser

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

func NewAuthUser

func NewAuthUser(user *User, roles []*Role) *AuthUser

func (*AuthUser) Admin

func (u *AuthUser) Admin() bool

func (*AuthUser) Anonymous

func (u *AuthUser) Anonymous() bool

func (*AuthUser) ID

func (u *AuthUser) ID() string

func (*AuthUser) IsAllowed

func (u *AuthUser) IsAllowed(perm string) bool

func (*AuthUser) IsInRole

func (u *AuthUser) IsInRole(roleID string) bool

func (*AuthUser) Name

func (u *AuthUser) Name() string

type Chart

type Chart struct {
	Name        string   `json:"name" bson:"_id" valid:"required"` // unique, the name of build-in charts has '$' prefix.
	Title       string   `json:"title" valid:"required"`
	Description string   `json:"desc"`
	Legend      string   `json:"legend"` // ${name} - ${instance}
	Query       string   `json:"query" valid:"required"`
	Kind        string   `json:"kind"`      // builtin/custom
	Dashboard   string   `json:"dashboard"` // home/service/task...
	Type        string   `json:"type"`      // pie/line...
	Unit        string   `json:"unit"`      // bytes/milliseconds/percent:100...
	Width       int32    `json:"width"`     // 1-12(12 columns total)
	Height      int32    `json:"height"`    // default 50
	Options     data.Map `json:"options"`
}

Chart represents a dashboard chart.

func NewChart

func NewChart(dashboard, name, title, legend, query, unit string) *Chart

type ChartDashboard

type ChartDashboard struct {
	Name            string        `json:"name"`
	Key             string        `json:"key"`
	Period          int32         `json:"period"`           // minutes
	RefreshInterval int32         `json:"refresh_interval"` // seconds, 0 means disabled.
	Charts          []ChartOption `json:"charts"`
}

func (*ChartDashboard) ID

func (cd *ChartDashboard) ID() string

type ChartLine

type ChartLine struct {
	Name string       `json:"name"`
	Data []ChartPoint `json:"data"`
}

type ChartMatrixData

type ChartMatrixData struct {
	Legend []string    `json:"legend"`
	Series []ChartLine `json:"series"`
}

type ChartOption

type ChartOption struct {
	Name   string `json:"name"`
	Width  int32  `json:"width"`
	Height int32  `json:"height"`
}

type ChartPoint

type ChartPoint struct {
	X int64   `json:"x"`
	Y float64 `json:"y"`
}

func (*ChartPoint) MarshalJSON

func (p *ChartPoint) MarshalJSON() ([]byte, error)

type ChartValue

type ChartValue struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

type ChartVectorData

type ChartVectorData struct {
	Legend []string     `json:"legend"`
	Data   []ChartValue `json:"data"`
}

type ConfigCreateInfo

type ConfigCreateInfo struct {
	Name   string  `json:"name"`
	Data   string  `json:"data"`
	Labels Options `json:"labels"`
}

type ConfigInfo

type ConfigInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	FileName string `json:"file_name"`
	UID      string `json:"uid"`
	GID      string `json:"gid"`
	Mode     uint32 `json:"mode"`
}

func NewConfigInfo

func NewConfigInfo(ref *swarm.ConfigReference) ConfigInfo

func NewSecretInfo

func NewSecretInfo(ref *swarm.SecretReference) ConfigInfo

func (ConfigInfo) ToConfig

func (ci ConfigInfo) ToConfig() *swarm.ConfigReference

func (ConfigInfo) ToSecret

func (ci ConfigInfo) ToSecret() *swarm.SecretReference

type ConfigUpdateInfo

type ConfigUpdateInfo struct {
	ID      string `json:"id"`
	Version uint64 `json:"version"`
	ConfigCreateInfo
}

type ContainerListArgs

type ContainerListArgs struct {
	// created|restarting|running|removing|paused|exited|dead
	Filter    string `bind:"filter"`
	Name      string `bind:"name"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type ContainerListInfo

type ContainerListInfo struct {
	types.Container
	CreatedAt time.Time
}

func NewContainerListInfo

func NewContainerListInfo(container types.Container) *ContainerListInfo

type EndpointPort

type EndpointPort struct {
	Name     string                   `json:"name"`
	Protocol swarm.PortConfigProtocol `json:"protocol"`
	// TargetPort is the port inside the container
	TargetPort uint32 `json:"target_port"`
	// PublishedPort is the port on the swarm hosts
	PublishedPort uint32 `json:"published_port"`
	// PublishMode is the mode in which port is published
	PublishMode swarm.PortConfigPublishMode `json:"publish_mode"`
}

type Event

type Event struct {
	ID       string      `bson:"_id"`
	Type     EventType   `bson:"type"`
	Action   EventAction `bson:"action"`
	Code     string      `bson:"code"`
	Name     string      `bson:"name"`
	UserID   string      `bson:"user_id"`
	Username string      `bson:"username"`
	Time     time.Time   `bson:"time"`
}

func (*Event) URL

func (e *Event) URL(et EventType, code string) string

type EventAction

type EventAction string
const (
	EventActionLogin EventAction = "Login"
	//EventActionLogout     EventAction = "Logout"
	EventActionCreate     EventAction = "Create"
	EventActionDelete     EventAction = "Delete"
	EventActionUpdate     EventAction = "Update"
	EventActionScale      EventAction = "Scale"
	EventActionRollback   EventAction = "Rollback"
	EventActionDisconnect EventAction = "Disconnect"
)

type EventListArgs

type EventListArgs struct {
	Type      string `bind:"type"`
	Name      string `bind:"name"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type EventType

type EventType string
const (
	EventTypeRegistry        EventType = "Registry"
	EventTypeNode            EventType = "Node"
	EventTypeNetwork         EventType = "Network"
	EventTypeService         EventType = "Service"
	EventTypeServiceTemplate EventType = "Service Template"
	EventTypeStackTask       EventType = "Stack Task"
	EventTypeStackArchive    EventType = "Stack Archive"
	EventTypeSecret          EventType = "Secret"
	EventTypeConfig          EventType = "Config"

	EventTypeVolume EventType = "Volume"

	EventTypeAuthentication EventType = "Authentication"
	EventTypeRole           EventType = "Role"
	EventTypeUser           EventType = "User"
	EventTypeSetting        EventType = "Setting"
)

type ImageListInfo

type ImageListInfo struct {
	types.ImageSummary
	CreatedAt time.Time
}

func NewImageListInfo

func NewImageListInfo(image types.ImageSummary) *ImageListInfo

type Mount

type Mount struct {
	Type        mount.Type        `json:"type"`
	Source      string            `json:"src"`
	Target      string            `json:"dst"`
	ReadOnly    bool              `json:"read_only"`
	Propagation mount.Propagation `json:"propagation"`
}

type Network

type Network struct {
	ID      string
	Name    string
	Address string
}

type NetworkCreateInfo

type NetworkCreateInfo struct {
	Name         string `json:"name"`
	Driver       string `json:"driver"`
	CustomDriver string `json:"custom_driver"`
	Internal     bool   `json:"internal"`
	Attachable   bool
	IPV4         struct {
		Subnet  string `json:"subnet"`
		Gateway string `json:"gateway"`
		IPRange string `json:"ip_range"`
	} `json:"ipv4"`
	IPV6 struct {
		Enabled bool   `json:"enabled"`
		Subnet  string `json:"subnet"`
		Gateway string `json:"gateway"`
	} `json:"ipv6"`
	Options   Options `json:"options"`
	Labels    Options `json:"labels"`
	LogDriver struct {
		Name    string  `json:"name"`
		Options Options `json:"options"`
	} `json:"log_driver"`
}

type NodeListInfo

type NodeListInfo struct {
	ID      string
	Name    string
	Role    swarm.NodeRole
	Version string
	CPU     int64
	Memory  float32
	Address string
	Status  swarm.NodeState
	Leader  bool
}

func NewNodeListInfo

func NewNodeListInfo(node swarm.Node) *NodeListInfo

type NodeUpdateInfo

type NodeUpdateInfo struct {
	Version      uint64                 `json:"version"`
	Name         string                 `json:"name"`
	Role         swarm.NodeRole         `json:"role"`
	Availability swarm.NodeAvailability `json:"availability"`
	Labels       Options                `json:"labels"`
}

type Option

type Option struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Options

type Options []*Option

func NewOptions

func NewOptions(m map[string]string) Options

func (Options) Compress

func (opts Options) Compress() Options

func (Options) ToMap

func (opts Options) ToMap() map[string]string

type Pager

type Pager struct {
	Count    int
	Size     int
	Page     int
	Pages    []int
	Previous int
	Next     int
	MaxPage  int
	URL      func(page int) string
}

Pager holds pagination info.

func NewPager

func NewPager(uri string, count, size, page int) *Pager

NewPager returns a Pager instance which displays max 7 pages.

type Perm

type Perm struct {
	ResType string   `json:"res_type"`
	ResID   string   `json:"res_id"`
	Scope   int32    `json:"scope"`
	Roles   []string `json:"roles"`
	Users   []string `json:"users"`
}

Perm holds permissions of Docker resource.

type PlacementConstraint

type PlacementConstraint struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Operator string `json:"op"`
}

func NewPlacementConstraint

func NewPlacementConstraint(c string) PlacementConstraint

func (*PlacementConstraint) ToConstraint

func (pc *PlacementConstraint) ToConstraint() string

type PlacementPreference

type PlacementPreference struct {
	Spread string `json:"spread"`
}

type Registry

type Registry struct {
	ID        string    `bson:"_id" json:"id,omitempty"`
	Name      string    `bson:"name" json:"name,omitempty" valid:"required"`
	URL       string    `bson:"url" json:"url,omitempty" valid:"required,url"`
	Username  string    `bson:"username" json:"username,omitempty" valid:"required"`
	Password  string    `bson:"password" json:"password,omitempty" valid:"required"`
	CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

func (*Registry) GetEncodedAuth

func (r *Registry) GetEncodedAuth() string

func (*Registry) Match

func (r *Registry) Match(image string) bool

type ResourceInfo

type ResourceInfo struct {
	CPU    float64 `json:"cpu"`
	Memory string  `json:"memory"`
}

func NewResourceInfo

func NewResourceInfo(res *swarm.Resources) ResourceInfo

func (ResourceInfo) IsSet

func (r ResourceInfo) IsSet() bool

func (ResourceInfo) ToResources

func (r ResourceInfo) ToResources() (res *swarm.Resources, err error)

type Role

type Role struct {
	ID          string    `bson:"_id" json:"id,omitempty"`
	Name        string    `bson:"name" json:"name,omitempty" valid:"required"`
	Description string    `bson:"desc" json:"desc,omitempty"`
	Perms       []string  `bson:"perms" json:"perms,omitempty"`
	CreatedAt   time.Time `bson:"created_at" json:"created_at,omitempty"`
	UpdatedAt   time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

type ServiceDetailInfo

type ServiceDetailInfo struct {
	swarm.Service
	// Name      string
	// Image     string
	// Mode      string
	// Actives   uint64
	Replicas uint64
	// UpdatedAt time.Time
	Env      map[string]string
	Networks []Network
	Command  string
	Args     string
}

func NewServiceDetailInfo

func NewServiceDetailInfo(service swarm.Service) *ServiceDetailInfo

type ServiceInfo

type ServiceInfo struct {
	Name            string       `json:"name"`
	Version         uint64       `json:"version"`
	Registry        string       `json:"registry"`
	RegistryURL     string       `json:"-"`
	RegistryAuth    string       `json:"-"`
	Image           string       `json:"image"`
	Mode            string       `json:"mode"`
	Replicas        uint64       `json:"replicas"`
	Command         string       `json:"command"`
	Args            string       `json:"args"`
	Dir             string       `json:"dir"`
	User            string       `json:"user"`
	Networks        []string     `json:"networks"`
	Secrets         []ConfigInfo `json:"secrets"`
	Configs         []ConfigInfo `json:"configs"`
	Environments    Options      `json:"envs"`
	ServiceLabels   Options      `json:"slabels"`
	ContainerLabels Options      `json:"clabels"`
	Endpoint        struct {
		Mode  swarm.ResolutionMode `json:"mode"`
		Ports []EndpointPort       `json:"ports"`
	} `json:"endpoint"`
	Mounts    []Mount `json:"mounts"`
	LogDriver struct {
		Name    string  `json:"name"`
		Options Options `json:"options"`
	} `json:"log_driver"`
	Placement struct {
		Constraints []PlacementConstraint `json:"constraints"`
		Preferences []PlacementPreference `json:"preferences"`
	} `json:"placement"`
	UpdatePolicy struct {
		// Maximum number of tasks updated simultaneously (0 to update all at once), default 1.
		Parallelism uint64 `json:"parallelism"`
		// Amount of time between updates.
		Delay string `json:"delay,omitempty"`
		// FailureAction is the action to take when an update failures. (“pause”|“continue”|“rollback”) (default “pause”)
		FailureAction string `json:"failure_action"`
		// Update order (“start-first”|“stop-first”) (default “stop-first”)
		Order string `json:"order"`
	} `json:"update_policy"`
	RollbackPolicy struct {
		// Maximum number of tasks updated simultaneously (0 to update all at once), default 1.
		Parallelism uint64 `json:"parallelism"`
		// Amount of time between updates.
		Delay string `json:"delay,omitempty"`
		// FailureAction is the action to take when an update failures. (“pause”|“continue”) (default “pause”)
		FailureAction string `json:"failure_action"`
		// Update order (“start-first”|“stop-first”) (default “stop-first”)
		Order string `json:"order"`
	} `json:"rollback_policy"`
	RestartPolicy struct {
		// Restart when condition is met (“none”|“on-failure”|“any”) (default “any”)
		Condition swarm.RestartPolicyCondition `json:"condition"`
		// Maximum number of restarts before giving up
		MaxAttempts uint64 `json:"max_attempts"`
		// Delay between restart attempts
		Delay string `json:"delay,omitempty"`
		// Window used to evaluate the restart policy.
		Window string `json:"window,omitempty"`
	} `json:"restart_policy"`
	Resource struct {
		Limit   ResourceInfo `json:"limit"`
		Reserve ResourceInfo `json:"reserve"`
	} `json:"resource"`
	DNS struct {
		Nameservers string `json:"nameservers,omitempty"`
		Search      string `json:"search,omitempty"`
		Options     string `json:"options,omitempty"`
	} `json:"dns"`
	Hostname string `json:"hostname"`
	Hosts    string `json:"hosts"`
}

func NewServiceInfo

func NewServiceInfo(service swarm.Service) *ServiceInfo

func (*ServiceInfo) GetDNSConfig

func (si *ServiceInfo) GetDNSConfig() *swarm.DNSConfig

func (*ServiceInfo) Normalize

func (si *ServiceInfo) Normalize()

func (*ServiceInfo) ToServiceSpec

func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec

TODO: finish this method

type ServiceListInfo

type ServiceListInfo struct {
	Name         string
	Image        string
	Mode         string
	Actives      uint64
	Replicas     uint64
	Rollback     bool
	UpdatedAt    time.Time
	UpdateStatus string
}

func NewServiceListInfo

func NewServiceListInfo(service swarm.Service, actives uint64) *ServiceListInfo

type Session

type Session struct {
	UserID    string    `bson:"_id" json:"id,omitempty"`
	Token     string    `bson:"token" json:"token,omitempty"`
	Expires   time.Time `bson:"expires" json:"expires,omitempty"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

type Setting

type Setting struct {
	Version string
	LDAP    struct {
		Enabled  bool   `bson:"enabled" json:"enabled,omitempty"`
		Address  string `bson:"address" json:"address,omitempty"`
		Security int32  `bson:"security" json:"security,omitempty"` // 0-None/1-TLS/2-StartTLS
		//TLSCert        string `bson:"tls_cert" json:"tls_cert,omitempty"`       // TLS cert
		//TLSVerify      bool   `bson:"tls_verify" json:"tls_verify,omitempty"`   // Verify cert
		Authentication int32  `bson:"auth" json:"auth,omitempty"`               // 0-Simple/1-Bind
		BindDN         string `bson:"bind_dn" json:"bind_dn,omitempty"`         // DN to bind with
		BindPassword   string `bson:"bind_pwd" json:"bind_pwd,omitempty"`       // Bind DN password
		BaseDN         string `bson:"base_dn" json:"base_dn,omitempty"`         // Base search path for users
		UserDN         string `bson:"user_dn" json:"user_dn,omitempty"`         // Template for the DN of the user for simple auth
		UserFilter     string `bson:"user_filter" json:"user_filter,omitempty"` // Search filter for user
		NameAttr       string `bson:"name_attr" json:"name_attr,omitempty"`
		EmailAttr      string `bson:"email_attr" json:"email_attr,omitempty"`
	} `bson:"ldap" json:"ldap,omitempty"`
	TimeZone struct {
		Name   string `bson:"name" json:"name,omitempty"`     // Asia/Shanghai
		Offset int32  `bson:"offset" json:"offset,omitempty"` // seconds east of UTC
	} `bson:"tz" json:"tz,omitempty"`
	Language string `bson:"lang" json:"lang,omitempty"`
	Metrics  struct {
		Prometheus string `bson:"prometheus" json:"prometheus"`
	} `bson:"metrics" json:"metrics"`
	UpdatedBy string    `bson:"updated_by" json:"updated_by,omitempty"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

Setting represents the options of swirl.

type StackListInfo

type StackListInfo struct {
	Name     string
	Services []string
}

type TaskInfo

type TaskInfo struct {
	swarm.Task
	NodeName string
	Image    string
}

func NewTaskInfo

func NewTaskInfo(task swarm.Task, nodeName string) *TaskInfo

type TaskListArgs

type TaskListArgs struct {
	Service   string `bind:"service"`
	Node      string `bind:"node"`
	Name      string `bind:"name"`
	State     string `bind:"state"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type Template

type Template struct {
	ID        string    `bson:"_id" json:"id,omitempty"`
	Name      string    `bson:"name" json:"name,omitempty"`
	Content   string    `bson:"content" json:"content,omitempty"`
	CreatedBy string    `bson:"created_by" json:"created_by,omitempty"`
	CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"`
	UpdatedBy string    `bson:"updated_by" json:"updated_by,omitempty"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
}

type TemplateListArgs

type TemplateListArgs struct {
	Name      string `bind:"name"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type User

type User struct {
	ID        string     `bson:"_id" json:"id,omitempty"`
	Name      string     `bson:"name" json:"name,omitempty" valid:"required"`
	LoginName string     `bson:"login_name" json:"login_name,omitempty" valid:"required"`
	Password  string     `bson:"password" json:"password,omitempty"`
	Salt      string     `bson:"salt" json:"salt,omitempty"`
	Email     string     `bson:"email" json:"email,omitempty" valid:"required"`
	Admin     bool       `bson:"admin" json:"admin,omitempty"`
	Type      UserType   `bson:"type" json:"type,omitempty"`
	Status    UserStatus `bson:"status" json:"status,omitempty"`
	Roles     []string   `bson:"roles" json:"roles,omitempty"`
	CreatedAt time.Time  `bson:"created_at" json:"created_at,omitempty"`
	UpdatedAt time.Time  `bson:"updated_at" json:"updated_at,omitempty"`
}

type UserListArgs

type UserListArgs struct {
	// admins, active, blocked
	Filter    string `bind:"filter"`
	Query     string `bind:"query"`
	PageIndex int    `bind:"page"`
	PageSize  int    `bind:"size"`
}

type UserStatus

type UserStatus int32
const (
	// UserStatusBlocked is the status which user is blocked
	UserStatusBlocked UserStatus = 0
	// UserStatusActive is the normal status
	UserStatusActive UserStatus = 1
)

type UserType

type UserType string
const (
	// UserTypeInternal is internal user of swirl
	UserTypeInternal UserType = "internal"
	// UserTypeLDAP is external user of LDAP
	UserTypeLDAP UserType = "ldap"
)

type VolumeCreateInfo

type VolumeCreateInfo struct {
	Name         string  `json:"name" valid:"required"`
	Driver       string  `json:"driver"`
	CustomDriver string  `json:"custom_driver"`
	Options      Options `json:"options"`
	Labels       Options `json:"labels"`
}

Jump to

Keyboard shortcuts

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