Parcourir la source

add project role and policy to projects table

Mohammed Nafees il y a 3 ans
Parent
commit
6c6da16610
3 fichiers modifiés avec 28 ajouts et 4 suppressions
  1. 4 4
      internal/models/policy.go
  2. 6 0
      internal/models/project.go
  3. 18 0
      internal/models/project_role.go

+ 4 - 4
internal/models/policy.go

@@ -12,10 +12,10 @@ type Policy struct {
 
 	UniqueID string `gorm:"unique"`
 
-	ProjectID       uint
-	CreatedByUserID uint
-	Name            string
-	PolicyBytes     []byte
+	ProjectID       uint   `gorm:"not null;check:project_id>0"`
+	CreatedByUserID uint   `gorm:"not null;check:created_by_user_id>0"`
+	Name            string `gorm:"not null;check:name!=''"`
+	PolicyBytes     []byte `gorm:"not null"`
 }
 
 func (p *Policy) ToAPIPolicyTypeMeta() *types.APIPolicyMeta {

+ 6 - 0
internal/models/project.go

@@ -48,6 +48,12 @@ type Project struct {
 	// provisioned aws infra
 	Infras []Infra `json:"infras"`
 
+	// linked policy documents
+	ProjectPolicies []Policy
+
+	// project roles
+	ProjectRoles []ProjectRole
+
 	// auth mechanisms
 	KubeIntegrations   []ints.KubeIntegration   `json:"kube_integrations"`
 	BasicIntegrations  []ints.BasicIntegration  `json:"basic_integrations"`

+ 18 - 0
internal/models/project_role.go

@@ -0,0 +1,18 @@
+package models
+
+import (
+	"gorm.io/gorm"
+)
+
+type ProjectRole struct {
+	gorm.Model
+
+	ProjectID uint `gorm:"not null;check:project_id>0"`
+	PolicyID  uint `gorm:"not null;check:policy_id>0"`
+
+	UniqueID string `gorm:"unique"`
+
+	Name string `gorm:"not null;check:name!=''"`
+
+	Users []User
+}