61
pkg/models/devops/common.go
Normal file
61
pkg/models/devops/common.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package devops
|
||||
|
||||
import (
|
||||
"github.com/fatih/structs"
|
||||
"kubesphere.io/kubesphere/pkg/utils/stringutils"
|
||||
)
|
||||
|
||||
func GetColumnsFromStruct(s interface{}) []string {
|
||||
names := structs.Names(s)
|
||||
for i, name := range names {
|
||||
names[i] = stringutils.CamelCaseToUnderscore(name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func GetColumnsFromStructWithPrefix(prefix string, s interface{}) []string {
|
||||
names := structs.Names(s)
|
||||
for i, name := range names {
|
||||
names[i] = WithPrefix(prefix, stringutils.CamelCaseToUnderscore(name))
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func WithPrefix(prefix, str string) string {
|
||||
return prefix + "." + str
|
||||
}
|
||||
|
||||
const (
|
||||
StatusActive = "active"
|
||||
StatusDeleted = "deleted"
|
||||
StatusDeleting = "deleting"
|
||||
StatusFailed = "failed"
|
||||
StatusPending = "pending"
|
||||
StatusWorking = "working"
|
||||
StatusSuccessful = "successful"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusColumn = "status"
|
||||
StatusTimeColumn = "status_time"
|
||||
)
|
||||
|
||||
const (
|
||||
VisibilityPrivate = "private"
|
||||
VisibilityPublic = "public"
|
||||
)
|
||||
|
||||
const (
|
||||
KS_ADMIN = "admin"
|
||||
)
|
||||
|
||||
const (
|
||||
ProjectOwner = "owner"
|
||||
ProjectMaintainer = "maintainer"
|
||||
ProjectDeveloper = "developer"
|
||||
ProjectReporter = "reporter"
|
||||
)
|
||||
|
||||
const (
|
||||
JenkinsAllUserRoleName = "kubesphere-user"
|
||||
)
|
||||
28
pkg/models/devops/membership.go
Normal file
28
pkg/models/devops/membership.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package devops
|
||||
|
||||
const (
|
||||
DevOpsProjectMembershipTableName = "project_membership"
|
||||
DevOpsProjectMembershipUsernameColumn = "project_membership.username"
|
||||
DevOpsProjectMembershipProjectIdColumn = "project_membership.project_id"
|
||||
DevOpsProjectMembershipRoleColumn = "project_membership.role"
|
||||
)
|
||||
|
||||
type DevOpsProjectMembership struct {
|
||||
Username string `json:"username"`
|
||||
ProjectId string `json:"project_id" db:"project_id"`
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
GrantBy string `json:"grand_by,omitempty"`
|
||||
}
|
||||
|
||||
var DevOpsProjectMembershipColumns = GetColumnsFromStruct(&DevOpsProjectMembership{})
|
||||
|
||||
func NewDevOpsProjectMemberShip(username, projectId, role, grantBy string) *DevOpsProjectMembership {
|
||||
return &DevOpsProjectMembership{
|
||||
Username: username,
|
||||
ProjectId: projectId,
|
||||
Role: role,
|
||||
Status: StatusActive,
|
||||
GrantBy: grantBy,
|
||||
}
|
||||
}
|
||||
45
pkg/models/devops/project.go
Normal file
45
pkg/models/devops/project.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package devops
|
||||
|
||||
import (
|
||||
"kubesphere.io/kubesphere/pkg/utils/idutils"
|
||||
"time"
|
||||
)
|
||||
|
||||
var DevOpsProjectColumns = GetColumnsFromStruct(&DevOpsProject{})
|
||||
|
||||
const (
|
||||
DevOpsProjectTableName = "project"
|
||||
DevOpsProjectPrefix = "project-"
|
||||
DevOpsProjectDescriptionColumn = "description"
|
||||
DevOpsProjectIdColumn = "project.project_id"
|
||||
DevOpsProjectNameColumn = "project.name"
|
||||
DevOpsProjectExtraColumn = "project.extra"
|
||||
DevOpsProjectWorkSpaceColumn = "project.workspace"
|
||||
DevOpsProjectCreateTimeColumn = "project.create_time"
|
||||
)
|
||||
|
||||
type DevOpsProject struct {
|
||||
ProjectId string `json:"project_id" db:"project_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Creator string `json:"creator"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
Status string `json:"status"`
|
||||
Visibility string `json:"visibility"`
|
||||
Extra string `json:"extra"`
|
||||
Workspace string `json:"workspace"`
|
||||
}
|
||||
|
||||
func NewDevOpsProject(name, description, creator, extra, workspace string) *DevOpsProject {
|
||||
return &DevOpsProject{
|
||||
ProjectId: idutils.GetUuid(DevOpsProjectPrefix),
|
||||
Name: name,
|
||||
Description: description,
|
||||
Creator: creator,
|
||||
CreateTime: time.Now(),
|
||||
Status: StatusActive,
|
||||
Visibility: VisibilityPrivate,
|
||||
Extra: extra,
|
||||
Workspace: workspace,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user