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
|
|
|
|
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-25 09:51:22 +00:00
|
|
|
SSL *bool
|
|
|
|
SSLCert *string
|
|
|
|
SSLKey *string
|
2017-04-16 07:54:51 +00:00
|
|
|
AdminPassword *string
|
2017-06-01 08:14:55 +00:00
|
|
|
// Deprecated fields
|
|
|
|
Logo *string
|
|
|
|
Templates *string
|
|
|
|
Labels *[]Pair
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status represents the application status.
|
|
|
|
Status struct {
|
|
|
|
Authentication bool `json:"Authentication"`
|
|
|
|
EndpointManagement bool `json:"EndpointManagement"`
|
|
|
|
Analytics bool `json:"Analytics"`
|
|
|
|
Version string `json:"Version"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 08:35:23 +00:00
|
|
|
// LDAPSettings represents the settings used to connect to a LDAP server.
|
|
|
|
LDAPSettings struct {
|
|
|
|
ReaderDN string `json:"ReaderDN"`
|
|
|
|
Password string `json:"Password"`
|
|
|
|
URL string `json:"URL"`
|
|
|
|
TLSConfig TLSConfiguration `json:"TLSConfig"`
|
|
|
|
StartTLS bool `json:"StartTLS"`
|
|
|
|
SearchSettings []LDAPSearchSettings `json:"SearchSettings"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TLSConfiguration represents a TLS configuration.
|
|
|
|
TLSConfiguration struct {
|
|
|
|
TLS bool `json:"TLS"`
|
|
|
|
TLSSkipVerify bool `json:"TLSSkipVerify"`
|
|
|
|
TLSCACertPath string `json:"TLSCACert,omitempty"`
|
|
|
|
TLSCertPath string `json:"TLSCert,omitempty"`
|
|
|
|
TLSKeyPath string `json:"TLSKey,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// LDAPSearchSettings represents settings used to search for users in a LDAP server.
|
|
|
|
LDAPSearchSettings struct {
|
|
|
|
BaseDN string `json:"BaseDN"`
|
|
|
|
Filter string `json:"Filter"`
|
|
|
|
UserNameAttribute string `json:"UserNameAttribute"`
|
|
|
|
}
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
// Settings represents the application settings.
|
2016-12-18 05:21:29 +00:00
|
|
|
Settings struct {
|
2017-08-10 08:35:23 +00:00
|
|
|
TemplatesURL string `json:"TemplatesURL"`
|
|
|
|
LogoURL string `json:"LogoURL"`
|
|
|
|
BlackListedLabels []Pair `json:"BlackListedLabels"`
|
|
|
|
DisplayExternalContributors bool `json:"DisplayExternalContributors"`
|
|
|
|
AuthenticationMethod AuthenticationMethod `json:"AuthenticationMethod"`
|
|
|
|
LDAPSettings LDAPSettings `json:"LDAPSettings"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// User represents a user account.
|
2016-12-18 05:21:29 +00:00
|
|
|
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
|
2017-05-23 18:56:10 +00:00
|
|
|
// or a regular user
|
2017-03-12 16:24:15 +00:00
|
|
|
UserRole int
|
|
|
|
|
2017-08-10 08:35:23 +00:00
|
|
|
// AuthenticationMethod represents the authentication method used to authenticate a user.
|
|
|
|
AuthenticationMethod int
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// Team represents a list of user accounts.
|
|
|
|
Team struct {
|
|
|
|
ID TeamID `json:"Id"`
|
|
|
|
Name string `json:"Name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TeamID represents a team identifier
|
|
|
|
TeamID int
|
|
|
|
|
|
|
|
// TeamMembership represents a membership association between a user and a team
|
|
|
|
TeamMembership struct {
|
|
|
|
ID TeamMembershipID `json:"Id"`
|
|
|
|
UserID UserID `json:"UserID"`
|
|
|
|
TeamID TeamID `json:"TeamID"`
|
|
|
|
Role MembershipRole `json:"Role"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TeamMembershipID represents a team membership identifier
|
|
|
|
TeamMembershipID int
|
|
|
|
|
|
|
|
// MembershipRole represents the role of a user within a team
|
|
|
|
MembershipRole 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
|
|
|
}
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
// RegistryID represents a registry identifier.
|
|
|
|
RegistryID int
|
|
|
|
|
|
|
|
// Registry represents a Docker registry with all the info required
|
|
|
|
// to connect to it.
|
|
|
|
Registry struct {
|
|
|
|
ID RegistryID `json:"Id"`
|
|
|
|
Name string `json:"Name"`
|
|
|
|
URL string `json:"URL"`
|
|
|
|
Authentication bool `json:"Authentication"`
|
|
|
|
Username string `json:"Username"`
|
|
|
|
Password string `json:"Password"`
|
|
|
|
AuthorizedUsers []UserID `json:"AuthorizedUsers"`
|
|
|
|
AuthorizedTeams []TeamID `json:"AuthorizedTeams"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DockerHub represents all the required information to connect and use the
|
|
|
|
// Docker Hub.
|
|
|
|
DockerHub struct {
|
|
|
|
Authentication bool `json:"Authentication"`
|
|
|
|
Username string `json:"Username"`
|
|
|
|
Password string `json:"Password"`
|
|
|
|
}
|
|
|
|
|
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"`
|
2017-05-01 10:19:43 +00:00
|
|
|
PublicURL string `json:"PublicURL"`
|
2017-03-12 16:24:15 +00:00
|
|
|
TLS bool `json:"TLS"`
|
|
|
|
TLSCACertPath string `json:"TLSCACert,omitempty"`
|
|
|
|
TLSCertPath string `json:"TLSCert,omitempty"`
|
|
|
|
TLSKeyPath string `json:"TLSKey,omitempty"`
|
|
|
|
AuthorizedUsers []UserID `json:"AuthorizedUsers"`
|
2017-05-23 18:56:10 +00:00
|
|
|
AuthorizedTeams []TeamID `json:"AuthorizedTeams"`
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// ResourceControlID represents a resource control identifier.
|
|
|
|
ResourceControlID int
|
|
|
|
|
|
|
|
// ResourceControl represent a reference to a Docker resource with specific access controls
|
2017-03-12 16:24:15 +00:00
|
|
|
ResourceControl struct {
|
2017-05-23 18:56:10 +00:00
|
|
|
ID ResourceControlID `json:"Id"`
|
|
|
|
ResourceID string `json:"ResourceId"`
|
|
|
|
SubResourceIDs []string `json:"SubResourceIds"`
|
|
|
|
Type ResourceControlType `json:"Type"`
|
|
|
|
AdministratorsOnly bool `json:"AdministratorsOnly"`
|
|
|
|
|
|
|
|
UserAccesses []UserResourceAccess `json:"UserAccesses"`
|
|
|
|
TeamAccesses []TeamResourceAccess `json:"TeamAccesses"`
|
|
|
|
|
|
|
|
// Deprecated fields
|
|
|
|
// Deprecated: OwnerID field is deprecated in DBVersion == 2
|
|
|
|
OwnerID UserID `json:"OwnerId"`
|
|
|
|
// Deprecated: AccessLevel field is deprecated in DBVersion == 2
|
2017-03-12 16:24:15 +00:00
|
|
|
AccessLevel ResourceAccessLevel `json:"AccessLevel"`
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// ResourceControlType represents the type of resource associated to the resource control (volume, container, service).
|
2017-03-12 16:24:15 +00:00
|
|
|
ResourceControlType int
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// UserResourceAccess represents the level of control on a resource for a specific user.
|
|
|
|
UserResourceAccess struct {
|
|
|
|
UserID UserID `json:"UserId"`
|
|
|
|
AccessLevel ResourceAccessLevel `json:"AccessLevel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TeamResourceAccess represents the level of control on a resource for a specific team.
|
|
|
|
TeamResourceAccess struct {
|
|
|
|
TeamID TeamID `json:"TeamId"`
|
|
|
|
AccessLevel ResourceAccessLevel `json:"AccessLevel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceAccessLevel represents the level of control associated to a resource.
|
2017-03-12 16:24:15 +00:00
|
|
|
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-05-23 18:56:10 +00:00
|
|
|
// TeamService represents a service for managing user data.
|
|
|
|
TeamService interface {
|
|
|
|
Team(ID TeamID) (*Team, error)
|
|
|
|
TeamByName(name string) (*Team, error)
|
|
|
|
Teams() ([]Team, error)
|
|
|
|
CreateTeam(team *Team) error
|
|
|
|
UpdateTeam(ID TeamID, team *Team) error
|
|
|
|
DeleteTeam(ID TeamID) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// TeamMembershipService represents a service for managing team membership data.
|
|
|
|
TeamMembershipService interface {
|
|
|
|
TeamMembership(ID TeamMembershipID) (*TeamMembership, error)
|
|
|
|
TeamMemberships() ([]TeamMembership, error)
|
|
|
|
TeamMembershipsByUserID(userID UserID) ([]TeamMembership, error)
|
|
|
|
TeamMembershipsByTeamID(teamID TeamID) ([]TeamMembership, error)
|
|
|
|
CreateTeamMembership(membership *TeamMembership) error
|
|
|
|
UpdateTeamMembership(ID TeamMembershipID, membership *TeamMembership) error
|
|
|
|
DeleteTeamMembership(ID TeamMembershipID) error
|
|
|
|
DeleteTeamMembershipByUserID(userID UserID) error
|
|
|
|
DeleteTeamMembershipByTeamID(teamID TeamID) error
|
|
|
|
}
|
|
|
|
|
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-06-20 11:00:32 +00:00
|
|
|
// RegistryService represents a service for managing registry data.
|
|
|
|
RegistryService interface {
|
|
|
|
Registry(ID RegistryID) (*Registry, error)
|
|
|
|
Registries() ([]Registry, error)
|
|
|
|
CreateRegistry(registry *Registry) error
|
|
|
|
UpdateRegistry(ID RegistryID, registry *Registry) error
|
|
|
|
DeleteRegistry(ID RegistryID) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// DockerHubService represents a service for managing the DockerHub object.
|
|
|
|
DockerHubService interface {
|
|
|
|
DockerHub() (*DockerHub, error)
|
|
|
|
StoreDockerHub(registry *DockerHub) error
|
|
|
|
}
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
// SettingsService represents a service for managing application settings.
|
|
|
|
SettingsService interface {
|
|
|
|
Settings() (*Settings, error)
|
|
|
|
StoreSettings(settings *Settings) error
|
|
|
|
}
|
|
|
|
|
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 {
|
2017-05-23 18:56:10 +00:00
|
|
|
ResourceControl(ID ResourceControlID) (*ResourceControl, error)
|
|
|
|
ResourceControlByResourceID(resourceID string) (*ResourceControl, error)
|
|
|
|
ResourceControls() ([]ResourceControl, error)
|
|
|
|
CreateResourceControl(rc *ResourceControl) error
|
|
|
|
UpdateResourceControl(ID ResourceControlID, resourceControl *ResourceControl) error
|
|
|
|
DeleteResourceControl(ID ResourceControlID) error
|
2017-03-12 16:24:15 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2017-08-10 08:35:23 +00:00
|
|
|
StoreTLSFile(folder string, fileType TLSFileType, r io.Reader) error
|
|
|
|
GetPathForTLSFile(folder string, fileType TLSFileType) (string, error)
|
|
|
|
DeleteTLSFiles(folder string) error
|
2016-12-25 20:34:02 +00:00
|
|
|
}
|
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
|
|
|
|
}
|
2017-08-10 08:35:23 +00:00
|
|
|
|
|
|
|
// LDAPService represents a service used to authenticate users against a LDAP/AD.
|
|
|
|
LDAPService interface {
|
|
|
|
AuthenticateUser(username, password string, settings *LDAPSettings) error
|
|
|
|
TestConnectivity(settings *LDAPSettings) error
|
|
|
|
}
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-05-23 18:56:10 +00:00
|
|
|
// APIVersion is the version number of the Portainer API.
|
2017-08-13 18:17:23 +00:00
|
|
|
APIVersion = "1.14.0"
|
2017-05-23 18:56:10 +00:00
|
|
|
// DBVersion is the version number of the Portainer database.
|
2017-08-10 08:35:23 +00:00
|
|
|
DBVersion = 3
|
2017-06-01 08:14:55 +00:00
|
|
|
// DefaultTemplatesURL represents the default URL for the templates definitions.
|
|
|
|
DefaultTemplatesURL = "https://raw.githubusercontent.com/portainer/templates/master/templates.json"
|
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
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
const (
|
|
|
|
_ MembershipRole = iota
|
|
|
|
// TeamLeader represents a leader role inside a team
|
|
|
|
TeamLeader
|
|
|
|
// TeamMember represents a member role inside a team
|
|
|
|
TeamMember
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2017-08-10 08:35:23 +00:00
|
|
|
const (
|
|
|
|
_ AuthenticationMethod = iota
|
|
|
|
// AuthenticationInternal represents the internal authentication method (authentication against Portainer API)
|
|
|
|
AuthenticationInternal
|
|
|
|
// AuthenticationLDAP represents the LDAP authentication method (authentication against a LDAP server)
|
|
|
|
AuthenticationLDAP
|
|
|
|
)
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
const (
|
|
|
|
_ ResourceAccessLevel = iota
|
|
|
|
// ReadWriteAccessLevel represents an access level with read-write permissions on a resource
|
|
|
|
ReadWriteAccessLevel
|
|
|
|
)
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
const (
|
|
|
|
_ ResourceControlType = iota
|
2017-05-23 18:56:10 +00:00
|
|
|
// ContainerResourceControl represents a resource control associated to a Docker container
|
2017-03-12 16:24:15 +00:00
|
|
|
ContainerResourceControl
|
2017-05-23 18:56:10 +00:00
|
|
|
// ServiceResourceControl represents a resource control associated to a Docker service
|
2017-03-12 16:24:15 +00:00
|
|
|
ServiceResourceControl
|
2017-05-23 18:56:10 +00:00
|
|
|
// VolumeResourceControl represents a resource control associated to a Docker volume
|
2017-03-12 16:24:15 +00:00
|
|
|
VolumeResourceControl
|
|
|
|
)
|