2016-12-18 05:21:29 +00:00
|
|
|
package portainer
|
|
|
|
|
2017-04-09 18:38:41 +00:00
|
|
|
import "io"
|
2016-12-25 20:34:02 +00:00
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
type (
|
|
|
|
// Pair defines a key/value string pair
|
|
|
|
Pair struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CLIFlags represents the available flags on the CLI.
|
|
|
|
CLIFlags struct {
|
2017-02-06 05:29:34 +00:00
|
|
|
Addr *string
|
|
|
|
Assets *string
|
|
|
|
Data *string
|
|
|
|
ExternalEndpoints *string
|
|
|
|
SyncInterval *string
|
|
|
|
Endpoint *string
|
|
|
|
Labels *[]Pair
|
|
|
|
Logo *string
|
|
|
|
Templates *string
|
|
|
|
NoAuth *bool
|
2017-03-03 11:54:22 +00:00
|
|
|
NoAnalytics *bool
|
2017-02-06 05:29:34 +00:00
|
|
|
TLSVerify *bool
|
|
|
|
TLSCacert *string
|
|
|
|
TLSCert *string
|
|
|
|
TLSKey *string
|
2017-04-16 07:54:51 +00:00
|
|
|
AdminPassword *string
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Settings represents Portainer settings.
|
|
|
|
Settings struct {
|
2017-02-06 05:29:34 +00:00
|
|
|
HiddenLabels []Pair `json:"hiddenLabels"`
|
|
|
|
Logo string `json:"logo"`
|
|
|
|
Authentication bool `json:"authentication"`
|
2017-03-03 11:54:22 +00:00
|
|
|
Analytics bool `json:"analytics"`
|
2017-02-06 05:29:34 +00:00
|
|
|
EndpointManagement bool `json:"endpointManagement"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// User represent a user account.
|
|
|
|
User struct {
|
2017-03-12 16:24:15 +00:00
|
|
|
ID UserID `json:"Id"`
|
|
|
|
Username string `json:"Username"`
|
|
|
|
Password string `json:"Password,omitempty"`
|
|
|
|
Role UserRole `json:"Role"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// UserID represents a user identifier
|
|
|
|
UserID int
|
|
|
|
|
|
|
|
// UserRole represents the role of a user. It can be either an administrator
|
|
|
|
// or a regular user.
|
|
|
|
UserRole int
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
// TokenData represents the data embedded in a JWT token.
|
|
|
|
TokenData struct {
|
2017-03-12 16:24:15 +00:00
|
|
|
ID UserID
|
2016-12-18 05:21:29 +00:00
|
|
|
Username string
|
2017-03-12 16:24:15 +00:00
|
|
|
Role UserRole
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
// EndpointID represents an endpoint identifier.
|
|
|
|
EndpointID int
|
|
|
|
|
|
|
|
// Endpoint represents a Docker endpoint with all the info required
|
|
|
|
// to connect to it.
|
|
|
|
Endpoint struct {
|
2017-03-12 16:24:15 +00:00
|
|
|
ID EndpointID `json:"Id"`
|
|
|
|
Name string `json:"Name"`
|
|
|
|
URL string `json:"URL"`
|
|
|
|
TLS bool `json:"TLS"`
|
|
|
|
TLSCACertPath string `json:"TLSCACert,omitempty"`
|
|
|
|
TLSCertPath string `json:"TLSCert,omitempty"`
|
|
|
|
TLSKeyPath string `json:"TLSKey,omitempty"`
|
|
|
|
AuthorizedUsers []UserID `json:"AuthorizedUsers"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// ResourceControl represent a reference to a Docker resource with specific controls
|
|
|
|
ResourceControl struct {
|
|
|
|
OwnerID UserID `json:"OwnerId"`
|
|
|
|
ResourceID string `json:"ResourceId"`
|
|
|
|
AccessLevel ResourceAccessLevel `json:"AccessLevel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceControlType represents a type of resource control.
|
|
|
|
// Can be one of: container, service or volume.
|
|
|
|
ResourceControlType int
|
|
|
|
|
|
|
|
// ResourceAccessLevel represents the level of control associated to a resource for a specific owner.
|
|
|
|
// Can be one of: full, restricted, limited.
|
|
|
|
ResourceAccessLevel int
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
// TLSFileType represents a type of TLS file required to connect to a Docker endpoint.
|
|
|
|
// It can be either a TLS CA file, a TLS certificate file or a TLS key file.
|
|
|
|
TLSFileType int
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
// CLIService represents a service for managing CLI.
|
|
|
|
CLIService interface {
|
|
|
|
ParseFlags(version string) (*CLIFlags, error)
|
|
|
|
ValidateFlags(flags *CLIFlags) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// DataStore defines the interface to manage the data.
|
|
|
|
DataStore interface {
|
|
|
|
Open() error
|
|
|
|
Close() error
|
2017-03-12 16:24:15 +00:00
|
|
|
MigrateData() error
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// Server defines the interface to serve the API.
|
2016-12-18 05:21:29 +00:00
|
|
|
Server interface {
|
|
|
|
Start() error
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// UserService represents a service for managing user data.
|
2016-12-18 05:21:29 +00:00
|
|
|
UserService interface {
|
2017-03-12 16:24:15 +00:00
|
|
|
User(ID UserID) (*User, error)
|
|
|
|
UserByUsername(username string) (*User, error)
|
|
|
|
Users() ([]User, error)
|
|
|
|
UsersByRole(role UserRole) ([]User, error)
|
|
|
|
CreateUser(user *User) error
|
|
|
|
UpdateUser(ID UserID, user *User) error
|
|
|
|
DeleteUser(ID UserID) error
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// EndpointService represents a service for managing endpoint data.
|
2016-12-25 20:34:02 +00:00
|
|
|
EndpointService interface {
|
|
|
|
Endpoint(ID EndpointID) (*Endpoint, error)
|
|
|
|
Endpoints() ([]Endpoint, error)
|
|
|
|
CreateEndpoint(endpoint *Endpoint) error
|
|
|
|
UpdateEndpoint(ID EndpointID, endpoint *Endpoint) error
|
|
|
|
DeleteEndpoint(ID EndpointID) error
|
2017-02-06 05:29:34 +00:00
|
|
|
Synchronize(toCreate, toUpdate, toDelete []*Endpoint) error
|
2016-12-25 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// VersionService represents a service for managing version data.
|
|
|
|
VersionService interface {
|
|
|
|
DBVersion() (int, error)
|
|
|
|
StoreDBVersion(version int) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceControlService represents a service for managing resource control data.
|
|
|
|
ResourceControlService interface {
|
|
|
|
ResourceControl(resourceID string, rcType ResourceControlType) (*ResourceControl, error)
|
|
|
|
ResourceControls(rcType ResourceControlType) ([]ResourceControl, error)
|
|
|
|
CreateResourceControl(resourceID string, rc *ResourceControl, rcType ResourceControlType) error
|
|
|
|
DeleteResourceControl(resourceID string, rcType ResourceControlType) error
|
|
|
|
}
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
// CryptoService represents a service for encrypting/hashing data.
|
|
|
|
CryptoService interface {
|
|
|
|
Hash(data string) (string, error)
|
|
|
|
CompareHashAndData(hash string, data string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// JWTService represents a service for managing JWT tokens.
|
|
|
|
JWTService interface {
|
|
|
|
GenerateToken(data *TokenData) (string, error)
|
2017-03-12 16:24:15 +00:00
|
|
|
ParseAndVerifyToken(token string) (*TokenData, error)
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
2016-12-25 20:34:02 +00:00
|
|
|
|
|
|
|
// FileService represents a service for managing files.
|
|
|
|
FileService interface {
|
|
|
|
StoreTLSFile(endpointID EndpointID, fileType TLSFileType, r io.Reader) error
|
|
|
|
GetPathForTLSFile(endpointID EndpointID, fileType TLSFileType) (string, error)
|
|
|
|
DeleteTLSFiles(endpointID EndpointID) error
|
|
|
|
}
|
2017-02-06 05:29:34 +00:00
|
|
|
|
|
|
|
// EndpointWatcher represents a service to synchronize the endpoints via an external source.
|
|
|
|
EndpointWatcher interface {
|
|
|
|
WatchEndpointFile(endpointFilePath string) error
|
|
|
|
}
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-03-12 16:24:15 +00:00
|
|
|
// APIVersion is the version number of Portainer API.
|
2017-04-06 08:37:26 +00:00
|
|
|
APIVersion = "1.12.4"
|
2017-03-12 16:24:15 +00:00
|
|
|
// DBVersion is the version number of Portainer database.
|
|
|
|
DBVersion = 1
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
2016-12-25 20:34:02 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
// TLSFileCA represents a TLS CA certificate file.
|
|
|
|
TLSFileCA TLSFileType = iota
|
|
|
|
// TLSFileCert represents a TLS certificate file.
|
|
|
|
TLSFileCert
|
|
|
|
// TLSFileKey represents a TLS key file.
|
|
|
|
TLSFileKey
|
|
|
|
)
|
2017-03-12 16:24:15 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
_ UserRole = iota
|
|
|
|
// AdministratorRole represents an administrator user role
|
|
|
|
AdministratorRole
|
|
|
|
// StandardUserRole represents a regular user role
|
|
|
|
StandardUserRole
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ ResourceControlType = iota
|
|
|
|
// ContainerResourceControl represents a resource control for a container
|
|
|
|
ContainerResourceControl
|
|
|
|
// ServiceResourceControl represents a resource control for a service
|
|
|
|
ServiceResourceControl
|
|
|
|
// VolumeResourceControl represents a resource control for a volume
|
|
|
|
VolumeResourceControl
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ ResourceAccessLevel = iota
|
|
|
|
// RestrictedResourceAccessLevel represents a restricted access level on a resource (private ownership)
|
|
|
|
RestrictedResourceAccessLevel
|
|
|
|
)
|