1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-10 00:05:24 +02:00

WIP: models

This commit is contained in:
Prabhat Khera 2023-04-28 21:07:34 +12:00
parent 8fa1875891
commit 22d960e51b
3 changed files with 212 additions and 107 deletions

View file

@ -163,7 +163,113 @@ func (connection *DbConnection) getEncryptionKey() []byte {
} }
func (connection *DbConnection) Init() error { func (connection *DbConnection) Init() error {
connection.DB.AutoMigrate(&models.Version{}) err := connection.DB.AutoMigrate(&models.Version{})
connection.DB.AutoMigrate(&portainer.Settings{}) if err != nil {
log.Err(err).Msgf("failed to auto migrate Version")
}
err = connection.DB.AutoMigrate(&portainer.Settings{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Settings")
}
err = connection.DB.AutoMigrate(&portainer.APIKey{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate APIKey")
}
err = connection.DB.AutoMigrate(&portainer.User{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate User")
}
err = connection.DB.AutoMigrate(&portainer.CustomTemplate{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate CustomTemplate")
}
err = connection.DB.AutoMigrate(&portainer.DockerHub{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate DockerHub")
}
err = connection.DB.AutoMigrate(&portainer.EdgeGroup{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate EdgeGroup")
}
err = connection.DB.AutoMigrate(&portainer.EdgeJob{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate EdgeJob")
}
err = connection.DB.AutoMigrate(&portainer.EdgeStack{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate EdgeStack")
}
err = connection.DB.AutoMigrate(&portainer.Endpoint{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Endpoint")
}
err = connection.DB.AutoMigrate(&portainer.EndpointGroup{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate EndpointGroup")
}
err = connection.DB.AutoMigrate(&portainer.EndpointRelation{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate EndpointRelation")
}
err = connection.DB.AutoMigrate(&portainer.Extension{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Extension")
}
err = connection.DB.AutoMigrate(&portainer.FDOProfile{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate FDOProfile")
}
err = connection.DB.AutoMigrate(&portainer.HelmUserRepository{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate HelmUserRepository")
}
err = connection.DB.AutoMigrate(&portainer.Registry{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Registry")
}
err = connection.DB.AutoMigrate(&portainer.ResourceControl{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate ResourceControl")
}
err = connection.DB.AutoMigrate(&portainer.Role{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Role")
}
err = connection.DB.AutoMigrate(&portainer.Schedule{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Schedule")
}
err = connection.DB.AutoMigrate(&portainer.Snapshot{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Snapshot")
}
err = connection.DB.AutoMigrate(&portainer.SSLSettings{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate SSLSettings")
}
err = connection.DB.AutoMigrate(&portainer.Stack{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Stack")
}
err = connection.DB.AutoMigrate(&portainer.Tag{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Tag")
}
err = connection.DB.AutoMigrate(&portainer.Team{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Team")
}
err = connection.DB.AutoMigrate(&portainer.TeamMembership{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate TeamMembership")
}
err = connection.DB.AutoMigrate(&portainer.TunnelServerInfo{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate TunnelServerInfo")
}
err = connection.DB.AutoMigrate(&portainer.Webhook{})
if err != nil {
log.Err(err).Msgf("failed to auto migrate Webhook")
}
return nil return nil
} }

View file

@ -127,7 +127,7 @@ func DecorateCustomTemplates(templates []portainer.CustomTemplate, resourceContr
resourceControl := GetResourceControlByResourceIDAndType(strconv.Itoa(int(template.ID)), portainer.CustomTemplateResourceControl, resourceControls) resourceControl := GetResourceControlByResourceIDAndType(strconv.Itoa(int(template.ID)), portainer.CustomTemplateResourceControl, resourceControls)
if resourceControl != nil { if resourceControl != nil {
templates[idx].ResourceControl = resourceControl templates[idx].ResourceControlID = resourceControl.ID
} }
} }
@ -152,7 +152,7 @@ func FilterAuthorizedCustomTemplates(customTemplates []portainer.CustomTemplate,
authorizedTemplates := make([]portainer.CustomTemplate, 0) authorizedTemplates := make([]portainer.CustomTemplate, 0)
for _, customTemplate := range customTemplates { for _, customTemplate := range customTemplates {
if customTemplate.CreatedByUserID == user.ID || (customTemplate.ResourceControl != nil && UserCanAccessResource(user.ID, userTeamIDs, customTemplate.ResourceControl)) { if customTemplate.CreatedByUserID == user.ID || (customTemplate.ResourceControlID == 0 && UserCanAccessResource(user.ID, userTeamIDs, customTemplate.ResourceControl)) {
authorizedTemplates = append(authorizedTemplates, customTemplate) authorizedTemplates = append(authorizedTemplates, customTemplate)
} }
} }

View file

@ -102,7 +102,7 @@ type (
FDOProfileID int FDOProfileID int
FDOProfile struct { FDOProfile struct {
ID FDOProfileID `json:"id"` ID FDOProfileID `json:"id" gorm:"unique,primaryKey,autoIncrement"`
Name string `json:"name"` Name string `json:"name"`
FilePath string `json:"filePath"` FilePath string `json:"filePath"`
NumberDevices int `json:"numberDevices"` NumberDevices int `json:"numberDevices"`
@ -159,7 +159,7 @@ type (
// CustomTemplate represents a custom template // CustomTemplate represents a custom template
CustomTemplate struct { CustomTemplate struct {
// CustomTemplate Identifier // CustomTemplate Identifier
ID CustomTemplateID `json:"Id" example:"1"` ID CustomTemplateID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Title of the template // Title of the template
Title string `json:"Title" example:"Nginx"` Title string `json:"Title" example:"Nginx"`
// Description of the template // Description of the template
@ -181,10 +181,10 @@ type (
// * 1 - swarm // * 1 - swarm
// * 2 - compose // * 2 - compose
// * 3 - kubernetes // * 3 - kubernetes
Type StackType `json:"Type" example:"1" enums:"1,2,3"` Type StackType `json:"Type" example:"1"`
ResourceControl *ResourceControl `json:"ResourceControl"` ResourceControlID ResourceControlID `json:"ResourceControl" gorm:"foreignKey"`
Variables []CustomTemplateVariableDefinition Variables []CustomTemplateVariableDefinition `json:"Variables" gorm:"serialize:json"`
GitConfig *gittypes.RepoConfig `json:"GitConfig"` GitConfig *gittypes.RepoConfig `json:"GitConfig" gorm:"serialize:json"`
// IsComposeFormat indicates if the Kubernetes template is created from a Docker Compose file // IsComposeFormat indicates if the Kubernetes template is created from a Docker Compose file
IsComposeFormat bool `example:"false"` IsComposeFormat bool `example:"false"`
} }
@ -247,11 +247,11 @@ type (
// EdgeGroup represents an Edge group // EdgeGroup represents an Edge group
EdgeGroup struct { EdgeGroup struct {
// EdgeGroup Identifier // EdgeGroup Identifier
ID EdgeGroupID `json:"Id" example:"1"` ID EdgeGroupID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Name string `json:"Name"` Name string `json:"Name"`
Dynamic bool `json:"Dynamic"` Dynamic bool `json:"Dynamic"`
TagIDs []TagID `json:"TagIds"` TagIDs []TagID `json:"TagIds" gorm:"serializable:json"`
Endpoints []EndpointID `json:"Endpoints"` Endpoints []EndpointID `json:"Endpoints" gorm:"serializable:json"`
PartialMatch bool `json:"PartialMatch"` PartialMatch bool `json:"PartialMatch"`
} }
@ -261,11 +261,11 @@ type (
// EdgeJob represents a job that can run on Edge environments(endpoints). // EdgeJob represents a job that can run on Edge environments(endpoints).
EdgeJob struct { EdgeJob struct {
// EdgeJob Identifier // EdgeJob Identifier
ID EdgeJobID `json:"Id" example:"1"` ID EdgeJobID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Created int64 `json:"Created"` Created int64 `json:"Created"`
CronExpression string `json:"CronExpression"` CronExpression string `json:"CronExpression"`
Endpoints map[EndpointID]EdgeJobEndpointMeta `json:"Endpoints"` Endpoints map[EndpointID]EdgeJobEndpointMeta `json:"Endpoints" gorm:"serializable:json"`
EdgeGroups []EdgeGroupID `json:"EdgeGroups"` EdgeGroups []EdgeGroupID `json:"EdgeGroups" gorm:"serializable:json"`
Name string `json:"Name"` Name string `json:"Name"`
ScriptPath string `json:"ScriptPath"` ScriptPath string `json:"ScriptPath"`
Recurring bool `json:"Recurring"` Recurring bool `json:"Recurring"`
@ -292,21 +292,21 @@ type (
// Deprecated: in favor of EdgeJob // Deprecated: in favor of EdgeJob
EdgeSchedule struct { EdgeSchedule struct {
// EdgeSchedule Identifier // EdgeSchedule Identifier
ID ScheduleID `json:"Id" example:"1"` ID ScheduleID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
CronExpression string `json:"CronExpression"` CronExpression string `json:"CronExpression"`
Script string `json:"Script"` Script string `json:"Script"`
Version int `json:"Version"` Version int `json:"Version"`
Endpoints []EndpointID `json:"Endpoints"` Endpoints []EndpointID `json:"Endpoints" gorm:"serealize:json"`
} }
//EdgeStack represents an edge stack //EdgeStack represents an edge stack
EdgeStack struct { EdgeStack struct {
// EdgeStack Identifier // EdgeStack Identifier
ID EdgeStackID `json:"Id" example:"1"` ID EdgeStackID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Name string `json:"Name"` Name string `json:"Name"`
Status map[EndpointID]EdgeStackStatus `json:"Status"` Status map[EndpointID]EdgeStackStatus `json:"Status" gorm:"serealize:json"`
CreationDate int64 `json:"CreationDate"` CreationDate int64 `json:"CreationDate"`
EdgeGroups []EdgeGroupID `json:"EdgeGroups"` EdgeGroups []EdgeGroupID `json:"EdgeGroups" gorm:"serealize:json"`
ProjectPath string `json:"ProjectPath"` ProjectPath string `json:"ProjectPath"`
EntryPoint string `json:"EntryPoint"` EntryPoint string `json:"EntryPoint"`
Version int `json:"Version"` Version int `json:"Version"`
@ -352,7 +352,7 @@ type (
// to connect to it // to connect to it
Endpoint struct { Endpoint struct {
// Environment(Endpoint) Identifier // Environment(Endpoint) Identifier
ID EndpointID `json:"Id" example:"1"` ID EndpointID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Environment(Endpoint) name // Environment(Endpoint) name
Name string `json:"Name" example:"my-environment"` Name string `json:"Name" example:"my-environment"`
// Environment(Endpoint) environment(endpoint) type. 1 for a Docker environment(endpoint), 2 for an agent on Docker environment(endpoint) or 3 for an Azure environment(endpoint). // Environment(Endpoint) environment(endpoint) type. 1 for a Docker environment(endpoint), 2 for an agent on Docker environment(endpoint) or 3 for an Azure environment(endpoint).
@ -363,19 +363,19 @@ type (
GroupID EndpointGroupID `json:"GroupId" example:"1"` GroupID EndpointGroupID `json:"GroupId" example:"1"`
// URL or IP address where exposed containers will be reachable // URL or IP address where exposed containers will be reachable
PublicURL string `json:"PublicURL" example:"docker.mydomain.tld:2375"` PublicURL string `json:"PublicURL" example:"docker.mydomain.tld:2375"`
Gpus []Pair `json:"Gpus"` Gpus []Pair `json:"Gpus" gorm:"serializable:json"`
TLSConfig TLSConfiguration `json:"TLSConfig"` TLSConfig TLSConfiguration `json:"TLSConfig" gorm:"serializable:json"`
AzureCredentials AzureCredentials `json:"AzureCredentials,omitempty"` AzureCredentials AzureCredentials `json:"AzureCredentials,omitempty" gorm:"serializable:json"`
// List of tag identifiers to which this environment(endpoint) is associated // List of tag identifiers to which this environment(endpoint) is associated
TagIDs []TagID `json:"TagIds"` TagIDs []TagID `json:"TagIds" gorm:"serializable:json"`
// The status of the environment(endpoint) (1 - up, 2 - down) // The status of the environment(endpoint) (1 - up, 2 - down)
Status EndpointStatus `json:"Status" example:"1"` Status EndpointStatus `json:"Status" example:"1"`
// List of snapshots // List of snapshots
Snapshots []DockerSnapshot `json:"Snapshots"` Snapshots []DockerSnapshot `json:"Snapshots" gorm:"serializable:json"`
// List of user identifiers authorized to connect to this environment(endpoint) // List of user identifiers authorized to connect to this environment(endpoint)
UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies"` UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies" gorm:"serializable:json"`
// List of team identifiers authorized to connect to this environment(endpoint) // List of team identifiers authorized to connect to this environment(endpoint)
TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies"` TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies" gorm:"serializable:json"`
// The identifier of the edge agent associated with this environment(endpoint) // The identifier of the edge agent associated with this environment(endpoint)
EdgeID string `json:"EdgeID,omitempty"` EdgeID string `json:"EdgeID,omitempty"`
// The key which is used to map the agent to Portainer // The key which is used to map the agent to Portainer
@ -383,11 +383,11 @@ type (
// The check in interval for edge agent (in seconds) // The check in interval for edge agent (in seconds)
EdgeCheckinInterval int `json:"EdgeCheckinInterval" example:"5"` EdgeCheckinInterval int `json:"EdgeCheckinInterval" example:"5"`
// Associated Kubernetes data // Associated Kubernetes data
Kubernetes KubernetesData `json:"Kubernetes"` Kubernetes KubernetesData `json:"Kubernetes" gorm:"serializable:json"`
// Maximum version of docker-compose // Maximum version of docker-compose
ComposeSyntaxMaxVersion string `json:"ComposeSyntaxMaxVersion" example:"3.8"` ComposeSyntaxMaxVersion string `json:"ComposeSyntaxMaxVersion" example:"3.8"`
// Environment(Endpoint) specific security settings // Environment(Endpoint) specific security settings
SecuritySettings EndpointSecuritySettings SecuritySettings EndpointSecuritySettings `gorm:"serializable:json"`
// The identifier of the AMT Device associated with this environment(endpoint) // The identifier of the AMT Device associated with this environment(endpoint)
AMTDeviceGUID string `json:"AMTDeviceGUID,omitempty" example:"4c4c4544-004b-3910-8037-b6c04f504633"` AMTDeviceGUID string `json:"AMTDeviceGUID,omitempty" example:"4c4c4544-004b-3910-8037-b6c04f504633"`
// LastCheckInDate mark last check-in date on checkin // LastCheckInDate mark last check-in date on checkin
@ -401,13 +401,13 @@ type (
UserTrusted bool UserTrusted bool
// Whether we need to run any "post init migrations". // Whether we need to run any "post init migrations".
PostInitMigrations EndpointPostInitMigrations `json:"PostInitMigrations"` PostInitMigrations EndpointPostInitMigrations `json:"PostInitMigrations" gorm:"serializable:json"`
Edge EnvironmentEdgeSettings Edge EnvironmentEdgeSettings `gorm:"serializable:json"`
Agent struct { Agent struct {
Version string `example:"1.0.0"` Version string `example:"1.0.0"`
} } `json:"Agent" gorm:"serializable:json"`
EnableGPUManagement bool `json:"EnableGPUManagement"` EnableGPUManagement bool `json:"EnableGPUManagement"`
@ -419,11 +419,11 @@ type (
TLSKeyPath string `json:"TLSKey,omitempty"` TLSKeyPath string `json:"TLSKey,omitempty"`
// Deprecated in DBVersion == 18 // Deprecated in DBVersion == 18
AuthorizedUsers []UserID `json:"AuthorizedUsers"` AuthorizedUsers []UserID `json:"AuthorizedUsers" gorm:"serializable:json"`
AuthorizedTeams []TeamID `json:"AuthorizedTeams"` AuthorizedTeams []TeamID `json:"AuthorizedTeams" gorm:"serializable:json"`
// Deprecated in DBVersion == 22 // Deprecated in DBVersion == 22
Tags []string `json:"Tags"` Tags []string `json:"Tags" gorm:"serializable:json"`
// Deprecated v2.18 // Deprecated v2.18
IsEdgeDevice bool IsEdgeDevice bool
@ -446,25 +446,25 @@ type (
// EndpointGroup represents a group of environments(endpoints) // EndpointGroup represents a group of environments(endpoints)
EndpointGroup struct { EndpointGroup struct {
// Environment(Endpoint) group Identifier // Environment(Endpoint) group Identifier
ID EndpointGroupID `json:"Id" example:"1"` ID EndpointGroupID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Environment(Endpoint) group name // Environment(Endpoint) group name
Name string `json:"Name" example:"my-environment-group"` Name string `json:"Name" example:"my-environment-group"`
// Description associated to the environment(endpoint) group // Description associated to the environment(endpoint) group
Description string `json:"Description" example:"Environment(Endpoint) group description"` Description string `json:"Description" example:"Environment(Endpoint) group description"`
UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies"` UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies" gorm:"serializable:json"`
TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies"` TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies" gorm:"serializable:json"`
// List of tags associated to this environment(endpoint) group // List of tags associated to this environment(endpoint) group
TagIDs []TagID `json:"TagIds"` TagIDs []TagID `json:"TagIds" gorm:"serializable:json"`
// Deprecated fields // Deprecated fields
Labels []Pair `json:"Labels"` Labels []Pair `json:"Labels" gorm:"serializable:json"`
// Deprecated in DBVersion == 18 // Deprecated in DBVersion == 18
AuthorizedUsers []UserID `json:"AuthorizedUsers"` AuthorizedUsers []UserID `json:"AuthorizedUsers" gorm:"serializable:json"`
AuthorizedTeams []TeamID `json:"AuthorizedTeams"` AuthorizedTeams []TeamID `json:"AuthorizedTeams" gorm:"serializable:json"`
// Deprecated in DBVersion == 22 // Deprecated in DBVersion == 22
Tags []string `json:"Tags"` Tags []string `json:"Tags" gorm:"serializable:json"`
} }
// EndpointGroupID represents an environment(endpoint) group identifier // EndpointGroupID represents an environment(endpoint) group identifier
@ -520,7 +520,7 @@ type (
// Extension represents a deprecated Portainer extension // Extension represents a deprecated Portainer extension
Extension struct { Extension struct {
// Extension Identifier // Extension Identifier
ID ExtensionID `json:"Id" example:"1"` ID ExtensionID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Enabled bool `json:"Enabled"` Enabled bool `json:"Enabled"`
Name string `json:"Name,omitempty"` Name string `json:"Name,omitempty"`
ShortDescription string `json:"ShortDescription,omitempty"` ShortDescription string `json:"ShortDescription,omitempty"`
@ -530,11 +530,11 @@ type (
PriceDescription string `json:"PriceDescription,omitempty"` PriceDescription string `json:"PriceDescription,omitempty"`
Deal bool `json:"Deal,omitempty"` Deal bool `json:"Deal,omitempty"`
Available bool `json:"Available,omitempty"` Available bool `json:"Available,omitempty"`
License LicenseInformation `json:"License,omitempty"` License LicenseInformation `json:"License,omitempty" gorm:"serializable:json"`
Version string `json:"Version"` Version string `json:"Version"`
UpdateAvailable bool `json:"UpdateAvailable"` UpdateAvailable bool `json:"UpdateAvailable"`
ShopURL string `json:"ShopURL,omitempty"` ShopURL string `json:"ShopURL,omitempty"`
Images []string `json:"Images,omitempty"` Images []string `json:"Images,omitempty" gorm:"serializable:json"`
Logo string `json:"Logo,omitempty"` Logo string `json:"Logo,omitempty"`
} }
@ -553,7 +553,7 @@ type (
// HelmUserRepositories stores a Helm repository URL for the given user // HelmUserRepositories stores a Helm repository URL for the given user
HelmUserRepository struct { HelmUserRepository struct {
// Membership Identifier // Membership Identifier
ID HelmUserRepositoryID `json:"Id" example:"1"` ID HelmUserRepositoryID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// User identifier // User identifier
UserID UserID `json:"UserId" example:"1"` UserID UserID `json:"UserId" example:"1"`
// Helm repository URL // Helm repository URL
@ -740,7 +740,7 @@ type (
// to connect to it // to connect to it
Registry struct { Registry struct {
// Registry Identifier // Registry Identifier
ID RegistryID `json:"Id" example:"1"` ID RegistryID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Registry Type (1 - Quay, 2 - Azure, 3 - Custom, 4 - Gitlab, 5 - ProGet, 6 - DockerHub, 7 - ECR) // Registry Type (1 - Quay, 2 - Azure, 3 - Custom, 4 - Gitlab, 5 - ProGet, 6 - DockerHub, 7 - ECR)
Type RegistryType `json:"Type" enums:"1,2,3,4,5,6,7"` Type RegistryType `json:"Type" enums:"1,2,3,4,5,6,7"`
// Registry Name // Registry Name
@ -755,22 +755,22 @@ type (
Username string `json:"Username" example:"registry user"` Username string `json:"Username" example:"registry user"`
// Password or SecretAccessKey used to authenticate against this registry // Password or SecretAccessKey used to authenticate against this registry
Password string `json:"Password,omitempty" example:"registry_password"` Password string `json:"Password,omitempty" example:"registry_password"`
ManagementConfiguration *RegistryManagementConfiguration `json:"ManagementConfiguration"` ManagementConfiguration *RegistryManagementConfiguration `json:"ManagementConfiguration" gorm:"serializable:json"`
Gitlab GitlabRegistryData `json:"Gitlab"` Gitlab GitlabRegistryData `json:"Gitlab" gorm:"serializable:json"`
Quay QuayRegistryData `json:"Quay"` Quay QuayRegistryData `json:"Quay" gorm:"serializable:json"`
Ecr EcrData `json:"Ecr"` Ecr EcrData `json:"Ecr" gorm:"serializable:json"`
RegistryAccesses RegistryAccesses `json:"RegistryAccesses"` RegistryAccesses RegistryAccesses `json:"RegistryAccesses" gorm:"serializable:json"`
// Deprecated fields // Deprecated fields
// Deprecated in DBVersion == 31 // Deprecated in DBVersion == 31
UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies"` UserAccessPolicies UserAccessPolicies `json:"UserAccessPolicies" gorm:"serializable:json"`
// Deprecated in DBVersion == 31 // Deprecated in DBVersion == 31
TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies"` TeamAccessPolicies TeamAccessPolicies `json:"TeamAccessPolicies" gorm:"serializable:json"`
// Deprecated in DBVersion == 18 // Deprecated in DBVersion == 18
AuthorizedUsers []UserID `json:"AuthorizedUsers"` AuthorizedUsers []UserID `json:"AuthorizedUsers" gorm:"serializable:json"`
// Deprecated in DBVersion == 18 // Deprecated in DBVersion == 18
AuthorizedTeams []TeamID `json:"AuthorizedTeams"` AuthorizedTeams []TeamID `json:"AuthorizedTeams" gorm:"serializable:json"`
// Stores temporary access token // Stores temporary access token
AccessToken string `json:"AccessToken,omitempty"` AccessToken string `json:"AccessToken,omitempty"`
@ -810,17 +810,17 @@ type (
// ResourceControl represent a reference to a Docker resource with specific access controls // ResourceControl represent a reference to a Docker resource with specific access controls
ResourceControl struct { ResourceControl struct {
// ResourceControl Identifier // ResourceControl Identifier
ID ResourceControlID `json:"Id" example:"1"` ID ResourceControlID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Docker resource identifier on which access control will be applied.\ // Docker resource identifier on which access control will be applied.\
// In the case of a resource control applied to a stack, use the stack name as identifier // In the case of a resource control applied to a stack, use the stack name as identifier
ResourceID string `json:"ResourceId" example:"617c5f22bb9b023d6daab7cba43a57576f83492867bc767d1c59416b065e5f08"` ResourceID string `json:"ResourceId" example:"617c5f22bb9b023d6daab7cba43a57576f83492867bc767d1c59416b065e5f08"`
// List of Docker resources that will inherit this access control // List of Docker resources that will inherit this access control
SubResourceIDs []string `json:"SubResourceIds" example:"617c5f22bb9b023d6daab7cba43a57576f83492867bc767d1c59416b065e5f08"` SubResourceIDs []string `json:"SubResourceIds" example:"617c5f22bb9b023d6daab7cba43a57576f83492867bc767d1c59416b065e5f08" gorm:"serializable:json"`
// Type of Docker resource. Valid values are: 1- container, 2 -service // Type of Docker resource. Valid values are: 1- container, 2 -service
// 3 - volume, 4 - secret, 5 - stack, 6 - config or 7 - custom template // 3 - volume, 4 - secret, 5 - stack, 6 - config or 7 - custom template
Type ResourceControlType `json:"Type" example:"1"` Type ResourceControlType `json:"Type" example:"1"`
UserAccesses []UserResourceAccess `json:"UserAccesses"` UserAccesses []UserResourceAccess `json:"UserAccesses" gorm:"serializable:json"`
TeamAccesses []TeamResourceAccess `json:"TeamAccesses"` TeamAccesses []TeamResourceAccess `json:"TeamAccesses" gorm:"serializable:json"`
// Permit access to the associated resource to any user // Permit access to the associated resource to any user
Public bool `json:"Public" example:"true"` Public bool `json:"Public" example:"true"`
// Permit access to resource only to admins // Permit access to resource only to admins
@ -843,13 +843,13 @@ type (
// to a team. // to a team.
Role struct { Role struct {
// Role Identifier // Role Identifier
ID RoleID `json:"Id" example:"1"` ID RoleID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Role name // Role name
Name string `json:"Name" example:"HelpDesk"` Name string `json:"Name" example:"HelpDesk"`
// Role description // Role description
Description string `json:"Description" example:"Read-only access of all resources in an environment(endpoint)"` Description string `json:"Description" example:"Read-only access of all resources in an environment(endpoint)"`
// Authorizations associated to a role // Authorizations associated to a role
Authorizations Authorizations `json:"Authorizations"` Authorizations Authorizations `json:"Authorizations" gorm:"serializable:json"`
Priority int `json:"Priority"` Priority int `json:"Priority"`
} }
@ -861,13 +861,13 @@ type (
// APIKey represents an API key // APIKey represents an API key
APIKey struct { APIKey struct {
ID APIKeyID `json:"id" example:"1"` ID APIKeyID `json:"id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
UserID UserID `json:"userId" example:"1"` UserID UserID `json:"userId" example:"1" gorm:"index,foreignKey=ID"`
Description string `json:"description" example:"portainer-api-key"` Description string `json:"description" example:"portainer-api-key"`
Prefix string `json:"prefix"` // API key identifier (7 char prefix) Prefix string `json:"prefix"` // API key identifier (7 char prefix)
DateCreated int64 `json:"dateCreated"` // Unix timestamp (UTC) when the API key was created DateCreated int64 `json:"dateCreated"` // Unix timestamp (UTC) when the API key was created
LastUsed int64 `json:"lastUsed"` // Unix timestamp (UTC) when the API key was last used LastUsed int64 `json:"lastUsed"` // Unix timestamp (UTC) when the API key was last used
Digest []byte `json:"digest,omitempty"` // Digest represents SHA256 hash of the raw API key Digest []byte `json:"digest,omitempty" gorm:"serializable:json"` // Digest represents SHA256 hash of the raw API key
} }
// Schedule represents a scheduled job. // Schedule represents a scheduled job.
@ -877,13 +877,13 @@ type (
// Deprecated in favor of EdgeJob // Deprecated in favor of EdgeJob
Schedule struct { Schedule struct {
// Schedule Identifier // Schedule Identifier
ID ScheduleID `json:"Id" example:"1"` ID ScheduleID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Name string Name string
CronExpression string CronExpression string
Recurring bool Recurring bool
Created int64 Created int64
JobType JobType JobType JobType
EdgeSchedule *EdgeSchedule EdgeSchedule *EdgeSchedule `json:"EdgeSchedule,omitempty" gorm:"foreignKey:ScheduleID"`
} }
// ScheduleID represents a schedule identifier. // ScheduleID represents a schedule identifier.
@ -989,7 +989,7 @@ type (
// Stack represents a Docker stack created via docker stack deploy // Stack represents a Docker stack created via docker stack deploy
Stack struct { Stack struct {
// Stack Identifier // Stack Identifier
ID StackID `json:"Id" example:"1"` ID StackID `json:"Id" gorm:"unique,primaryKey,autoIncrement" example:"1"`
// Stack name // Stack name
Name string `json:"Name" example:"myStack"` Name string `json:"Name" example:"myStack"`
// Stack type. 1 for a Swarm stack, 2 for a Compose stack // Stack type. 1 for a Swarm stack, 2 for a Compose stack
@ -1003,7 +1003,7 @@ type (
// A list of environment(endpoint) variables used during stack deployment // A list of environment(endpoint) variables used during stack deployment
Env []Pair `json:"Env"` Env []Pair `json:"Env"`
// //
ResourceControl *ResourceControl `json:"ResourceControl"` ResourceControl *ResourceControl `json:"ResourceControl" gorm:"serializer:json"`
// Stack status (1 - active, 2 - inactive) // Stack status (1 - active, 2 - inactive)
Status StackStatus `json:"Status" example:"1"` Status StackStatus `json:"Status" example:"1"`
// Path on disk to the repository hosting the Stack file // Path on disk to the repository hosting the Stack file
@ -1019,11 +1019,11 @@ type (
// Only applies when deploying stack with multiple files // Only applies when deploying stack with multiple files
AdditionalFiles []string `json:"AdditionalFiles"` AdditionalFiles []string `json:"AdditionalFiles"`
// The auto update settings of a git stack // The auto update settings of a git stack
AutoUpdate *AutoUpdateSettings `json:"AutoUpdate"` AutoUpdate *AutoUpdateSettings `json:"AutoUpdate" gorm:"serializer:json"`
// The stack deployment option // The stack deployment option
Option *StackOption `json:"Option"` Option *StackOption `json:"Option" gorm:"serializer:json"`
// The git config of this stack // The git config of this stack
GitConfig *gittypes.RepoConfig GitConfig *gittypes.RepoConfig `json:"GitConfig" gorm:"serializer:json"`
// Whether the stack is from a app template // Whether the stack is from a app template
FromAppTemplate bool `example:"false"` FromAppTemplate bool `example:"false"`
// Kubernetes namespace if stack is a kube application // Kubernetes namespace if stack is a kube application
@ -1058,13 +1058,13 @@ type (
// Tag represents a tag that can be associated to a resource // Tag represents a tag that can be associated to a resource
Tag struct { Tag struct {
// Tag identifier // Tag identifier
ID TagID `example:"1"` ID TagID `example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Tag name // Tag name
Name string `json:"Name" example:"org/acme"` Name string `json:"Name" example:"org/acme"`
// A set of environment(endpoint) ids that have this tag // A set of environment(endpoint) ids that have this tag
Endpoints map[EndpointID]bool `json:"Endpoints"` Endpoints map[EndpointID]bool `json:"Endpoints" gorm:"serializer:json"`
// A set of environment(endpoint) group ids that have this tag // A set of environment(endpoint) group ids that have this tag
EndpointGroups map[EndpointGroupID]bool `json:"EndpointGroups"` EndpointGroups map[EndpointGroupID]bool `json:"EndpointGroups" gorm:"serializer:json"`
} }
// TagID represents a tag identifier // TagID represents a tag identifier
@ -1073,7 +1073,7 @@ type (
// Team represents a list of user accounts // Team represents a list of user accounts
Team struct { Team struct {
// Team Identifier // Team Identifier
ID TeamID `json:"Id" example:"1"` ID TeamID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Team name // Team name
Name string `json:"Name" example:"developers"` Name string `json:"Name" example:"developers"`
} }
@ -1087,7 +1087,7 @@ type (
// TeamMembership represents a membership association between a user and a team // TeamMembership represents a membership association between a user and a team
TeamMembership struct { TeamMembership struct {
// Membership Identifier // Membership Identifier
ID TeamMembershipID `json:"Id" example:"1"` ID TeamMembershipID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// User identifier // User identifier
UserID UserID `json:"UserID" example:"1"` UserID UserID `json:"UserID" example:"1"`
// Team identifier // Team identifier
@ -1102,7 +1102,7 @@ type (
// TeamResourceAccess represents the level of control on a resource for a specific team // TeamResourceAccess represents the level of control on a resource for a specific team
TeamResourceAccess struct { TeamResourceAccess struct {
TeamID TeamID `json:"TeamId"` TeamID TeamID `json:"TeamId"`
AccessLevel ResourceAccessLevel `json:"AccessLevel"` AccessLevel ResourceAccessLevel `json:"AccessLevel" gorm:"serializer:json"`
} }
// Template represents an application template that can be used as an App Template // Template represents an application template that can be used as an App Template
@ -1110,7 +1110,7 @@ type (
Template struct { Template struct {
// Mandatory container/stack fields // Mandatory container/stack fields
// Template Identifier // Template Identifier
ID TemplateID `json:"Id" example:"1"` ID TemplateID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
// Template type. Valid values are: 1 (container), 2 (Swarm stack) or 3 (Compose stack) // Template type. Valid values are: 1 (container), 2 (Swarm stack) or 3 (Compose stack)
Type TemplateType `json:"type" example:"1"` Type TemplateType `json:"type" example:"1"`
// Title of the template // Title of the template
@ -1125,7 +1125,7 @@ type (
Image string `json:"image" example:"nginx:latest"` Image string `json:"image" example:"nginx:latest"`
// Mandatory stack fields // Mandatory stack fields
Repository TemplateRepository `json:"repository"` Repository TemplateRepository `json:"repository" gorm:"serializer:json"`
// Mandatory Edge stack fields // Mandatory Edge stack fields
// Stack file used for this template // Stack file used for this template
@ -1137,14 +1137,14 @@ type (
// URL of the template's logo // URL of the template's logo
Logo string `json:"logo,omitempty" example:"https://portainer.io/img/logo.svg"` Logo string `json:"logo,omitempty" example:"https://portainer.io/img/logo.svg"`
// A list of environment(endpoint) variables used during the template deployment // A list of environment(endpoint) variables used during the template deployment
Env []TemplateEnv `json:"env,omitempty"` Env []TemplateEnv `json:"env,omitempty" gorm:"serializer:json"`
// A note that will be displayed in the UI. Supports HTML content // A note that will be displayed in the UI. Supports HTML content
Note string `json:"note,omitempty" example:"This is my <b>custom</b> template"` Note string `json:"note,omitempty" example:"This is my <b>custom</b> template"`
// Platform associated to the template. // Platform associated to the template.
// Valid values are: 'linux', 'windows' or leave empty for multi-platform // Valid values are: 'linux', 'windows' or leave empty for multi-platform
Platform string `json:"platform,omitempty" example:"linux"` Platform string `json:"platform,omitempty" example:"linux"`
// A list of categories associated to the template // A list of categories associated to the template
Categories []string `json:"categories,omitempty" example:"database"` Categories []string `json:"categories,omitempty" example:"database" gorm:"serializer:json"`
// Optional container fields // Optional container fields
// The URL of a registry associated to the image for a container template // The URL of a registry associated to the image for a container template
@ -1154,11 +1154,11 @@ type (
// Name of a network that will be used on container deployment if it exists inside the environment(endpoint) // Name of a network that will be used on container deployment if it exists inside the environment(endpoint)
Network string `json:"network,omitempty" example:"mynet"` Network string `json:"network,omitempty" example:"mynet"`
// A list of volumes used during the container template deployment // A list of volumes used during the container template deployment
Volumes []TemplateVolume `json:"volumes,omitempty"` Volumes []TemplateVolume `json:"volumes,omitempty" gorm:"serializer:json"`
// A list of ports exposed by the container // A list of ports exposed by the container
Ports []string `json:"ports,omitempty" example:"8080:80/tcp"` Ports []string `json:"ports,omitempty" example:"8080:80/tcp" gorm:"serializer:json"`
// Container labels // Container labels
Labels []Pair `json:"labels,omitempty"` Labels []Pair `json:"labels,omitempty" gorm:"serializer:json"`
// Whether the container should be started in privileged mode // Whether the container should be started in privileged mode
Privileged bool `json:"privileged,omitempty" example:"true"` Privileged bool `json:"privileged,omitempty" example:"true"`
// Whether the container should be started in // Whether the container should be started in
@ -1183,7 +1183,7 @@ type (
// If set to true, will not generate any input for this variable in the UI // If set to true, will not generate any input for this variable in the UI
Preset bool `json:"preset,omitempty" example:"false"` Preset bool `json:"preset,omitempty" example:"false"`
// A list of name/value that will be used to generate a dropdown in the UI // A list of name/value that will be used to generate a dropdown in the UI
Select []TemplateEnvSelect `json:"select,omitempty"` Select []TemplateEnvSelect `json:"select,omitempty" gorm:"serializer:json"`
} }
// TemplateEnvSelect represents text/value pair that will be displayed as a choice for the // TemplateEnvSelect represents text/value pair that will be displayed as a choice for the
@ -1264,22 +1264,22 @@ type (
// User represents a user account // User represents a user account
User struct { User struct {
// User Identifier // User Identifier
ID UserID `json:"Id" example:"1"` ID UserID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Username string `json:"Username" example:"bob"` Username string `json:"Username" example:"bob"`
Password string `json:"Password,omitempty" swaggerignore:"true"` Password string `json:"Password,omitempty" swaggerignore:"true"`
// User role (1 for administrator account and 2 for regular account) // User role (1 for administrator account and 2 for regular account)
Role UserRole `json:"Role" example:"1"` Role UserRole `json:"Role" example:"1"`
TokenIssueAt int64 `json:"TokenIssueAt" example:"1"` TokenIssueAt int64 `json:"TokenIssueAt" example:"1"`
ThemeSettings UserThemeSettings ThemeSettings UserThemeSettings `gorm:"serializer:json"`
// Deprecated fields // Deprecated fields
// Deprecated // Deprecated
UserTheme string `example:"dark"` UserTheme string `example:"dark"`
// Deprecated in DBVersion == 25 // Deprecated in DBVersion == 25
PortainerAuthorizations Authorizations PortainerAuthorizations Authorizations `gorm:"serializer:json"`
// Deprecated in DBVersion == 25 // Deprecated in DBVersion == 25
EndpointAuthorizations EndpointAuthorizations EndpointAuthorizations EndpointAuthorizations `gorm:"serializer:json"`
} }
// UserAccessPolicies represent the association of an access policy and a user // UserAccessPolicies represent the association of an access policy and a user
@ -1291,7 +1291,7 @@ type (
// UserResourceAccess represents the level of control on a resource for a specific user // UserResourceAccess represents the level of control on a resource for a specific user
UserResourceAccess struct { UserResourceAccess struct {
UserID UserID `json:"UserId"` UserID UserID `json:"UserId"`
AccessLevel ResourceAccessLevel `json:"AccessLevel"` AccessLevel ResourceAccessLevel `json:"AccessLevel" gorm:"serializer:json"`
} }
// UserRole represents the role of a user. It can be either an administrator // UserRole represents the role of a user. It can be either an administrator
@ -1307,12 +1307,11 @@ type (
// Webhook represents a url webhook that can be used to update a service // Webhook represents a url webhook that can be used to update a service
Webhook struct { Webhook struct {
// Webhook Identifier // Webhook Identifier
ID WebhookID `json:"Id" example:"1"` ID WebhookID `json:"Id" example:"1" gorm:"unique,primaryKey,autoIncrement"`
Token string `json:"Token"` Token string `json:"Token"`
ResourceID string `json:"ResourceId"` ResourceID string `json:"ResourceId"`
EndpointID EndpointID `json:"EndpointId"` EndpointID EndpointID `json:"EndpointId"`
RegistryID RegistryID `json:"RegistryId"` RegistryID RegistryID `json:"RegistryId"`
// Type of webhook (1 - service)
WebhookType WebhookType `json:"Type"` WebhookType WebhookType `json:"Type"`
} }
@ -1324,8 +1323,8 @@ type (
Snapshot struct { Snapshot struct {
EndpointID EndpointID `json:"EndpointId"` EndpointID EndpointID `json:"EndpointId"`
Docker *DockerSnapshot `json:"Docker"` Docker *DockerSnapshot `json:"Docker" gorm:"serializer:json"`
Kubernetes *KubernetesSnapshot `json:"Kubernetes"` Kubernetes *KubernetesSnapshot `json:"Kubernetes" gorm:"serializer:json"`
} }
// CLIService represents a service for managing CLI // CLIService represents a service for managing CLI