diff --git a/api/admin/clean.go b/api/admin/clean.go
index da3949568..74f172705 100644
--- a/api/admin/clean.go
+++ b/api/admin/clean.go
@@ -11,10 +11,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
- "github.com/go-vela/types"
- "github.com/go-vela/types/constants"
)
// swagger:operation PUT /api/v1/admin/clean admin AdminCleanResources
diff --git a/api/admin/secret.go b/api/admin/secret.go
index f287e4227..f5e131e54 100644
--- a/api/admin/secret.go
+++ b/api/admin/secret.go
@@ -9,9 +9,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/admin/secret admin AdminUpdateSecret
@@ -57,7 +57,7 @@ func UpdateSecret(c *gin.Context) {
l.Debug("platform admin: updating secret")
// capture body from API request
- input := new(library.Secret)
+ input := new(types.Secret)
err := c.Bind(input)
if err != nil {
diff --git a/api/admin/service.go b/api/admin/service.go
index 13d33d199..5e5e5dcba 100644
--- a/api/admin/service.go
+++ b/api/admin/service.go
@@ -10,9 +10,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/admin/service admin AdminUpdateService
@@ -59,7 +59,7 @@ func UpdateService(c *gin.Context) {
l.Debug("platform admin: updating service")
// capture body from API request
- input := new(library.Service)
+ input := new(types.Service)
err := c.Bind(input)
if err != nil {
diff --git a/api/admin/step.go b/api/admin/step.go
index b29fc57e0..6e7ad4cdb 100644
--- a/api/admin/step.go
+++ b/api/admin/step.go
@@ -10,9 +10,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/admin/step admin AdminUpdateStep
@@ -58,7 +58,7 @@ func UpdateStep(c *gin.Context) {
l.Debug("platform admin: updating step")
// capture body from API request
- input := new(library.Step)
+ input := new(types.Step)
err := c.Bind(input)
if err != nil {
diff --git a/api/admin/worker.go b/api/admin/worker.go
index 59ed71a5e..955375818 100644
--- a/api/admin/worker.go
+++ b/api/admin/worker.go
@@ -9,10 +9,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/admin/workers/{worker}/register admin RegisterToken
@@ -72,5 +72,5 @@ func RegisterToken(c *gin.Context) {
l.Infof("platform admin: generated worker registration token for %s", host)
- c.JSON(http.StatusOK, library.Token{Token: &rt})
+ c.JSON(http.StatusOK, types.Token{Token: &rt})
}
diff --git a/api/auth/get_token.go b/api/auth/get_token.go
index 07df70b0c..1379ccea3 100644
--- a/api/auth/get_token.go
+++ b/api/auth/get_token.go
@@ -14,7 +14,6 @@ import (
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /authenticate authenticate GetAuthToken
@@ -140,7 +139,7 @@ func GetAuthToken(c *gin.Context) {
}).Info("new user created")
// return the jwt access token
- c.JSON(http.StatusOK, library.Token{Token: &at})
+ c.JSON(http.StatusOK, types.Token{Token: &at})
return
}
@@ -178,5 +177,5 @@ func GetAuthToken(c *gin.Context) {
}).Info("user updated - new token")
// return the user with their jwt access token
- c.JSON(http.StatusOK, library.Token{Token: &at})
+ c.JSON(http.StatusOK, types.Token{Token: &at})
}
diff --git a/api/auth/logout.go b/api/auth/logout.go
index 9acb575cd..77ac9c97f 100644
--- a/api/auth/logout.go
+++ b/api/auth/logout.go
@@ -10,11 +10,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /logout authenticate GetLogout
diff --git a/api/auth/post_token.go b/api/auth/post_token.go
index d5fc345c9..236082ff4 100644
--- a/api/auth/post_token.go
+++ b/api/auth/post_token.go
@@ -9,12 +9,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /authenticate/token authenticate PostAuthToken
@@ -98,5 +98,5 @@ func PostAuthToken(c *gin.Context) {
}
// return jwt access token
- c.JSON(http.StatusOK, library.Token{Token: &at})
+ c.JSON(http.StatusOK, types.Token{Token: &at})
}
diff --git a/api/auth/refresh.go b/api/auth/refresh.go
index 69d61bb1e..cec351cf7 100644
--- a/api/auth/refresh.go
+++ b/api/auth/refresh.go
@@ -9,10 +9,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/auth"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /token-refresh authenticate GetRefreshAccessToken
@@ -65,5 +65,5 @@ func RefreshAccessToken(c *gin.Context) {
return
}
- c.JSON(http.StatusOK, library.Token{Token: &newAccessToken})
+ c.JSON(http.StatusOK, types.Token{Token: &newAccessToken})
}
diff --git a/api/badge.go b/api/badge.go
index 37ffeb694..ce0ce0d76 100644
--- a/api/badge.go
+++ b/api/badge.go
@@ -8,10 +8,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /badge/{org}/{repo}/status.svg base GetBadge
diff --git a/api/build/approve.go b/api/build/approve.go
index 61b1b6a4e..bab499ae6 100644
--- a/api/build/approve.go
+++ b/api/build/approve.go
@@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/queue/models"
@@ -19,7 +20,6 @@ import (
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/approve builds ApproveBuild
diff --git a/api/build/auto_cancel.go b/api/build/auto_cancel.go
index 7f8a77f81..c34d24917 100644
--- a/api/build/auto_cancel.go
+++ b/api/build/auto_cancel.go
@@ -16,9 +16,9 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
- "github.com/go-vela/types/constants"
)
// AutoCancel is a helper function that checks to see if any pending or running
diff --git a/api/build/auto_cancel_test.go b/api/build/auto_cancel_test.go
index d3ad75ae7..bcd52ae6d 100644
--- a/api/build/auto_cancel_test.go
+++ b/api/build/auto_cancel_test.go
@@ -7,7 +7,7 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func Test_isCancelable(t *testing.T) {
diff --git a/api/build/cancel.go b/api/build/cancel.go
index 79d186799..3804f5deb 100644
--- a/api/build/cancel.go
+++ b/api/build/cancel.go
@@ -13,6 +13,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/build"
@@ -20,7 +21,6 @@ import (
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation DELETE /api/v1/repos/{org}/{repo}/builds/{build}/cancel builds CancelBuild
diff --git a/api/build/clean.go b/api/build/clean.go
index 5c70b5164..ead0f164b 100644
--- a/api/build/clean.go
+++ b/api/build/clean.go
@@ -10,15 +10,14 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// cleanBuild is a helper function to kill the build
// without execution. This will kill all resources,
// like steps and services, for the build.
-func CleanBuild(ctx context.Context, database database.Interface, b *types.Build, services []*library.Service, steps []*library.Step, e error) {
+func CleanBuild(ctx context.Context, database database.Interface, b *types.Build, services []*types.Service, steps []*types.Step, e error) {
l := logrus.WithFields(logrus.Fields{
"build": b.GetNumber(),
"build_id": b.GetID(),
diff --git a/api/build/compile_publish.go b/api/build/compile_publish.go
index 05111de4a..cc99e8579 100644
--- a/api/build/compile_publish.go
+++ b/api/build/compile_publish.go
@@ -16,12 +16,12 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/queue/models"
"github.com/go-vela/server/scm"
- "github.com/go-vela/types/constants"
)
// CompileAndPublishConfig is a struct that contains information for the CompileAndPublish function.
diff --git a/api/build/executable.go b/api/build/executable.go
index c0324a4de..866708689 100644
--- a/api/build/executable.go
+++ b/api/build/executable.go
@@ -17,7 +17,6 @@ import (
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/repos/{org}/{repo}/builds/{build}/executable builds GetBuildExecutable
@@ -106,7 +105,7 @@ func PublishBuildExecutable(ctx context.Context, db database.Interface, p *pipel
}
// create build executable to push to database
- bExecutable := new(library.BuildExecutable)
+ bExecutable := new(types.BuildExecutable)
bExecutable.SetBuildID(b.GetID())
bExecutable.SetData(byteExecutable)
diff --git a/api/build/graph.go b/api/build/graph.go
index 086c9261d..5db83eaa4 100644
--- a/api/build/graph.go
+++ b/api/build/graph.go
@@ -11,8 +11,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/router/middleware/build"
@@ -20,8 +22,6 @@ import (
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// Graph contains nodes, and relationships between nodes, or edges.
@@ -46,10 +46,10 @@ type node struct {
Name string `json:"name"`
// vela metadata
- Status string `json:"status"`
- StartedAt int `json:"started_at"`
- FinishedAt int `json:"finished_at"`
- Steps []*library.Step `json:"steps"`
+ Status string `json:"status"`
+ StartedAt int `json:"started_at"`
+ FinishedAt int `json:"finished_at"`
+ Steps []*types.Step `json:"steps"`
// unexported data used for building edges
Stage *pipeline.Stage `json:"-"`
@@ -67,7 +67,7 @@ type edge struct {
// stg represents a stage's steps and some metadata for producing node/edge information.
type stg struct {
- steps []*library.Step
+ steps []*types.Step
// used for tracking stage status
success int
running int
@@ -241,7 +241,7 @@ func GetBuildGraph(c *gin.Context) {
}
// retrieve the steps for the build from the step table
- steps := []*library.Step{}
+ steps := []*types.Step{}
page := 1
perPage := 100
@@ -279,7 +279,7 @@ func GetBuildGraph(c *gin.Context) {
}
// retrieve the services for the build from the service table
- services := []*library.Service{}
+ services := []*types.Service{}
page = 1
perPage = 100
@@ -359,7 +359,7 @@ func GetBuildGraph(c *gin.Context) {
// initialize a stage tracker
if _, ok := stageMap[name]; !ok {
stageMap[name] = &stg{
- steps: []*library.Step{},
+ steps: []*types.Step{},
}
}
@@ -615,13 +615,13 @@ func nodeFromStage(nodeID, cluster int, stage *pipeline.Stage, s *stg) *node {
}
// nodeFromService returns a new node from a service.
-func nodeFromService(nodeID int, service *library.Service) *node {
+func nodeFromService(nodeID int, service *types.Service) *node {
return &node{
ID: nodeID,
Cluster: ServiceCluster,
Name: service.GetName(),
Stage: nil,
- Steps: []*library.Step{},
+ Steps: []*types.Step{},
Status: service.GetStatus(),
StartedAt: int(service.GetStarted()),
FinishedAt: int(service.GetFinished()),
diff --git a/api/build/id_request_token.go b/api/build/id_request_token.go
index 77869a44c..e557a2ee5 100644
--- a/api/build/id_request_token.go
+++ b/api/build/id_request_token.go
@@ -12,11 +12,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/repos/{org}/{repo}/builds/{build}/id_request_token builds GetIDRequestToken
@@ -145,5 +145,5 @@ func GetIDRequestToken(c *gin.Context) {
return
}
- c.JSON(http.StatusOK, library.Token{Token: &idrt})
+ c.JSON(http.StatusOK, types.Token{Token: &idrt})
}
diff --git a/api/build/id_token.go b/api/build/id_token.go
index e049dcebd..f896d8df4 100644
--- a/api/build/id_token.go
+++ b/api/build/id_token.go
@@ -9,13 +9,13 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/repos/{org}/{repo}/builds/{build}/id_token builds GetIDToken
@@ -127,5 +127,5 @@ func GetIDToken(c *gin.Context) {
return
}
- c.JSON(http.StatusOK, library.Token{Token: &idt})
+ c.JSON(http.StatusOK, types.Token{Token: &idt})
}
diff --git a/api/build/list_org.go b/api/build/list_org.go
index 6dca24e1b..fd00559ef 100644
--- a/api/build/list_org.go
+++ b/api/build/list_org.go
@@ -12,12 +12,12 @@ import (
"github.com/go-vela/server/api"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /api/v1/repos/{org}/builds builds ListBuildsForOrg
diff --git a/api/build/list_repo.go b/api/build/list_repo.go
index 44ffee206..1d7fae833 100644
--- a/api/build/list_repo.go
+++ b/api/build/list_repo.go
@@ -13,10 +13,10 @@ import (
"github.com/go-vela/server/api"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /api/v1/repos/{org}/{repo}/builds builds ListBuildsForRepo
diff --git a/api/build/restart.go b/api/build/restart.go
index 24b30409d..56cffae38 100644
--- a/api/build/restart.go
+++ b/api/build/restart.go
@@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/compiler"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/queue"
@@ -21,7 +22,6 @@ import (
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build} builds RestartBuild
diff --git a/api/build/token.go b/api/build/token.go
index b2126bb84..a2c56d45e 100644
--- a/api/build/token.go
+++ b/api/build/token.go
@@ -11,13 +11,13 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/repos/{org}/{repo}/builds/{build}/token builds GetBuildToken
@@ -109,5 +109,5 @@ func GetBuildToken(c *gin.Context) {
return
}
- c.JSON(http.StatusOK, library.Token{Token: &bt})
+ c.JSON(http.StatusOK, types.Token{Token: &bt})
}
diff --git a/api/build/update.go b/api/build/update.go
index eabe94981..83fc3f9b3 100644
--- a/api/build/update.go
+++ b/api/build/update.go
@@ -10,13 +10,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build} builds UpdateBuild
@@ -191,7 +190,7 @@ func UpdateComponentStatuses(c *gin.Context, b *types.Build, status string) erro
l.Debug("updating component statuses")
// retrieve the steps for the build from the step table
- steps := []*library.Step{}
+ steps := []*types.Step{}
page := 1
perPage := 100
@@ -230,7 +229,7 @@ func UpdateComponentStatuses(c *gin.Context, b *types.Build, status string) erro
}
// retrieve the services for the build from the service table
- services := []*library.Service{}
+ services := []*types.Service{}
page = 1
for page > 0 {
diff --git a/api/log/create_service.go b/api/log/create_service.go
index 736f1fca5..fda667ae5 100644
--- a/api/log/create_service.go
+++ b/api/log/create_service.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/service"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/services/{service}/logs services CreateServiceLog
@@ -90,7 +90,7 @@ func CreateServiceLog(c *gin.Context) {
l.Debugf("creating logs for service %s", entry)
// capture body from API request
- input := new(library.Log)
+ input := new(types.Log)
err := c.Bind(input)
if err != nil {
diff --git a/api/log/create_step.go b/api/log/create_step.go
index 2a92abab7..507d19798 100644
--- a/api/log/create_step.go
+++ b/api/log/create_step.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/step"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/steps/{step}/logs steps CreateStepLog
@@ -90,7 +90,7 @@ func CreateStepLog(c *gin.Context) {
l.Debugf("creating logs for step %s", entry)
// capture body from API request
- input := new(library.Log)
+ input := new(types.Log)
err := c.Bind(input)
if err != nil {
diff --git a/api/log/update_service.go b/api/log/update_service.go
index dd8b8329d..646a0d031 100644
--- a/api/log/update_service.go
+++ b/api/log/update_service.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/service"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build}/services/{service}/logs services UpdateServiceLog
@@ -100,7 +100,7 @@ func UpdateServiceLog(c *gin.Context) {
}
// capture body from API request
- input := new(library.Log)
+ input := new(types.Log)
err = c.Bind(input)
if err != nil {
diff --git a/api/log/update_step.go b/api/log/update_step.go
index ff19da7da..7204afdb0 100644
--- a/api/log/update_step.go
+++ b/api/log/update_step.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/step"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build}/steps/{step}/logs steps UpdateStepLog
@@ -100,7 +100,7 @@ func UpdateStepLog(c *gin.Context) {
}
// capture body from API request
- input := new(library.Log)
+ input := new(types.Log)
err = c.Bind(input)
if err != nil {
diff --git a/api/metrics.go b/api/metrics.go
index e23fa1d62..77609c497 100644
--- a/api/metrics.go
+++ b/api/metrics.go
@@ -12,9 +12,9 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/queue"
- "github.com/go-vela/types/constants"
)
// MetricsQueryParameters holds query parameter information pertaining to requested metrics.
diff --git a/api/pipeline/template.go b/api/pipeline/template.go
index 8703bd9c9..aef79d165 100644
--- a/api/pipeline/template.go
+++ b/api/pipeline/template.go
@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/compiler/registry/github"
"github.com/go-vela/server/compiler/types/yaml"
@@ -20,7 +21,6 @@ import (
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/pipelines/{org}/{repo}/{pipeline}/templates pipelines GetTemplates
@@ -110,9 +110,9 @@ func GetTemplates(c *gin.Context) {
baseErr := fmt.Sprintf("unable to set template links for %s", entry)
- templates := make(map[string]*library.Template)
+ templates := make(map[string]*types.Template)
for name, template := range pipeline.Templates.Map() {
- templates[name] = template.ToLibrary()
+ templates[name] = template.ToAPI()
// create a compiler registry client for parsing (no address or token needed for Parse)
registry, err := github.New(ctx, "", "")
diff --git a/api/queue/queue.go b/api/queue/queue.go
index 2c5698bb6..ff7410095 100644
--- a/api/queue/queue.go
+++ b/api/queue/queue.go
@@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/api/types"
)
// swagger:operation POST /api/v1/queue/info queue Info
@@ -43,7 +43,7 @@ func Info(c *gin.Context) {
// extract the queue-address that was packed into gin context
a := c.MustGet("queue-address").(string)
- wr := library.QueueInfo{
+ wr := types.QueueInfo{
QueuePublicKey: &k,
QueueAddress: &a,
}
diff --git a/api/repo/create.go b/api/repo/create.go
index cdd6848a3..3e35be3f0 100644
--- a/api/repo/create.go
+++ b/api/repo/create.go
@@ -14,12 +14,12 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/settings"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation POST /api/v1/repos repos CreateRepo
diff --git a/api/repo/list_org.go b/api/repo/list_org.go
index ba306e942..75f6a2aa1 100644
--- a/api/repo/list_org.go
+++ b/api/repo/list_org.go
@@ -11,12 +11,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /api/v1/repos/{org} repos ListReposForOrg
diff --git a/api/repo/update.go b/api/repo/update.go
index 683df18bc..001a67626 100644
--- a/api/repo/update.go
+++ b/api/repo/update.go
@@ -13,12 +13,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation PUT /api/v1/repos/{org}/{repo} repos UpdateRepo
diff --git a/api/secret/create.go b/api/secret/create.go
index 6c4c502b1..fd89341b9 100644
--- a/api/secret/create.go
+++ b/api/secret/create.go
@@ -11,13 +11,13 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/api/types/actions"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
- "github.com/go-vela/types/library/actions"
)
// swagger:operation POST /api/v1/secrets/{engine}/{type}/{org}/{name} secrets CreateSecret
@@ -175,7 +175,7 @@ func CreateSecret(c *gin.Context) {
logger.Debugf("creating new secret %s for %s service", entry, e)
// capture body from API request
- input := new(library.Secret)
+ input := new(types.Secret)
err := c.Bind(input)
if err != nil {
@@ -211,7 +211,7 @@ func CreateSecret(c *gin.Context) {
// default event set for secrets
if input.GetAllowEvents().ToDatabase() == 0 {
- e := new(library.Events)
+ e := new(types.Events)
push := new(actions.Push)
push.SetBranch(true)
diff --git a/api/secret/delete.go b/api/secret/delete.go
index c038c1a08..f50e1e619 100644
--- a/api/secret/delete.go
+++ b/api/secret/delete.go
@@ -10,9 +10,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation DELETE /api/v1/secrets/{engine}/{type}/{org}/{name}/{secret} secrets DeleteSecret
diff --git a/api/secret/get.go b/api/secret/get.go
index 72a84fc18..71f0f3d60 100644
--- a/api/secret/get.go
+++ b/api/secret/get.go
@@ -10,10 +10,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// swagger:operation GET /api/v1/secrets/{engine}/{type}/{org}/{name}/{secret} secrets GetSecret
diff --git a/api/secret/list.go b/api/secret/list.go
index d06371398..f7e21e706 100644
--- a/api/secret/list.go
+++ b/api/secret/list.go
@@ -12,12 +12,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation GET /api/v1/secrets/{engine}/{type}/{org}/{name} secrets ListSecrets
@@ -195,7 +195,7 @@ func ListSecrets(c *gin.Context) {
pagination.SetHeaderLink(c)
// variable we want to return
- secrets := []*library.Secret{}
+ secrets := []*types.Secret{}
// iterate through all secrets
for _, secret := range s {
// https://golang.org/doc/faq#closures_and_goroutines
diff --git a/api/secret/update.go b/api/secret/update.go
index 0d7d62072..dbd5eb971 100644
--- a/api/secret/update.go
+++ b/api/secret/update.go
@@ -11,11 +11,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
//
@@ -118,7 +118,7 @@ func UpdateSecret(c *gin.Context) {
l.WithFields(fields).Debugf("updating secret %s for %s service", entry, e)
// capture body from API request
- input := new(library.Secret)
+ input := new(types.Secret)
err := c.Bind(input)
if err != nil {
diff --git a/api/service/create.go b/api/service/create.go
index 4e3ee47c7..fd8909f20 100644
--- a/api/service/create.go
+++ b/api/service/create.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/services services CreateService
@@ -85,7 +85,7 @@ func CreateService(c *gin.Context) {
l.Debugf("creating new service for build %s", entry)
// capture body from API request
- input := new(library.Service)
+ input := new(types.Service)
err := c.Bind(input)
if err != nil {
diff --git a/api/service/plan.go b/api/service/plan.go
index 6efa6b2a5..963522120 100644
--- a/api/service/plan.go
+++ b/api/service/plan.go
@@ -11,22 +11,21 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// PlanServices is a helper function to plan all services
// in the build for execution. This creates the services
// for the build.
-func PlanServices(ctx context.Context, database database.Interface, p *pipeline.Build, b *types.Build) ([]*library.Service, error) {
+func PlanServices(ctx context.Context, database database.Interface, p *pipeline.Build, b *types.Build) ([]*types.Service, error) {
// variable to store planned services
- services := []*library.Service{}
+ services := []*types.Service{}
// iterate through all pipeline services
for _, service := range p.Services {
// create the service object
- s := new(library.Service)
+ s := new(types.Service)
s.SetBuildID(b.GetID())
s.SetRepoID(b.GetRepo().GetID())
s.SetName(service.Name)
@@ -49,16 +48,13 @@ func PlanServices(ctx context.Context, database database.Interface, p *pipeline.
"repo_id": b.GetRepo().GetID(),
}).Info("service created")
- // populate environment variables from service library
- //
- // https://pkg.go.dev/github.com/go-vela/types/library#Service.Environment
err = service.MergeEnv(s.Environment())
if err != nil {
return services, err
}
// create the log object
- l := new(library.Log)
+ l := new(types.Log)
l.SetServiceID(s.GetID())
l.SetBuildID(b.GetID())
l.SetRepoID(b.GetRepo().GetID())
diff --git a/api/service/update.go b/api/service/update.go
index a7e047a60..5815f1abb 100644
--- a/api/service/update.go
+++ b/api/service/update.go
@@ -9,12 +9,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/service"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
//
@@ -91,7 +91,7 @@ func UpdateService(c *gin.Context) {
l.Debugf("updating service %s", entry)
// capture body from API request
- input := new(library.Service)
+ input := new(types.Service)
err := c.Bind(input)
if err != nil {
diff --git a/api/step/create.go b/api/step/create.go
index b9a113de4..6bbbe7746 100644
--- a/api/step/create.go
+++ b/api/step/create.go
@@ -10,12 +10,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/steps steps CreateStep
@@ -85,7 +85,7 @@ func CreateStep(c *gin.Context) {
l.Debugf("creating new step for build %s", entry)
// capture body from API request
- input := new(library.Step)
+ input := new(types.Step)
err := c.Bind(input)
if err != nil {
diff --git a/api/step/plan.go b/api/step/plan.go
index 5bbc1ac84..cb85d1c35 100644
--- a/api/step/plan.go
+++ b/api/step/plan.go
@@ -11,18 +11,17 @@ import (
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/scm"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// PlanSteps is a helper function to plan all steps
// in the build for execution. This creates the steps
// for the build.
-func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*library.Step, error) {
+func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*types.Step, error) {
// variable to store planned steps
- steps := []*library.Step{}
+ steps := []*types.Step{}
// iterate through all pipeline stages
for _, stage := range p.Stages {
@@ -51,9 +50,9 @@ func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service
return steps, nil
}
-func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*library.Step, error) {
+func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*types.Step, error) {
// create the step object
- s := new(library.Step)
+ s := new(types.Step)
s.SetBuildID(b.GetID())
s.SetRepoID(b.GetRepo().GetID())
s.SetNumber(c.Number)
@@ -78,16 +77,14 @@ func planStep(ctx context.Context, database database.Interface, scm scm.Service,
"repo_id": b.GetRepo().GetID(),
}).Info("step created")
- // populate environment variables from step library
- //
- // https://pkg.go.dev/github.com/go-vela/types/library#step.Environment
+ // populate environment variables from step
err = c.MergeEnv(s.Environment())
if err != nil {
return nil, err
}
// create the log object
- l := new(library.Log)
+ l := new(types.Log)
l.SetStepID(s.GetID())
l.SetBuildID(b.GetID())
l.SetRepoID(b.GetRepo().GetID())
diff --git a/api/step/update.go b/api/step/update.go
index c543de2c8..d456956d6 100644
--- a/api/step/update.go
+++ b/api/step/update.go
@@ -9,14 +9,14 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/step"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build}/steps/{step} steps UpdateStep
@@ -92,7 +92,7 @@ func UpdateStep(c *gin.Context) {
l.Debugf("updating step %s", entry)
// capture body from API request
- input := new(library.Step)
+ input := new(types.Step)
err := c.Bind(input)
if err != nil {
diff --git a/api/types/actions/comment.go b/api/types/actions/comment.go
index 552aa3800..716d87a3c 100644
--- a/api/types/actions/comment.go
+++ b/api/types/actions/comment.go
@@ -2,7 +2,7 @@
package actions
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Comment is the API representation of the various actions associated
// with the comment event webhook from the SCM.
diff --git a/api/types/actions/comment_test.go b/api/types/actions/comment_test.go
index 1ffc465b8..2344f1d3b 100644
--- a/api/types/actions/comment_test.go
+++ b/api/types/actions/comment_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Comment_Getters(t *testing.T) {
diff --git a/api/types/actions/deploy.go b/api/types/actions/deploy.go
index 5dd7a4242..1664c39d3 100644
--- a/api/types/actions/deploy.go
+++ b/api/types/actions/deploy.go
@@ -3,7 +3,7 @@
//nolint:dupl // similar code to schedule.go
package actions
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Deploy is the API representation of the various actions associated
// with the deploy event webhook from the SCM.
diff --git a/api/types/actions/deploy_test.go b/api/types/actions/deploy_test.go
index 373407c7f..05809764c 100644
--- a/api/types/actions/deploy_test.go
+++ b/api/types/actions/deploy_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Deploy_Getters(t *testing.T) {
diff --git a/api/types/actions/pull.go b/api/types/actions/pull.go
index fd35fe7eb..1635709d5 100644
--- a/api/types/actions/pull.go
+++ b/api/types/actions/pull.go
@@ -2,7 +2,7 @@
package actions
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Pull is the API representation of the various actions associated
// with the pull_request event webhook from the SCM.
diff --git a/api/types/actions/pull_test.go b/api/types/actions/pull_test.go
index 0ff17d6ad..4be4b0b60 100644
--- a/api/types/actions/pull_test.go
+++ b/api/types/actions/pull_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestActions_Pull_Getters(t *testing.T) {
diff --git a/api/types/actions/push.go b/api/types/actions/push.go
index 6d5b24a6f..e48eb0f3d 100644
--- a/api/types/actions/push.go
+++ b/api/types/actions/push.go
@@ -2,7 +2,7 @@
package actions
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Push is the API representation of the various actions associated
// with the push event webhook from the SCM.
diff --git a/api/types/actions/push_test.go b/api/types/actions/push_test.go
index 259f7db2b..1d1be093a 100644
--- a/api/types/actions/push_test.go
+++ b/api/types/actions/push_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Push_Getters(t *testing.T) {
diff --git a/api/types/actions/schedule.go b/api/types/actions/schedule.go
index bc4588d2f..296f0ba16 100644
--- a/api/types/actions/schedule.go
+++ b/api/types/actions/schedule.go
@@ -3,7 +3,7 @@
//nolint:dupl // similar code to deploy.go
package actions
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Schedule is the API representation of the various actions associated
// with the schedule event.
diff --git a/api/types/actions/schedule_test.go b/api/types/actions/schedule_test.go
index 8a06b0d75..5d3c9fa03 100644
--- a/api/types/actions/schedule_test.go
+++ b/api/types/actions/schedule_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Schedule_Getters(t *testing.T) {
diff --git a/api/types/build.go b/api/types/build.go
index f9ba8ea49..f5af28911 100644
--- a/api/types/build.go
+++ b/api/types/build.go
@@ -8,7 +8,7 @@ import (
"time"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Build is the API types representation of a build for a pipeline.
diff --git a/api/types/build_executable.go b/api/types/build_executable.go
new file mode 100644
index 000000000..95030d423
--- /dev/null
+++ b/api/types/build_executable.go
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+)
+
+// BuildExecutable is the API representation of a BuildExecutable.
+//
+// swagger:model BuildExecutable
+type BuildExecutable struct {
+ ID *int64 `json:"id,omitempty"`
+ BuildID *int64 `json:"build_id,omitempty"`
+ // swagger:strfmt base64
+ Data *[]byte `json:"data,omitempty"`
+}
+
+// GetID returns the ID field.
+//
+// When the provided BuildExecutable type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (b *BuildExecutable) GetID() int64 {
+ // return zero value if BuildExecutable type or ID field is nil
+ if b == nil || b.ID == nil {
+ return 0
+ }
+
+ return *b.ID
+}
+
+// GetBuildID returns the BuildID field.
+//
+// When the provided BuildExecutable type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (b *BuildExecutable) GetBuildID() int64 {
+ // return zero value if BuildExecutable type or BuildID field is nil
+ if b == nil || b.BuildID == nil {
+ return 0
+ }
+
+ return *b.BuildID
+}
+
+// GetData returns the Data field.
+//
+// When the provided BuildExecutable type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (b *BuildExecutable) GetData() []byte {
+ // return zero value if BuildExecutable type or Data field is nil
+ if b == nil || b.Data == nil {
+ return []byte{}
+ }
+
+ return *b.Data
+}
+
+// SetID sets the ID field.
+//
+// When the provided BuildExecutable type is nil, it
+// will set nothing and immediately return.
+func (b *BuildExecutable) SetID(v int64) {
+ // return if BuildExecutable type is nil
+ if b == nil {
+ return
+ }
+
+ b.ID = &v
+}
+
+// SetBuildID sets the BuildID field.
+//
+// When the provided BuildExecutable type is nil, it
+// will set nothing and immediately return.
+func (b *BuildExecutable) SetBuildID(v int64) {
+ // return if BuildExecutable type is nil
+ if b == nil {
+ return
+ }
+
+ b.BuildID = &v
+}
+
+// SetData sets the Data field.
+//
+// When the provided BuildExecutable type is nil, it
+// will set nothing and immediately return.
+func (b *BuildExecutable) SetData(v []byte) {
+ // return if Log type is nil
+ if b == nil {
+ return
+ }
+
+ b.Data = &v
+}
+
+// String implements the Stringer interface for the BuildExecutable type.
+func (b *BuildExecutable) String() string {
+ return fmt.Sprintf(`{
+ ID: %d,
+ BuildID: %d,
+ Data: %s,
+}`,
+ b.GetID(),
+ b.GetBuildID(),
+ b.GetData(),
+ )
+}
diff --git a/api/types/build_executable_test.go b/api/types/build_executable_test.go
new file mode 100644
index 000000000..21ab41e6a
--- /dev/null
+++ b/api/types/build_executable_test.go
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestTypes_BuildExecutable_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ buildExecutable *BuildExecutable
+ want *BuildExecutable
+ }{
+ {
+ buildExecutable: testBuildExecutable(),
+ want: testBuildExecutable(),
+ },
+ {
+ buildExecutable: new(BuildExecutable),
+ want: new(BuildExecutable),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.buildExecutable.GetID() != test.want.GetID() {
+ t.Errorf("GetID is %v, want %v", test.buildExecutable.GetID(), test.want.GetID())
+ }
+
+ if test.buildExecutable.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("GetBuildID is %v, want %v", test.buildExecutable.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if !reflect.DeepEqual(test.buildExecutable.GetData(), test.want.GetData()) {
+ t.Errorf("GetData is %v, want %v", test.buildExecutable.GetData(), test.want.GetData())
+ }
+ }
+}
+
+func TestTypes_BuildExecutable_Setters(t *testing.T) {
+ // setup types
+ var bExecutable *BuildExecutable
+
+ // setup tests
+ tests := []struct {
+ buildExecutable *BuildExecutable
+ want *BuildExecutable
+ }{
+ {
+ buildExecutable: testBuildExecutable(),
+ want: testBuildExecutable(),
+ },
+ {
+ buildExecutable: bExecutable,
+ want: new(BuildExecutable),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.buildExecutable.SetID(test.want.GetID())
+ test.buildExecutable.SetBuildID(test.want.GetBuildID())
+ test.buildExecutable.SetData(test.want.GetData())
+
+ if test.buildExecutable.GetID() != test.want.GetID() {
+ t.Errorf("SetID is %v, want %v", test.buildExecutable.GetID(), test.want.GetID())
+ }
+
+ if test.buildExecutable.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("SetRepoID is %v, want %v", test.buildExecutable.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if !reflect.DeepEqual(test.buildExecutable.GetData(), test.want.GetData()) {
+ t.Errorf("SetData is %v, want %v", test.buildExecutable.GetData(), test.want.GetData())
+ }
+ }
+}
+
+func TestTypes_BuildExecutable_String(t *testing.T) {
+ // setup types
+ bExecutable := testBuildExecutable()
+
+ want := fmt.Sprintf(`{
+ ID: %d,
+ BuildID: %d,
+ Data: %s,
+}`,
+ bExecutable.GetID(),
+ bExecutable.GetBuildID(),
+ bExecutable.GetData(),
+ )
+
+ // run test
+ got := bExecutable.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+// testBuildExecutable is a test helper function to create a Pipeline
+// type with all fields set to a fake value.
+func testBuildExecutable() *BuildExecutable {
+ p := new(BuildExecutable)
+
+ p.SetID(1)
+ p.SetBuildID(1)
+ p.SetData(testBuildExecutableData())
+
+ return p
+}
+
+// testBuildExecutableData is a test helper function to create the
+// content for the Data field for the Pipeline type.
+func testBuildExecutableData() []byte {
+ return []byte(`
+{
+ "id": "step_name",
+ "version": "1",
+ "metadata":{
+ "clone":true,
+ "environment":["steps","services","secrets"]},
+ "worker":{},
+ "steps":[
+ {
+ "id":"step_github_octocat_1_init",
+ "directory":"/vela/src/github.com/github/octocat",
+ "environment": {"BUILD_AUTHOR":"Octocat"}
+ }
+ ]
+}
+`)
+}
diff --git a/api/types/error.go b/api/types/error.go
new file mode 100644
index 000000000..a3c7b919b
--- /dev/null
+++ b/api/types/error.go
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import "fmt"
+
+// Error is the json error message from the server for a given http response.
+//
+// swagger:model Error
+type Error struct {
+ Message *string `json:"error"`
+}
+
+func (e *Error) String() string {
+ return fmt.Sprintf("%+v", *e)
+}
diff --git a/api/types/error_test.go b/api/types/error_test.go
new file mode 100644
index 000000000..4c1c7b3d0
--- /dev/null
+++ b/api/types/error_test.go
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestResp_String(t *testing.T) {
+ // setup types
+ str := "foo"
+ e := &Error{
+ Message: &str,
+ }
+ want := fmt.Sprintf("%+v", *e)
+
+ // run test
+ got := e.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
diff --git a/api/types/events.go b/api/types/events.go
index 8bf27db8c..0bc0b10ee 100644
--- a/api/types/events.go
+++ b/api/types/events.go
@@ -6,7 +6,7 @@ import (
"fmt"
"github.com/go-vela/server/api/types/actions"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Events is the API representation of the various events that generate a
diff --git a/api/types/events_test.go b/api/types/events_test.go
index 68f6f5709..882364f97 100644
--- a/api/types/events_test.go
+++ b/api/types/events_test.go
@@ -9,7 +9,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/go-vela/server/api/types/actions"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Events_Getters(t *testing.T) {
diff --git a/api/types/log.go b/api/types/log.go
new file mode 100644
index 000000000..3f2c52d5b
--- /dev/null
+++ b/api/types/log.go
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "bytes"
+ "fmt"
+
+ "github.com/go-vela/server/constants"
+)
+
+// Log is the API representation of a log for a step in a build.
+//
+// swagger:model Log
+type Log struct {
+ ID *int64 `json:"id,omitempty"`
+ BuildID *int64 `json:"build_id,omitempty"`
+ RepoID *int64 `json:"repo_id,omitempty"`
+ ServiceID *int64 `json:"service_id,omitempty"`
+ StepID *int64 `json:"step_id,omitempty"`
+ // swagger:strfmt base64
+ Data *[]byte `json:"data,omitempty"`
+}
+
+// AppendData adds the provided data to the end of
+// the Data field for the Log type. If the Data
+// field is empty, then the function overwrites
+// the entire Data field.
+func (l *Log) AppendData(data []byte) {
+ // check if Data field is empty
+ if len(l.GetData()) == 0 {
+ // overwrite the Data field
+ l.SetData(data)
+
+ return
+ }
+
+ // add the data to the Data field
+ l.SetData(append(l.GetData(), data...))
+}
+
+// MaskData reads through the log data and masks
+// all values provided in the string slice. If the
+// log is empty, we do nothing.
+func (l *Log) MaskData(secrets []string) {
+ data := l.GetData()
+
+ // early exit on empty log or secret list
+ if len(data) == 0 || len(secrets) == 0 {
+ return
+ }
+
+ // byte replace data with masked logs
+ for _, secret := range secrets {
+ data = bytes.ReplaceAll(data, []byte(secret), []byte(constants.SecretLogMask))
+ }
+
+ // update data field to masked logs
+ l.SetData(data)
+}
+
+// GetID returns the ID field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetID() int64 {
+ // return zero value if Log type or ID field is nil
+ if l == nil || l.ID == nil {
+ return 0
+ }
+
+ return *l.ID
+}
+
+// GetBuildID returns the BuildID field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetBuildID() int64 {
+ // return zero value if Log type or BuildID field is nil
+ if l == nil || l.BuildID == nil {
+ return 0
+ }
+
+ return *l.BuildID
+}
+
+// GetRepoID returns the RepoID field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetRepoID() int64 {
+ // return zero value if Log type or RepoID field is nil
+ if l == nil || l.RepoID == nil {
+ return 0
+ }
+
+ return *l.RepoID
+}
+
+// GetServiceID returns the ServiceID field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetServiceID() int64 {
+ // return zero value if Log type or ServiceID field is nil
+ if l == nil || l.ServiceID == nil {
+ return 0
+ }
+
+ return *l.ServiceID
+}
+
+// GetStepID returns the StepID field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetStepID() int64 {
+ // return zero value if Log type or StepID field is nil
+ if l == nil || l.StepID == nil {
+ return 0
+ }
+
+ return *l.StepID
+}
+
+// GetData returns the Data field.
+//
+// When the provided Log type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Log) GetData() []byte {
+ // return zero value if Log type or Data field is nil
+ if l == nil || l.Data == nil {
+ return []byte{}
+ }
+
+ return *l.Data
+}
+
+// SetID sets the ID field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetID(v int64) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.ID = &v
+}
+
+// SetBuildID sets the BuildID field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetBuildID(v int64) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.BuildID = &v
+}
+
+// SetRepoID sets the RepoID field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetRepoID(v int64) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.RepoID = &v
+}
+
+// SetServiceID sets the ServiceID field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetServiceID(v int64) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.ServiceID = &v
+}
+
+// SetStepID sets the StepID field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetStepID(v int64) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.StepID = &v
+}
+
+// SetData sets the Data field.
+//
+// When the provided Log type is nil, it
+// will set nothing and immediately return.
+func (l *Log) SetData(v []byte) {
+ // return if Log type is nil
+ if l == nil {
+ return
+ }
+
+ l.Data = &v
+}
+
+// String implements the Stringer interface for the Log type.
+func (l *Log) String() string {
+ return fmt.Sprintf(`{
+ BuildID: %d,
+ Data: %s,
+ ID: %d,
+ RepoID: %d,
+ ServiceID: %d,
+ StepID: %d,
+}`,
+ l.GetBuildID(),
+ l.GetData(),
+ l.GetID(),
+ l.GetRepoID(),
+ l.GetServiceID(),
+ l.GetStepID(),
+ )
+}
diff --git a/api/types/log_test.go b/api/types/log_test.go
new file mode 100644
index 000000000..39a3f68ae
--- /dev/null
+++ b/api/types/log_test.go
@@ -0,0 +1,277 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestTypes_Log_AppendData(t *testing.T) {
+ // setup types
+ data := []byte("bar")
+
+ want := testLog()
+ want.SetData([]byte("foobar"))
+
+ // setup tests
+ tests := []struct {
+ log *Log
+ want *Log
+ }{
+ {
+ log: testLog(),
+ want: want,
+ },
+ {
+ log: new(Log),
+ want: &Log{Data: &data},
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.log.AppendData(data)
+
+ if !reflect.DeepEqual(test.log, test.want) {
+ t.Errorf("AppendData is %v, want %v", test.log, test.want)
+ }
+ }
+}
+
+func TestTypes_Log_MaskData(t *testing.T) {
+ // set up test secrets
+ sVals := []string{"gh_abc123def456", "((%.YY245***pP.><@@}}", "quick-bear-fox-squid", "SUPERSECRETVALUE"}
+
+ tests := []struct {
+ log []byte
+ want []byte
+ secrets []string
+ }{
+ { // no secrets in log
+ log: []byte(
+ "$ echo hello\nhello\n",
+ ),
+ want: []byte(
+ "$ echo hello\nhello\n",
+ ),
+ secrets: sVals,
+ },
+ { // one secret in log
+ log: []byte(
+ "((%.YY245***pP.><@@}}",
+ ),
+ want: []byte(
+ "***",
+ ),
+ secrets: sVals,
+ },
+ { // multiple secrets in log
+ log: []byte(
+ "$ echo $SECRET1\n((%.YY245***pP.><@@}}\n$ echo $SECRET2\nquick-bear-fox-squid\n",
+ ),
+ want: []byte(
+ "$ echo $SECRET1\n***\n$ echo $SECRET2\n***\n",
+ ),
+ secrets: sVals,
+ },
+ { // secret with leading =
+ log: []byte(
+ "SOME_SECRET=((%.YY245***pP.><@@}}",
+ ),
+ want: []byte(
+ "SOME_SECRET=***",
+ ),
+ secrets: sVals,
+ },
+ { // secret baked in URL query params
+ log: []byte(
+ "www.example.com?username=quick-bear-fox-squid&password=SUPERSECRETVALUE",
+ ),
+ want: []byte(
+ "www.example.com?username=***&password=***",
+ ),
+ secrets: sVals,
+ },
+ { // secret in verbose brackets
+ log: []byte(
+ "[token: gh_abc123def456]",
+ ),
+ want: []byte(
+ "[token: ***]",
+ ),
+ secrets: sVals,
+ },
+ { // double secret
+ log: []byte(
+ "echo ${GITHUB_TOKEN}${SUPER_SECRET}\ngh_abc123def456SUPERSECRETVALUE\n",
+ ),
+ want: []byte(
+ "echo ${GITHUB_TOKEN}${SUPER_SECRET}\n******\n",
+ ),
+ secrets: sVals,
+ },
+ { // empty secrets slice
+ log: []byte(
+ "echo hello\nhello\n",
+ ),
+ want: []byte(
+ "echo hello\nhello\n",
+ ),
+ secrets: []string{},
+ },
+ }
+ // run tests
+ l := testLog()
+ for _, test := range tests {
+ l.SetData(test.log)
+ l.MaskData(test.secrets)
+
+ got := l.GetData()
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("MaskData is %v, want %v", string(got), string(test.want))
+ }
+ }
+}
+
+func TestTypes_Log_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ log *Log
+ want *Log
+ }{
+ {
+ log: testLog(),
+ want: testLog(),
+ },
+ {
+ log: new(Log),
+ want: new(Log),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.log.GetID() != test.want.GetID() {
+ t.Errorf("GetID is %v, want %v", test.log.GetID(), test.want.GetID())
+ }
+
+ if test.log.GetServiceID() != test.want.GetServiceID() {
+ t.Errorf("GetServiceID is %v, want %v", test.log.GetServiceID(), test.want.GetServiceID())
+ }
+
+ if test.log.GetStepID() != test.want.GetStepID() {
+ t.Errorf("GetStepID is %v, want %v", test.log.GetStepID(), test.want.GetStepID())
+ }
+
+ if test.log.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("GetBuildID is %v, want %v", test.log.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if test.log.GetRepoID() != test.want.GetRepoID() {
+ t.Errorf("GetRepoID is %v, want %v", test.log.GetRepoID(), test.want.GetRepoID())
+ }
+
+ if !reflect.DeepEqual(test.log.GetData(), test.want.GetData()) {
+ t.Errorf("GetData is %v, want %v", test.log.GetData(), test.want.GetData())
+ }
+ }
+}
+
+func TestTypes_Log_Setters(t *testing.T) {
+ // setup types
+ var l *Log
+
+ // setup tests
+ tests := []struct {
+ log *Log
+ want *Log
+ }{
+ {
+ log: testLog(),
+ want: testLog(),
+ },
+ {
+ log: l,
+ want: new(Log),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.log.SetID(test.want.GetID())
+ test.log.SetServiceID(test.want.GetServiceID())
+ test.log.SetStepID(test.want.GetStepID())
+ test.log.SetBuildID(test.want.GetBuildID())
+ test.log.SetRepoID(test.want.GetRepoID())
+ test.log.SetData(test.want.GetData())
+
+ if test.log.GetID() != test.want.GetID() {
+ t.Errorf("SetID is %v, want %v", test.log.GetID(), test.want.GetID())
+ }
+
+ if test.log.GetServiceID() != test.want.GetServiceID() {
+ t.Errorf("SetServiceID is %v, want %v", test.log.GetServiceID(), test.want.GetServiceID())
+ }
+
+ if test.log.GetStepID() != test.want.GetStepID() {
+ t.Errorf("SetStepID is %v, want %v", test.log.GetStepID(), test.want.GetStepID())
+ }
+
+ if test.log.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("SetBuildID is %v, want %v", test.log.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if test.log.GetRepoID() != test.want.GetRepoID() {
+ t.Errorf("SetRepoID is %v, want %v", test.log.GetRepoID(), test.want.GetRepoID())
+ }
+
+ if !reflect.DeepEqual(test.log.GetData(), test.want.GetData()) {
+ t.Errorf("SetData is %v, want %v", test.log.GetData(), test.want.GetData())
+ }
+ }
+}
+
+func TestTypes_Log_String(t *testing.T) {
+ // setup types
+ l := testLog()
+
+ want := fmt.Sprintf(`{
+ BuildID: %d,
+ Data: %s,
+ ID: %d,
+ RepoID: %d,
+ ServiceID: %d,
+ StepID: %d,
+}`,
+ l.GetBuildID(),
+ l.GetData(),
+ l.GetID(),
+ l.GetRepoID(),
+ l.GetServiceID(),
+ l.GetStepID(),
+ )
+
+ // run test
+ got := l.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+// testLog is a test helper function to create a Log
+// type with all fields set to a fake value.
+func testLog() *Log {
+ l := new(Log)
+
+ l.SetID(1)
+ l.SetServiceID(1)
+ l.SetStepID(1)
+ l.SetBuildID(1)
+ l.SetRepoID(1)
+ l.SetData([]byte("foo"))
+
+ return l
+}
diff --git a/api/types/pipeline_test.go b/api/types/pipeline_test.go
index a06d299ca..a925d9940 100644
--- a/api/types/pipeline_test.go
+++ b/api/types/pipeline_test.go
@@ -8,7 +8,7 @@ import (
"testing"
)
-func TestLibrary_Pipeline_Getters(t *testing.T) {
+func TestAPI_Pipeline_Getters(t *testing.T) {
// setup tests
tests := []struct {
pipeline *Pipeline
@@ -88,7 +88,7 @@ func TestLibrary_Pipeline_Getters(t *testing.T) {
}
}
-func TestLibrary_Pipeline_Setters(t *testing.T) {
+func TestAPI_Pipeline_Setters(t *testing.T) {
// setup types
var p *Pipeline
@@ -187,7 +187,7 @@ func TestLibrary_Pipeline_Setters(t *testing.T) {
}
}
-func TestLibrary_Pipeline_String(t *testing.T) {
+func TestAPI_Pipeline_String(t *testing.T) {
// setup types
p := testPipeline()
diff --git a/api/types/queue_info.go b/api/types/queue_info.go
new file mode 100644
index 000000000..bf10b8cc0
--- /dev/null
+++ b/api/types/queue_info.go
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+// QueueInfo is the API representation of a QueueInfo.
+//
+// swagger:model QueueInfo
+type QueueInfo struct {
+ QueuePublicKey *string `json:"queue_public_key,omitempty"`
+ QueueAddress *string `json:"queue_address,omitempty"`
+}
+
+// GetPublicKey returns the QueuePublicKey field.
+//
+// When the provided QueueInfo type is nil, or the field within
+// the type is nil, it returns an empty string for the field.
+func (w *QueueInfo) GetPublicKey() string {
+ // return zero value if QueueInfo type or QueuePublicKey field is nil
+ if w == nil || w.QueuePublicKey == nil {
+ return ""
+ }
+
+ return *w.QueuePublicKey
+}
+
+// GetQueueAddress returns the QueueAddress field.
+//
+// When the provided QueueInfo type is nil, or the field within
+// the type is nil, it returns an empty string for the field.
+func (w *QueueInfo) GetQueueAddress() string {
+ // return zero value if QueueInfo type or QueueAddress field is nil
+ if w == nil || w.QueueAddress == nil {
+ return ""
+ }
+
+ return *w.QueueAddress
+}
+
+// SetPublicKey sets the QueuePublicKey field.
+//
+// When the provided QueueInfo type is nil, it
+// will set nothing and immediately return.
+func (w *QueueInfo) SetPublicKey(v string) {
+ // return if QueueInfo type is nil
+ if w == nil {
+ return
+ }
+
+ w.QueuePublicKey = &v
+}
+
+// SetQueueAddress sets the QueueAddress field.
+//
+// When the provided QueueInfo type is nil, it
+// will set nothing and immediately return.
+func (w *QueueInfo) SetQueueAddress(v string) {
+ // return if QueueInfo type is nil
+ if w == nil {
+ return
+ }
+
+ w.QueueAddress = &v
+}
diff --git a/api/types/queue_info_test.go b/api/types/queue_info_test.go
new file mode 100644
index 000000000..42a4f3535
--- /dev/null
+++ b/api/types/queue_info_test.go
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "testing"
+)
+
+func TestTypes_QueueInfo_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ qR *QueueInfo
+ want *QueueInfo
+ }{
+ {
+ qR: testQueueInfo(),
+ want: testQueueInfo(),
+ },
+ {
+ qR: new(QueueInfo),
+ want: new(QueueInfo),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.qR.GetQueueAddress() != test.want.GetQueueAddress() {
+ t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress())
+ }
+
+ if test.qR.GetPublicKey() != test.want.GetPublicKey() {
+ t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey())
+ }
+ }
+}
+
+func TestTypes_QueueInfo_Setters(t *testing.T) {
+ // setup types
+ var w *QueueInfo
+
+ // setup tests
+ tests := []struct {
+ qR *QueueInfo
+ want *QueueInfo
+ }{
+ {
+ qR: testQueueInfo(),
+ want: testQueueInfo(),
+ },
+ {
+ qR: w,
+ want: new(QueueInfo),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.qR.SetQueueAddress(test.want.GetQueueAddress())
+ test.qR.SetPublicKey(test.want.GetPublicKey())
+
+ if test.qR.GetQueueAddress() != test.want.GetQueueAddress() {
+ t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress())
+ }
+
+ if test.qR.GetPublicKey() != test.want.GetPublicKey() {
+ t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey())
+ }
+ }
+}
+
+// testQueueInfo is a test helper function to register a QueueInfo
+// type with all fields set to a fake value.
+func testQueueInfo() *QueueInfo {
+ w := new(QueueInfo)
+ w.SetQueueAddress("http://localhost:8080")
+ w.SetPublicKey("CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=")
+
+ return w
+}
diff --git a/api/types/repo_test.go b/api/types/repo_test.go
index 2cbe84639..c7e20407d 100644
--- a/api/types/repo_test.go
+++ b/api/types/repo_test.go
@@ -9,7 +9,7 @@ import (
"github.com/google/go-cmp/cmp"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTypes_Repo_Environment(t *testing.T) {
diff --git a/api/types/secret.go b/api/types/secret.go
new file mode 100644
index 000000000..1cb9eb48a
--- /dev/null
+++ b/api/types/secret.go
@@ -0,0 +1,546 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
+)
+
+// Secret is the API representation of a secret.
+//
+// swagger:model Secret
+type Secret struct {
+ ID *int64 `json:"id,omitempty"`
+ Org *string `json:"org,omitempty"`
+ Repo *string `json:"repo,omitempty"`
+ Team *string `json:"team,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Value *string `json:"value,omitempty"`
+ Type *string `json:"type,omitempty"`
+ Images *[]string `json:"images,omitempty"`
+ AllowEvents *Events `json:"allow_events,omitempty" yaml:"allow_events"`
+ AllowCommand *bool `json:"allow_command,omitempty"`
+ AllowSubstitution *bool `json:"allow_substitution,omitempty"`
+ CreatedAt *int64 `json:"created_at,omitempty"`
+ CreatedBy *string `json:"created_by,omitempty"`
+ UpdatedAt *int64 `json:"updated_at,omitempty"`
+ UpdatedBy *string `json:"updated_by,omitempty"`
+}
+
+// UnmarshalYAML implements the Unmarshaler interface for the Secret type.
+// This allows custom fields in the Secret type to be read from a YAML file, like AllowEvents.
+func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error {
+ // create an alias to perform a normal unmarshal and avoid an infinite loop
+ type jsonSecret Secret
+
+ tmp := &jsonSecret{}
+
+ err := unmarshal(tmp)
+ if err != nil {
+ return err
+ }
+
+ // overwrite existing secret
+ *s = Secret(*tmp)
+
+ return nil
+}
+
+// Sanitize creates a duplicate of the Secret without the value.
+func (s *Secret) Sanitize() *Secret {
+ // create a variable since constants can not be addressable
+ //
+ // https://golang.org/ref/spec#Address_operators
+ value := constants.SecretMask
+
+ return &Secret{
+ ID: s.ID,
+ Org: s.Org,
+ Repo: s.Repo,
+ Team: s.Team,
+ Name: s.Name,
+ Value: &value,
+ Type: s.Type,
+ Images: s.Images,
+ AllowEvents: s.AllowEvents,
+ AllowCommand: s.AllowCommand,
+ AllowSubstitution: s.AllowSubstitution,
+ CreatedAt: s.CreatedAt,
+ CreatedBy: s.CreatedBy,
+ UpdatedAt: s.UpdatedAt,
+ UpdatedBy: s.UpdatedBy,
+ }
+}
+
+// Match returns true when the provided container matches
+// the conditions to inject a secret into a pipeline container
+// resource.
+func (s *Secret) Match(from *pipeline.Container) bool {
+ eACL, iACL := false, false
+ images, commands := s.GetImages(), s.GetAllowCommand()
+
+ // check if commands are utilized when not allowed
+ if !commands && len(from.Commands) > 0 {
+ return false
+ }
+
+ // check if a custom entrypoint is utilized when not allowed
+ if !commands && len(from.Commands) == 0 && len(from.Entrypoint) > 0 {
+ return false
+ }
+
+ eACL = s.GetAllowEvents().Allowed(
+ from.Environment["VELA_BUILD_EVENT"],
+ from.Environment["VELA_BUILD_EVENT_ACTION"],
+ )
+
+ // check images whitelist
+ for _, i := range images {
+ if strings.HasPrefix(from.Image, i) && (len(i) != 0) {
+ iACL = true
+ break
+ }
+ }
+
+ // inject secrets into environment
+ switch {
+ case eACL && (len(images) == 0):
+ return true
+ case eACL && iACL:
+ return true
+ }
+
+ // return false if not match is found
+ return false
+}
+
+// GetID returns the ID field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetID() int64 {
+ // return zero value if Secret type or ID field is nil
+ if s == nil || s.ID == nil {
+ return 0
+ }
+
+ return *s.ID
+}
+
+// GetOrg returns the Org field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetOrg() string {
+ // return zero value if Secret type or Org field is nil
+ if s == nil || s.Org == nil {
+ return ""
+ }
+
+ return *s.Org
+}
+
+// GetRepo returns the Repo field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetRepo() string {
+ // return zero value if Secret type or Repo field is nil
+ if s == nil || s.Repo == nil {
+ return ""
+ }
+
+ return *s.Repo
+}
+
+// GetTeam returns the Team field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetTeam() string {
+ // return zero value if Secret type or Team field is nil
+ if s == nil || s.Team == nil {
+ return ""
+ }
+
+ return *s.Team
+}
+
+// GetName returns the Name field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetName() string {
+ // return zero value if Secret type or Name field is nil
+ if s == nil || s.Name == nil {
+ return ""
+ }
+
+ return *s.Name
+}
+
+// GetValue returns the Value field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetValue() string {
+ // return zero value if Secret type or Value field is nil
+ if s == nil || s.Value == nil {
+ return ""
+ }
+
+ return *s.Value
+}
+
+// GetType returns the Type field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetType() string {
+ // return zero value if Secret type or Type field is nil
+ if s == nil || s.Type == nil {
+ return ""
+ }
+
+ return *s.Type
+}
+
+// GetImages returns the Images field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetImages() []string {
+ // return zero value if Secret type or Images field is nil
+ if s == nil || s.Images == nil {
+ return []string{}
+ }
+
+ return *s.Images
+}
+
+// GetAllowEvents returns the AllowEvents field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetAllowEvents() *Events {
+ // return zero value if Secret type or AllowEvents field is nil
+ if s == nil || s.AllowEvents == nil {
+ return new(Events)
+ }
+
+ return s.AllowEvents
+}
+
+// GetAllowCommand returns the AllowCommand field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetAllowCommand() bool {
+ // return zero value if Secret type or Images field is nil
+ if s == nil || s.AllowCommand == nil {
+ return false
+ }
+
+ return *s.AllowCommand
+}
+
+// GetAllowSubstitution returns the AllowSubstitution field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetAllowSubstitution() bool {
+ // return zero value if Secret type or AllowSubstitution field is nil
+ if s == nil || s.AllowSubstitution == nil {
+ return false
+ }
+
+ return *s.AllowSubstitution
+}
+
+// GetCreatedAt returns the CreatedAt field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetCreatedAt() int64 {
+ // return zero value if Secret type or CreatedAt field is nil
+ if s == nil || s.CreatedAt == nil {
+ return 0
+ }
+
+ return *s.CreatedAt
+}
+
+// GetCreatedBy returns the CreatedBy field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetCreatedBy() string {
+ // return zero value if Secret type or CreatedBy field is nil
+ if s == nil || s.CreatedBy == nil {
+ return ""
+ }
+
+ return *s.CreatedBy
+}
+
+// GetUpdatedAt returns the UpdatedAt field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetUpdatedAt() int64 {
+ // return zero value if Secret type or UpdatedAt field is nil
+ if s == nil || s.UpdatedAt == nil {
+ return 0
+ }
+
+ return *s.UpdatedAt
+}
+
+// GetUpdatedBy returns the UpdatedBy field.
+//
+// When the provided Secret type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Secret) GetUpdatedBy() string {
+ // return zero value if Secret type or UpdatedBy field is nil
+ if s == nil || s.UpdatedBy == nil {
+ return ""
+ }
+
+ return *s.UpdatedBy
+}
+
+// SetID sets the ID field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetID(v int64) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.ID = &v
+}
+
+// SetOrg sets the Org field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetOrg(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Org = &v
+}
+
+// SetRepo sets the Repo field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetRepo(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Repo = &v
+}
+
+// SetTeam sets the Team field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetTeam(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Team = &v
+}
+
+// SetName sets the Name field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetName(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Name = &v
+}
+
+// SetValue sets the Value field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetValue(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Value = &v
+}
+
+// SetType sets the Type field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetType(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Type = &v
+}
+
+// SetImages sets the Images field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetImages(v []string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.Images = &v
+}
+
+// SetAllowEvents sets the AllowEvents field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetAllowEvents(v *Events) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.AllowEvents = v
+}
+
+// SetAllowCommand sets the AllowCommand field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetAllowCommand(v bool) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.AllowCommand = &v
+}
+
+// SetAllowSubstitution sets the AllowSubstitution field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetAllowSubstitution(v bool) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.AllowSubstitution = &v
+}
+
+// SetCreatedAt sets the CreatedAt field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetCreatedAt(v int64) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.CreatedAt = &v
+}
+
+// SetCreatedBy sets the CreatedBy field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetCreatedBy(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.CreatedBy = &v
+}
+
+// SetUpdatedAt sets the UpdatedAt field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetUpdatedAt(v int64) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.UpdatedAt = &v
+}
+
+// SetUpdatedBy sets the UpdatedBy field.
+//
+// When the provided Secret type is nil, it
+// will set nothing and immediately return.
+func (s *Secret) SetUpdatedBy(v string) {
+ // return if Secret type is nil
+ if s == nil {
+ return
+ }
+
+ s.UpdatedBy = &v
+}
+
+// String implements the Stringer interface for the Secret type.
+func (s *Secret) String() string {
+ return fmt.Sprintf(`{
+ AllowCommand: %t,
+ AllowEvents: %s,
+ AllowSubstitution: %t,
+ ID: %d,
+ Images: %s,
+ Name: %s,
+ Org: %s,
+ Repo: %s,
+ Team: %s,
+ Type: %s,
+ Value: %s,
+ CreatedAt: %d,
+ CreatedBy: %s,
+ UpdatedAt: %d,
+ UpdatedBy: %s,
+}`,
+ s.GetAllowCommand(),
+ s.GetAllowEvents().List(),
+ s.GetAllowSubstitution(),
+ s.GetID(),
+ s.GetImages(),
+ s.GetName(),
+ s.GetOrg(),
+ s.GetRepo(),
+ s.GetTeam(),
+ s.GetType(),
+ s.GetValue(),
+ s.GetCreatedAt(),
+ s.GetCreatedBy(),
+ s.GetUpdatedAt(),
+ s.GetUpdatedBy(),
+ )
+}
diff --git a/api/types/secret_test.go b/api/types/secret_test.go
new file mode 100644
index 000000000..80562755f
--- /dev/null
+++ b/api/types/secret_test.go
@@ -0,0 +1,644 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+ "time"
+
+ "github.com/google/go-cmp/cmp"
+
+ "github.com/go-vela/server/api/types/actions"
+ "github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
+)
+
+func TestTypes_Secret_Sanitize(t *testing.T) {
+ // setup types
+ s := testSecret()
+
+ want := testSecret()
+ want.SetValue(constants.SecretMask)
+
+ // run test
+ got := s.Sanitize()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Sanitize is %v, want %v", got, want)
+ }
+}
+
+func TestTypes_Secret_Match(t *testing.T) {
+ // setup types
+ v := "foo"
+ fBool := false
+ tBool := true
+
+ testEvents := &Events{
+ Push: &actions.Push{
+ Branch: &tBool,
+ Tag: &tBool,
+ },
+ PullRequest: &actions.Pull{
+ Opened: &fBool,
+ Synchronize: &tBool,
+ Edited: &fBool,
+ },
+ Deployment: &actions.Deploy{
+ Created: &tBool,
+ },
+ Comment: &actions.Comment{
+ Created: &tBool,
+ Edited: &tBool,
+ },
+ Schedule: &actions.Schedule{
+ Run: &tBool,
+ },
+ }
+
+ // setup tests
+ tests := []struct {
+ name string
+ step *pipeline.Container
+ sec *Secret
+ want bool
+ }{
+ { // test matching secret events
+ name: "push",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "pull request opened fail",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{
+ "VELA_BUILD_EVENT": "pull_request",
+ "VELA_BUILD_EVENT_ACTION": "opened",
+ },
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: false,
+ },
+ {
+ name: "tag",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "tag"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "deployment",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{
+ "VELA_BUILD_EVENT": "deployment",
+ "VELA_BUILD_EVENT_ACTION": "created",
+ },
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "comment created",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{
+ "VELA_BUILD_EVENT": "comment",
+ "VELA_BUILD_EVENT_ACTION": "created",
+ },
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "fake event",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "fake_event"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: false,
+ },
+ {
+ name: "push with empty image constraint",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "schedule",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "schedule"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+
+ { // test matching secret images
+ name: "image basic",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "image and tag",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine:latest"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "mismatch tag with same image",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine:1"},
+ AllowEvents: testEvents,
+ },
+ want: false,
+ },
+ {
+ name: "multiple allowed images",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine", "centos"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+
+ { // test matching secret events and images
+ name: "push and image pass",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "push and image tag pass",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine:latest"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "push and bad image tag",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine:1"},
+ AllowEvents: testEvents,
+ },
+ want: false,
+ },
+ {
+ name: "mismatch event and match image",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{
+ "VELA_BUILD_EVENT": "pull_request",
+ "VELA_BUILD_EVENT_ACTION": "edited",
+ },
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine:latest"},
+ AllowEvents: testEvents,
+ },
+ want: false,
+ },
+ {
+ name: "event and multi image allowed pass",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine", "centos"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+
+ { // test build events with image ACLs and rulesets
+ name: "rulesets and push pass",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ Ruleset: pipeline.Ruleset{
+ If: pipeline.Rules{
+ Event: []string{"push"},
+ },
+ },
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine"},
+ AllowEvents: testEvents,
+ },
+ want: true,
+ },
+ {
+ name: "no commands allowed",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ Ruleset: pipeline.Ruleset{
+ If: pipeline.Rules{
+ Event: []string{"push"},
+ },
+ },
+ Commands: []string{"echo hi"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine"},
+ AllowEvents: testEvents,
+ AllowCommand: &fBool,
+ },
+ want: false,
+ },
+ {
+ name: "no commands allowed - entrypoint provided",
+ step: &pipeline.Container{
+ Image: "alpine:latest",
+ Environment: map[string]string{"VELA_BUILD_EVENT": "push"},
+ Ruleset: pipeline.Ruleset{
+ If: pipeline.Rules{
+ Event: []string{"push"},
+ },
+ },
+ Entrypoint: []string{"sh", "-c", "echo hi"},
+ },
+ sec: &Secret{
+ Name: &v,
+ Value: &v,
+ Images: &[]string{"alpine"},
+ AllowEvents: testEvents,
+ AllowCommand: &fBool,
+ },
+ want: false,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.sec.Match(test.step)
+
+ if got != test.want {
+ t.Errorf("Match for %s is %v, want %v", test.name, got, test.want)
+ }
+ }
+}
+
+func TestTypes_Secret_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ secret *Secret
+ want *Secret
+ }{
+ {
+ secret: testSecret(),
+ want: testSecret(),
+ },
+ {
+ secret: new(Secret),
+ want: new(Secret),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.secret.GetID() != test.want.GetID() {
+ t.Errorf("GetID is %v, want %v", test.secret.GetID(), test.want.GetID())
+ }
+
+ if test.secret.GetOrg() != test.want.GetOrg() {
+ t.Errorf("GetOrg is %v, want %v", test.secret.GetOrg(), test.want.GetOrg())
+ }
+
+ if test.secret.GetRepo() != test.want.GetRepo() {
+ t.Errorf("GetRepo is %v, want %v", test.secret.GetRepo(), test.want.GetRepo())
+ }
+
+ if test.secret.GetTeam() != test.want.GetTeam() {
+ t.Errorf("GetTeam is %v, want %v", test.secret.GetTeam(), test.want.GetTeam())
+ }
+
+ if test.secret.GetName() != test.want.GetName() {
+ t.Errorf("GetName is %v, want %v", test.secret.GetName(), test.want.GetName())
+ }
+
+ if test.secret.GetValue() != test.want.GetValue() {
+ t.Errorf("GetValue is %v, want %v", test.secret.GetValue(), test.want.GetValue())
+ }
+
+ if test.secret.GetType() != test.want.GetType() {
+ t.Errorf("GetType is %v, want %v", test.secret.GetType(), test.want.GetType())
+ }
+
+ if !reflect.DeepEqual(test.secret.GetImages(), test.want.GetImages()) {
+ t.Errorf("GetImages is %v, want %v", test.secret.GetImages(), test.want.GetImages())
+ }
+
+ if !reflect.DeepEqual(test.secret.GetAllowEvents(), test.want.GetAllowEvents()) {
+ t.Errorf("GetAllowEvents is %v, want %v", test.secret.GetAllowEvents(), test.want.GetAllowEvents())
+ }
+
+ if test.secret.GetAllowCommand() != test.want.GetAllowCommand() {
+ t.Errorf("GetAllowCommand is %v, want %v", test.secret.GetAllowCommand(), test.want.GetAllowCommand())
+ }
+
+ if test.secret.GetAllowSubstitution() != test.want.GetAllowSubstitution() {
+ t.Errorf("GetAllowSubstitution is %v, want %v", test.secret.GetAllowSubstitution(), test.want.GetAllowSubstitution())
+ }
+
+ if test.secret.GetCreatedAt() != test.want.GetCreatedAt() {
+ t.Errorf("GetCreatedAt is %v, want %v", test.secret.GetCreatedAt(), test.want.GetCreatedAt())
+ }
+
+ if test.secret.GetCreatedBy() != test.want.GetCreatedBy() {
+ t.Errorf("GetCreatedBy is %v, want %v", test.secret.GetCreatedBy(), test.want.GetCreatedBy())
+ }
+
+ if test.secret.GetUpdatedAt() != test.want.GetUpdatedAt() {
+ t.Errorf("GetUpdatedAt is %v, want %v", test.secret.GetUpdatedAt(), test.want.GetUpdatedAt())
+ }
+
+ if test.secret.GetUpdatedBy() != test.want.GetUpdatedBy() {
+ t.Errorf("GetUpdatedBy is %v, want %v", test.secret.GetUpdatedBy(), test.want.GetUpdatedBy())
+ }
+ }
+}
+
+func TestTypes_Secret_Setters(t *testing.T) {
+ // setup types
+ var s *Secret
+
+ // setup tests
+ tests := []struct {
+ secret *Secret
+ want *Secret
+ }{
+ {
+ secret: testSecret(),
+ want: testSecret(),
+ },
+ {
+ secret: s,
+ want: new(Secret),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.secret.SetID(test.want.GetID())
+ test.secret.SetOrg(test.want.GetOrg())
+ test.secret.SetRepo(test.want.GetRepo())
+ test.secret.SetTeam(test.want.GetTeam())
+ test.secret.SetName(test.want.GetName())
+ test.secret.SetValue(test.want.GetValue())
+ test.secret.SetType(test.want.GetType())
+ test.secret.SetImages(test.want.GetImages())
+ test.secret.SetAllowEvents(test.want.GetAllowEvents())
+ test.secret.SetAllowCommand(test.want.GetAllowCommand())
+ test.secret.SetAllowSubstitution(test.want.GetAllowSubstitution())
+ test.secret.SetCreatedAt(test.want.GetCreatedAt())
+ test.secret.SetCreatedBy(test.want.GetCreatedBy())
+ test.secret.SetUpdatedAt(test.want.GetUpdatedAt())
+ test.secret.SetUpdatedBy(test.want.GetUpdatedBy())
+
+ if test.secret.GetID() != test.want.GetID() {
+ t.Errorf("SetID is %v, want %v", test.secret.GetID(), test.want.GetID())
+ }
+
+ if test.secret.GetOrg() != test.want.GetOrg() {
+ t.Errorf("SetOrg is %v, want %v", test.secret.GetOrg(), test.want.GetOrg())
+ }
+
+ if test.secret.GetRepo() != test.want.GetRepo() {
+ t.Errorf("SetRepo is %v, want %v", test.secret.GetRepo(), test.want.GetRepo())
+ }
+
+ if test.secret.GetTeam() != test.want.GetTeam() {
+ t.Errorf("SetTeam is %v, want %v", test.secret.GetTeam(), test.want.GetTeam())
+ }
+
+ if test.secret.GetName() != test.want.GetName() {
+ t.Errorf("SetName is %v, want %v", test.secret.GetName(), test.want.GetName())
+ }
+
+ if test.secret.GetValue() != test.want.GetValue() {
+ t.Errorf("SetValue is %v, want %v", test.secret.GetValue(), test.want.GetValue())
+ }
+
+ if test.secret.GetType() != test.want.GetType() {
+ t.Errorf("SetType is %v, want %v", test.secret.GetType(), test.want.GetType())
+ }
+
+ if !reflect.DeepEqual(test.secret.GetImages(), test.want.GetImages()) {
+ t.Errorf("SetImages is %v, want %v", test.secret.GetImages(), test.want.GetImages())
+ }
+
+ if !reflect.DeepEqual(test.secret.GetAllowEvents(), test.want.GetAllowEvents()) {
+ t.Errorf("SetAllowEvents is %v, want %v", test.secret.GetAllowEvents(), test.want.GetAllowEvents())
+ }
+
+ if test.secret.GetAllowCommand() != test.want.GetAllowCommand() {
+ t.Errorf("SetAllowCommand is %v, want %v", test.secret.GetAllowCommand(), test.want.GetAllowCommand())
+ }
+
+ if test.secret.GetAllowSubstitution() != test.want.GetAllowSubstitution() {
+ t.Errorf("SetAllowSubstitution is %v, want %v", test.secret.GetAllowSubstitution(), test.want.GetAllowSubstitution())
+ }
+
+ if test.secret.GetCreatedAt() != test.want.GetCreatedAt() {
+ t.Errorf("SetCreatedAt is %v, want %v", test.secret.GetCreatedAt(), test.want.GetCreatedAt())
+ }
+
+ if test.secret.GetCreatedBy() != test.want.GetCreatedBy() {
+ t.Errorf("SetCreatedBy is %v, want %v", test.secret.GetCreatedBy(), test.want.GetCreatedBy())
+ }
+
+ if test.secret.GetUpdatedAt() != test.want.GetUpdatedAt() {
+ t.Errorf("SetUpdatedAt is %v, want %v", test.secret.GetUpdatedAt(), test.want.GetUpdatedAt())
+ }
+
+ if test.secret.GetUpdatedBy() != test.want.GetUpdatedBy() {
+ t.Errorf("SetUpdatedBy is %v, want %v", test.secret.GetUpdatedBy(), test.want.GetUpdatedBy())
+ }
+ }
+}
+
+func TestTypes_Secret_String(t *testing.T) {
+ // setup types
+ s := testSecret()
+
+ want := fmt.Sprintf(`{
+ AllowCommand: %t,
+ AllowEvents: %v,
+ AllowSubstitution: %t,
+ ID: %d,
+ Images: %s,
+ Name: %s,
+ Org: %s,
+ Repo: %s,
+ Team: %s,
+ Type: %s,
+ Value: %s,
+ CreatedAt: %d,
+ CreatedBy: %s,
+ UpdatedAt: %d,
+ UpdatedBy: %s,
+}`,
+ s.GetAllowCommand(),
+ s.GetAllowEvents().List(),
+ s.GetAllowSubstitution(),
+ s.GetID(),
+ s.GetImages(),
+ s.GetName(),
+ s.GetOrg(),
+ s.GetRepo(),
+ s.GetTeam(),
+ s.GetType(),
+ s.GetValue(),
+ s.GetCreatedAt(),
+ s.GetCreatedBy(),
+ s.GetUpdatedAt(),
+ s.GetUpdatedBy(),
+ )
+
+ // run test
+ got := s.String()
+
+ if diff := cmp.Diff(got, want); diff != "" {
+ t.Errorf("String Mismatch: -want +got):\n%s", diff)
+ }
+}
+
+// testSecret is a test helper function to create a Secret
+// type with all fields set to a fake value.
+func testSecret() *Secret {
+ currentTime := time.Now()
+ tsCreate := currentTime.UTC().Unix()
+ tsUpdate := currentTime.Add(time.Hour * 1).UTC().Unix()
+ s := new(Secret)
+
+ s.SetID(1)
+ s.SetOrg("github")
+ s.SetRepo("octocat")
+ s.SetTeam("octokitties")
+ s.SetName("foo")
+ s.SetValue("bar")
+ s.SetType("repo")
+ s.SetImages([]string{"alpine"})
+ s.SetAllowEvents(NewEventsFromMask(1))
+ s.SetAllowCommand(true)
+ s.SetAllowSubstitution(true)
+ s.SetCreatedAt(tsCreate)
+ s.SetCreatedBy("octocat")
+ s.SetUpdatedAt(tsUpdate)
+ s.SetUpdatedBy("octocat2")
+
+ return s
+}
diff --git a/api/types/service.go b/api/types/service.go
new file mode 100644
index 000000000..075beb44f
--- /dev/null
+++ b/api/types/service.go
@@ -0,0 +1,645 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "strconv"
+ "time"
+
+ "github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
+)
+
+// Service is the API representation of a service in a build.
+//
+// swagger:model Service
+type Service struct {
+ ID *int64 `json:"id,omitempty"`
+ BuildID *int64 `json:"build_id,omitempty"`
+ RepoID *int64 `json:"repo_id,omitempty"`
+ Number *int `json:"number,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Image *string `json:"image,omitempty"`
+ Status *string `json:"status,omitempty"`
+ Error *string `json:"error,omitempty"`
+ ExitCode *int `json:"exit_code,omitempty"`
+ Created *int64 `json:"created,omitempty"`
+ Started *int64 `json:"started,omitempty"`
+ Finished *int64 `json:"finished,omitempty"`
+ Host *string `json:"host,omitempty"`
+ Runtime *string `json:"runtime,omitempty"`
+ Distribution *string `json:"distribution,omitempty"`
+}
+
+// Duration calculates and returns the total amount of
+// time the service ran for in a human-readable format.
+func (s *Service) Duration() string {
+ // check if the service doesn't have a started timestamp
+ if s.GetStarted() == 0 {
+ return "..."
+ }
+
+ // capture started unix timestamp from the service
+ started := time.Unix(s.GetStarted(), 0)
+
+ // check if the service doesn't have a finished timestamp
+ if s.GetFinished() == 0 {
+ // return the duration in a human-readable form by
+ // subtracting the service started time from the
+ // current time rounded to the nearest second
+ return time.Since(started).Round(time.Second).String()
+ }
+
+ // capture finished unix timestamp from the service
+ finished := time.Unix(s.GetFinished(), 0)
+
+ // calculate the duration by subtracting the service
+ // started time from the service finished time
+ duration := finished.Sub(started)
+
+ // return the duration in a human-readable form
+ return duration.String()
+}
+
+// Environment returns a list of environment variables
+// provided from the fields of the Service type.
+func (s *Service) Environment() map[string]string {
+ return map[string]string{
+ "VELA_SERVICE_CREATED": ToString(s.GetCreated()),
+ "VELA_SERVICE_DISTRIBUTION": ToString(s.GetDistribution()),
+ "VELA_SERVICE_EXIT_CODE": ToString(s.GetExitCode()),
+ "VELA_SERVICE_HOST": ToString(s.GetHost()),
+ "VELA_SERVICE_IMAGE": ToString(s.GetImage()),
+ "VELA_SERVICE_NAME": ToString(s.GetName()),
+ "VELA_SERVICE_NUMBER": ToString(s.GetNumber()),
+ "VELA_SERVICE_RUNTIME": ToString(s.GetRuntime()),
+ "VELA_SERVICE_STARTED": ToString(s.GetStarted()),
+ "VELA_SERVICE_STATUS": ToString(s.GetStatus()),
+ }
+}
+
+// GetID returns the ID field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetID() int64 {
+ // return zero value if Service type or ID field is nil
+ if s == nil || s.ID == nil {
+ return 0
+ }
+
+ return *s.ID
+}
+
+// GetBuildID returns the BuildID field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetBuildID() int64 {
+ // return zero value if Service type or BuildID field is nil
+ if s == nil || s.BuildID == nil {
+ return 0
+ }
+
+ return *s.BuildID
+}
+
+// GetRepoID returns the RepoID field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetRepoID() int64 {
+ // return zero value if Service type or RepoID field is nil
+ if s == nil || s.RepoID == nil {
+ return 0
+ }
+
+ return *s.RepoID
+}
+
+// GetNumber returns the Number field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetNumber() int {
+ // return zero value if Service type or Number field is nil
+ if s == nil || s.Number == nil {
+ return 0
+ }
+
+ return *s.Number
+}
+
+// GetName returns the Name field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetName() string {
+ // return zero value if Service type or Name field is nil
+ if s == nil || s.Name == nil {
+ return ""
+ }
+
+ return *s.Name
+}
+
+// GetImage returns the Image field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetImage() string {
+ // return zero value if Service type or Image field is nil
+ if s == nil || s.Image == nil {
+ return ""
+ }
+
+ return *s.Image
+}
+
+// GetStatus returns the Status field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetStatus() string {
+ // return zero value if Service type or Status field is nil
+ if s == nil || s.Status == nil {
+ return ""
+ }
+
+ return *s.Status
+}
+
+// GetError returns the Error field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetError() string {
+ // return zero value if Service type or Error field is nil
+ if s == nil || s.Error == nil {
+ return ""
+ }
+
+ return *s.Error
+}
+
+// GetExitCode returns the ExitCode field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetExitCode() int {
+ // return zero value if Service type or ExitCode field is nil
+ if s == nil || s.ExitCode == nil {
+ return 0
+ }
+
+ return *s.ExitCode
+}
+
+// GetCreated returns the Created field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetCreated() int64 {
+ // return zero value if Service type or Created field is nil
+ if s == nil || s.Created == nil {
+ return 0
+ }
+
+ return *s.Created
+}
+
+// GetStarted returns the Started field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetStarted() int64 {
+ // return zero value if Service type or Started field is nil
+ if s == nil || s.Started == nil {
+ return 0
+ }
+
+ return *s.Started
+}
+
+// GetFinished returns the Finished field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetFinished() int64 {
+ // return zero value if Service type or Finished field is nil
+ if s == nil || s.Finished == nil {
+ return 0
+ }
+
+ return *s.Finished
+}
+
+// GetHost returns the Host field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetHost() string {
+ // return zero value if Service type or Host field is nil
+ if s == nil || s.Host == nil {
+ return ""
+ }
+
+ return *s.Host
+}
+
+// GetRuntime returns the Runtime field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetRuntime() string {
+ // return zero value if Service type or Runtime field is nil
+ if s == nil || s.Runtime == nil {
+ return ""
+ }
+
+ return *s.Runtime
+}
+
+// GetDistribution returns the Runtime field.
+//
+// When the provided Service type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Service) GetDistribution() string {
+ // return zero value if Service type or Distribution field is nil
+ if s == nil || s.Distribution == nil {
+ return ""
+ }
+
+ return *s.Distribution
+}
+
+// SetID sets the ID field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetID(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.ID = &v
+}
+
+// SetBuildID sets the BuildID field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetBuildID(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.BuildID = &v
+}
+
+// SetRepoID sets the RepoID field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetRepoID(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.RepoID = &v
+}
+
+// SetNumber sets the Number field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetNumber(v int) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Number = &v
+}
+
+// SetName sets the Name field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetName(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Name = &v
+}
+
+// SetImage sets the Image field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetImage(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Image = &v
+}
+
+// SetStatus sets the Status field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetStatus(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Status = &v
+}
+
+// SetError sets the Error field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetError(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Error = &v
+}
+
+// SetExitCode sets the ExitCode field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetExitCode(v int) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.ExitCode = &v
+}
+
+// SetCreated sets the Created field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetCreated(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Created = &v
+}
+
+// SetStarted sets the Started field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetStarted(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Started = &v
+}
+
+// SetFinished sets the Finished field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetFinished(v int64) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Finished = &v
+}
+
+// SetHost sets the Host field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetHost(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Host = &v
+}
+
+// SetRuntime sets the Runtime field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetRuntime(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Runtime = &v
+}
+
+// SetDistribution sets the Runtime field.
+//
+// When the provided Service type is nil, it
+// will set nothing and immediately return.
+func (s *Service) SetDistribution(v string) {
+ // return if Service type is nil
+ if s == nil {
+ return
+ }
+
+ s.Distribution = &v
+}
+
+// String implements the Stringer interface for the Service type.
+func (s *Service) String() string {
+ return fmt.Sprintf(`{
+ BuildID: %d,
+ Created: %d,
+ Distribution: %s,
+ Error: %s,
+ ExitCode: %d,
+ Finished: %d,
+ Host: %s,
+ ID: %d,
+ Image: %s,
+ Name: %s,
+ Number: %d,
+ RepoID: %d,
+ Runtime: %s,
+ Started: %d,
+ Status: %s,
+}`,
+ s.GetBuildID(),
+ s.GetCreated(),
+ s.GetDistribution(),
+ s.GetError(),
+ s.GetExitCode(),
+ s.GetFinished(),
+ s.GetHost(),
+ s.GetID(),
+ s.GetImage(),
+ s.GetName(),
+ s.GetNumber(),
+ s.GetRepoID(),
+ s.GetRuntime(),
+ s.GetStarted(),
+ s.GetStatus(),
+ )
+}
+
+// ServiceFromBuildContainer creates a new Service based on a Build and pipeline Container.
+func ServiceFromBuildContainer(build *Build, ctn *pipeline.Container) *Service {
+ // create new service type we want to return
+ s := new(Service)
+
+ // default status to Pending
+ s.SetStatus(constants.StatusPending)
+
+ // copy fields from build
+ if build != nil {
+ // set values from the build
+ s.SetHost(build.GetHost())
+ s.SetRuntime(build.GetRuntime())
+ s.SetDistribution(build.GetDistribution())
+ }
+
+ // copy fields from container
+ if ctn != nil && ctn.Name != "" {
+ // set values from the container
+ s.SetName(ctn.Name)
+ s.SetNumber(ctn.Number)
+ s.SetImage(ctn.Image)
+ }
+
+ return s
+}
+
+// ServiceFromContainerEnvironment converts the pipeline Container
+// to an API Service using the container's Environment.
+func ServiceFromContainerEnvironment(ctn *pipeline.Container) *Service {
+ // check if container or container environment are nil
+ if ctn == nil || ctn.Environment == nil {
+ return nil
+ }
+
+ // create new service type we want to return
+ s := new(Service)
+
+ // check if the VELA_SERVICE_DISTRIBUTION environment variable exists
+ value, ok := ctn.Environment["VELA_SERVICE_DISTRIBUTION"]
+ if ok {
+ // set the Distribution field to the value from environment variable
+ s.SetDistribution(value)
+ }
+
+ // check if the VELA_SERVICE_HOST environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_HOST"]
+ if ok {
+ // set the Host field to the value from environment variable
+ s.SetHost(value)
+ }
+
+ // check if the VELA_SERVICE_IMAGE environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_IMAGE"]
+ if ok {
+ // set the Image field to the value from environment variable
+ s.SetImage(value)
+ }
+
+ // check if the VELA_SERVICE_NAME environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_NAME"]
+ if ok {
+ // set the Name field to the value from environment variable
+ s.SetName(value)
+ }
+
+ // check if the VELA_SERVICE_RUNTIME environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_RUNTIME"]
+ if ok {
+ // set the Runtime field to the value from environment variable
+ s.SetRuntime(value)
+ }
+
+ // check if the VELA_SERVICE_STATUS environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_STATUS"]
+ if ok {
+ // set the Status field to the value from environment variable
+ s.SetStatus(value)
+ }
+
+ // check if the VELA_SERVICE_CREATED environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_CREATED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Created field to the parsed int64
+ s.SetCreated(i)
+ }
+ }
+
+ // check if the VELA_SERVICE_EXIT_CODE environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_EXIT_CODE"]
+ if ok {
+ // parse the environment variable value into an int
+ i, err := strconv.ParseInt(value, 10, 0)
+ if err == nil {
+ // set the ExitCode field to the parsed int
+ s.SetExitCode(int(i))
+ }
+ }
+
+ // check if the VELA_SERVICE_FINISHED environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_FINISHED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Finished field to the parsed int64
+ s.SetFinished(i)
+ }
+ }
+
+ // check if the VELA_SERVICE_NUMBER environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_NUMBER"]
+ if ok {
+ // parse the environment variable value into an int
+ i, err := strconv.ParseInt(value, 10, 0)
+ if err == nil {
+ // set the Number field to the parsed int
+ s.SetNumber(int(i))
+ }
+ }
+
+ // check if the VELA_SERVICE_STARTED environment variable exists
+ value, ok = ctn.Environment["VELA_SERVICE_STARTED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Started field to the parsed int64
+ s.SetStarted(i)
+ }
+ }
+
+ return s
+}
diff --git a/api/types/service_test.go b/api/types/service_test.go
new file mode 100644
index 000000000..41e93bf21
--- /dev/null
+++ b/api/types/service_test.go
@@ -0,0 +1,449 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+ "time"
+
+ "github.com/go-vela/server/compiler/types/pipeline"
+)
+
+func TestTypes_Service_Duration(t *testing.T) {
+ // setup types
+ unfinished := testService()
+ unfinished.SetFinished(0)
+
+ // setup tests
+ tests := []struct {
+ service *Service
+ want string
+ }{
+ {
+ service: testService(),
+ want: "1s",
+ },
+ {
+ service: unfinished,
+ want: time.Since(time.Unix(unfinished.GetStarted(), 0)).Round(time.Second).String(),
+ },
+ {
+ service: new(Service),
+ want: "...",
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.service.Duration()
+
+ if got != test.want {
+ t.Errorf("Duration is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestTypes_Service_Environment(t *testing.T) {
+ // setup types
+ want := map[string]string{
+ "VELA_SERVICE_CREATED": "1563474076",
+ "VELA_SERVICE_DISTRIBUTION": "linux",
+ "VELA_SERVICE_EXIT_CODE": "0",
+ "VELA_SERVICE_HOST": "example.company.com",
+ "VELA_SERVICE_IMAGE": "postgres:12-alpine",
+ "VELA_SERVICE_NAME": "postgres",
+ "VELA_SERVICE_NUMBER": "1",
+ "VELA_SERVICE_RUNTIME": "docker",
+ "VELA_SERVICE_STARTED": "1563474078",
+ "VELA_SERVICE_STATUS": "running",
+ }
+
+ // run test
+ got := testService().Environment()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Environment is %v, want %v", got, want)
+ }
+}
+
+func TestTypes_Service_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ service *Service
+ want *Service
+ }{
+ {
+ service: testService(),
+ want: testService(),
+ },
+ {
+ service: new(Service),
+ want: new(Service),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.service.GetID() != test.want.GetID() {
+ t.Errorf("GetID is %v, want %v", test.service.GetID(), test.want.GetID())
+ }
+
+ if test.service.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("GetBuildID is %v, want %v", test.service.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if test.service.GetRepoID() != test.want.GetRepoID() {
+ t.Errorf("GetRepoID is %v, want %v", test.service.GetRepoID(), test.want.GetRepoID())
+ }
+
+ if test.service.GetNumber() != test.want.GetNumber() {
+ t.Errorf("GetNumber is %v, want %v", test.service.GetNumber(), test.want.GetNumber())
+ }
+
+ if test.service.GetName() != test.want.GetName() {
+ t.Errorf("GetName is %v, want %v", test.service.GetName(), test.want.GetName())
+ }
+
+ if test.service.GetImage() != test.want.GetImage() {
+ t.Errorf("GetImage is %v, want %v", test.service.GetImage(), test.want.GetImage())
+ }
+
+ if test.service.GetStatus() != test.want.GetStatus() {
+ t.Errorf("GetStatus is %v, want %v", test.service.GetStatus(), test.want.GetStatus())
+ }
+
+ if test.service.GetError() != test.want.GetError() {
+ t.Errorf("GetError is %v, want %v", test.service.GetError(), test.want.GetError())
+ }
+
+ if test.service.GetExitCode() != test.want.GetExitCode() {
+ t.Errorf("GetExitCode is %v, want %v", test.service.GetExitCode(), test.want.GetExitCode())
+ }
+
+ if test.service.GetCreated() != test.want.GetCreated() {
+ t.Errorf("GetCreated is %v, want %v", test.service.GetCreated(), test.want.GetCreated())
+ }
+
+ if test.service.GetStarted() != test.want.GetStarted() {
+ t.Errorf("GetStarted is %v, want %v", test.service.GetStarted(), test.want.GetStarted())
+ }
+
+ if test.service.GetFinished() != test.want.GetFinished() {
+ t.Errorf("GetFinished is %v, want %v", test.service.GetFinished(), test.want.GetFinished())
+ }
+
+ if test.service.GetHost() != test.want.GetHost() {
+ t.Errorf("GetHost is %v, want %v", test.service.GetHost(), test.want.GetHost())
+ }
+
+ if test.service.GetRuntime() != test.want.GetRuntime() {
+ t.Errorf("GetRuntime is %v, want %v", test.service.GetRuntime(), test.want.GetRuntime())
+ }
+
+ if test.service.GetDistribution() != test.want.GetDistribution() {
+ t.Errorf("GetDistribution is %v, want %v", test.service.GetDistribution(), test.want.GetDistribution())
+ }
+ }
+}
+
+func TestTypes_Service_Setters(t *testing.T) {
+ // setup types
+ var s *Service
+
+ // setup tests
+ tests := []struct {
+ service *Service
+ want *Service
+ }{
+ {
+ service: testService(),
+ want: testService(),
+ },
+ {
+ service: s,
+ want: new(Service),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.want.SetID(test.service.GetID())
+ test.want.SetBuildID(test.service.GetBuildID())
+ test.want.SetRepoID(test.service.GetRepoID())
+ test.want.SetNumber(test.service.GetNumber())
+ test.want.SetName(test.service.GetName())
+ test.want.SetImage(test.service.GetImage())
+ test.want.SetStatus(test.service.GetStatus())
+ test.want.SetError(test.service.GetError())
+ test.want.SetExitCode(test.service.GetExitCode())
+ test.want.SetCreated(test.service.GetCreated())
+ test.want.SetStarted(test.service.GetStarted())
+ test.want.SetFinished(test.service.GetFinished())
+ test.want.SetHost(test.service.GetHost())
+ test.want.SetRuntime(test.service.GetRuntime())
+ test.want.SetDistribution(test.service.GetDistribution())
+
+ if test.want.GetID() != test.service.GetID() {
+ t.Errorf("SetID is %v, want %v", test.service.GetID(), test.service.GetID())
+ }
+
+ if test.want.GetBuildID() != test.service.GetBuildID() {
+ t.Errorf("SetBuildID is %v, want %v", test.service.GetBuildID(), test.service.GetBuildID())
+ }
+
+ if test.want.GetRepoID() != test.service.GetRepoID() {
+ t.Errorf("SetRepoID is %v, want %v", test.service.GetRepoID(), test.service.GetRepoID())
+ }
+
+ if test.want.GetNumber() != test.service.GetNumber() {
+ t.Errorf("SetNumber is %v, want %v", test.service.GetNumber(), test.service.GetNumber())
+ }
+
+ if test.want.GetName() != test.service.GetName() {
+ t.Errorf("SetName is %v, want %v", test.service.GetName(), test.service.GetName())
+ }
+
+ if test.want.GetImage() != test.service.GetImage() {
+ t.Errorf("SetImage is %v, want %v", test.service.GetImage(), test.service.GetImage())
+ }
+
+ if test.want.GetStatus() != test.service.GetStatus() {
+ t.Errorf("SetStatus is %v, want %v", test.service.GetStatus(), test.service.GetStatus())
+ }
+
+ if test.want.GetError() != test.service.GetError() {
+ t.Errorf("SetError is %v, want %v", test.service.GetError(), test.service.GetError())
+ }
+
+ if test.want.GetExitCode() != test.service.GetExitCode() {
+ t.Errorf("SetExitCode is %v, want %v", test.service.GetExitCode(), test.service.GetExitCode())
+ }
+
+ if test.want.GetCreated() != test.service.GetCreated() {
+ t.Errorf("SetCreated is %v, want %v", test.service.GetCreated(), test.service.GetCreated())
+ }
+
+ if test.want.GetStarted() != test.service.GetStarted() {
+ t.Errorf("SetStarted is %v, want %v", test.service.GetStarted(), test.service.GetStarted())
+ }
+
+ if test.want.GetFinished() != test.service.GetFinished() {
+ t.Errorf("SetFinished is %v, want %v", test.service.GetFinished(), test.service.GetFinished())
+ }
+
+ if test.want.GetHost() != test.service.GetHost() {
+ t.Errorf("SetHost is %v, want %v", test.service.GetHost(), test.service.GetHost())
+ }
+
+ if test.want.GetRuntime() != test.service.GetRuntime() {
+ t.Errorf("SetRuntime is %v, want %v", test.service.GetRuntime(), test.service.GetRuntime())
+ }
+
+ if test.want.GetDistribution() != test.service.GetDistribution() {
+ t.Errorf("SetDistribution is %v, want %v", test.service.GetDistribution(), test.service.GetDistribution())
+ }
+ }
+}
+
+func TestTypes_Service_String(t *testing.T) {
+ // setup types
+ s := testService()
+
+ want := fmt.Sprintf(`{
+ BuildID: %d,
+ Created: %d,
+ Distribution: %s,
+ Error: %s,
+ ExitCode: %d,
+ Finished: %d,
+ Host: %s,
+ ID: %d,
+ Image: %s,
+ Name: %s,
+ Number: %d,
+ RepoID: %d,
+ Runtime: %s,
+ Started: %d,
+ Status: %s,
+}`,
+ s.GetBuildID(),
+ s.GetCreated(),
+ s.GetDistribution(),
+ s.GetError(),
+ s.GetExitCode(),
+ s.GetFinished(),
+ s.GetHost(),
+ s.GetID(),
+ s.GetImage(),
+ s.GetName(),
+ s.GetNumber(),
+ s.GetRepoID(),
+ s.GetRuntime(),
+ s.GetStarted(),
+ s.GetStatus(),
+ )
+
+ // run test
+ got := s.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+func TestTypes_ServiceFromBuildContainer(t *testing.T) {
+ // setup types
+ s := testService()
+ s.SetStatus("pending")
+
+ // modify fields that aren't set
+ s.ID = nil
+ s.BuildID = nil
+ s.RepoID = nil
+ s.ExitCode = nil
+ s.Created = nil
+ s.Started = nil
+ s.Finished = nil
+
+ tests := []struct {
+ name string
+ container *pipeline.Container
+ build *Build
+ want *Service
+ }{
+ {
+ name: "nil container with nil build",
+ container: nil,
+ build: nil,
+ want: &Service{Status: s.Status},
+ },
+ {
+ name: "empty container with nil build",
+ container: new(pipeline.Container),
+ build: nil,
+ want: &Service{Status: s.Status},
+ },
+ {
+ name: "nil container with build",
+ container: nil,
+ build: testBuild(),
+ want: &Service{
+ Status: s.Status,
+ Host: s.Host,
+ Runtime: s.Runtime,
+ Distribution: s.Distribution,
+ },
+ },
+ {
+ name: "empty container with build",
+ container: new(pipeline.Container),
+ build: testBuild(),
+ want: &Service{
+ Status: s.Status,
+ Host: s.Host,
+ Runtime: s.Runtime,
+ Distribution: s.Distribution,
+ },
+ },
+ {
+ name: "container with build",
+ container: &pipeline.Container{
+ Name: s.GetName(),
+ Number: s.GetNumber(),
+ Image: s.GetImage(),
+ },
+ build: testBuild(),
+ want: s,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := ServiceFromBuildContainer(test.build, test.container)
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("ServiceFromBuildContainer for %s is %v, want %v", test.name, got, test.want)
+ }
+ }
+}
+
+func TestTypes_ServiceFromContainerEnvironment(t *testing.T) {
+ // setup types
+ s := testService()
+
+ // modify fields that aren't set via environment variables
+ s.ID = nil
+ s.BuildID = nil
+ s.RepoID = nil
+
+ // setup tests
+ tests := []struct {
+ name string
+ container *pipeline.Container
+ want *Service
+ }{
+ {
+ name: "nil container",
+ container: nil,
+ want: nil,
+ },
+ {
+ name: "empty container",
+ container: new(pipeline.Container),
+ want: nil,
+ },
+ {
+ name: "container",
+ container: &pipeline.Container{
+ Environment: map[string]string{
+ "VELA_SERVICE_CREATED": "1563474076",
+ "VELA_SERVICE_DISTRIBUTION": "linux",
+ "VELA_SERVICE_EXIT_CODE": "0",
+ "VELA_SERVICE_FINISHED": "1563474079",
+ "VELA_SERVICE_HOST": "example.company.com",
+ "VELA_SERVICE_IMAGE": "postgres:12-alpine",
+ "VELA_SERVICE_NAME": "postgres",
+ "VELA_SERVICE_NUMBER": "1",
+ "VELA_SERVICE_RUNTIME": "docker",
+ "VELA_SERVICE_STARTED": "1563474078",
+ "VELA_SERVICE_STATUS": "running",
+ },
+ },
+ want: s,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := ServiceFromContainerEnvironment(test.container)
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("ServiceFromContainerEnvironment for %s is %v, want %v", test.name, got, test.want)
+ }
+ }
+}
+
+// testService is a test helper function to create a Service
+// type with all fields set to a fake value.
+func testService() *Service {
+ s := new(Service)
+
+ s.SetID(1)
+ s.SetBuildID(1)
+ s.SetRepoID(1)
+ s.SetNumber(1)
+ s.SetName("postgres")
+ s.SetImage("postgres:12-alpine")
+ s.SetStatus("running")
+ s.SetExitCode(0)
+ s.SetCreated(1563474076)
+ s.SetStarted(1563474078)
+ s.SetFinished(1563474079)
+ s.SetHost("example.company.com")
+ s.SetRuntime("docker")
+ s.SetDistribution("linux")
+
+ return s
+}
diff --git a/api/types/step.go b/api/types/step.go
new file mode 100644
index 000000000..52d96f45c
--- /dev/null
+++ b/api/types/step.go
@@ -0,0 +1,727 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "strconv"
+ "time"
+
+ "github.com/go-vela/server/compiler/types/pipeline"
+ "github.com/go-vela/server/constants"
+)
+
+// Step is the API representation of a step in a build.
+//
+// swagger:model Step
+type Step struct {
+ ID *int64 `json:"id,omitempty"`
+ BuildID *int64 `json:"build_id,omitempty"`
+ RepoID *int64 `json:"repo_id,omitempty"`
+ Number *int `json:"number,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Image *string `json:"image,omitempty"`
+ Stage *string `json:"stage,omitempty"`
+ Status *string `json:"status,omitempty"`
+ Error *string `json:"error,omitempty"`
+ ExitCode *int `json:"exit_code,omitempty"`
+ Created *int64 `json:"created,omitempty"`
+ Started *int64 `json:"started,omitempty"`
+ Finished *int64 `json:"finished,omitempty"`
+ Host *string `json:"host,omitempty"`
+ Runtime *string `json:"runtime,omitempty"`
+ Distribution *string `json:"distribution,omitempty"`
+ ReportAs *string `json:"report_as,omitempty"`
+}
+
+// Duration calculates and returns the total amount of
+// time the step ran for in a human-readable format.
+func (s *Step) Duration() string {
+ // check if the step doesn't have a started timestamp
+ if s.GetStarted() == 0 {
+ return "..."
+ }
+
+ // capture started unix timestamp from the step
+ started := time.Unix(s.GetStarted(), 0)
+
+ // check if the step doesn't have a finished timestamp
+ if s.GetFinished() == 0 {
+ // return the duration in a human-readable form by
+ // subtracting the step started time from the
+ // current time rounded to the nearest second
+ return time.Since(started).Round(time.Second).String()
+ }
+
+ // capture finished unix timestamp from the step
+ finished := time.Unix(s.GetFinished(), 0)
+
+ // calculate the duration by subtracting the step
+ // started time from the step finished time
+ duration := finished.Sub(started)
+
+ // return the duration in a human-readable form
+ return duration.String()
+}
+
+// Environment returns a list of environment variables
+// provided from the fields of the Step type.
+func (s *Step) Environment() map[string]string {
+ return map[string]string{
+ "VELA_STEP_CREATED": ToString(s.GetCreated()),
+ "VELA_STEP_DISTRIBUTION": ToString(s.GetDistribution()),
+ "VELA_STEP_EXIT_CODE": ToString(s.GetExitCode()),
+ "VELA_STEP_HOST": ToString(s.GetHost()),
+ "VELA_STEP_IMAGE": ToString(s.GetImage()),
+ "VELA_STEP_NAME": ToString(s.GetName()),
+ "VELA_STEP_NUMBER": ToString(s.GetNumber()),
+ "VELA_STEP_RUNTIME": ToString(s.GetRuntime()),
+ "VELA_STEP_STAGE": ToString(s.GetStage()),
+ "VELA_STEP_STARTED": ToString(s.GetStarted()),
+ "VELA_STEP_STATUS": ToString(s.GetStatus()),
+ "VELA_STEP_REPORT_AS": ToString(s.GetReportAs()),
+ }
+}
+
+// GetID returns the ID field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetID() int64 {
+ // return zero value if Step type or ID field is nil
+ if s == nil || s.ID == nil {
+ return 0
+ }
+
+ return *s.ID
+}
+
+// GetBuildID returns the BuildID field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetBuildID() int64 {
+ // return zero value if Step type or BuildID field is nil
+ if s == nil || s.BuildID == nil {
+ return 0
+ }
+
+ return *s.BuildID
+}
+
+// GetRepoID returns the RepoID field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetRepoID() int64 {
+ // return zero value if Step type or RepoID field is nil
+ if s == nil || s.RepoID == nil {
+ return 0
+ }
+
+ return *s.RepoID
+}
+
+// GetNumber returns the Number field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetNumber() int {
+ // return zero value if Step type or Number field is nil
+ if s == nil || s.Number == nil {
+ return 0
+ }
+
+ return *s.Number
+}
+
+// GetName returns the Name field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetName() string {
+ // return zero value if Step type or Name field is nil
+ if s == nil || s.Name == nil {
+ return ""
+ }
+
+ return *s.Name
+}
+
+// GetImage returns the Image field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetImage() string {
+ // return zero value if Step type of Image field is nil
+ if s == nil || s.Image == nil {
+ return ""
+ }
+
+ return *s.Image
+}
+
+// GetStage returns the Stage field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetStage() string {
+ // return zero value if Step type or Stage field is nil
+ if s == nil || s.Stage == nil {
+ return ""
+ }
+
+ return *s.Stage
+}
+
+// GetStatus returns the Status field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetStatus() string {
+ // return zero value if Step type or Status field is nil
+ if s == nil || s.Status == nil {
+ return ""
+ }
+
+ return *s.Status
+}
+
+// GetError returns the Error field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetError() string {
+ // return zero value if Step type or Error field is nil
+ if s == nil || s.Error == nil {
+ return ""
+ }
+
+ return *s.Error
+}
+
+// GetExitCode returns the ExitCode field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetExitCode() int {
+ // return zero value if Step type or ExitCode field is nil
+ if s == nil || s.ExitCode == nil {
+ return 0
+ }
+
+ return *s.ExitCode
+}
+
+// GetCreated returns the Created field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetCreated() int64 {
+ // return zero value if Step type or Created field is nil
+ if s == nil || s.Created == nil {
+ return 0
+ }
+
+ return *s.Created
+}
+
+// GetStarted returns the Started field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetStarted() int64 {
+ // return zero value if Step type or Started field is nil
+ if s == nil || s.Started == nil {
+ return 0
+ }
+
+ return *s.Started
+}
+
+// GetFinished returns the Finished field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetFinished() int64 {
+ // return zero value if Step type or Finished field is nil
+ if s == nil || s.Finished == nil {
+ return 0
+ }
+
+ return *s.Finished
+}
+
+// GetHost returns the Host field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetHost() string {
+ // return zero value if Step type or Host field is nil
+ if s == nil || s.Host == nil {
+ return ""
+ }
+
+ return *s.Host
+}
+
+// GetRuntime returns the Runtime field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetRuntime() string {
+ // return zero value if Step type or Runtime field is nil
+ if s == nil || s.Runtime == nil {
+ return ""
+ }
+
+ return *s.Runtime
+}
+
+// GetDistribution returns the Runtime field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetDistribution() string {
+ // return zero value if Step type or Distribution field is nil
+ if s == nil || s.Distribution == nil {
+ return ""
+ }
+
+ return *s.Distribution
+}
+
+// GetReportAs returns the ReportAs field.
+//
+// When the provided Step type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (s *Step) GetReportAs() string {
+ // return zero value if Step type or ReportAs field is nil
+ if s == nil || s.ReportAs == nil {
+ return ""
+ }
+
+ return *s.ReportAs
+}
+
+// SetID sets the ID field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetID(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.ID = &v
+}
+
+// SetBuildID sets the BuildID field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetBuildID(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.BuildID = &v
+}
+
+// SetRepoID sets the RepoID field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetRepoID(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.RepoID = &v
+}
+
+// SetNumber sets the Number field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetNumber(v int) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Number = &v
+}
+
+// SetName sets the Name field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetName(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Name = &v
+}
+
+// SetImage sets the Image field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetImage(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Image = &v
+}
+
+// SetStage sets the Stage field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetStage(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Stage = &v
+}
+
+// SetStatus sets the Status field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetStatus(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Status = &v
+}
+
+// SetError sets the Error field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetError(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Error = &v
+}
+
+// SetExitCode sets the ExitCode field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetExitCode(v int) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.ExitCode = &v
+}
+
+// SetCreated sets the Created field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetCreated(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Created = &v
+}
+
+// SetStarted sets the Started field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetStarted(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Started = &v
+}
+
+// SetFinished sets the Finished field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetFinished(v int64) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Finished = &v
+}
+
+// SetHost sets the Host field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetHost(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Host = &v
+}
+
+// SetRuntime sets the Runtime field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetRuntime(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Runtime = &v
+}
+
+// SetDistribution sets the Distribution field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetDistribution(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.Distribution = &v
+}
+
+// SetReportAs sets the ReportAs field.
+//
+// When the provided Step type is nil, it
+// will set nothing and immediately return.
+func (s *Step) SetReportAs(v string) {
+ // return if Step type is nil
+ if s == nil {
+ return
+ }
+
+ s.ReportAs = &v
+}
+
+// String implements the Stringer interface for the Step type.
+func (s *Step) String() string {
+ return fmt.Sprintf(`{
+ BuildID: %d,
+ Created: %d,
+ Distribution: %s,
+ Error: %s,
+ ExitCode: %d,
+ Finished: %d,
+ Host: %s,
+ ID: %d,
+ Image: %s,
+ Name: %s,
+ Number: %d,
+ RepoID: %d,
+ ReportAs: %s,
+ Runtime: %s,
+ Stage: %s,
+ Started: %d,
+ Status: %s,
+}`,
+ s.GetBuildID(),
+ s.GetCreated(),
+ s.GetDistribution(),
+ s.GetError(),
+ s.GetExitCode(),
+ s.GetFinished(),
+ s.GetHost(),
+ s.GetID(),
+ s.GetImage(),
+ s.GetName(),
+ s.GetNumber(),
+ s.GetRepoID(),
+ s.GetReportAs(),
+ s.GetRuntime(),
+ s.GetStage(),
+ s.GetStarted(),
+ s.GetStatus(),
+ )
+}
+
+// StepFromBuildContainer creates a new Step based on a Build and pipeline Container.
+func StepFromBuildContainer(build *Build, ctn *pipeline.Container) *Step {
+ // create new step type we want to return
+ s := new(Step)
+
+ // default status to Pending
+ s.SetStatus(constants.StatusPending)
+
+ // copy fields from build
+ if build != nil {
+ // set values from the build
+ s.SetHost(build.GetHost())
+ s.SetRuntime(build.GetRuntime())
+ s.SetDistribution(build.GetDistribution())
+ }
+
+ // copy fields from container
+ if ctn != nil && ctn.Name != "" {
+ // set values from the container
+ s.SetName(ctn.Name)
+ s.SetNumber(ctn.Number)
+ s.SetImage(ctn.Image)
+ s.SetReportAs(ctn.ReportAs)
+
+ // check if the VELA_STEP_STAGE environment variable exists
+ value, ok := ctn.Environment["VELA_STEP_STAGE"]
+ if ok {
+ // set the Stage field to the value from environment variable
+ s.SetStage(value)
+ }
+ }
+
+ return s
+}
+
+// StepFromContainerEnvironment converts the pipeline Container
+// to an API Step using the container's Environment.
+func StepFromContainerEnvironment(ctn *pipeline.Container) *Step {
+ // check if container or container environment are nil
+ if ctn == nil || ctn.Environment == nil {
+ return nil
+ }
+
+ // create new step type we want to return
+ s := new(Step)
+
+ // check if the VELA_STEP_DISTRIBUTION environment variable exists
+ value, ok := ctn.Environment["VELA_STEP_DISTRIBUTION"]
+ if ok {
+ // set the Distribution field to the value from environment variable
+ s.SetDistribution(value)
+ }
+
+ // check if the VELA_STEP_HOST environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_HOST"]
+ if ok {
+ // set the Host field to the value from environment variable
+ s.SetHost(value)
+ }
+
+ // check if the VELA_STEP_IMAGE environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_IMAGE"]
+ if ok {
+ // set the Image field to the value from environment variable
+ s.SetImage(value)
+ }
+
+ // check if the VELA_STEP_NAME environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_NAME"]
+ if ok {
+ // set the Name field to the value from environment variable
+ s.SetName(value)
+ }
+
+ // check if the VELA_STEP_REPORT_AS environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_REPORT_AS"]
+ if ok {
+ // set the ReportAs field to the value from environment variable
+ s.SetReportAs(value)
+ }
+
+ // check if the VELA_STEP_RUNTIME environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_RUNTIME"]
+ if ok {
+ // set the Runtime field to the value from environment variable
+ s.SetRuntime(value)
+ }
+
+ // check if the VELA_STEP_STAGE environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_STAGE"]
+ if ok {
+ // set the Stage field to the value from environment variable
+ s.SetStage(value)
+ }
+
+ // check if the VELA_STEP_STATUS environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_STATUS"]
+ if ok {
+ // set the Status field to the value from environment variable
+ s.SetStatus(value)
+ }
+
+ // check if the VELA_STEP_CREATED environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_CREATED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Created field to the parsed int64
+ s.SetCreated(i)
+ }
+ }
+
+ // check if the VELA_STEP_EXIT_CODE environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_EXIT_CODE"]
+ if ok {
+ // parse the environment variable value into an int
+ i, err := strconv.ParseInt(value, 10, 0)
+ if err == nil {
+ // set the ExitCode field to the parsed int
+ s.SetExitCode(int(i))
+ }
+ }
+
+ // check if the VELA_STEP_FINISHED environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_FINISHED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Finished field to the parsed int64
+ s.SetFinished(i)
+ }
+ }
+
+ // check if the VELA_STEP_NUMBER environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_NUMBER"]
+ if ok {
+ // parse the environment variable value into an int
+ i, err := strconv.ParseInt(value, 10, 0)
+ if err == nil {
+ // set the Number field to the parsed int
+ s.SetNumber(int(i))
+ }
+ }
+
+ // check if the VELA_STEP_STARTED environment variable exists
+ value, ok = ctn.Environment["VELA_STEP_STARTED"]
+ if ok {
+ // parse the environment variable value into an int64
+ i, err := strconv.ParseInt(value, 10, 64)
+ if err == nil {
+ // set the Started field to the parsed int64
+ s.SetStarted(i)
+ }
+ }
+
+ return s
+}
diff --git a/api/types/step_test.go b/api/types/step_test.go
new file mode 100644
index 000000000..861f50f23
--- /dev/null
+++ b/api/types/step_test.go
@@ -0,0 +1,482 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+ "time"
+
+ "github.com/go-vela/server/compiler/types/pipeline"
+)
+
+func TestTypes_Step_Duration(t *testing.T) {
+ // setup types
+ unfinished := testStep()
+ unfinished.SetFinished(0)
+
+ // setup tests
+ tests := []struct {
+ step *Step
+ want string
+ }{
+ {
+ step: testStep(),
+ want: "1s",
+ },
+ {
+ step: unfinished,
+ want: time.Since(time.Unix(unfinished.GetStarted(), 0)).Round(time.Second).String(),
+ },
+ {
+ step: new(Step),
+ want: "...",
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.step.Duration()
+
+ if got != test.want {
+ t.Errorf("Duration is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestTypes_Step_Environment(t *testing.T) {
+ // setup types
+ want := map[string]string{
+ "VELA_STEP_CREATED": "1563474076",
+ "VELA_STEP_DISTRIBUTION": "linux",
+ "VELA_STEP_EXIT_CODE": "0",
+ "VELA_STEP_HOST": "example.company.com",
+ "VELA_STEP_IMAGE": "target/vela-git:v0.3.0",
+ "VELA_STEP_NAME": "clone",
+ "VELA_STEP_NUMBER": "1",
+ "VELA_STEP_REPORT_AS": "test",
+ "VELA_STEP_RUNTIME": "docker",
+ "VELA_STEP_STAGE": "",
+ "VELA_STEP_STARTED": "1563474078",
+ "VELA_STEP_STATUS": "running",
+ }
+
+ // run test
+ got := testStep().Environment()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Environment is %v, want %v", got, want)
+ }
+}
+
+func TestTypes_Step_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ step *Step
+ want *Step
+ }{
+ {
+ step: testStep(),
+ want: testStep(),
+ },
+ {
+ step: new(Step),
+ want: new(Step),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.step.GetID() != test.want.GetID() {
+ t.Errorf("GetID is %v, want %v", test.step.GetID(), test.want.GetID())
+ }
+
+ if test.step.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("GetBuildID is %v, want %v", test.step.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if test.step.GetRepoID() != test.want.GetRepoID() {
+ t.Errorf("GetRepoID is %v, want %v", test.step.GetRepoID(), test.want.GetRepoID())
+ }
+
+ if test.step.GetNumber() != test.want.GetNumber() {
+ t.Errorf("GetNumber is %v, want %v", test.step.GetNumber(), test.want.GetNumber())
+ }
+
+ if test.step.GetName() != test.want.GetName() {
+ t.Errorf("GetName is %v, want %v", test.step.GetName(), test.want.GetName())
+ }
+
+ if test.step.GetImage() != test.want.GetImage() {
+ t.Errorf("GetImage is %v, want %v", test.step.GetImage(), test.want.GetImage())
+ }
+
+ if test.step.GetStage() != test.want.GetStage() {
+ t.Errorf("GetStage is %v, want %v", test.step.GetStage(), test.want.GetStage())
+ }
+
+ if test.step.GetStatus() != test.want.GetStatus() {
+ t.Errorf("GetStatus is %v, want %v", test.step.GetStatus(), test.want.GetStatus())
+ }
+
+ if test.step.GetError() != test.want.GetError() {
+ t.Errorf("GetError is %v, want %v", test.step.GetError(), test.want.GetError())
+ }
+
+ if test.step.GetExitCode() != test.want.GetExitCode() {
+ t.Errorf("GetExitCode is %v, want %v", test.step.GetExitCode(), test.want.GetExitCode())
+ }
+
+ if test.step.GetCreated() != test.want.GetCreated() {
+ t.Errorf("GetCreated is %v, want %v", test.step.GetCreated(), test.want.GetCreated())
+ }
+
+ if test.step.GetStarted() != test.want.GetStarted() {
+ t.Errorf("GetStarted is %v, want %v", test.step.GetStarted(), test.want.GetStarted())
+ }
+
+ if test.step.GetFinished() != test.want.GetFinished() {
+ t.Errorf("GetFinished is %v, want %v", test.step.GetFinished(), test.want.GetFinished())
+ }
+
+ if test.step.GetHost() != test.want.GetHost() {
+ t.Errorf("GetHost is %v, want %v", test.step.GetHost(), test.want.GetHost())
+ }
+
+ if test.step.GetRuntime() != test.want.GetRuntime() {
+ t.Errorf("GetRuntime is %v, want %v", test.step.GetRuntime(), test.want.GetRuntime())
+ }
+
+ if test.step.GetDistribution() != test.want.GetDistribution() {
+ t.Errorf("GetDistribution is %v, want %v", test.step.GetDistribution(), test.want.GetDistribution())
+ }
+
+ if test.step.GetReportAs() != test.want.GetReportAs() {
+ t.Errorf("GetReportAs is %v, want %v", test.step.GetReportAs(), test.want.GetReportAs())
+ }
+ }
+}
+
+func TestTypes_Step_Setters(t *testing.T) {
+ // setup types
+ var s *Step
+
+ // setup tests
+ tests := []struct {
+ step *Step
+ want *Step
+ }{
+ {
+ step: testStep(),
+ want: testStep(),
+ },
+ {
+ step: s,
+ want: new(Step),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.step.SetID(test.want.GetID())
+ test.step.SetBuildID(test.want.GetBuildID())
+ test.step.SetRepoID(test.want.GetRepoID())
+ test.step.SetNumber(test.want.GetNumber())
+ test.step.SetName(test.want.GetName())
+ test.step.SetImage(test.want.GetImage())
+ test.step.SetStage(test.want.GetStage())
+ test.step.SetStatus(test.want.GetStatus())
+ test.step.SetError(test.want.GetError())
+ test.step.SetExitCode(test.want.GetExitCode())
+ test.step.SetCreated(test.want.GetCreated())
+ test.step.SetStarted(test.want.GetStarted())
+ test.step.SetFinished(test.want.GetFinished())
+ test.step.SetHost(test.want.GetHost())
+ test.step.SetRuntime(test.want.GetRuntime())
+ test.step.SetDistribution(test.want.GetDistribution())
+ test.step.SetReportAs(test.want.GetReportAs())
+
+ if test.step.GetID() != test.want.GetID() {
+ t.Errorf("SetID is %v, want %v", test.step.GetID(), test.want.GetID())
+ }
+
+ if test.step.GetBuildID() != test.want.GetBuildID() {
+ t.Errorf("SetBuildID is %v, want %v", test.step.GetBuildID(), test.want.GetBuildID())
+ }
+
+ if test.step.GetRepoID() != test.want.GetRepoID() {
+ t.Errorf("SetRepoID is %v, want %v", test.step.GetRepoID(), test.want.GetRepoID())
+ }
+
+ if test.step.GetNumber() != test.want.GetNumber() {
+ t.Errorf("SetNumber is %v, want %v", test.step.GetNumber(), test.want.GetNumber())
+ }
+
+ if test.step.GetName() != test.want.GetName() {
+ t.Errorf("SetName is %v, want %v", test.step.GetName(), test.want.GetName())
+ }
+
+ if test.step.GetImage() != test.want.GetImage() {
+ t.Errorf("SetImage is %v, want %v", test.step.GetImage(), test.want.GetImage())
+ }
+
+ if test.step.GetStage() != test.want.GetStage() {
+ t.Errorf("SetStage is %v, want %v", test.step.GetStage(), test.want.GetStage())
+ }
+
+ if test.step.GetStatus() != test.want.GetStatus() {
+ t.Errorf("SetStatus is %v, want %v", test.step.GetStatus(), test.want.GetStatus())
+ }
+
+ if test.step.GetError() != test.want.GetError() {
+ t.Errorf("SetError is %v, want %v", test.step.GetError(), test.want.GetError())
+ }
+
+ if test.step.GetExitCode() != test.want.GetExitCode() {
+ t.Errorf("SetExitCode is %v, want %v", test.step.GetExitCode(), test.want.GetExitCode())
+ }
+
+ if test.step.GetCreated() != test.want.GetCreated() {
+ t.Errorf("SetCreated is %v, want %v", test.step.GetCreated(), test.want.GetCreated())
+ }
+
+ if test.step.GetStarted() != test.want.GetStarted() {
+ t.Errorf("SetStarted is %v, want %v", test.step.GetStarted(), test.want.GetStarted())
+ }
+
+ if test.step.GetFinished() != test.want.GetFinished() {
+ t.Errorf("SetFinished is %v, want %v", test.step.GetFinished(), test.want.GetFinished())
+ }
+
+ if test.step.GetHost() != test.want.GetHost() {
+ t.Errorf("SetHost is %v, want %v", test.step.GetHost(), test.want.GetHost())
+ }
+
+ if test.step.GetRuntime() != test.want.GetRuntime() {
+ t.Errorf("SetRuntime is %v, want %v", test.step.GetRuntime(), test.want.GetRuntime())
+ }
+
+ if test.step.GetDistribution() != test.want.GetDistribution() {
+ t.Errorf("SetDistribution is %v, want %v", test.step.GetDistribution(), test.want.GetDistribution())
+ }
+
+ if test.step.GetReportAs() != test.want.GetReportAs() {
+ t.Errorf("SetReportAs is %v, want %v", test.step.GetReportAs(), test.want.GetReportAs())
+ }
+ }
+}
+
+func TestTypes_Step_String(t *testing.T) {
+ // setup types
+ s := testStep()
+
+ want := fmt.Sprintf(`{
+ BuildID: %d,
+ Created: %d,
+ Distribution: %s,
+ Error: %s,
+ ExitCode: %d,
+ Finished: %d,
+ Host: %s,
+ ID: %d,
+ Image: %s,
+ Name: %s,
+ Number: %d,
+ RepoID: %d,
+ ReportAs: %s,
+ Runtime: %s,
+ Stage: %s,
+ Started: %d,
+ Status: %s,
+}`,
+ s.GetBuildID(),
+ s.GetCreated(),
+ s.GetDistribution(),
+ s.GetError(),
+ s.GetExitCode(),
+ s.GetFinished(),
+ s.GetHost(),
+ s.GetID(),
+ s.GetImage(),
+ s.GetName(),
+ s.GetNumber(),
+ s.GetRepoID(),
+ s.GetReportAs(),
+ s.GetRuntime(),
+ s.GetStage(),
+ s.GetStarted(),
+ s.GetStatus(),
+ )
+
+ // run test
+ got := s.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+func TestTypes_StepFromBuildContainer(t *testing.T) {
+ // setup types
+ s := testStep()
+ s.SetStage("clone")
+ s.SetStatus("pending")
+
+ // modify fields that aren't set
+ s.ID = nil
+ s.BuildID = nil
+ s.RepoID = nil
+ s.ExitCode = nil
+ s.Created = nil
+ s.Started = nil
+ s.Finished = nil
+
+ tests := []struct {
+ name string
+ container *pipeline.Container
+ build *Build
+ want *Step
+ }{
+ {
+ name: "nil container with nil build",
+ container: nil,
+ build: nil,
+ want: &Step{Status: s.Status},
+ },
+ {
+ name: "empty container with nil build",
+ container: new(pipeline.Container),
+ build: nil,
+ want: &Step{Status: s.Status},
+ },
+ {
+ name: "nil container with build",
+ container: nil,
+ build: testBuild(),
+ want: &Step{
+ Status: s.Status,
+ Host: s.Host,
+ Runtime: s.Runtime,
+ Distribution: s.Distribution,
+ },
+ },
+ {
+ name: "empty container with build",
+ container: new(pipeline.Container),
+ build: testBuild(),
+ want: &Step{
+ Status: s.Status,
+ Host: s.Host,
+ Runtime: s.Runtime,
+ Distribution: s.Distribution,
+ },
+ },
+ {
+ name: "container with build",
+ container: &pipeline.Container{
+ Name: s.GetName(),
+ Number: s.GetNumber(),
+ Image: s.GetImage(),
+ ReportAs: s.GetReportAs(),
+ Environment: map[string]string{
+ "VELA_STEP_STAGE": "clone",
+ },
+ },
+ build: testBuild(),
+ want: s,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := StepFromBuildContainer(test.build, test.container)
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("StepFromBuildContainer for %s is %v, want %v", test.name, got, test.want)
+ }
+ }
+}
+
+func TestTypes_StepFromContainerEnvironment(t *testing.T) {
+ // setup types
+ s := testStep()
+ s.SetStage("clone")
+
+ // modify fields that aren't set via environment variables
+ s.ID = nil
+ s.BuildID = nil
+ s.RepoID = nil
+
+ // setup tests
+ tests := []struct {
+ name string
+ container *pipeline.Container
+ want *Step
+ }{
+ {
+ name: "nil container",
+ container: nil,
+ want: nil,
+ },
+ {
+ name: "empty container",
+ container: new(pipeline.Container),
+ want: nil,
+ },
+ {
+ name: "container",
+ container: &pipeline.Container{
+ Environment: map[string]string{
+ "VELA_STEP_CREATED": "1563474076",
+ "VELA_STEP_DISTRIBUTION": "linux",
+ "VELA_STEP_EXIT_CODE": "0",
+ "VELA_STEP_FINISHED": "1563474079",
+ "VELA_STEP_HOST": "example.company.com",
+ "VELA_STEP_IMAGE": "target/vela-git:v0.3.0",
+ "VELA_STEP_NAME": "clone",
+ "VELA_STEP_NUMBER": "1",
+ "VELA_STEP_REPORT_AS": "test",
+ "VELA_STEP_RUNTIME": "docker",
+ "VELA_STEP_STAGE": "clone",
+ "VELA_STEP_STARTED": "1563474078",
+ "VELA_STEP_STATUS": "running",
+ },
+ },
+ want: s,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := StepFromContainerEnvironment(test.container)
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("StepFromContainerEnvironment for %s is %v, want %v", test.name, got, test.want)
+ }
+ }
+}
+
+// testStep is a test helper function to create a Step
+// type with all fields set to a fake value.
+func testStep() *Step {
+ s := new(Step)
+
+ s.SetID(1)
+ s.SetBuildID(1)
+ s.SetRepoID(1)
+ s.SetNumber(1)
+ s.SetName("clone")
+ s.SetImage("target/vela-git:v0.3.0")
+ s.SetStatus("running")
+ s.SetExitCode(0)
+ s.SetCreated(1563474076)
+ s.SetStarted(1563474078)
+ s.SetFinished(1563474079)
+ s.SetHost("example.company.com")
+ s.SetRuntime("docker")
+ s.SetDistribution("linux")
+ s.SetReportAs("test")
+
+ return s
+}
diff --git a/api/types/template.go b/api/types/template.go
new file mode 100644
index 000000000..2090e5ae7
--- /dev/null
+++ b/api/types/template.go
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: Apache-2.0
+
+//nolint:dupl // ignore false positive with build_queue.go
+package types
+
+import (
+ "fmt"
+)
+
+// Template is the API representation of a template for a pipeline.
+//
+// swagger:model Template
+type Template struct {
+ Link *string `json:"link,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Source *string `json:"source,omitempty"`
+ Type *string `json:"type,omitempty"`
+}
+
+// GetLink returns the Link field.
+//
+// When the provided Template type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (t *Template) GetLink() string {
+ // return zero value if Template type or Link field is nil
+ if t == nil || t.Link == nil {
+ return ""
+ }
+
+ return *t.Link
+}
+
+// GetName returns the Name field.
+//
+// When the provided Template type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (t *Template) GetName() string {
+ // return zero value if Template type or Name field is nil
+ if t == nil || t.Name == nil {
+ return ""
+ }
+
+ return *t.Name
+}
+
+// GetSource returns the Source field.
+//
+// When the provided Template type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (t *Template) GetSource() string {
+ // return zero value if Template type or Source field is nil
+ if t == nil || t.Source == nil {
+ return ""
+ }
+
+ return *t.Source
+}
+
+// GetType returns the Type field.
+//
+// When the provided Template type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (t *Template) GetType() string {
+ // return zero value if Template type or Type field is nil
+ if t == nil || t.Type == nil {
+ return ""
+ }
+
+ return *t.Type
+}
+
+// SetLink sets the Link field.
+//
+// When the provided Template type is nil, it
+// will set nothing and immediately return.
+func (t *Template) SetLink(v string) {
+ // return if Template type is nil
+ if t == nil {
+ return
+ }
+
+ t.Link = &v
+}
+
+// SetName sets the Name field.
+//
+// When the provided Template type is nil, it
+// will set nothing and immediately return.
+func (t *Template) SetName(v string) {
+ // return if Template type is nil
+ if t == nil {
+ return
+ }
+
+ t.Name = &v
+}
+
+// SetSource sets the Source field.
+//
+// When the provided Template type is nil, it
+// will set nothing and immediately return.
+func (t *Template) SetSource(v string) {
+ // return if Template type is nil
+ if t == nil {
+ return
+ }
+
+ t.Source = &v
+}
+
+// SetType sets the Type field.
+//
+// When the provided Template type is nil, it
+// will set nothing and immediately return.
+func (t *Template) SetType(v string) {
+ // return if Template type is nil
+ if t == nil {
+ return
+ }
+
+ t.Type = &v
+}
+
+// String implements the Stringer interface for the Template type.
+func (t *Template) String() string {
+ return fmt.Sprintf(`{
+ Link: %s,
+ Name: %s,
+ Source: %s,
+ Type: %s,
+}`,
+ t.GetLink(),
+ t.GetName(),
+ t.GetSource(),
+ t.GetType(),
+ )
+}
diff --git a/api/types/template_test.go b/api/types/template_test.go
new file mode 100644
index 000000000..c08793222
--- /dev/null
+++ b/api/types/template_test.go
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestTypes_Template_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ template *Template
+ want *Template
+ }{
+ {
+ template: testTemplate(),
+ want: testTemplate(),
+ },
+ {
+ template: new(Template),
+ want: new(Template),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.template.GetLink() != test.want.GetLink() {
+ t.Errorf("GetLink is %v, want %v", test.template.GetLink(), test.want.GetLink())
+ }
+
+ if test.template.GetName() != test.want.GetName() {
+ t.Errorf("GetName is %v, want %v", test.template.GetName(), test.want.GetName())
+ }
+
+ if test.template.GetSource() != test.want.GetSource() {
+ t.Errorf("GetSource is %v, want %v", test.template.GetSource(), test.want.GetSource())
+ }
+
+ if test.template.GetType() != test.want.GetType() {
+ t.Errorf("GetType is %v, want %v", test.template.GetType(), test.want.GetType())
+ }
+ }
+}
+
+func TestTypes_Template_Setters(t *testing.T) {
+ // setup types
+ var tmpl *Template
+
+ // setup tests
+ tests := []struct {
+ template *Template
+ want *Template
+ }{
+ {
+ template: testTemplate(),
+ want: testTemplate(),
+ },
+ {
+ template: tmpl,
+ want: new(Template),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.template.SetLink(test.want.GetLink())
+ test.template.SetName(test.want.GetName())
+ test.template.SetSource(test.want.GetSource())
+ test.template.SetType(test.want.GetType())
+
+ if test.template.GetLink() != test.want.GetLink() {
+ t.Errorf("SetLink is %v, want %v", test.template.GetLink(), test.want.GetLink())
+ }
+
+ if test.template.GetName() != test.want.GetName() {
+ t.Errorf("SetName is %v, want %v", test.template.GetName(), test.want.GetName())
+ }
+
+ if test.template.GetSource() != test.want.GetSource() {
+ t.Errorf("SetSource is %v, want %v", test.template.GetSource(), test.want.GetSource())
+ }
+
+ if test.template.GetType() != test.want.GetType() {
+ t.Errorf("SetType is %v, want %v", test.template.GetType(), test.want.GetType())
+ }
+ }
+}
+
+func TestTypes_Template_String(t *testing.T) {
+ // setup types
+ tmpl := testTemplate()
+
+ want := fmt.Sprintf(`{
+ Link: %s,
+ Name: %s,
+ Source: %s,
+ Type: %s,
+}`,
+ tmpl.GetLink(),
+ tmpl.GetName(),
+ tmpl.GetSource(),
+ tmpl.GetType(),
+ )
+
+ // run test
+ got := tmpl.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+// testTemplate is a test helper function to create a Template
+// type with all fields set to a fake value.
+func testTemplate() *Template {
+ t := new(Template)
+
+ t.SetLink("https://github.com/github/octocat/blob/branch/template.yml")
+ t.SetName("template")
+ t.SetSource("github.com/github/octocat/template.yml@branch")
+ t.SetType("github")
+
+ return t
+}
diff --git a/api/types/token.go b/api/types/token.go
new file mode 100644
index 000000000..e49159254
--- /dev/null
+++ b/api/types/token.go
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import "fmt"
+
+// Token is the API representation of a token response from server.
+//
+// swagger:model Token
+type Token struct {
+ Token *string `json:"token,omitempty"`
+}
+
+// GetToken returns the Token field.
+//
+// When the provided Token type is nil, or the field within
+// the type is nil, it returns the zero value for the field.
+func (l *Token) GetToken() string {
+ // return zero value if Token type or Token field is nil
+ if l == nil || l.Token == nil {
+ return ""
+ }
+
+ return *l.Token
+}
+
+// SetToken sets the Token field.
+//
+// When the provided Token type is nil, it
+// will set nothing and immediately return.
+func (l *Token) SetToken(v string) {
+ // return if Token type is nil
+ if l == nil {
+ return
+ }
+
+ l.Token = &v
+}
+
+// String implements the Stringer interface for the Token type.
+func (l *Token) String() string {
+ return fmt.Sprintf(`{
+ Token: %s,
+}`,
+ l.GetToken(),
+ )
+}
diff --git a/api/types/token_test.go b/api/types/token_test.go
new file mode 100644
index 000000000..26fa57912
--- /dev/null
+++ b/api/types/token_test.go
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestTypes_Token_Getters(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ token *Token
+ want *Token
+ }{
+ {
+ token: testToken(),
+ want: testToken(),
+ },
+ {
+ token: new(Token),
+ want: new(Token),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ if test.token.GetToken() != test.want.GetToken() {
+ t.Errorf("GetToken is %v, want %v", test.token.GetToken(), test.want.GetToken())
+ }
+ }
+}
+
+func TestTypes_Token_Setters(t *testing.T) {
+ // setup types
+ var l *Token
+
+ // setup tests
+ tests := []struct {
+ token *Token
+ want *Token
+ }{
+ {
+ token: testToken(),
+ want: testToken(),
+ },
+ {
+ token: l,
+ want: new(Token),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ test.token.SetToken(test.want.GetToken())
+
+ if test.token.GetToken() != test.want.GetToken() {
+ t.Errorf("SetToken is %v, want %v", test.token.GetToken(), test.want.GetToken())
+ }
+ }
+}
+
+func TestToken_String(t *testing.T) {
+ // setup types
+ l := testToken()
+
+ want := fmt.Sprintf(`{
+ Token: %s,
+}`,
+ l.GetToken(),
+ )
+
+ // run test
+ got := l.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+// testToken is a test helper function to create a Token
+// type with all fields set to a fake value.
+func testToken() *Token {
+ l := new(Token)
+
+ l.SetToken("superSecretToken")
+
+ return l
+}
diff --git a/api/user/create_token.go b/api/user/create_token.go
index 2eb0c9028..bb1345193 100644
--- a/api/user/create_token.go
+++ b/api/user/create_token.go
@@ -10,11 +10,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/user/token users CreateToken
@@ -76,5 +76,5 @@ func CreateToken(c *gin.Context) {
l.Info("user updated - token created")
- c.JSON(http.StatusOK, library.Token{Token: &at})
+ c.JSON(http.StatusOK, types.Token{Token: &at})
}
diff --git a/api/user/delete_token.go b/api/user/delete_token.go
index 8ee9f27da..6a03d21e8 100644
--- a/api/user/delete_token.go
+++ b/api/user/delete_token.go
@@ -10,11 +10,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// swagger:operation DELETE /api/v1/user/token users DeleteToken
@@ -76,5 +76,5 @@ func DeleteToken(c *gin.Context) {
l.Info("user updated - token rotated")
- c.JSON(http.StatusOK, library.Token{Token: &at})
+ c.JSON(http.StatusOK, types.Token{Token: &at})
}
diff --git a/api/user/get_source.go b/api/user/get_source.go
index 19b75eea3..4a7fe2bf2 100644
--- a/api/user/get_source.go
+++ b/api/user/get_source.go
@@ -71,7 +71,7 @@ func GetSourceRepos(c *gin.Context) {
name := srepo.Name
active := false
- // library struct to omit optional fields
+ // API struct to omit optional fields
repo := types.Repo{
Org: org,
Name: name,
diff --git a/api/webhook/post.go b/api/webhook/post.go
index 20576acd3..d8ca86ab7 100644
--- a/api/webhook/post.go
+++ b/api/webhook/post.go
@@ -20,13 +20,12 @@ import (
"github.com/go-vela/server/api/build"
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
var baseErr = "unable to process webhook"
@@ -780,7 +779,7 @@ func RenameRepository(ctx context.Context, h *types.Hook, r *types.Repo, c *gin.
return nil, fmt.Errorf("unable to get secret count for repo %s/%s: %w", dbR.GetOrg(), dbR.GetName(), err)
}
- secrets := []*library.Secret{}
+ secrets := []*types.Secret{}
page := 1
// capture all secrets belonging to certain repo in database
for repoSecrets := int64(0); repoSecrets < t; repoSecrets += 100 {
diff --git a/api/worker/create.go b/api/worker/create.go
index cfac76e54..9437f47df 100644
--- a/api/worker/create.go
+++ b/api/worker/create.go
@@ -12,12 +12,11 @@ import (
"github.com/sirupsen/logrus"
"github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/workers workers CreateWorker
@@ -105,7 +104,7 @@ func CreateWorker(c *gin.Context) {
// if symmetric token configured, send back symmetric token
case constants.ServerWorkerTokenType:
if secret, ok := c.Value("secret").(string); ok {
- tkn := new(library.Token)
+ tkn := new(types.Token)
tkn.SetToken(secret)
c.JSON(http.StatusCreated, tkn)
@@ -127,7 +126,7 @@ func CreateWorker(c *gin.Context) {
Hostname: cl.Subject,
}
- tkn := new(library.Token)
+ tkn := new(types.Token)
wt, err := tm.MintToken(wmto)
if err != nil {
diff --git a/api/worker/refresh.go b/api/worker/refresh.go
index 51098efe2..7a1c86766 100644
--- a/api/worker/refresh.go
+++ b/api/worker/refresh.go
@@ -11,13 +11,13 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/worker"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// swagger:operation POST /api/v1/workers/{worker}/refresh workers RefreshWorkerAuth
@@ -98,7 +98,7 @@ func Refresh(c *gin.Context) {
// if symmetric token configured, send back symmetric token
case constants.ServerWorkerTokenType:
if secret, ok := c.Value("secret").(string); ok {
- tkn := new(library.Token)
+ tkn := new(types.Token)
tkn.SetToken(secret)
c.JSON(http.StatusOK, tkn)
@@ -120,7 +120,7 @@ func Refresh(c *gin.Context) {
Hostname: cl.Subject,
}
- tkn := new(library.Token)
+ tkn := new(types.Token)
wt, err := tm.MintToken(wmto)
if err != nil {
diff --git a/cmd/vela-server/main.go b/cmd/vela-server/main.go
index d1207328f..5af8a852c 100644
--- a/cmd/vela-server/main.go
+++ b/cmd/vela-server/main.go
@@ -13,13 +13,13 @@ import (
_ "github.com/joho/godotenv/autoload"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/secret"
"github.com/go-vela/server/tracing"
"github.com/go-vela/server/version"
- "github.com/go-vela/types/constants"
)
//nolint:funlen // ignore line length
diff --git a/cmd/vela-server/schedule.go b/cmd/vela-server/schedule.go
index 21729bed9..a06c724a1 100644
--- a/cmd/vela-server/schedule.go
+++ b/cmd/vela-server/schedule.go
@@ -16,12 +16,12 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/settings"
"github.com/go-vela/server/compiler"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
const (
diff --git a/cmd/vela-server/secret.go b/cmd/vela-server/secret.go
index 2ca65615a..474b4d0d9 100644
--- a/cmd/vela-server/secret.go
+++ b/cmd/vela-server/secret.go
@@ -6,9 +6,9 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/secret"
- "github.com/go-vela/types/constants"
)
// helper function to setup the secrets engines from the CLI arguments.
diff --git a/cmd/vela-server/validate.go b/cmd/vela-server/validate.go
index a8ba5e064..4dd9509df 100644
--- a/cmd/vela-server/validate.go
+++ b/cmd/vela-server/validate.go
@@ -10,7 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func validate(c *cli.Context) error {
diff --git a/compiler/engine.go b/compiler/engine.go
index 0f09c7ecb..31f85852e 100644
--- a/compiler/engine.go
+++ b/compiler/engine.go
@@ -117,7 +117,7 @@ type Engine interface {
// With Compiler Interface Functions
// WithBuild defines a function that sets
- // the library build type in the Engine.
+ // the API build type in the Engine.
WithBuild(*api.Build) Engine
// WithComment defines a function that sets
// the comment in the Engine.
@@ -138,10 +138,10 @@ type Engine interface {
// the compiler Metadata type in the Engine.
WithMetadata(*internal.Metadata) Engine
// WithRepo defines a function that sets
- // the library repo type in the Engine.
+ // the API repo type in the Engine.
WithRepo(*api.Repo) Engine
// WithUser defines a function that sets
- // the library user type in the Engine.
+ // the API user type in the Engine.
WithUser(*api.User) Engine
// WithLabel defines a function that sets
// the label(s) in the Engine.
diff --git a/compiler/native/clone.go b/compiler/native/clone.go
index da1aacdf3..f6f4ffdbc 100644
--- a/compiler/native/clone.go
+++ b/compiler/native/clone.go
@@ -4,7 +4,7 @@ package native
import (
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/compiler/native/compile.go b/compiler/native/compile.go
index d7880cab2..49d071431 100644
--- a/compiler/native/compile.go
+++ b/compiler/native/compile.go
@@ -20,7 +20,7 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ModifyRequest contains the payload passed to the modification endpoint.
@@ -109,7 +109,7 @@ func (c *client) CompileLite(ctx context.Context, v interface{}, ruleData *pipel
return nil, nil, err
}
- // create the library pipeline object from the yaml configuration
+ // create the API pipeline object from the yaml configuration
_pipeline := p.ToPipelineAPI()
_pipeline.SetData(data)
_pipeline.SetType(c.repo.GetPipelineType())
@@ -503,7 +503,7 @@ func errorHandler(resp *http.Response, err error, attempts int) (*http.Response,
}
// modifyConfig sends the configuration to external http endpoint for modification.
-func (c *client) modifyConfig(build *yaml.Build, libraryBuild *api.Build, repo *api.Repo) (*yaml.Build, error) {
+func (c *client) modifyConfig(build *yaml.Build, apiBuild *api.Build, repo *api.Repo) (*yaml.Build, error) {
// create request to send to endpoint
data, err := yml.Marshal(build)
if err != nil {
@@ -512,10 +512,10 @@ func (c *client) modifyConfig(build *yaml.Build, libraryBuild *api.Build, repo *
modReq := &ModifyRequest{
Pipeline: string(data),
- Build: libraryBuild.GetNumber(),
+ Build: apiBuild.GetNumber(),
Repo: repo.GetName(),
Org: repo.GetOrg(),
- User: libraryBuild.GetAuthor(),
+ User: apiBuild.GetAuthor(),
}
// marshal json to send in request
diff --git a/compiler/native/compile_test.go b/compiler/native/compile_test.go
index c575a3494..e98b13e2b 100644
--- a/compiler/native/compile_test.go
+++ b/compiler/native/compile_test.go
@@ -23,8 +23,8 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
"github.com/go-vela/server/compiler/types/yaml"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
)
func TestNative_Compile_StagesPipeline(t *testing.T) {
@@ -321,9 +321,9 @@ func TestNative_Compile_StagesPipeline_Modification(t *testing.T) {
}
type args struct {
- endpoint string
- libraryBuild *api.Build
- repo *api.Repo
+ endpoint string
+ apiBuild *api.Build
+ repo *api.Repo
}
tests := []struct {
@@ -332,14 +332,14 @@ func TestNative_Compile_StagesPipeline_Modification(t *testing.T) {
wantErr bool
}{
{"bad url", args{
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: "bad",
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: "bad",
}, true},
{"invalid return", args{
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/bad"),
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/bad"),
}, true},
}
@@ -410,9 +410,9 @@ func TestNative_Compile_StepsPipeline_Modification(t *testing.T) {
}
type args struct {
- endpoint string
- libraryBuild *api.Build
- repo *api.Repo
+ endpoint string
+ apiBuild *api.Build
+ repo *api.Repo
}
tests := []struct {
@@ -421,14 +421,14 @@ func TestNative_Compile_StepsPipeline_Modification(t *testing.T) {
wantErr bool
}{
{"bad url", args{
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: "bad",
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: "bad",
}, true},
{"invalid return", args{
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/bad"),
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/bad"),
}, true},
}
@@ -440,7 +440,7 @@ func TestNative_Compile_StepsPipeline_Modification(t *testing.T) {
Endpoint: tt.args.endpoint,
},
repo: tt.args.repo,
- build: tt.args.libraryBuild,
+ build: tt.args.apiBuild,
metadata: m,
}
_, _, err := compiler.Compile(context.Background(), yaml)
@@ -2168,10 +2168,10 @@ func Test_client_modifyConfig(t *testing.T) {
number := 1
type args struct {
- endpoint string
- build *yaml.Build
- libraryBuild *api.Build
- repo *api.Repo
+ endpoint string
+ build *yaml.Build
+ apiBuild *api.Build
+ repo *api.Repo
}
tests := []struct {
@@ -2181,40 +2181,40 @@ func Test_client_modifyConfig(t *testing.T) {
wantErr bool
}{
{"unmodified", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/unmodified"),
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/unmodified"),
}, want, false},
{"modified", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/modified"),
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/modified"),
}, want2, false},
{"invalid endpoint", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: "bad",
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: "bad",
}, nil, true},
{"unauthorized endpoint", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/unauthorized"),
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/unauthorized"),
}, nil, true},
{"timeout endpoint", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/timeout"),
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/timeout"),
}, nil, true},
{"empty payload", args{
- build: want,
- libraryBuild: &api.Build{Number: &number, Author: &author},
- repo: &api.Repo{Name: &name},
- endpoint: fmt.Sprintf("%s/%s", s.URL, "config/empty"),
+ build: want,
+ apiBuild: &api.Build{Number: &number, Author: &author},
+ repo: &api.Repo{Name: &name},
+ endpoint: fmt.Sprintf("%s/%s", s.URL, "config/empty"),
}, nil, true},
}
@@ -2227,7 +2227,7 @@ func Test_client_modifyConfig(t *testing.T) {
Endpoint: tt.args.endpoint,
},
}
- got, err := compiler.modifyConfig(tt.args.build, tt.args.libraryBuild, tt.args.repo)
+ got, err := compiler.modifyConfig(tt.args.build, tt.args.apiBuild, tt.args.repo)
if (err != nil) != tt.wantErr {
t.Errorf("modifyConfig() error = %v, wantErr %v", err, tt.wantErr)
return
diff --git a/compiler/native/environment.go b/compiler/native/environment.go
index d9a82ed55..fae7557d1 100644
--- a/compiler/native/environment.go
+++ b/compiler/native/environment.go
@@ -10,9 +10,8 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/raw"
"github.com/go-vela/server/compiler/types/yaml"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// EnvironmentStages injects environment variables
@@ -133,7 +132,7 @@ func (c *client) EnvironmentStep(s *yaml.Step, stageEnv raw.StringSliceMap) (*ya
// parameter values are passed to the image
// as string environment variables
- env[k] = library.ToString(v)
+ env[k] = api.ToString(v)
}
// overwrite existing build step environment
@@ -234,7 +233,7 @@ func (c *client) EnvironmentSecrets(s yaml.SecretSlice, globalEnv raw.StringSlic
// parameter values are passed to the image
// as string environment variables
- env[k] = library.ToString(v)
+ env[k] = api.ToString(v)
}
// overwrite existing build secret environment
@@ -291,7 +290,7 @@ func environment(b *api.Build, m *internal.Metadata, r *api.Repo, u *api.User) m
env := make(map[string]string)
// vela specific environment variables
- env["VELA"] = library.ToString(true)
+ env["VELA"] = api.ToString(true)
env["VELA_ADDR"] = notImplemented
env["VELA_CHANNEL"] = notImplemented
env["VELA_DATABASE"] = notImplemented
@@ -324,11 +323,11 @@ func environment(b *api.Build, m *internal.Metadata, r *api.Repo, u *api.User) m
env["VELA_WORKSPACE"] = workspace
- // populate environment variables from repo library
+ // populate environment variables from repo api
env = appendMap(env, r.Environment())
- // populate environment variables from build library
+ // populate environment variables from build api
env = appendMap(env, b.Environment(workspace, channel))
- // populate environment variables from user library
+ // populate environment variables from user api
env = appendMap(env, u.Environment())
return env
diff --git a/compiler/native/expand.go b/compiler/native/expand.go
index a971b8efd..0420338c0 100644
--- a/compiler/native/expand.go
+++ b/compiler/native/expand.go
@@ -16,7 +16,7 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ExpandStages injects the template for each
diff --git a/compiler/native/initialize.go b/compiler/native/initialize.go
index 21c9e3b16..bbfdb071c 100644
--- a/compiler/native/initialize.go
+++ b/compiler/native/initialize.go
@@ -4,7 +4,7 @@ package native
import (
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/compiler/native/native.go b/compiler/native/native.go
index db28375e5..0c83b0728 100644
--- a/compiler/native/native.go
+++ b/compiler/native/native.go
@@ -135,7 +135,7 @@ func (c *client) Duplicate() compiler.Engine {
return cc
}
-// WithBuild sets the library build type in the Engine.
+// WithBuild sets the API build type in the Engine.
func (c *client) WithBuild(b *api.Build) compiler.Engine {
if b != nil {
c.build = b
@@ -205,7 +205,7 @@ func (c *client) WithPrivateGitHub(ctx context.Context, url, token string) compi
return c
}
-// WithRepo sets the library repo type in the Engine.
+// WithRepo sets the API repo type in the Engine.
func (c *client) WithRepo(r *api.Repo) compiler.Engine {
if r != nil {
c.repo = r
@@ -214,7 +214,7 @@ func (c *client) WithRepo(r *api.Repo) compiler.Engine {
return c
}
-// WithUser sets the library user type in the Engine.
+// WithUser sets the API user type in the Engine.
func (c *client) WithUser(u *api.User) compiler.Engine {
if u != nil {
c.user = u
diff --git a/compiler/native/parse.go b/compiler/native/parse.go
index 47924ac0a..7afeefef3 100644
--- a/compiler/native/parse.go
+++ b/compiler/native/parse.go
@@ -13,7 +13,7 @@ import (
"github.com/go-vela/server/compiler/template/starlark"
typesRaw "github.com/go-vela/server/compiler/types/raw"
types "github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ParseRaw converts an object to a string.
diff --git a/compiler/native/parse_test.go b/compiler/native/parse_test.go
index 91b13c9cb..fa2635a48 100644
--- a/compiler/native/parse_test.go
+++ b/compiler/native/parse_test.go
@@ -16,7 +16,7 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/raw"
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestNative_Parse_Metadata_Bytes(t *testing.T) {
diff --git a/compiler/native/validate.go b/compiler/native/validate.go
index cabe3f602..0c0775019 100644
--- a/compiler/native/validate.go
+++ b/compiler/native/validate.go
@@ -8,7 +8,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Validate verifies the yaml configuration is valid.
diff --git a/compiler/types/pipeline/build.go b/compiler/types/pipeline/build.go
index 681269d5d..aef5eaea8 100644
--- a/compiler/types/pipeline/build.go
+++ b/compiler/types/pipeline/build.go
@@ -8,7 +8,7 @@ import (
"unicode/utf8"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Build is the pipeline representation of a build for a pipeline.
diff --git a/compiler/types/pipeline/build_test.go b/compiler/types/pipeline/build_test.go
index a693a89be..a94d05f85 100644
--- a/compiler/types/pipeline/build_test.go
+++ b/compiler/types/pipeline/build_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestPipeline_Build_Purge(t *testing.T) {
diff --git a/compiler/types/pipeline/container.go b/compiler/types/pipeline/container.go
index 85a96d8b8..246076bd3 100644
--- a/compiler/types/pipeline/container.go
+++ b/compiler/types/pipeline/container.go
@@ -14,7 +14,7 @@ import (
"github.com/drone/envsubst"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/pipeline/container_test.go b/compiler/types/pipeline/container_test.go
index a7ae573c2..8d581f464 100644
--- a/compiler/types/pipeline/container_test.go
+++ b/compiler/types/pipeline/container_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestPipeline_ContainerSlice_Purge(t *testing.T) {
diff --git a/compiler/types/pipeline/ruleset.go b/compiler/types/pipeline/ruleset.go
index c5394eb68..36d6c1302 100644
--- a/compiler/types/pipeline/ruleset.go
+++ b/compiler/types/pipeline/ruleset.go
@@ -8,7 +8,7 @@ import (
"regexp"
"strings"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/pipeline/ruleset_test.go b/compiler/types/pipeline/ruleset_test.go
index 5ce9c0b04..5f9bf7bc2 100644
--- a/compiler/types/pipeline/ruleset_test.go
+++ b/compiler/types/pipeline/ruleset_test.go
@@ -5,7 +5,7 @@ package pipeline
import (
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestPipeline_Ruleset_Match(t *testing.T) {
diff --git a/compiler/types/pipeline/secret.go b/compiler/types/pipeline/secret.go
index bbc5e2602..2f28821a7 100644
--- a/compiler/types/pipeline/secret.go
+++ b/compiler/types/pipeline/secret.go
@@ -7,7 +7,7 @@ import (
"fmt"
"strings"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/pipeline/stage.go b/compiler/types/pipeline/stage.go
index 2325f340f..4a7001327 100644
--- a/compiler/types/pipeline/stage.go
+++ b/compiler/types/pipeline/stage.go
@@ -5,7 +5,7 @@ package pipeline
import (
"fmt"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/pipeline/stage_test.go b/compiler/types/pipeline/stage_test.go
index 3ae29b10f..fb1071d81 100644
--- a/compiler/types/pipeline/stage_test.go
+++ b/compiler/types/pipeline/stage_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestPipeline_StageSlice_Purge(t *testing.T) {
diff --git a/compiler/types/yaml/build_test.go b/compiler/types/yaml/build_test.go
index f4095d48d..fc72abc85 100644
--- a/compiler/types/yaml/build_test.go
+++ b/compiler/types/yaml/build_test.go
@@ -13,7 +13,7 @@ import (
"github.com/go-vela/server/compiler/types/raw"
)
-func TestYaml_Build_ToLibrary(t *testing.T) {
+func TestYaml_Build_ToAPI(t *testing.T) {
build := new(api.Pipeline)
build.SetFlavor("16cpu8gb")
build.SetPlatform("gcp")
@@ -87,7 +87,7 @@ func TestYaml_Build_ToLibrary(t *testing.T) {
got := b.ToPipelineAPI()
if !reflect.DeepEqual(got, test.want) {
- t.Errorf("ToPipelineLibrary for %s is %v, want %v", test.name, got, test.want)
+ t.Errorf("ToPipelineAPI for %s is %v, want %v", test.name, got, test.want)
}
}
}
diff --git a/compiler/types/yaml/ruleset.go b/compiler/types/yaml/ruleset.go
index e49b64a5a..ee3c014e3 100644
--- a/compiler/types/yaml/ruleset.go
+++ b/compiler/types/yaml/ruleset.go
@@ -5,7 +5,7 @@ package yaml
import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/yaml/secret.go b/compiler/types/yaml/secret.go
index 887e1a21c..a99f452e8 100644
--- a/compiler/types/yaml/secret.go
+++ b/compiler/types/yaml/secret.go
@@ -9,7 +9,7 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/yaml/service.go b/compiler/types/yaml/service.go
index 38fa87a90..f5d5103cc 100644
--- a/compiler/types/yaml/service.go
+++ b/compiler/types/yaml/service.go
@@ -8,7 +8,7 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/yaml/step.go b/compiler/types/yaml/step.go
index 42dd7c320..0b579f614 100644
--- a/compiler/types/yaml/step.go
+++ b/compiler/types/yaml/step.go
@@ -8,7 +8,7 @@ import (
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/compiler/types/yaml/template.go b/compiler/types/yaml/template.go
index 22dbf2753..99da1964f 100644
--- a/compiler/types/yaml/template.go
+++ b/compiler/types/yaml/template.go
@@ -3,7 +3,7 @@
package yaml
import (
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
type (
@@ -46,10 +46,10 @@ func (t *TemplateSlice) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}
-// ToLibrary converts the Template type
-// to a library Template type.
-func (t *Template) ToLibrary() *library.Template {
- template := new(library.Template)
+// ToAPI converts the Template type
+// to an API Template type.
+func (t *Template) ToAPI() *api.Template {
+ template := new(api.Template)
template.SetName(t.Name)
template.SetSource(t.Source)
@@ -58,9 +58,9 @@ func (t *Template) ToLibrary() *library.Template {
return template
}
-// TemplateFromLibrary converts the library Template type
+// TemplateFromAPI converts the API Template type
// to a yaml Template type.
-func TemplateFromLibrary(t *library.Template) *Template {
+func TemplateFromAPI(t *api.Template) *Template {
template := &Template{
Name: t.GetName(),
Source: t.GetSource(),
diff --git a/compiler/types/yaml/template_test.go b/compiler/types/yaml/template_test.go
index e7f760cb7..b000cd70b 100644
--- a/compiler/types/yaml/template_test.go
+++ b/compiler/types/yaml/template_test.go
@@ -9,7 +9,7 @@ import (
"github.com/buildkite/yaml"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestBuild_TemplateSlice_UnmarshalYAML(t *testing.T) {
@@ -78,9 +78,9 @@ func TestBuild_TemplateSlice_UnmarshalYAML(t *testing.T) {
}
}
-func TestYAML_Template_ToLibrary(t *testing.T) {
+func TestYAML_Template_ToAPI(t *testing.T) {
// setup types
- want := new(library.Template)
+ want := new(api.Template)
want.SetName("docker_build")
want.SetSource("github.com/go-vela/atlas/stable/docker_build")
want.SetType("github")
@@ -92,14 +92,14 @@ func TestYAML_Template_ToLibrary(t *testing.T) {
}
// run test
- got := tmpl.ToLibrary()
+ got := tmpl.ToAPI()
if !reflect.DeepEqual(got, want) {
- t.Errorf("ToLibrary is %v, want %v", got, want)
+ t.Errorf("ToAPI is %v, want %v", got, want)
}
}
-func TestYAML_TemplateFromLibrary(t *testing.T) {
+func TestYAML_TemplateFromAPI(t *testing.T) {
// setup types
want := &Template{
Name: "docker_build",
@@ -107,15 +107,15 @@ func TestYAML_TemplateFromLibrary(t *testing.T) {
Type: "github",
}
- tmpl := new(library.Template)
+ tmpl := new(api.Template)
tmpl.SetName("docker_build")
tmpl.SetSource("github.com/go-vela/atlas/stable/docker_build")
tmpl.SetType("github")
// run test
- got := TemplateFromLibrary(tmpl)
+ got := TemplateFromAPI(tmpl)
if !reflect.DeepEqual(got, want) {
- t.Errorf("TemplateFromLibrary is %v, want %v", got, want)
+ t.Errorf("TemplateFromAPI is %v, want %v", got, want)
}
}
diff --git a/constants/action.go b/constants/action.go
new file mode 100644
index 000000000..67e4e8354
--- /dev/null
+++ b/constants/action.go
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Build and repo events.
+const (
+ // ActionOpened defines the action for opening pull requests.
+ ActionOpened = "opened"
+
+ // ActionCreated defines the action for creating deployments or issue comments.
+ ActionCreated = "created"
+
+ // ActionEdited defines the action for the editing of pull requests or issue comments.
+ ActionEdited = "edited"
+
+ // ActionRenamed defines the action for renaming a repository.
+ ActionRenamed = "renamed"
+
+ // ActionReopened defines the action for re-opening a pull request (or issue).
+ ActionReopened = "reopened"
+
+ // ActionSynchronize defines the action for the synchronizing of pull requests.
+ ActionSynchronize = "synchronize"
+
+ // ActionLabeled defines the action for the labeling of pull requests.
+ ActionLabeled = "labeled"
+
+ // ActionUnlabeled defines the action for the unlabeling of pull requests.
+ ActionUnlabeled = "unlabeled"
+
+ // ActionTransferred defines the action for transferring repository ownership.
+ ActionTransferred = "transferred"
+
+ // ActionBranch defines the action for deleting a branch.
+ ActionBranch = "branch"
+
+ // ActionTag defines the action for deleting a tag.
+ ActionTag = "tag"
+
+ // ActionRun defines the action for running a schedule.
+ ActionRun = "run"
+)
diff --git a/constants/allow_events.go b/constants/allow_events.go
new file mode 100644
index 000000000..5df539264
--- /dev/null
+++ b/constants/allow_events.go
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Allowed repo events. NOTE: these can NOT change order. New events must be added at the end.
+const (
+ AllowPushBranch = 1 << iota // 00000001 = 1
+ AllowPushTag // 00000010 = 2
+ AllowPullOpen // 00000100 = 4
+ AllowPullEdit // ...
+ AllowPullSync
+ _ // AllowPullAssigned - Not Implemented
+ _ // AllowPullMilestoned - Not Implemented
+ AllowPullLabel
+ _ // AllowPullLocked - Not Implemented
+ _ // AllowPullReady - Not Implemented
+ AllowPullReopen
+ _ // AllowPullReviewRequest - Not Implemented
+ _ // AllowPullClosed - Not Implemented
+ AllowDeployCreate
+ AllowCommentCreate
+ AllowCommentEdit
+ AllowSchedule
+ AllowPushDeleteBranch
+ AllowPushDeleteTag
+ AllowPullUnlabel
+)
diff --git a/constants/badge.go b/constants/badge.go
new file mode 100644
index 000000000..b92638ac0
--- /dev/null
+++ b/constants/badge.go
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Constants for build badges.
+//
+//nolint:godot // due to providing pretty printed svgs
+const (
+ // Badge for unknown state
+ //
+ BadgeUnknown = ``
+
+ // Badge for success state
+ //
+ BadgeSuccess = ``
+
+ // Badge for failed state
+ //
+ BadgeFailed = ``
+
+ // Badge for error state
+ //
+ BadgeError = ``
+
+ // Badge for running status
+ //
+ BadgeRunning = ``
+)
diff --git a/constants/compression.go b/constants/compression.go
new file mode 100644
index 000000000..6a1d11a6d
--- /dev/null
+++ b/constants/compression.go
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Log Compression Levels.
+const (
+ // The default compression level for the compress/zlib library
+ // for log data stored in the database.
+ CompressionNegOne = -1
+
+ // Enables no compression for log data stored in the database.
+ //
+ // This produces no compression for the log data.
+ CompressionZero = 0
+
+ // Enables the best speed for log data stored in the database.
+ //
+ // This produces compression for the log data the fastest but
+ // has a tradeoff of producing the largest amounts of data.
+ CompressionOne = 1
+
+ // Second compression level for log data stored in the database.
+ CompressionTwo = 2
+
+ // Third compression level for log data stored in the database.
+ CompressionThree = 3
+
+ // Fourth compression level for log data stored in the database.
+ CompressionFour = 4
+
+ // Enables an even balance of speed and compression for log
+ // data stored in the database.
+ //
+ // This produces compression for the log data with an even
+ // balance of speed while producing smaller amounts of data.
+ CompressionFive = 5
+
+ // Sixth compression level for log data stored in the database.
+ CompressionSix = 6
+
+ // Seventh compression level for log data stored in the database.
+ CompressionSeven = 7
+
+ // Eighth compression level for log data stored in the database.
+ CompressionEight = 8
+
+ // Enables the best compression for log data stored in the database.
+ //
+ // This produces compression for the log data the slowest but
+ // has a tradeoff of producing the smallest amounts of data.
+ CompressionNine = 9
+)
diff --git a/constants/doc.go b/constants/doc.go
new file mode 100644
index 000000000..301d93aee
--- /dev/null
+++ b/constants/doc.go
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: Apache-2.0
+
+// Package constants provides the defined constant types for Vela.
+//
+// Usage:
+//
+// import "github.com/go-vela/server/constants"
+package constants
diff --git a/constants/event.go b/constants/event.go
new file mode 100644
index 000000000..c2ec26aad
--- /dev/null
+++ b/constants/event.go
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Build and repo events.
+const (
+ // EventComment defines the event type for comments added to a pull request.
+ EventComment = "comment"
+
+ // EventDelete defines the event type for build and repo delete events.
+ EventDelete = "delete"
+
+ // EventDeploy defines the event type for build and repo deployment events.
+ EventDeploy = "deployment"
+
+ // EventPull defines the event type for build and repo pull_request events.
+ EventPull = "pull_request"
+
+ // EventPush defines the event type for build and repo push events.
+ EventPush = "push"
+
+ // EventRepository defines the general event type for repo management.
+ EventRepository = "repository"
+
+ // EventSchedule defines the event type for build and repo schedule events.
+ EventSchedule = "schedule"
+
+ // EventTag defines the event type for build and repo tag events.
+ EventTag = "tag"
+
+ // Alternates for common user inputs that do not match our set constants.
+
+ // EventPullAlternate defines the alternate event type for build and repo pull_request events.
+ EventPullAlternate = "pull"
+
+ // EventDeployAlternate defines the alternate event type for build and repo deployment events.
+ EventDeployAlternate = "deploy"
+)
diff --git a/constants/limit.go b/constants/limit.go
index 8b492ec3e..4321c4e79 100644
--- a/constants/limit.go
+++ b/constants/limit.go
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
+
package constants
// Limits and constraints.
diff --git a/constants/matcher.go b/constants/matcher.go
new file mode 100644
index 000000000..ef4c79470
--- /dev/null
+++ b/constants/matcher.go
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Ruleset matchers.
+const (
+ // MatcherFilepath defines the ruleset type for the filepath matcher.
+ MatcherFilepath = "filepath"
+
+ // MatcherRegex defines the ruleset type for the regex matcher.
+ MatcherRegex = "regexp"
+)
diff --git a/constants/operator.go b/constants/operator.go
new file mode 100644
index 000000000..f6a209016
--- /dev/null
+++ b/constants/operator.go
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Ruleset operators.
+const (
+ // OperatorAnd defines the ruleset type for the and operator.
+ OperatorAnd = "and"
+
+ // OperatorOr defines the ruleset type for the or operator.
+ OperatorOr = "or"
+)
diff --git a/constants/pipeline.go b/constants/pipeline.go
new file mode 100644
index 000000000..f3f49ff38
--- /dev/null
+++ b/constants/pipeline.go
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Pipeline types.
+const (
+ // PipelineStages defines the type for a pipeline with stages.
+ PipelineStage = "stages"
+
+ // PipelineStep defines the type for a pipeline with steps.
+ PipelineStep = "steps"
+
+ // PipelineTemplate defines the type for a pipeline as a template.
+ PipelineTemplate = "template"
+)
diff --git a/constants/pull.go b/constants/pull.go
new file mode 100644
index 000000000..131679984
--- /dev/null
+++ b/constants/pull.go
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Service and step pull policies.
+const (
+ // PullAlways defines the pull policy type for
+ // a service or step to always pull an image.
+ PullAlways = "always"
+
+ // PullNotPresent defines the pull policy type for
+ // a service or step to only pull an image if it doesn't exist.
+ PullNotPresent = "not_present"
+
+ // PullOnStart defines the pull policy type for
+ // a service or step to only pull an image before the container starts.
+ PullOnStart = "on_start"
+
+ // PullNever defines the pull policy type for
+ // a service or step to never pull an image.
+ PullNever = "never"
+)
diff --git a/constants/queue.go b/constants/queue.go
new file mode 100644
index 000000000..fe3b8087e
--- /dev/null
+++ b/constants/queue.go
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Queue types.
+const (
+ // DefaultRoute defines the default route all workers listen on.
+ DefaultRoute = "vela"
+)
diff --git a/constants/table.go b/constants/table.go
index 871225fe1..be640a576 100644
--- a/constants/table.go
+++ b/constants/table.go
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
+
package constants
// Database tables.
diff --git a/constants/worker_status.go b/constants/worker_status.go
new file mode 100644
index 000000000..70d17111c
--- /dev/null
+++ b/constants/worker_status.go
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Worker statuses.
+const (
+ // WorkerStatusIdle defines the status for a worker
+ // where worker RunningBuildIDs.length = 0.
+ WorkerStatusIdle = "idle"
+
+ // WorkerStatusAvailable defines the status type for a worker in an available state,
+ // where worker RunningBuildIDs.length > 0 and < worker BuildLimit.
+ WorkerStatusAvailable = "available"
+
+ // WorkerStatusBusy defines the status type for a worker in an unavailable state,
+ // where worker BuildLimit == worker RunningBuildIDs.length.
+ WorkerStatusBusy = "busy"
+
+ // WorkerStatusError defines the status for a worker in an error state.
+ WorkerStatusError = "error"
+)
diff --git a/constants/workspace.go b/constants/workspace.go
new file mode 100644
index 000000000..9efb1b984
--- /dev/null
+++ b/constants/workspace.go
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package constants
+
+// Service and Step workspace paths.
+const (
+ // WorkspaceDefault defines the default workspace path for a service or a step.
+ WorkspaceDefault = "/vela/src"
+
+ // WorkspaceMount defines the mount workspace path for a service or a step.
+ WorkspaceMount = "/vela"
+)
diff --git a/database/build/build.go b/database/build/build.go
index b425731f3..1dc82d36e 100644
--- a/database/build/build.go
+++ b/database/build/build.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/build/clean.go b/database/build/clean.go
index 81a461469..521e24121 100644
--- a/database/build/clean.go
+++ b/database/build/clean.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CleanBuilds updates builds to an error with a provided message with a created timestamp prior to a defined moment.
diff --git a/database/build/count.go b/database/build/count.go
index 6b26c3f28..3d50bde6e 100644
--- a/database/build/count.go
+++ b/database/build/count.go
@@ -5,7 +5,7 @@ package build
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountBuilds gets the count of all builds from the database.
diff --git a/database/build/count_deployment.go b/database/build/count_deployment.go
index 631228915..f8ac7a061 100644
--- a/database/build/count_deployment.go
+++ b/database/build/count_deployment.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountBuildsForDeployment gets the count of builds by deployment URL from the database.
diff --git a/database/build/count_org.go b/database/build/count_org.go
index 5a349c730..e78e22480 100644
--- a/database/build/count_org.go
+++ b/database/build/count_org.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountBuildsForOrg gets the count of builds by org name from the database.
diff --git a/database/build/count_org_test.go b/database/build/count_org_test.go
index 546e59678..5454b82dd 100644
--- a/database/build/count_org_test.go
+++ b/database/build/count_org_test.go
@@ -9,9 +9,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_CountBuildsForOrg(t *testing.T) {
diff --git a/database/build/count_repo.go b/database/build/count_repo.go
index 138b4d6d4..df59ee2fe 100644
--- a/database/build/count_repo.go
+++ b/database/build/count_repo.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountBuildsForRepo gets the count of builds by repo ID from the database.
diff --git a/database/build/count_status.go b/database/build/count_status.go
index 8fb401ffb..e3f199d2b 100644
--- a/database/build/count_status.go
+++ b/database/build/count_status.go
@@ -5,7 +5,7 @@ package build
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountBuildsForStatus gets the count of builds by status from the database.
diff --git a/database/build/create.go b/database/build/create.go
index 7789434cb..d8f122470 100644
--- a/database/build/create.go
+++ b/database/build/create.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateBuild creates a new build in the database.
diff --git a/database/build/delete.go b/database/build/delete.go
index f03387a5f..a5ba38ef2 100644
--- a/database/build/delete.go
+++ b/database/build/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteBuild deletes an existing build from the database.
diff --git a/database/build/get.go b/database/build/get.go
index dc7f0e2de..42aa5b8af 100644
--- a/database/build/get.go
+++ b/database/build/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetBuild gets a build by ID from the database.
diff --git a/database/build/get_repo.go b/database/build/get_repo.go
index 1bc9dfb39..66250ef48 100644
--- a/database/build/get_repo.go
+++ b/database/build/get_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetBuildForRepo gets a build by repo ID and number from the database.
diff --git a/database/build/get_repo_test.go b/database/build/get_repo_test.go
index 327b2f14d..2be48a249 100644
--- a/database/build/get_repo_test.go
+++ b/database/build/get_repo_test.go
@@ -10,8 +10,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_GetBuildForRepo(t *testing.T) {
diff --git a/database/build/get_test.go b/database/build/get_test.go
index e4a26d852..3dc2e95e8 100644
--- a/database/build/get_test.go
+++ b/database/build/get_test.go
@@ -10,9 +10,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_GetBuild(t *testing.T) {
diff --git a/database/build/last_repo.go b/database/build/last_repo.go
index 517579240..c001bbf0d 100644
--- a/database/build/last_repo.go
+++ b/database/build/last_repo.go
@@ -10,8 +10,8 @@ import (
"gorm.io/gorm"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// LastBuildForRepo gets the last build by repo ID and branch from the database.
diff --git a/database/build/last_repo_test.go b/database/build/last_repo_test.go
index 7b518afee..55b74e5b6 100644
--- a/database/build/last_repo_test.go
+++ b/database/build/last_repo_test.go
@@ -10,8 +10,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_LastBuildForRepo(t *testing.T) {
diff --git a/database/build/list.go b/database/build/list.go
index 4074618c7..1a3e22a5b 100644
--- a/database/build/list.go
+++ b/database/build/list.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListBuilds gets a list of all builds from the database.
diff --git a/database/build/list_dashboard.go b/database/build/list_dashboard.go
index 7ba0c379a..65fc8549e 100644
--- a/database/build/list_dashboard.go
+++ b/database/build/list_dashboard.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListBuildsForDashboardRepo gets a list of builds by repo ID from the database.
diff --git a/database/build/list_org.go b/database/build/list_org.go
index d1c33a7a7..5f8259753 100644
--- a/database/build/list_org.go
+++ b/database/build/list_org.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListBuildsForOrg gets a list of builds by org name from the database.
diff --git a/database/build/list_org_test.go b/database/build/list_org_test.go
index 4d25d6062..965955891 100644
--- a/database/build/list_org_test.go
+++ b/database/build/list_org_test.go
@@ -10,9 +10,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_ListBuildsForOrg(t *testing.T) {
diff --git a/database/build/list_pending_running.go b/database/build/list_pending_running.go
index 6a08dcbac..9e7d1e244 100644
--- a/database/build/list_pending_running.go
+++ b/database/build/list_pending_running.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListPendingAndRunningBuilds gets a list of all pending and running builds in the provided timeframe from the database.
diff --git a/database/build/list_pending_running_repo.go b/database/build/list_pending_running_repo.go
index c475ccc1a..36a41d69a 100644
--- a/database/build/list_pending_running_repo.go
+++ b/database/build/list_pending_running_repo.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListPendingAndRunningBuilds gets a list of all pending and running builds in the provided timeframe from the database.
diff --git a/database/build/list_pending_running_test.go b/database/build/list_pending_running_test.go
index c164827d8..840b30622 100644
--- a/database/build/list_pending_running_test.go
+++ b/database/build/list_pending_running_test.go
@@ -10,9 +10,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_ListPendingAndRunningBuilds(t *testing.T) {
diff --git a/database/build/list_repo.go b/database/build/list_repo.go
index 772a7ee6b..470b448d3 100644
--- a/database/build/list_repo.go
+++ b/database/build/list_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListBuildsForRepo gets a list of builds by repo ID from the database.
diff --git a/database/build/list_repo_test.go b/database/build/list_repo_test.go
index 0933d0ea3..8071e3a67 100644
--- a/database/build/list_repo_test.go
+++ b/database/build/list_repo_test.go
@@ -11,8 +11,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_ListBuildsForRepo(t *testing.T) {
diff --git a/database/build/list_test.go b/database/build/list_test.go
index 15688d252..e440a162c 100644
--- a/database/build/list_test.go
+++ b/database/build/list_test.go
@@ -10,9 +10,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestBuild_Engine_ListBuilds(t *testing.T) {
diff --git a/database/build/table.go b/database/build/table.go
index 2a7af528c..756a621cb 100644
--- a/database/build/table.go
+++ b/database/build/table.go
@@ -5,7 +5,7 @@ package build
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/build/update.go b/database/build/update.go
index 07b029093..2d838d9db 100644
--- a/database/build/update.go
+++ b/database/build/update.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateBuild updates an existing build in the database.
diff --git a/database/dashboard/table.go b/database/dashboard/table.go
index cef302382..b10917a27 100644
--- a/database/dashboard/table.go
+++ b/database/dashboard/table.go
@@ -5,7 +5,7 @@ package dashboard
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/database.go b/database/database.go
index 6f21ec40a..3976edad1 100644
--- a/database/database.go
+++ b/database/database.go
@@ -13,6 +13,7 @@ import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/build"
"github.com/go-vela/server/database/dashboard"
"github.com/go-vela/server/database/deployment"
@@ -30,7 +31,6 @@ import (
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/server/tracing"
- "github.com/go-vela/types/constants"
)
type (
diff --git a/database/deployment/count.go b/database/deployment/count.go
index f1c9e5b14..124990d0e 100644
--- a/database/deployment/count.go
+++ b/database/deployment/count.go
@@ -5,7 +5,7 @@ package deployment
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountDeployments gets the count of all deployments from the database.
diff --git a/database/deployment/count_repo.go b/database/deployment/count_repo.go
index 8a2afd6fc..1746b876c 100644
--- a/database/deployment/count_repo.go
+++ b/database/deployment/count_repo.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountDeploymentsForRepo gets the count of deployments by repo ID from the database.
diff --git a/database/deployment/create.go b/database/deployment/create.go
index b3c85a188..98f162345 100644
--- a/database/deployment/create.go
+++ b/database/deployment/create.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateDeployment creates a new deployment in the database.
@@ -18,7 +18,7 @@ func (e *engine) CreateDeployment(ctx context.Context, d *api.Deployment) (*api.
"deployment": d.GetID(),
}).Tracef("creating deployment %d", d.GetID())
- // cast the library type to database type
+ // cast the API type to database type
deployment := types.DeploymentFromAPI(d)
// validate the necessary fields are populated
diff --git a/database/deployment/delete.go b/database/deployment/delete.go
index b0f76c7fc..4a216a0bd 100644
--- a/database/deployment/delete.go
+++ b/database/deployment/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteDeployment deletes an existing deployment from the database.
@@ -18,7 +18,7 @@ func (e *engine) DeleteDeployment(ctx context.Context, d *api.Deployment) error
"deployment": d.GetID(),
}).Tracef("deleting deployment %d", d.GetID())
- // cast the library type to database type
+ // cast the API type to database type
deployment := types.DeploymentFromAPI(d)
// send query to the database
diff --git a/database/deployment/deployment.go b/database/deployment/deployment.go
index e1fbefad0..ce890809e 100644
--- a/database/deployment/deployment.go
+++ b/database/deployment/deployment.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/deployment/get.go b/database/deployment/get.go
index aef68bc7f..7e51a4ef5 100644
--- a/database/deployment/get.go
+++ b/database/deployment/get.go
@@ -7,8 +7,8 @@ import (
"strconv"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetDeployment gets a deployment by ID from the database.
diff --git a/database/deployment/get_repo.go b/database/deployment/get_repo.go
index f9894789a..43615e798 100644
--- a/database/deployment/get_repo.go
+++ b/database/deployment/get_repo.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetDeploymentForRepo gets a deployment by repo ID and number from the database.
diff --git a/database/deployment/list.go b/database/deployment/list.go
index b5101eb06..e608b83cc 100644
--- a/database/deployment/list.go
+++ b/database/deployment/list.go
@@ -7,8 +7,8 @@ import (
"strconv"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListDeployments gets a list of all deployments from the database.
@@ -65,7 +65,7 @@ func (e *engine) ListDeployments(ctx context.Context) ([]*api.Deployment, error)
e.logger.Errorf("unable to decrypt repo: %v", err)
}
- // convert query result to library type
+ // convert query result to API type
deployments = append(deployments, tmp.ToAPI(builds))
}
diff --git a/database/deployment/list_repo.go b/database/deployment/list_repo.go
index 08419397a..b4d11c3a9 100644
--- a/database/deployment/list_repo.go
+++ b/database/deployment/list_repo.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListDeploymentsForRepo gets a list of deployments by repo ID from the database.
diff --git a/database/deployment/table.go b/database/deployment/table.go
index 9baef0284..13ad4248b 100644
--- a/database/deployment/table.go
+++ b/database/deployment/table.go
@@ -5,7 +5,7 @@ package deployment
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/deployment/update.go b/database/deployment/update.go
index 0cb7c8b51..586e0f507 100644
--- a/database/deployment/update.go
+++ b/database/deployment/update.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateDeployment updates an existing deployment in the database.
@@ -18,7 +18,7 @@ func (e *engine) UpdateDeployment(ctx context.Context, d *api.Deployment) (*api.
"deployment": d.GetID(),
}).Tracef("updating deployment %d", d.GetID())
- // cast the library type to database type
+ // cast the API type to database type
deployment := types.DeploymentFromAPI(d)
// validate the necessary fields are populated
diff --git a/database/executable/clean.go b/database/executable/clean.go
index ba4c06172..4a770f3dd 100644
--- a/database/executable/clean.go
+++ b/database/executable/clean.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const CleanExecutablesPostgres = `
diff --git a/database/executable/clean_test.go b/database/executable/clean_test.go
index 92c8be8e8..da5b86ed1 100644
--- a/database/executable/clean_test.go
+++ b/database/executable/clean_test.go
@@ -9,24 +9,24 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
+ "github.com/go-vela/server/database/types"
)
func TestExecutable_Engine_CleanExecutables(t *testing.T) {
// setup types
- _buildOne := testBuild()
+ _buildOne := testutils.APIBuild()
_buildOne.SetID(1)
- _buildOne.SetRepoID(1)
+ _buildOne.SetRepo(testutils.APIRepo())
_buildOne.SetNumber(1)
_buildOne.SetStatus("pending")
_buildOne.SetCreated(1)
_buildOne.SetDeployPayload(nil)
- _buildTwo := testBuild()
+ _buildTwo := testutils.APIBuild()
_buildTwo.SetID(2)
- _buildTwo.SetRepoID(1)
+ _buildTwo.SetRepo(testutils.APIRepo())
_buildTwo.SetNumber(2)
_buildTwo.SetStatus("error")
_buildTwo.SetCreated(1)
@@ -63,17 +63,17 @@ func TestExecutable_Engine_CleanExecutables(t *testing.T) {
t.Errorf("unable to create test build for sqlite: %v", err)
}
- err = _sqlite.client.AutoMigrate(&database.Build{})
+ err = _sqlite.client.AutoMigrate(&types.Build{})
if err != nil {
t.Errorf("unable to create repo table for sqlite: %v", err)
}
- err = _sqlite.client.Table(constants.TableBuild).Create(database.BuildFromLibrary(_buildOne)).Error
+ err = _sqlite.client.Table(constants.TableBuild).Create(types.BuildFromAPI(_buildOne)).Error
if err != nil {
t.Errorf("unable to create test repo for sqlite: %v", err)
}
- err = _sqlite.client.Table(constants.TableBuild).Create(database.BuildFromLibrary(_buildTwo)).Error
+ err = _sqlite.client.Table(constants.TableBuild).Create(types.BuildFromAPI(_buildTwo)).Error
if err != nil {
t.Errorf("unable to create test repo for sqlite: %v", err)
}
@@ -124,40 +124,3 @@ func TestExecutable_Engine_CleanExecutables(t *testing.T) {
})
}
}
-
-// testBuild is a test helper function to create a library
-// Build type with all fields set to their zero values.
-func testBuild() *library.Build {
- return &library.Build{
- ID: new(int64),
- RepoID: new(int64),
- PipelineID: new(int64),
- Number: new(int),
- Parent: new(int),
- Event: new(string),
- EventAction: new(string),
- Status: new(string),
- Error: new(string),
- Enqueued: new(int64),
- Created: new(int64),
- Started: new(int64),
- Finished: new(int64),
- Deploy: new(string),
- Clone: new(string),
- Source: new(string),
- Title: new(string),
- Message: new(string),
- Commit: new(string),
- Sender: new(string),
- Author: new(string),
- Email: new(string),
- Link: new(string),
- Branch: new(string),
- Ref: new(string),
- BaseRef: new(string),
- HeadRef: new(string),
- Host: new(string),
- Runtime: new(string),
- Distribution: new(string),
- }
-}
diff --git a/database/executable/create.go b/database/executable/create.go
index e231f01fb..779ad92fc 100644
--- a/database/executable/create.go
+++ b/database/executable/create.go
@@ -8,41 +8,32 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CreateBuildExecutable creates a new build executable in the database.
-func (e *engine) CreateBuildExecutable(ctx context.Context, b *library.BuildExecutable) error {
+func (e *engine) CreateBuildExecutable(ctx context.Context, b *api.BuildExecutable) error {
e.logger.WithFields(logrus.Fields{
"build": b.GetBuildID(),
}).Tracef("creating build executable for build %d in the database", b.GetBuildID())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutableFromLibrary
- executable := database.BuildExecutableFromLibrary(b)
+ // convert API type to database type
+ executable := types.BuildExecutableFromAPI(b)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutable.Validate
err := executable.Validate()
if err != nil {
return err
}
// compress data for the build executable
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutable.Compress
err = executable.Compress(e.config.CompressionLevel)
if err != nil {
return err
}
// encrypt the data field for the build executable
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutable.Encrypt
err = executable.Encrypt(e.config.EncryptionKey)
if err != nil {
return fmt.Errorf("unable to encrypt build executable for build %d: %w", b.GetBuildID(), err)
diff --git a/database/executable/executable.go b/database/executable/executable.go
index 8ac0475ef..cb32b2a52 100644
--- a/database/executable/executable.go
+++ b/database/executable/executable.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/executable/executable_test.go b/database/executable/executable_test.go
index 2869001a8..4ea323323 100644
--- a/database/executable/executable_test.go
+++ b/database/executable/executable_test.go
@@ -13,8 +13,8 @@ import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
func TestExecutable_New(t *testing.T) {
@@ -188,10 +188,10 @@ func testSqlite(t *testing.T) *engine {
return _engine
}
-// testBuildExecutable is a test helper function to create a library
+// testBuildExecutable is a test helper function to create a API
// BuildExecutable type with all fields set to their zero values.
-func testBuildExecutable() *library.BuildExecutable {
- return &library.BuildExecutable{
+func testBuildExecutable() *api.BuildExecutable {
+ return &api.BuildExecutable{
ID: new(int64),
BuildID: new(int64),
Data: new([]byte),
diff --git a/database/executable/interface.go b/database/executable/interface.go
index ee0cd056f..33c58e9ce 100644
--- a/database/executable/interface.go
+++ b/database/executable/interface.go
@@ -5,7 +5,7 @@ package executable
import (
"context"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
// BuildExecutableInterface represents the Vela interface for build executable
@@ -23,7 +23,7 @@ type BuildExecutableInterface interface {
// CleanBuildExecutables defines a function that deletes errored builds' corresponding executables.
CleanBuildExecutables(context.Context) (int64, error)
// CreateBuildExecutable defines a function that creates a build executable.
- CreateBuildExecutable(context.Context, *library.BuildExecutable) error
+ CreateBuildExecutable(context.Context, *api.BuildExecutable) error
// PopBuildExecutable defines a function that gets and deletes a build executable.
- PopBuildExecutable(context.Context, int64) (*library.BuildExecutable, error)
+ PopBuildExecutable(context.Context, int64) (*api.BuildExecutable, error)
}
diff --git a/database/executable/pop.go b/database/executable/pop.go
index 9625ad984..f4477363c 100644
--- a/database/executable/pop.go
+++ b/database/executable/pop.go
@@ -7,17 +7,17 @@ import (
"gorm.io/gorm/clause"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// PopBuildExecutable pops a build executable by build_id from the database.
-func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*library.BuildExecutable, error) {
+func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*api.BuildExecutable, error) {
e.logger.Tracef("popping build executable for build %d", id)
// variable to store query results
- b := new(database.BuildExecutable)
+ b := new(types.BuildExecutable)
// at the time of coding, GORM does not implement a version of Sqlite3 that supports RETURNING.
// so we have to select and delete for the Sqlite driver.
@@ -59,23 +59,16 @@ func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*library.Bui
}
// decrypt the fields for the build executable
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Decrypt
err := b.Decrypt(e.config.EncryptionKey)
if err != nil {
return nil, err
}
// decompress data for the build executable
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutable.Decompress
err = b.Decompress()
if err != nil {
return nil, err
}
- // return the decompressed build executable
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#BuildExecutable.ToLibrary
- return b.ToLibrary(), nil
+ return b.ToAPI(), nil
}
diff --git a/database/executable/pop_test.go b/database/executable/pop_test.go
index 6826b2feb..347079e74 100644
--- a/database/executable/pop_test.go
+++ b/database/executable/pop_test.go
@@ -9,7 +9,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestExecutable_Engine_PopBuildExecutable(t *testing.T) {
@@ -43,7 +43,7 @@ func TestExecutable_Engine_PopBuildExecutable(t *testing.T) {
failure bool
name string
database *engine
- want *library.BuildExecutable
+ want *api.BuildExecutable
}{
{
failure: false,
diff --git a/database/executable/table.go b/database/executable/table.go
index 0a7a3c147..bbe8e615b 100644
--- a/database/executable/table.go
+++ b/database/executable/table.go
@@ -5,7 +5,7 @@ package executable
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/flags.go b/database/flags.go
index 129143655..035b016aa 100644
--- a/database/flags.go
+++ b/database/flags.go
@@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Flags represents all supported command line interface (CLI) flags for the database.
diff --git a/database/hook/last_repo.go b/database/hook/last_repo.go
index 0073d8a8b..8d17aef0b 100644
--- a/database/hook/last_repo.go
+++ b/database/hook/last_repo.go
@@ -10,8 +10,8 @@ import (
"gorm.io/gorm"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// LastHookForRepo gets the last hook by repo ID from the database.
diff --git a/database/hook/update.go b/database/hook/update.go
index aec428053..ca648cc83 100644
--- a/database/hook/update.go
+++ b/database/hook/update.go
@@ -20,9 +20,6 @@ func (e *engine) UpdateHook(ctx context.Context, h *api.Hook) (*api.Hook, error)
hook := types.HookFromAPI(h)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Hook.Validate
err := hook.Validate()
if err != nil {
return nil, err
diff --git a/database/integration_test.go b/database/integration_test.go
index 5fb10fe5f..89eda666a 100644
--- a/database/integration_test.go
+++ b/database/integration_test.go
@@ -17,6 +17,7 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/settings"
"github.com/go-vela/server/compiler/types/raw"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/build"
"github.com/go-vela/server/database/dashboard"
"github.com/go-vela/server/database/deployment"
@@ -35,8 +36,6 @@ import (
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/server/tracing"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
)
// Resources represents the object containing test resources.
@@ -44,16 +43,16 @@ type Resources struct {
Builds []*api.Build
Dashboards []*api.Dashboard
Deployments []*api.Deployment
- Executables []*library.BuildExecutable
+ Executables []*api.BuildExecutable
Hooks []*api.Hook
JWKs jwk.Set
- Logs []*library.Log
+ Logs []*api.Log
Pipelines []*api.Pipeline
Repos []*api.Repo
Schedules []*api.Schedule
- Secrets []*library.Secret
- Services []*library.Service
- Steps []*library.Step
+ Secrets []*api.Secret
+ Services []*api.Service
+ Steps []*api.Step
Users []*api.User
Workers []*api.Worker
Platform []*settings.Platform
@@ -1122,7 +1121,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) {
methods["ListLogsForBuild"] = true
// lookup the logs by service
- for _, log := range []*library.Log{resources.Logs[0], resources.Logs[1]} {
+ for _, log := range []*api.Log{resources.Logs[0], resources.Logs[1]} {
service := resources.Services[log.GetServiceID()-1]
got, err := db.GetLogForService(context.TODO(), service)
if err != nil {
@@ -1135,7 +1134,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) {
methods["GetLogForService"] = true
// lookup the logs by service
- for _, log := range []*library.Log{resources.Logs[2], resources.Logs[3]} {
+ for _, log := range []*api.Log{resources.Logs[2], resources.Logs[3]} {
step := resources.Steps[log.GetStepID()-1]
got, err := db.GetLogForStep(context.TODO(), step)
if err != nil {
@@ -1756,8 +1755,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) {
if int(count) != 1 {
t.Errorf("ListSecretsForOrg() is %v, want %v", count, 1)
}
- if !cmp.Equal(list, []*library.Secret{secret}) {
- t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*library.Secret{secret})
+ if !cmp.Equal(list, []*api.Secret{secret}) {
+ t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*api.Secret{secret})
}
methods["ListSecretsForOrg"] = true
case constants.SecretRepo:
@@ -1769,8 +1768,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) {
if int(count) != 1 {
t.Errorf("ListSecretsForRepo() is %v, want %v", count, 1)
}
- if !cmp.Equal(list, []*library.Secret{secret}, CmpOptApproxUpdatedAt()) {
- t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*library.Secret{secret})
+ if !cmp.Equal(list, []*api.Secret{secret}, CmpOptApproxUpdatedAt()) {
+ t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*api.Secret{secret})
}
methods["ListSecretsForRepo"] = true
case constants.SecretShared:
@@ -1782,8 +1781,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) {
if int(count) != 1 {
t.Errorf("ListSecretsForTeam() is %v, want %v", count, 1)
}
- if !cmp.Equal(list, []*library.Secret{secret}, CmpOptApproxUpdatedAt()) {
- t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*library.Secret{secret})
+ if !cmp.Equal(list, []*api.Secret{secret}, CmpOptApproxUpdatedAt()) {
+ t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*api.Secret{secret})
}
methods["ListSecretsForTeam"] = true
@@ -1795,8 +1794,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) {
if int(count) != 1 {
t.Errorf("ListSecretsForTeams() is %v, want %v", count, 1)
}
- if !cmp.Equal(list, []*library.Secret{secret}, CmpOptApproxUpdatedAt()) {
- t.Errorf("ListSecretsForTeams() is %v, want %v", list, []*library.Secret{secret})
+ if !cmp.Equal(list, []*api.Secret{secret}, CmpOptApproxUpdatedAt()) {
+ t.Errorf("ListSecretsForTeams() is %v, want %v", list, []*api.Secret{secret})
}
methods["ListSecretsForTeams"] = true
default:
@@ -1935,8 +1934,8 @@ func testServices(t *testing.T, db Interface, resources *Resources) {
if err != nil {
t.Errorf("unable to list services for build %d: %v", resources.Builds[0].GetID(), err)
}
- if !cmp.Equal(list, []*library.Service{resources.Services[1], resources.Services[0]}) {
- t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{resources.Services[1], resources.Services[0]})
+ if !cmp.Equal(list, []*api.Service{resources.Services[1], resources.Services[0]}) {
+ t.Errorf("ListServicesForBuild() is %v, want %v", list, []*api.Service{resources.Services[1], resources.Services[0]})
}
if int(count) != len(resources.Services) {
t.Errorf("ListServicesForBuild() is %v, want %v", count, len(resources.Services))
@@ -2090,8 +2089,8 @@ func testSteps(t *testing.T, db Interface, resources *Resources) {
if err != nil {
t.Errorf("unable to list steps for build %d: %v", resources.Builds[0].GetID(), err)
}
- if !cmp.Equal(list, []*library.Step{resources.Steps[1], resources.Steps[0]}) {
- t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{resources.Steps[1], resources.Steps[0]})
+ if !cmp.Equal(list, []*api.Step{resources.Steps[1], resources.Steps[0]}) {
+ t.Errorf("ListStepsForBuild() is %v, want %v", list, []*api.Step{resources.Steps[1], resources.Steps[0]})
}
if int(count) != len(resources.Steps) {
t.Errorf("ListStepsForBuild() is %v, want %v", count, len(resources.Steps))
@@ -2623,12 +2622,12 @@ func newResources() *Resources {
dashboardTwo.SetAdmins(dashboardAdmins)
dashboardTwo.SetRepos([]*api.DashboardRepo{dashRepo})
- executableOne := new(library.BuildExecutable)
+ executableOne := new(api.BuildExecutable)
executableOne.SetID(1)
executableOne.SetBuildID(1)
executableOne.SetData([]byte("foo"))
- executableTwo := new(library.BuildExecutable)
+ executableTwo := new(api.BuildExecutable)
executableTwo.SetID(2)
executableTwo.SetBuildID(2)
executableTwo.SetData([]byte("foo"))
@@ -2724,7 +2723,7 @@ func newResources() *Resources {
_ = jwkSet.AddKey(jwkTwo)
- logServiceOne := new(library.Log)
+ logServiceOne := new(api.Log)
logServiceOne.SetID(1)
logServiceOne.SetBuildID(1)
logServiceOne.SetRepoID(1)
@@ -2732,7 +2731,7 @@ func newResources() *Resources {
logServiceOne.SetStepID(0)
logServiceOne.SetData([]byte("foo"))
- logServiceTwo := new(library.Log)
+ logServiceTwo := new(api.Log)
logServiceTwo.SetID(2)
logServiceTwo.SetBuildID(1)
logServiceTwo.SetRepoID(1)
@@ -2740,7 +2739,7 @@ func newResources() *Resources {
logServiceTwo.SetStepID(0)
logServiceTwo.SetData([]byte("foo"))
- logStepOne := new(library.Log)
+ logStepOne := new(api.Log)
logStepOne.SetID(3)
logStepOne.SetBuildID(1)
logStepOne.SetRepoID(1)
@@ -2748,7 +2747,7 @@ func newResources() *Resources {
logStepOne.SetStepID(1)
logStepOne.SetData([]byte("foo"))
- logStepTwo := new(library.Log)
+ logStepTwo := new(api.Log)
logStepTwo.SetID(4)
logStepTwo.SetBuildID(1)
logStepTwo.SetRepoID(1)
@@ -2826,7 +2825,7 @@ func newResources() *Resources {
scheduleTwo.SetError("no version: YAML property provided")
scheduleTwo.SetNextRun(nextTime.Unix())
- secretOrg := new(library.Secret)
+ secretOrg := new(api.Secret)
secretOrg.SetID(1)
secretOrg.SetOrg("github")
secretOrg.SetRepo("*")
@@ -2835,7 +2834,7 @@ func newResources() *Resources {
secretOrg.SetValue("bar")
secretOrg.SetType("org")
secretOrg.SetImages([]string{"alpine"})
- secretOrg.SetAllowEvents(library.NewEventsFromMask(1))
+ secretOrg.SetAllowEvents(api.NewEventsFromMask(1))
secretOrg.SetAllowCommand(true)
secretOrg.SetAllowSubstitution(true)
secretOrg.SetCreatedAt(time.Now().UTC().Unix())
@@ -2843,7 +2842,7 @@ func newResources() *Resources {
secretOrg.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix())
secretOrg.SetUpdatedBy("octokitty")
- secretRepo := new(library.Secret)
+ secretRepo := new(api.Secret)
secretRepo.SetID(2)
secretRepo.SetOrg("github")
secretRepo.SetRepo("octocat")
@@ -2852,7 +2851,7 @@ func newResources() *Resources {
secretRepo.SetValue("bar")
secretRepo.SetType("repo")
secretRepo.SetImages([]string{"alpine"})
- secretRepo.SetAllowEvents(library.NewEventsFromMask(1))
+ secretRepo.SetAllowEvents(api.NewEventsFromMask(1))
secretRepo.SetAllowCommand(true)
secretRepo.SetAllowSubstitution(true)
secretRepo.SetCreatedAt(time.Now().UTC().Unix())
@@ -2860,7 +2859,7 @@ func newResources() *Resources {
secretRepo.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix())
secretRepo.SetUpdatedBy("octokitty")
- secretShared := new(library.Secret)
+ secretShared := new(api.Secret)
secretShared.SetID(3)
secretShared.SetOrg("github")
secretShared.SetRepo("")
@@ -2871,13 +2870,13 @@ func newResources() *Resources {
secretShared.SetImages([]string{"alpine"})
secretShared.SetAllowCommand(true)
secretShared.SetAllowSubstitution(true)
- secretShared.SetAllowEvents(library.NewEventsFromMask(1))
+ secretShared.SetAllowEvents(api.NewEventsFromMask(1))
secretShared.SetCreatedAt(time.Now().UTC().Unix())
secretShared.SetCreatedBy("octocat")
secretShared.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix())
secretShared.SetUpdatedBy("octokitty")
- serviceOne := new(library.Service)
+ serviceOne := new(api.Service)
serviceOne.SetID(1)
serviceOne.SetBuildID(1)
serviceOne.SetRepoID(1)
@@ -2894,7 +2893,7 @@ func newResources() *Resources {
serviceOne.SetRuntime("docker")
serviceOne.SetDistribution("linux")
- serviceTwo := new(library.Service)
+ serviceTwo := new(api.Service)
serviceTwo.SetID(2)
serviceTwo.SetBuildID(1)
serviceTwo.SetRepoID(1)
@@ -2911,7 +2910,7 @@ func newResources() *Resources {
serviceTwo.SetRuntime("docker")
serviceTwo.SetDistribution("linux")
- stepOne := new(library.Step)
+ stepOne := new(api.Step)
stepOne.SetID(1)
stepOne.SetBuildID(1)
stepOne.SetRepoID(1)
@@ -2930,7 +2929,7 @@ func newResources() *Resources {
stepOne.SetDistribution("linux")
stepOne.SetReportAs("")
- stepTwo := new(library.Step)
+ stepTwo := new(api.Step)
stepTwo.SetID(2)
stepTwo.SetBuildID(1)
stepTwo.SetRepoID(1)
@@ -2987,16 +2986,16 @@ func newResources() *Resources {
Builds: []*api.Build{buildOne, buildTwo},
Dashboards: []*api.Dashboard{dashboardOne, dashboardTwo},
Deployments: []*api.Deployment{deploymentOne, deploymentTwo},
- Executables: []*library.BuildExecutable{executableOne, executableTwo},
+ Executables: []*api.BuildExecutable{executableOne, executableTwo},
Hooks: []*api.Hook{hookOne, hookTwo, hookThree},
JWKs: jwkSet,
- Logs: []*library.Log{logServiceOne, logServiceTwo, logStepOne, logStepTwo},
+ Logs: []*api.Log{logServiceOne, logServiceTwo, logStepOne, logStepTwo},
Pipelines: []*api.Pipeline{pipelineOne, pipelineTwo},
Repos: []*api.Repo{repoOne, repoTwo},
Schedules: []*api.Schedule{scheduleOne, scheduleTwo},
- Secrets: []*library.Secret{secretOrg, secretRepo, secretShared},
- Services: []*library.Service{serviceOne, serviceTwo},
- Steps: []*library.Step{stepOne, stepTwo},
+ Secrets: []*api.Secret{secretOrg, secretRepo, secretShared},
+ Services: []*api.Service{serviceOne, serviceTwo},
+ Steps: []*api.Step{stepOne, stepTwo},
Users: []*api.User{userOne, userTwo},
Workers: []*api.Worker{workerOne, workerTwo},
}
diff --git a/database/jwk/table.go b/database/jwk/table.go
index ee5895fcb..81f8ccfc2 100644
--- a/database/jwk/table.go
+++ b/database/jwk/table.go
@@ -5,7 +5,7 @@ package jwk
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/log/count.go b/database/log/count.go
index d31c37f62..dd30fe00f 100644
--- a/database/log/count.go
+++ b/database/log/count.go
@@ -5,7 +5,7 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountLogs gets the count of all logs from the database.
diff --git a/database/log/count_build.go b/database/log/count_build.go
index 36cd2984f..ff6eb84fb 100644
--- a/database/log/count_build.go
+++ b/database/log/count_build.go
@@ -6,7 +6,7 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountLogsForBuild gets the count of logs by build ID from the database.
diff --git a/database/log/create.go b/database/log/create.go
index 4d0ee3428..98ec63beb 100644
--- a/database/log/create.go
+++ b/database/log/create.go
@@ -7,13 +7,13 @@ import (
"context"
"fmt"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CreateLog creates a new log in the database.
-func (e *engine) CreateLog(ctx context.Context, l *library.Log) error {
+func (e *engine) CreateLog(ctx context.Context, l *api.Log) error {
// check what the log entry is for
switch {
case l.GetServiceID() > 0:
@@ -22,22 +22,15 @@ func (e *engine) CreateLog(ctx context.Context, l *library.Log) error {
e.logger.Tracef("creating log for step %d for build %d", l.GetStepID(), l.GetBuildID())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#LogFromLibrary
- log := database.LogFromLibrary(l)
+ // cast the API type to database type
+ log := types.LogFromAPI(l)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Validate
err := log.Validate()
if err != nil {
return err
}
// compress log data for the resource
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Compress
err = log.Compress(e.config.CompressionLevel)
if err != nil {
switch {
diff --git a/database/log/create_test.go b/database/log/create_test.go
index 3b86fbe44..c24b0d7f9 100644
--- a/database/log/create_test.go
+++ b/database/log/create_test.go
@@ -8,8 +8,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_CreateLog(t *testing.T) {
@@ -54,19 +54,19 @@ VALUES ($1,$2,$3,$4,$5,$6) RETURNING "id"`).
failure bool
name string
database *engine
- logs []*library.Log
+ logs []*api.Log
}{
{
failure: false,
name: "postgres",
database: _postgres,
- logs: []*library.Log{_service, _step},
+ logs: []*api.Log{_service, _step},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- logs: []*library.Log{_service, _step},
+ logs: []*api.Log{_service, _step},
},
}
diff --git a/database/log/delete.go b/database/log/delete.go
index 394321159..8b077c174 100644
--- a/database/log/delete.go
+++ b/database/log/delete.go
@@ -5,13 +5,13 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// DeleteLog deletes an existing log from the database.
-func (e *engine) DeleteLog(ctx context.Context, l *library.Log) error {
+func (e *engine) DeleteLog(ctx context.Context, l *api.Log) error {
// check what the log entry is for
switch {
case l.GetServiceID() > 0:
@@ -20,10 +20,8 @@ func (e *engine) DeleteLog(ctx context.Context, l *library.Log) error {
e.logger.Tracef("deleting log for step %d for build %d", l.GetStepID(), l.GetBuildID())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#LogFromLibrary
- log := database.LogFromLibrary(l)
+ // cast the API type to database type
+ log := types.LogFromAPI(l)
// send query to the database
return e.client.
diff --git a/database/log/get.go b/database/log/get.go
index cf66dbfd7..9054b8c5e 100644
--- a/database/log/get.go
+++ b/database/log/get.go
@@ -5,17 +5,17 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetLog gets a log by ID from the database.
-func (e *engine) GetLog(ctx context.Context, id int64) (*library.Log, error) {
+func (e *engine) GetLog(ctx context.Context, id int64) (*api.Log, error) {
e.logger.Tracef("getting log %d", id)
// variable to store query results
- l := new(database.Log)
+ l := new(types.Log)
// send query to the database and store result in variable
err := e.client.
@@ -29,8 +29,6 @@ func (e *engine) GetLog(ctx context.Context, id int64) (*library.Log, error) {
}
// decompress log data
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Decompress
err = l.Decompress()
if err != nil {
// ensures that the change is backwards compatible
@@ -39,11 +37,9 @@ func (e *engine) GetLog(ctx context.Context, id int64) (*library.Log, error) {
e.logger.Errorf("unable to decompress log %d: %v", id, err)
// return the uncompressed log
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
// return the log
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.ToLibrary
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
diff --git a/database/log/get_service.go b/database/log/get_service.go
index ad4156a8d..f760af06e 100644
--- a/database/log/get_service.go
+++ b/database/log/get_service.go
@@ -6,17 +6,17 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetLogForService gets a log by service ID from the database.
-func (e *engine) GetLogForService(ctx context.Context, s *library.Service) (*library.Log, error) {
+func (e *engine) GetLogForService(ctx context.Context, s *api.Service) (*api.Log, error) {
e.logger.Tracef("getting log for service %d for build %d", s.GetID(), s.GetBuildID())
// variable to store query results
- l := new(database.Log)
+ l := new(types.Log)
// send query to the database and store result in variable
err := e.client.
@@ -30,8 +30,6 @@ func (e *engine) GetLogForService(ctx context.Context, s *library.Service) (*lib
}
// decompress log data for the service
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Decompress
err = l.Decompress()
if err != nil {
// ensures that the change is backwards compatible
@@ -40,11 +38,9 @@ func (e *engine) GetLogForService(ctx context.Context, s *library.Service) (*lib
e.logger.Errorf("unable to decompress log for service %d for build %d: %v", s.GetID(), s.GetBuildID(), err)
// return the uncompressed log
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
// return the log
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.ToLibrary
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
diff --git a/database/log/get_service_test.go b/database/log/get_service_test.go
index b4ae5efe5..8a9083486 100644
--- a/database/log/get_service_test.go
+++ b/database/log/get_service_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_GetLogForService(t *testing.T) {
@@ -53,7 +53,7 @@ func TestLog_Engine_GetLogForService(t *testing.T) {
failure bool
name string
database *engine
- want *library.Log
+ want *api.Log
}{
{
failure: false,
diff --git a/database/log/get_step.go b/database/log/get_step.go
index 6d0084712..ff92bac10 100644
--- a/database/log/get_step.go
+++ b/database/log/get_step.go
@@ -6,17 +6,17 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetLogForStep gets a log by step ID from the database.
-func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.Log, error) {
+func (e *engine) GetLogForStep(ctx context.Context, s *api.Step) (*api.Log, error) {
e.logger.Tracef("getting log for step %d for build %d", s.GetID(), s.GetBuildID())
// variable to store query results
- l := new(database.Log)
+ l := new(types.Log)
// send query to the database and store result in variable
err := e.client.
@@ -30,8 +30,6 @@ func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.L
}
// decompress log data for the step
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Decompress
err = l.Decompress()
if err != nil {
// ensures that the change is backwards compatible
@@ -40,11 +38,9 @@ func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.L
e.logger.Errorf("unable to decompress log for step %d for build %d: %v", s.GetID(), s.GetBuildID(), err)
// return the uncompressed log
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
// return the log
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.ToLibrary
- return l.ToLibrary(), nil
+ return l.ToAPI(), nil
}
diff --git a/database/log/get_step_test.go b/database/log/get_step_test.go
index 68073bf85..0b7a6dc8d 100644
--- a/database/log/get_step_test.go
+++ b/database/log/get_step_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_GetLogForStep(t *testing.T) {
@@ -53,7 +53,7 @@ func TestLog_Engine_GetLogForStep(t *testing.T) {
failure bool
name string
database *engine
- want *library.Log
+ want *api.Log
}{
{
failure: false,
diff --git a/database/log/get_test.go b/database/log/get_test.go
index d2263704f..4ac2bc78c 100644
--- a/database/log/get_test.go
+++ b/database/log/get_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_GetLog(t *testing.T) {
@@ -46,7 +46,7 @@ func TestLog_Engine_GetLog(t *testing.T) {
failure bool
name string
database *engine
- want *library.Log
+ want *api.Log
}{
{
failure: false,
diff --git a/database/log/interface.go b/database/log/interface.go
index 97ace05c6..d5e77ead3 100644
--- a/database/log/interface.go
+++ b/database/log/interface.go
@@ -6,7 +6,6 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/library"
)
// LogInterface represents the Vela interface for log
@@ -32,19 +31,19 @@ type LogInterface interface {
// CountLogsForBuild defines a function that gets the count of logs by build ID.
CountLogsForBuild(context.Context, *api.Build) (int64, error)
// CreateLog defines a function that creates a new log.
- CreateLog(context.Context, *library.Log) error
+ CreateLog(context.Context, *api.Log) error
// DeleteLog defines a function that deletes an existing log.
- DeleteLog(context.Context, *library.Log) error
+ DeleteLog(context.Context, *api.Log) error
// GetLog defines a function that gets a log by ID.
- GetLog(context.Context, int64) (*library.Log, error)
+ GetLog(context.Context, int64) (*api.Log, error)
// GetLogForService defines a function that gets a log by service ID.
- GetLogForService(context.Context, *library.Service) (*library.Log, error)
+ GetLogForService(context.Context, *api.Service) (*api.Log, error)
// GetLogForStep defines a function that gets a log by step ID.
- GetLogForStep(context.Context, *library.Step) (*library.Log, error)
+ GetLogForStep(context.Context, *api.Step) (*api.Log, error)
// ListLogs defines a function that gets a list of all logs.
- ListLogs(context.Context) ([]*library.Log, error)
+ ListLogs(context.Context) ([]*api.Log, error)
// ListLogsForBuild defines a function that gets a list of logs by build ID.
- ListLogsForBuild(context.Context, *api.Build, int, int) ([]*library.Log, int64, error)
+ ListLogsForBuild(context.Context, *api.Build, int, int) ([]*api.Log, int64, error)
// UpdateLog defines a function that updates an existing log.
- UpdateLog(context.Context, *library.Log) error
+ UpdateLog(context.Context, *api.Log) error
}
diff --git a/database/log/list.go b/database/log/list.go
index ed6ecdcb7..aa0e816b1 100644
--- a/database/log/list.go
+++ b/database/log/list.go
@@ -5,19 +5,19 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListLogs gets a list of all logs from the database.
-func (e *engine) ListLogs(ctx context.Context) ([]*library.Log, error) {
+func (e *engine) ListLogs(ctx context.Context) ([]*api.Log, error) {
e.logger.Trace("listing all logs")
// variables to store query results and return value
count := int64(0)
- l := new([]database.Log)
- logs := []*library.Log{}
+ l := new([]types.Log)
+ logs := []*api.Log{}
// count the results
count, err := e.CountLogs(ctx)
@@ -46,8 +46,6 @@ func (e *engine) ListLogs(ctx context.Context) ([]*library.Log, error) {
tmp := log
// decompress log data
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Decompress
err = tmp.Decompress()
if err != nil {
// ensures that the change is backwards compatible
@@ -56,10 +54,8 @@ func (e *engine) ListLogs(ctx context.Context) ([]*library.Log, error) {
e.logger.Errorf("unable to decompress logs: %v", err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.ToLibrary
- logs = append(logs, tmp.ToLibrary())
+ // convert query result to API type
+ logs = append(logs, tmp.ToAPI())
}
return logs, nil
diff --git a/database/log/list_build.go b/database/log/list_build.go
index f27798b78..4318a3b5a 100644
--- a/database/log/list_build.go
+++ b/database/log/list_build.go
@@ -6,19 +6,18 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListLogsForBuild gets a list of logs by build ID from the database.
-func (e *engine) ListLogsForBuild(ctx context.Context, b *api.Build, page, perPage int) ([]*library.Log, int64, error) {
+func (e *engine) ListLogsForBuild(ctx context.Context, b *api.Build, page, perPage int) ([]*api.Log, int64, error) {
e.logger.Tracef("listing logs for build %d", b.GetID())
// variables to store query results and return value
count := int64(0)
- l := new([]database.Log)
- logs := []*library.Log{}
+ l := new([]types.Log)
+ logs := []*api.Log{}
// count the results
count, err := e.CountLogsForBuild(ctx, b)
@@ -55,8 +54,6 @@ func (e *engine) ListLogsForBuild(ctx context.Context, b *api.Build, page, perPa
tmp := log
// decompress log data for the build
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Decompress
err = tmp.Decompress()
if err != nil {
// ensures that the change is backwards compatible
@@ -65,10 +62,8 @@ func (e *engine) ListLogsForBuild(ctx context.Context, b *api.Build, page, perPa
e.logger.Errorf("unable to decompress logs for build %d: %v", b.GetID(), err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.ToLibrary
- logs = append(logs, tmp.ToLibrary())
+ // convert query result to API type
+ logs = append(logs, tmp.ToAPI())
}
return logs, count, nil
diff --git a/database/log/list_build_test.go b/database/log/list_build_test.go
index e4b9038cd..29ad6a162 100644
--- a/database/log/list_build_test.go
+++ b/database/log/list_build_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_ListLogsForBuild(t *testing.T) {
@@ -73,19 +73,19 @@ func TestLog_Engine_ListLogsForBuild(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Log
+ want []*api.Log
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Log{_service, _step},
+ want: []*api.Log{_service, _step},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Log{_service, _step},
+ want: []*api.Log{_service, _step},
},
}
diff --git a/database/log/list_test.go b/database/log/list_test.go
index 6371c9fd2..d2249d0c1 100644
--- a/database/log/list_test.go
+++ b/database/log/list_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_ListLogs(t *testing.T) {
@@ -64,19 +64,19 @@ func TestLog_Engine_ListLogs(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Log
+ want []*api.Log
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Log{_service, _step},
+ want: []*api.Log{_service, _step},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Log{_service, _step},
+ want: []*api.Log{_service, _step},
},
}
diff --git a/database/log/log.go b/database/log/log.go
index e95dc6d04..f990eff40 100644
--- a/database/log/log.go
+++ b/database/log/log.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/log/table.go b/database/log/table.go
index fbf74cd28..6ac0e53f9 100644
--- a/database/log/table.go
+++ b/database/log/table.go
@@ -5,7 +5,7 @@ package log
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/log/update.go b/database/log/update.go
index ae9819e4a..0854a9c2d 100644
--- a/database/log/update.go
+++ b/database/log/update.go
@@ -7,13 +7,13 @@ import (
"context"
"fmt"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// UpdateLog updates an existing log in the database.
-func (e *engine) UpdateLog(ctx context.Context, l *library.Log) error {
+func (e *engine) UpdateLog(ctx context.Context, l *api.Log) error {
// check what the log entry is for
switch {
case l.GetServiceID() > 0:
@@ -22,22 +22,16 @@ func (e *engine) UpdateLog(ctx context.Context, l *library.Log) error {
e.logger.Tracef("updating log for step %d for build %d", l.GetStepID(), l.GetBuildID())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#LogFromLibrary
- log := database.LogFromLibrary(l)
+ // cast the API type to database type
+ log := types.LogFromAPI(l)
// validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Validate
err := log.Validate()
if err != nil {
return err
}
// compress log data for the resource
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Log.Compress
err = log.Compress(e.config.CompressionLevel)
if err != nil {
switch {
diff --git a/database/log/update_test.go b/database/log/update_test.go
index ae2ca53f0..163185f31 100644
--- a/database/log/update_test.go
+++ b/database/log/update_test.go
@@ -8,8 +8,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestLog_Engine_UpdateLog(t *testing.T) {
@@ -63,19 +63,19 @@ WHERE "id" = $6`).
failure bool
name string
database *engine
- logs []*library.Log
+ logs []*api.Log
}{
{
failure: false,
name: "postgres",
database: _postgres,
- logs: []*library.Log{_service, _step},
+ logs: []*api.Log{_service, _step},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- logs: []*library.Log{_service, _step},
+ logs: []*api.Log{_service, _step},
},
}
diff --git a/database/pipeline/count.go b/database/pipeline/count.go
index 818982b52..b7f3d83f7 100644
--- a/database/pipeline/count.go
+++ b/database/pipeline/count.go
@@ -5,7 +5,7 @@ package pipeline
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountPipelines gets the count of all pipelines from the database.
diff --git a/database/pipeline/count_repo.go b/database/pipeline/count_repo.go
index 147ae552b..3c174e340 100644
--- a/database/pipeline/count_repo.go
+++ b/database/pipeline/count_repo.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountPipelinesForRepo gets the count of pipelines by repo ID from the database.
diff --git a/database/pipeline/create.go b/database/pipeline/create.go
index d6ce01cd0..032742533 100644
--- a/database/pipeline/create.go
+++ b/database/pipeline/create.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreatePipeline creates a new pipeline in the database.
diff --git a/database/pipeline/delete.go b/database/pipeline/delete.go
index ecd87611e..fb9ad8407 100644
--- a/database/pipeline/delete.go
+++ b/database/pipeline/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeletePipeline deletes an existing pipeline from the database.
diff --git a/database/pipeline/get.go b/database/pipeline/get.go
index 0721ba36d..e7d570ece 100644
--- a/database/pipeline/get.go
+++ b/database/pipeline/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetPipeline gets a pipeline by ID from the database.
diff --git a/database/pipeline/get_repo.go b/database/pipeline/get_repo.go
index b84c320f3..5da0f9281 100644
--- a/database/pipeline/get_repo.go
+++ b/database/pipeline/get_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetPipelineForRepo gets a pipeline by number and repo ID from the database.
diff --git a/database/pipeline/list.go b/database/pipeline/list.go
index e288965bd..85e39a3cd 100644
--- a/database/pipeline/list.go
+++ b/database/pipeline/list.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListPipelines gets a list of all pipelines from the database.
diff --git a/database/pipeline/list_repo.go b/database/pipeline/list_repo.go
index 5476cd925..cc179febe 100644
--- a/database/pipeline/list_repo.go
+++ b/database/pipeline/list_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListPipelinesForRepo gets a list of pipelines by repo ID from the database.
diff --git a/database/pipeline/pipeline.go b/database/pipeline/pipeline.go
index 433f9d2fc..18beb9cf8 100644
--- a/database/pipeline/pipeline.go
+++ b/database/pipeline/pipeline.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/pipeline/table.go b/database/pipeline/table.go
index 919b1b652..4bd874c83 100644
--- a/database/pipeline/table.go
+++ b/database/pipeline/table.go
@@ -5,7 +5,7 @@ package pipeline
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/pipeline/update.go b/database/pipeline/update.go
index 23251f1a1..66eecaefa 100644
--- a/database/pipeline/update.go
+++ b/database/pipeline/update.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdatePipeline updates an existing pipeline in the database.
diff --git a/database/repo/count.go b/database/repo/count.go
index 6db509b06..585b2417b 100644
--- a/database/repo/count.go
+++ b/database/repo/count.go
@@ -5,7 +5,7 @@ package repo
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountRepos gets the count of all repos from the database.
diff --git a/database/repo/count_org.go b/database/repo/count_org.go
index 915a0d9a7..cb5c53868 100644
--- a/database/repo/count_org.go
+++ b/database/repo/count_org.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountReposForOrg gets the count of repos by org name from the database.
diff --git a/database/repo/count_user.go b/database/repo/count_user.go
index 57f3ecb3c..7fd8c212d 100644
--- a/database/repo/count_user.go
+++ b/database/repo/count_user.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountReposForUser gets the count of repos by user ID from the database.
diff --git a/database/repo/create.go b/database/repo/create.go
index 7500b4101..2768a72be 100644
--- a/database/repo/create.go
+++ b/database/repo/create.go
@@ -10,8 +10,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateRepo creates a new repo in the database.
@@ -21,7 +21,7 @@ func (e *engine) CreateRepo(ctx context.Context, r *api.Repo) (*api.Repo, error)
"repo": r.GetName(),
}).Tracef("creating repo %s", r.GetFullName())
- // cast the library type to database type
+ // cast the API type to database type
repo := types.RepoFromAPI(r)
// validate the necessary fields are populated
diff --git a/database/repo/delete.go b/database/repo/delete.go
index cfd6dffa3..72f80af10 100644
--- a/database/repo/delete.go
+++ b/database/repo/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteRepo deletes an existing repo from the database.
@@ -19,7 +19,7 @@ func (e *engine) DeleteRepo(ctx context.Context, r *api.Repo) error {
"repo": r.GetName(),
}).Tracef("deleting repo %s", r.GetFullName())
- // cast the library type to database type
+ // cast the API type to database type
repo := types.RepoFromAPI(r)
// send query to the database
diff --git a/database/repo/get.go b/database/repo/get.go
index 15a301290..4f241425b 100644
--- a/database/repo/get.go
+++ b/database/repo/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetRepo gets a repo by ID from the database.
@@ -30,8 +30,6 @@ func (e *engine) GetRepo(ctx context.Context, id int64) (*api.Repo, error) {
}
// decrypt the fields for the repo
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Decrypt
err = r.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -42,13 +40,9 @@ func (e *engine) GetRepo(ctx context.Context, id int64) (*api.Repo, error) {
e.logger.Errorf("unable to decrypt repo %d: %v", id, err)
// return the unencrypted repo
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Repo.ToLibrary
return r.ToAPI(), nil
}
// return the decrypted repo
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Repo.ToLibrary
return r.ToAPI(), nil
}
diff --git a/database/repo/get_org.go b/database/repo/get_org.go
index 38b32d4ca..368832eb5 100644
--- a/database/repo/get_org.go
+++ b/database/repo/get_org.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetRepoForOrg gets a repo by org and repo name from the database.
diff --git a/database/repo/get_org_test.go b/database/repo/get_org_test.go
index 1570398c0..ed912ca1f 100644
--- a/database/repo/get_org_test.go
+++ b/database/repo/get_org_test.go
@@ -10,9 +10,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_GetRepoForOrg(t *testing.T) {
diff --git a/database/repo/get_test.go b/database/repo/get_test.go
index bab82c6f3..720f9bf07 100644
--- a/database/repo/get_test.go
+++ b/database/repo/get_test.go
@@ -10,9 +10,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_GetRepo(t *testing.T) {
diff --git a/database/repo/list.go b/database/repo/list.go
index 980044d97..5fd587dd4 100644
--- a/database/repo/list.go
+++ b/database/repo/list.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListRepos gets a list of all repos from the database.
@@ -57,7 +57,7 @@ func (e *engine) ListRepos(ctx context.Context) ([]*api.Repo, error) {
e.logger.Errorf("unable to decrypt repo %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
+ // convert query result to API type
repos = append(repos, tmp.ToAPI())
}
diff --git a/database/repo/list_org.go b/database/repo/list_org.go
index 1b39feea8..b390192d4 100644
--- a/database/repo/list_org.go
+++ b/database/repo/list_org.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListReposForOrg gets a list of repos by org name from the database.
diff --git a/database/repo/list_org_test.go b/database/repo/list_org_test.go
index 9a7bb5aa6..9aad55864 100644
--- a/database/repo/list_org_test.go
+++ b/database/repo/list_org_test.go
@@ -11,9 +11,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_ListReposForOrg(t *testing.T) {
diff --git a/database/repo/list_test.go b/database/repo/list_test.go
index a4f40dcbe..176d70369 100644
--- a/database/repo/list_test.go
+++ b/database/repo/list_test.go
@@ -10,9 +10,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_ListRepos(t *testing.T) {
diff --git a/database/repo/list_user.go b/database/repo/list_user.go
index 997fe15f4..c0bedbe66 100644
--- a/database/repo/list_user.go
+++ b/database/repo/list_user.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListReposForUser gets a list of repos by user ID from the database.
@@ -98,7 +98,7 @@ func (e *engine) ListReposForUser(ctx context.Context, u *api.User, sortBy strin
e.logger.Errorf("unable to decrypt repo %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
+ // convert query result to API type
repos = append(repos, tmp.ToAPI())
}
diff --git a/database/repo/list_user_test.go b/database/repo/list_user_test.go
index 49261c95e..5b9fda28a 100644
--- a/database/repo/list_user_test.go
+++ b/database/repo/list_user_test.go
@@ -11,9 +11,9 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_ListReposForUser(t *testing.T) {
diff --git a/database/repo/repo.go b/database/repo/repo.go
index 2a915192f..55e47587b 100644
--- a/database/repo/repo.go
+++ b/database/repo/repo.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/repo/table.go b/database/repo/table.go
index 0b16bae94..f49c26933 100644
--- a/database/repo/table.go
+++ b/database/repo/table.go
@@ -5,7 +5,7 @@ package repo
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/repo/update.go b/database/repo/update.go
index 05af67470..8168bf404 100644
--- a/database/repo/update.go
+++ b/database/repo/update.go
@@ -10,8 +10,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateRepo updates an existing repo in the database.
@@ -21,7 +21,7 @@ func (e *engine) UpdateRepo(ctx context.Context, r *api.Repo) (*api.Repo, error)
"repo": r.GetName(),
}).Tracef("creating repo %s", r.GetFullName())
- // cast the library type to database type
+ // cast the API type to database type
repo := types.RepoFromAPI(r)
// validate the necessary fields are populated
diff --git a/database/repo/update_test.go b/database/repo/update_test.go
index e175a349a..a447d6973 100644
--- a/database/repo/update_test.go
+++ b/database/repo/update_test.go
@@ -10,8 +10,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestRepo_Engine_UpdateRepo(t *testing.T) {
diff --git a/database/schedule/count.go b/database/schedule/count.go
index e199e8ed0..e55ef0175 100644
--- a/database/schedule/count.go
+++ b/database/schedule/count.go
@@ -5,7 +5,7 @@ package schedule
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSchedules gets the count of all schedules from the database.
diff --git a/database/schedule/count_active.go b/database/schedule/count_active.go
index 5aa6e7209..5f8197e28 100644
--- a/database/schedule/count_active.go
+++ b/database/schedule/count_active.go
@@ -5,7 +5,7 @@ package schedule
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountActiveSchedules gets the count of all active schedules from the database.
diff --git a/database/schedule/count_active_test.go b/database/schedule/count_active_test.go
index a94af19c6..5cb6efb4f 100644
--- a/database/schedule/count_active_test.go
+++ b/database/schedule/count_active_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_CountActiveSchedules(t *testing.T) {
diff --git a/database/schedule/count_repo.go b/database/schedule/count_repo.go
index 41246b800..79b4eef98 100644
--- a/database/schedule/count_repo.go
+++ b/database/schedule/count_repo.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSchedulesForRepo gets the count of schedules by repo ID from the database.
diff --git a/database/schedule/count_repo_test.go b/database/schedule/count_repo_test.go
index 2b95abd10..847b341cc 100644
--- a/database/schedule/count_repo_test.go
+++ b/database/schedule/count_repo_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_CountSchedulesForRepo(t *testing.T) {
diff --git a/database/schedule/count_test.go b/database/schedule/count_test.go
index 13be42a30..df58cdd45 100644
--- a/database/schedule/count_test.go
+++ b/database/schedule/count_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_CountSchedules(t *testing.T) {
diff --git a/database/schedule/create.go b/database/schedule/create.go
index 891237c26..ac2ded2b2 100644
--- a/database/schedule/create.go
+++ b/database/schedule/create.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateSchedule creates a new schedule in the database.
diff --git a/database/schedule/create_test.go b/database/schedule/create_test.go
index ac028099e..cb29cd8aa 100644
--- a/database/schedule/create_test.go
+++ b/database/schedule/create_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_CreateSchedule(t *testing.T) {
diff --git a/database/schedule/delete.go b/database/schedule/delete.go
index 8f28c1173..6ce7db101 100644
--- a/database/schedule/delete.go
+++ b/database/schedule/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteSchedule deletes an existing schedule from the database.
diff --git a/database/schedule/delete_test.go b/database/schedule/delete_test.go
index 971377d92..ca7351863 100644
--- a/database/schedule/delete_test.go
+++ b/database/schedule/delete_test.go
@@ -11,8 +11,8 @@ import (
"github.com/adhocore/gronx"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_DeleteSchedule(t *testing.T) {
diff --git a/database/schedule/get.go b/database/schedule/get.go
index 887d4e002..db02cb521 100644
--- a/database/schedule/get.go
+++ b/database/schedule/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetSchedule gets a schedule by ID from the database.
diff --git a/database/schedule/get_repo.go b/database/schedule/get_repo.go
index 8f0cff429..6602ea5a8 100644
--- a/database/schedule/get_repo.go
+++ b/database/schedule/get_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetScheduleForRepo gets a schedule by repo ID and name from the database.
diff --git a/database/schedule/get_repo_test.go b/database/schedule/get_repo_test.go
index 346119b3b..07f49bcf3 100644
--- a/database/schedule/get_repo_test.go
+++ b/database/schedule/get_repo_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_GetScheduleForRepo(t *testing.T) {
diff --git a/database/schedule/get_test.go b/database/schedule/get_test.go
index 5d6f44fca..88ad9df3c 100644
--- a/database/schedule/get_test.go
+++ b/database/schedule/get_test.go
@@ -12,9 +12,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_GetSchedule(t *testing.T) {
diff --git a/database/schedule/list.go b/database/schedule/list.go
index 44f548352..53e3c6361 100644
--- a/database/schedule/list.go
+++ b/database/schedule/list.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListSchedules gets a list of all schedules from the database.
diff --git a/database/schedule/list_active.go b/database/schedule/list_active.go
index 8952de929..665682e2c 100644
--- a/database/schedule/list_active.go
+++ b/database/schedule/list_active.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListActiveSchedules gets a list of all active schedules from the database.
diff --git a/database/schedule/list_active_test.go b/database/schedule/list_active_test.go
index 385cdf595..d015f0e38 100644
--- a/database/schedule/list_active_test.go
+++ b/database/schedule/list_active_test.go
@@ -12,9 +12,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_ListActiveSchedules(t *testing.T) {
diff --git a/database/schedule/list_repo.go b/database/schedule/list_repo.go
index 766e5e1c0..2f23d985d 100644
--- a/database/schedule/list_repo.go
+++ b/database/schedule/list_repo.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListSchedulesForRepo gets a list of schedules by repo ID from the database.
diff --git a/database/schedule/list_repo_test.go b/database/schedule/list_repo_test.go
index d73107f6e..a1b8f7131 100644
--- a/database/schedule/list_repo_test.go
+++ b/database/schedule/list_repo_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_ListSchedulesForRepo(t *testing.T) {
diff --git a/database/schedule/list_test.go b/database/schedule/list_test.go
index b699a12c4..5d8b5d738 100644
--- a/database/schedule/list_test.go
+++ b/database/schedule/list_test.go
@@ -12,9 +12,9 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_ListSchedules(t *testing.T) {
diff --git a/database/schedule/schedule.go b/database/schedule/schedule.go
index b7a83b2dd..66d345f1d 100644
--- a/database/schedule/schedule.go
+++ b/database/schedule/schedule.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/schedule/table.go b/database/schedule/table.go
index 86eda10bc..c6db79c4a 100644
--- a/database/schedule/table.go
+++ b/database/schedule/table.go
@@ -5,7 +5,7 @@ package schedule
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/schedule/update.go b/database/schedule/update.go
index d2f9cbf33..8ff3c478c 100644
--- a/database/schedule/update.go
+++ b/database/schedule/update.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateSchedule updates an existing schedule in the database.
diff --git a/database/schedule/update_test.go b/database/schedule/update_test.go
index c936b2ab1..bcf675edb 100644
--- a/database/schedule/update_test.go
+++ b/database/schedule/update_test.go
@@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestSchedule_Engine_UpdateSchedule_Config(t *testing.T) {
diff --git a/database/secret/count.go b/database/secret/count.go
index 2b9b36ad0..0af09e015 100644
--- a/database/secret/count.go
+++ b/database/secret/count.go
@@ -5,7 +5,7 @@ package secret
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSecrets gets the count of all secrets from the database.
diff --git a/database/secret/count_org.go b/database/secret/count_org.go
index 85fb17624..ecea526c1 100644
--- a/database/secret/count_org.go
+++ b/database/secret/count_org.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSecretsForOrg gets the count of secrets by org name from the database.
diff --git a/database/secret/count_org_test.go b/database/secret/count_org_test.go
index 22f8543f8..bcad30bc0 100644
--- a/database/secret/count_org_test.go
+++ b/database/secret/count_org_test.go
@@ -9,12 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_CountSecretsForOrg(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("*")
@@ -26,7 +27,7 @@ func TestSecret_Engine_CountSecretsForOrg(t *testing.T) {
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("bar")
_secretTwo.SetRepo("*")
diff --git a/database/secret/count_repo.go b/database/secret/count_repo.go
index 6430f7fe9..08772e47f 100644
--- a/database/secret/count_repo.go
+++ b/database/secret/count_repo.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSecretsForRepo gets the count of secrets by org and repo name from the database.
diff --git a/database/secret/count_repo_test.go b/database/secret/count_repo_test.go
index c925853f8..fad58a926 100644
--- a/database/secret/count_repo_test.go
+++ b/database/secret/count_repo_test.go
@@ -9,12 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_CountSecretsForRepo(t *testing.T) {
// setup types
- _repo := testRepo()
+ _repo := testutils.APIRepo()
_repo.SetID(1)
_repo.GetOwner().SetID(1)
_repo.SetHash("baz")
@@ -24,7 +25,7 @@ func TestSecret_Engine_CountSecretsForRepo(t *testing.T) {
_repo.SetVisibility("public")
_repo.SetPipelineType("yaml")
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("bar")
@@ -36,7 +37,7 @@ func TestSecret_Engine_CountSecretsForRepo(t *testing.T) {
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("bar")
_secretTwo.SetRepo("foo")
diff --git a/database/secret/count_team.go b/database/secret/count_team.go
index af158dcbc..03346756d 100644
--- a/database/secret/count_team.go
+++ b/database/secret/count_team.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSecretsForTeam gets the count of secrets by org and team name from the database.
diff --git a/database/secret/count_team_test.go b/database/secret/count_team_test.go
index 071e7902f..316510b43 100644
--- a/database/secret/count_team_test.go
+++ b/database/secret/count_team_test.go
@@ -9,12 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_CountSecretsForTeam(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetTeam("bar")
@@ -26,7 +27,7 @@ func TestSecret_Engine_CountSecretsForTeam(t *testing.T) {
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("bar")
_secretTwo.SetTeam("foo")
@@ -110,7 +111,7 @@ func TestSecret_Engine_CountSecretsForTeam(t *testing.T) {
func TestSecret_Engine_CountSecretsForTeams(t *testing.T) {
// setup types
- _repo := testRepo()
+ _repo := testutils.APIRepo()
_repo.SetID(1)
_repo.GetOwner().SetID(1)
_repo.SetHash("baz")
@@ -120,7 +121,7 @@ func TestSecret_Engine_CountSecretsForTeams(t *testing.T) {
_repo.SetVisibility("public")
_repo.SetPipelineType("yaml")
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetTeam("bar")
@@ -132,7 +133,7 @@ func TestSecret_Engine_CountSecretsForTeams(t *testing.T) {
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("bar")
_secretTwo.SetTeam("foo")
diff --git a/database/secret/count_test.go b/database/secret/count_test.go
index 127cb3371..5ae0944c4 100644
--- a/database/secret/count_test.go
+++ b/database/secret/count_test.go
@@ -8,11 +8,13 @@ import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
+
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_CountSecrets(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("bar")
@@ -24,7 +26,7 @@ func TestSecret_Engine_CountSecrets(t *testing.T) {
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("bar")
_secretTwo.SetRepo("foo")
diff --git a/database/secret/create.go b/database/secret/create.go
index 163e72776..c0ac65dc7 100644
--- a/database/secret/create.go
+++ b/database/secret/create.go
@@ -9,13 +9,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CreateSecret creates a new secret in the database.
-func (e *engine) CreateSecret(ctx context.Context, s *library.Secret) (*library.Secret, error) {
+func (e *engine) CreateSecret(ctx context.Context, s *api.Secret) (*api.Secret, error) {
// handle the secret based off the type
switch s.GetType() {
case constants.SecretShared:
@@ -34,22 +34,13 @@ func (e *engine) CreateSecret(ctx context.Context, s *library.Secret) (*library.
}).Tracef("creating secret %s/%s/%s/%s", s.GetType(), s.GetOrg(), s.GetRepo(), s.GetName())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#SecretFromLibrary
- secret := database.SecretFromLibrary(s)
+ secret := types.SecretFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Validate
err := secret.Validate()
if err != nil {
return nil, err
}
- // encrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Encrypt
err = secret.Encrypt(e.config.EncryptionKey)
if err != nil {
switch s.GetType() {
@@ -81,5 +72,5 @@ func (e *engine) CreateSecret(ctx context.Context, s *library.Secret) (*library.
}
}
- return secret.ToLibrary(), nil
+ return secret.ToAPI(), nil
}
diff --git a/database/secret/create_test.go b/database/secret/create_test.go
index ed3d95591..9a96326d1 100644
--- a/database/secret/create_test.go
+++ b/database/secret/create_test.go
@@ -9,13 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestSecret_Engine_CreateSecret(t *testing.T) {
// setup types
- _secretRepo := testSecret()
+ _secretRepo := testutils.APISecret()
_secretRepo.SetID(1)
_secretRepo.SetOrg("foo")
_secretRepo.SetRepo("bar")
@@ -26,9 +26,9 @@ func TestSecret_Engine_CreateSecret(t *testing.T) {
_secretRepo.SetCreatedBy("user")
_secretRepo.SetUpdatedAt(1)
_secretRepo.SetUpdatedBy("user2")
- _secretRepo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretRepo.SetAllowEvents(api.NewEventsFromMask(1))
- _secretOrg := testSecret()
+ _secretOrg := testutils.APISecret()
_secretOrg.SetID(2)
_secretOrg.SetOrg("foo")
_secretOrg.SetRepo("*")
@@ -39,9 +39,9 @@ func TestSecret_Engine_CreateSecret(t *testing.T) {
_secretOrg.SetCreatedBy("user")
_secretOrg.SetUpdatedAt(1)
_secretOrg.SetUpdatedBy("user2")
- _secretOrg.SetAllowEvents(library.NewEventsFromMask(3))
+ _secretOrg.SetAllowEvents(api.NewEventsFromMask(3))
- _secretShared := testSecret()
+ _secretShared := testutils.APISecret()
_secretShared.SetID(3)
_secretShared.SetOrg("foo")
_secretShared.SetTeam("bar")
@@ -52,7 +52,7 @@ func TestSecret_Engine_CreateSecret(t *testing.T) {
_secretShared.SetCreatedBy("user")
_secretShared.SetUpdatedAt(1)
_secretShared.SetUpdatedBy("user2")
- _secretShared.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretShared.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -89,7 +89,7 @@ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15) RETURNING "id"`).
failure bool
name string
database *engine
- secret *library.Secret
+ secret *api.Secret
}{
{
failure: false,
diff --git a/database/secret/delete.go b/database/secret/delete.go
index aa87ba1ea..59c781237 100644
--- a/database/secret/delete.go
+++ b/database/secret/delete.go
@@ -7,13 +7,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// DeleteSecret deletes an existing secret from the database.
-func (e *engine) DeleteSecret(ctx context.Context, s *library.Secret) error {
+func (e *engine) DeleteSecret(ctx context.Context, s *api.Secret) error {
// handle the secret based off the type
//
//nolint:dupl // ignore similar code with update.go
@@ -34,10 +34,7 @@ func (e *engine) DeleteSecret(ctx context.Context, s *library.Secret) error {
}).Tracef("deleting secret %s/%s/%s/%s", s.GetType(), s.GetOrg(), s.GetRepo(), s.GetName())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#SecretFromLibrary
- secret := database.SecretFromLibrary(s)
+ secret := types.SecretFromAPI(s)
// send query to the database
return e.client.
diff --git a/database/secret/delete_test.go b/database/secret/delete_test.go
index 57db11e88..88465b11e 100644
--- a/database/secret/delete_test.go
+++ b/database/secret/delete_test.go
@@ -8,12 +8,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_DeleteSecret(t *testing.T) {
// setup types
- _secretRepo := testSecret()
+ _secretRepo := testutils.APISecret()
_secretRepo.SetID(1)
_secretRepo.SetOrg("foo")
_secretRepo.SetRepo("bar")
@@ -25,7 +26,7 @@ func TestSecret_Engine_DeleteSecret(t *testing.T) {
_secretRepo.SetUpdatedAt(1)
_secretRepo.SetUpdatedBy("user2")
- _secretOrg := testSecret()
+ _secretOrg := testutils.APISecret()
_secretOrg.SetID(2)
_secretOrg.SetOrg("foo")
_secretOrg.SetRepo("*")
@@ -37,7 +38,7 @@ func TestSecret_Engine_DeleteSecret(t *testing.T) {
_secretOrg.SetUpdatedAt(1)
_secretOrg.SetUpdatedBy("user2")
- _secretShared := testSecret()
+ _secretShared := testutils.APISecret()
_secretShared.SetID(3)
_secretShared.SetOrg("foo")
_secretShared.SetTeam("bar")
@@ -90,7 +91,7 @@ func TestSecret_Engine_DeleteSecret(t *testing.T) {
failure bool
name string
database *engine
- secret *library.Secret
+ secret *api.Secret
}{
{
failure: false,
diff --git a/database/secret/get.go b/database/secret/get.go
index 4f4d04199..7b546a035 100644
--- a/database/secret/get.go
+++ b/database/secret/get.go
@@ -5,17 +5,17 @@ package secret
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetSecret gets a secret by ID from the database.
-func (e *engine) GetSecret(ctx context.Context, id int64) (*library.Secret, error) {
+func (e *engine) GetSecret(ctx context.Context, id int64) (*api.Secret, error) {
e.logger.Tracef("getting secret %d", id)
// variable to store query results
- s := new(database.Secret)
+ s := new(types.Secret)
// send query to the database and store result in variable
err := e.client.
@@ -28,9 +28,6 @@ func (e *engine) GetSecret(ctx context.Context, id int64) (*library.Secret, erro
return nil, err
}
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = s.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -39,15 +36,7 @@ func (e *engine) GetSecret(ctx context.Context, id int64) (*library.Secret, erro
// by logging the error instead of returning it
// which allows us to fetch unencrypted secrets
e.logger.Errorf("unable to decrypt secret %d: %v", id, err)
-
- // return the unencrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
}
- // return the decrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/secret/get_org.go b/database/secret/get_org.go
index 473d5a1a6..0c5d50fb9 100644
--- a/database/secret/get_org.go
+++ b/database/secret/get_org.go
@@ -7,13 +7,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetSecretForOrg gets a secret by org name from the database.
-func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*library.Secret, error) {
+func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*api.Secret, error) {
e.logger.WithFields(logrus.Fields{
"org": org,
"secret": name,
@@ -21,7 +21,7 @@ func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*librar
}).Tracef("getting org secret %s/%s", org, name)
// variable to store query results
- s := new(database.Secret)
+ s := new(types.Secret)
// send query to the database and store result in variable
err := e.client.
@@ -37,8 +37,6 @@ func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*librar
}
// decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = s.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -47,15 +45,7 @@ func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*librar
// by logging the error instead of returning it
// which allows us to fetch unencrypted secrets
e.logger.Errorf("unable to decrypt org secret %s/%s: %v", org, name, err)
-
- // return the unencrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
}
- // return the decrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/secret/get_org_test.go b/database/secret/get_org_test.go
index af127fab3..71298a4ab 100644
--- a/database/secret/get_org_test.go
+++ b/database/secret/get_org_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_GetSecretForOrg(t *testing.T) {
// setup types
- _secret := testSecret()
+ _secret := testutils.APISecret()
_secret.SetID(1)
_secret.SetOrg("foo")
_secret.SetRepo("*")
@@ -26,7 +27,7 @@ func TestSecret_Engine_GetSecretForOrg(t *testing.T) {
_secret.SetCreatedBy("user")
_secret.SetUpdatedAt(1)
_secret.SetUpdatedBy("user2")
- _secret.SetAllowEvents(library.NewEventsFromMask(1))
+ _secret.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -53,7 +54,7 @@ func TestSecret_Engine_GetSecretForOrg(t *testing.T) {
failure bool
name string
database *engine
- want *library.Secret
+ want *api.Secret
}{
{
failure: false,
diff --git a/database/secret/get_repo.go b/database/secret/get_repo.go
index 27a5f3cfb..dc83a60fa 100644
--- a/database/secret/get_repo.go
+++ b/database/secret/get_repo.go
@@ -8,13 +8,12 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetSecretForRepo gets a secret by org and repo name from the database.
-func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo) (*library.Secret, error) {
+func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo) (*api.Secret, error) {
e.logger.WithFields(logrus.Fields{
"org": r.GetOrg(),
"repo": r.GetName(),
@@ -23,7 +22,7 @@ func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo)
}).Tracef("getting repo secret %s/%s", r.GetFullName(), name)
// variable to store query results
- s := new(database.Secret)
+ s := new(types.Secret)
// send query to the database and store result in variable
err := e.client.
@@ -39,9 +38,6 @@ func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo)
return nil, err
}
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = s.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -50,15 +46,7 @@ func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo)
// by logging the error instead of returning it
// which allows us to fetch unencrypted secrets
e.logger.Errorf("unable to decrypt repo secret %s/%s: %v", r.GetFullName(), name, err)
-
- // return the unencrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
}
- // return the decrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/secret/get_repo_test.go b/database/secret/get_repo_test.go
index 99ea7610d..f2ab5b8ef 100644
--- a/database/secret/get_repo_test.go
+++ b/database/secret/get_repo_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_GetSecretForRepo(t *testing.T) {
// setup types
- _repo := testRepo()
+ _repo := testutils.APIRepo()
_repo.SetID(1)
_repo.GetOwner().SetID(1)
_repo.SetHash("baz")
@@ -25,7 +26,7 @@ func TestSecret_Engine_GetSecretForRepo(t *testing.T) {
_repo.SetVisibility("public")
_repo.SetPipelineType("yaml")
- _secret := testSecret()
+ _secret := testutils.APISecret()
_secret.SetID(1)
_secret.SetOrg("foo")
_secret.SetRepo("bar")
@@ -36,7 +37,7 @@ func TestSecret_Engine_GetSecretForRepo(t *testing.T) {
_secret.SetCreatedBy("user")
_secret.SetUpdatedAt(1)
_secret.SetUpdatedBy("user2")
- _secret.SetAllowEvents(library.NewEventsFromMask(1))
+ _secret.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -63,7 +64,7 @@ func TestSecret_Engine_GetSecretForRepo(t *testing.T) {
failure bool
name string
database *engine
- want *library.Secret
+ want *api.Secret
}{
{
failure: false,
diff --git a/database/secret/get_team.go b/database/secret/get_team.go
index ee82409c6..5bc795765 100644
--- a/database/secret/get_team.go
+++ b/database/secret/get_team.go
@@ -7,13 +7,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetSecretForTeam gets a secret by org and team name from the database.
-func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (*library.Secret, error) {
+func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (*api.Secret, error) {
e.logger.WithFields(logrus.Fields{
"org": org,
"team": team,
@@ -22,7 +22,7 @@ func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (
}).Tracef("getting shared secret %s/%s/%s", org, team, name)
// variable to store query results
- s := new(database.Secret)
+ s := new(types.Secret)
// send query to the database and store result in variable
err := e.client.
@@ -39,8 +39,6 @@ func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (
}
// decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = s.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -51,13 +49,9 @@ func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (
e.logger.Errorf("unable to decrypt shared secret %s/%s/%s: %v", org, team, name, err)
// return the unencrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
// return the decrypted secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/secret/get_team_test.go b/database/secret/get_team_test.go
index 96e3bf880..757f0ed39 100644
--- a/database/secret/get_team_test.go
+++ b/database/secret/get_team_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_GetSecretForTeam(t *testing.T) {
// setup types
- _secret := testSecret()
+ _secret := testutils.APISecret()
_secret.SetID(1)
_secret.SetOrg("foo")
_secret.SetTeam("bar")
@@ -26,7 +27,7 @@ func TestSecret_Engine_GetSecretForTeam(t *testing.T) {
_secret.SetCreatedBy("user")
_secret.SetUpdatedAt(1)
_secret.SetUpdatedBy("user2")
- _secret.SetAllowEvents(library.NewEventsFromMask(1))
+ _secret.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -53,7 +54,7 @@ func TestSecret_Engine_GetSecretForTeam(t *testing.T) {
failure bool
name string
database *engine
- want *library.Secret
+ want *api.Secret
}{
{
failure: false,
diff --git a/database/secret/get_test.go b/database/secret/get_test.go
index 0d38aa679..fda275129 100644
--- a/database/secret/get_test.go
+++ b/database/secret/get_test.go
@@ -9,12 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_GetSecret(t *testing.T) {
// setup types
- _secret := testSecret()
+ _secret := testutils.APISecret()
_secret.SetID(1)
_secret.SetOrg("foo")
_secret.SetRepo("bar")
@@ -25,7 +26,7 @@ func TestSecret_Engine_GetSecret(t *testing.T) {
_secret.SetCreatedBy("user")
_secret.SetUpdatedAt(1)
_secret.SetUpdatedBy("user2")
- _secret.SetAllowEvents(library.NewEventsFromMask(1))
+ _secret.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -51,7 +52,7 @@ func TestSecret_Engine_GetSecret(t *testing.T) {
failure bool
name string
database *engine
- want *library.Secret
+ want *api.Secret
}{
{
failure: false,
diff --git a/database/secret/interface.go b/database/secret/interface.go
index b5aa4f73e..f38cf6a75 100644
--- a/database/secret/interface.go
+++ b/database/secret/interface.go
@@ -6,7 +6,6 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/library"
)
// SecretInterface represents the Vela interface for secret
@@ -38,27 +37,27 @@ type SecretInterface interface {
// CountSecretsForTeams defines a function that gets the count of secrets by teams within an org.
CountSecretsForTeams(context.Context, string, []string, map[string]interface{}) (int64, error)
// CreateSecret defines a function that creates a new secret.
- CreateSecret(context.Context, *library.Secret) (*library.Secret, error)
+ CreateSecret(context.Context, *api.Secret) (*api.Secret, error)
// DeleteSecret defines a function that deletes an existing secret.
- DeleteSecret(context.Context, *library.Secret) error
+ DeleteSecret(context.Context, *api.Secret) error
// GetSecret defines a function that gets a secret by ID.
- GetSecret(context.Context, int64) (*library.Secret, error)
+ GetSecret(context.Context, int64) (*api.Secret, error)
// GetSecretForOrg defines a function that gets a secret by org name.
- GetSecretForOrg(context.Context, string, string) (*library.Secret, error)
+ GetSecretForOrg(context.Context, string, string) (*api.Secret, error)
// GetSecretForRepo defines a function that gets a secret by org and repo name.
- GetSecretForRepo(context.Context, string, *api.Repo) (*library.Secret, error)
+ GetSecretForRepo(context.Context, string, *api.Repo) (*api.Secret, error)
// GetSecretForTeam defines a function that gets a secret by org and team name.
- GetSecretForTeam(context.Context, string, string, string) (*library.Secret, error)
+ GetSecretForTeam(context.Context, string, string, string) (*api.Secret, error)
// ListSecrets defines a function that gets a list of all secrets.
- ListSecrets(context.Context) ([]*library.Secret, error)
+ ListSecrets(context.Context) ([]*api.Secret, error)
// ListSecretsForOrg defines a function that gets a list of secrets by org name.
- ListSecretsForOrg(context.Context, string, map[string]interface{}, int, int) ([]*library.Secret, int64, error)
+ ListSecretsForOrg(context.Context, string, map[string]interface{}, int, int) ([]*api.Secret, int64, error)
// ListSecretsForRepo defines a function that gets a list of secrets by org and repo name.
- ListSecretsForRepo(context.Context, *api.Repo, map[string]interface{}, int, int) ([]*library.Secret, int64, error)
+ ListSecretsForRepo(context.Context, *api.Repo, map[string]interface{}, int, int) ([]*api.Secret, int64, error)
// ListSecretsForTeam defines a function that gets a list of secrets by org and team name.
- ListSecretsForTeam(context.Context, string, string, map[string]interface{}, int, int) ([]*library.Secret, int64, error)
+ ListSecretsForTeam(context.Context, string, string, map[string]interface{}, int, int) ([]*api.Secret, int64, error)
// ListSecretsForTeams defines a function that gets a list of secrets by teams within an org.
- ListSecretsForTeams(context.Context, string, []string, map[string]interface{}, int, int) ([]*library.Secret, int64, error)
+ ListSecretsForTeams(context.Context, string, []string, map[string]interface{}, int, int) ([]*api.Secret, int64, error)
// UpdateSecret defines a function that updates an existing secret.
- UpdateSecret(context.Context, *library.Secret) (*library.Secret, error)
+ UpdateSecret(context.Context, *api.Secret) (*api.Secret, error)
}
diff --git a/database/secret/list.go b/database/secret/list.go
index fe2031f89..0f11b750f 100644
--- a/database/secret/list.go
+++ b/database/secret/list.go
@@ -5,19 +5,19 @@ package secret
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListSecrets gets a list of all secrets from the database.
-func (e *engine) ListSecrets(ctx context.Context) ([]*library.Secret, error) {
+func (e *engine) ListSecrets(ctx context.Context) ([]*api.Secret, error) {
e.logger.Trace("listing all secrets")
// variables to store query results and return value
count := int64(0)
- s := new([]database.Secret)
- secrets := []*library.Secret{}
+ s := new([]types.Secret)
+ secrets := []*api.Secret{}
// count the results
count, err := e.CountSecrets(ctx)
@@ -45,9 +45,6 @@ func (e *engine) ListSecrets(ctx context.Context) ([]*library.Secret, error) {
// https://golang.org/doc/faq#closures_and_goroutines
tmp := secret
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = tmp.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -58,10 +55,7 @@ func (e *engine) ListSecrets(ctx context.Context) ([]*library.Secret, error) {
e.logger.Errorf("unable to decrypt secret %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- secrets = append(secrets, tmp.ToLibrary())
+ secrets = append(secrets, tmp.ToAPI())
}
return secrets, nil
diff --git a/database/secret/list_org.go b/database/secret/list_org.go
index c75fa8f8d..a32ddda34 100644
--- a/database/secret/list_org.go
+++ b/database/secret/list_org.go
@@ -7,15 +7,15 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListSecretsForOrg gets a list of secrets by org name from the database.
//
//nolint:lll // ignore long line length due to variable names
-func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[string]interface{}, page, perPage int) ([]*library.Secret, int64, error) {
+func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[string]interface{}, page, perPage int) ([]*api.Secret, int64, error) {
e.logger.WithFields(logrus.Fields{
"org": org,
"type": constants.SecretOrg,
@@ -23,8 +23,8 @@ func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[
// variables to store query results and return values
count := int64(0)
- s := new([]database.Secret)
- secrets := []*library.Secret{}
+ s := new([]types.Secret)
+ secrets := []*api.Secret{}
// count the results
count, err := e.CountSecretsForOrg(ctx, org, filters)
@@ -61,9 +61,6 @@ func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[
// https://golang.org/doc/faq#closures_and_goroutines
tmp := secret
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = tmp.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -74,10 +71,7 @@ func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[
e.logger.Errorf("unable to decrypt secret %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- secrets = append(secrets, tmp.ToLibrary())
+ secrets = append(secrets, tmp.ToAPI())
}
return secrets, count, nil
diff --git a/database/secret/list_org_test.go b/database/secret/list_org_test.go
index f3a95f0cd..f5a274679 100644
--- a/database/secret/list_org_test.go
+++ b/database/secret/list_org_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_ListSecretsForOrg(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("*")
@@ -26,9 +27,9 @@ func TestSecret_Engine_ListSecretsForOrg(t *testing.T) {
_secretOne.SetCreatedBy("user")
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretOne.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOne.SetAllowEvents(api.NewEventsFromMask(1))
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("foo")
_secretTwo.SetRepo("*")
@@ -39,7 +40,7 @@ func TestSecret_Engine_ListSecretsForOrg(t *testing.T) {
_secretTwo.SetCreatedBy("user")
_secretTwo.SetUpdatedAt(1)
_secretTwo.SetUpdatedBy("user2")
- _secretTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretTwo.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -79,19 +80,19 @@ func TestSecret_Engine_ListSecretsForOrg(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Secret
+ want []*api.Secret
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
{
failure: false,
name: "sqlite",
database: _sqlite,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
}
diff --git a/database/secret/list_repo.go b/database/secret/list_repo.go
index 593139869..59520ea12 100644
--- a/database/secret/list_repo.go
+++ b/database/secret/list_repo.go
@@ -8,15 +8,14 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListSecretsForRepo gets a list of secrets by org name from the database.
//
//nolint:lll // ignore long line length due to variable names
-func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters map[string]interface{}, page, perPage int) ([]*library.Secret, int64, error) {
+func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters map[string]interface{}, page, perPage int) ([]*api.Secret, int64, error) {
e.logger.WithFields(logrus.Fields{
"org": r.GetOrg(),
"repo": r.GetName(),
@@ -25,8 +24,8 @@ func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters ma
// variables to store query results and return values
count := int64(0)
- s := new([]database.Secret)
- secrets := []*library.Secret{}
+ s := new([]types.Secret)
+ secrets := []*api.Secret{}
// count the results
count, err := e.CountSecretsForRepo(ctx, r, filters)
@@ -64,9 +63,6 @@ func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters ma
// https://golang.org/doc/faq#closures_and_goroutines
tmp := secret
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = tmp.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -77,10 +73,7 @@ func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters ma
e.logger.Errorf("unable to decrypt secret %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- secrets = append(secrets, tmp.ToLibrary())
+ secrets = append(secrets, tmp.ToAPI())
}
return secrets, count, nil
diff --git a/database/secret/list_repo_test.go b/database/secret/list_repo_test.go
index 1b70c1bda..685cc52bb 100644
--- a/database/secret/list_repo_test.go
+++ b/database/secret/list_repo_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_ListSecretsForRepo(t *testing.T) {
// setup types
- _repo := testRepo()
+ _repo := testutils.APIRepo()
_repo.SetID(1)
_repo.GetOwner().SetID(1)
_repo.SetHash("baz")
@@ -25,7 +26,7 @@ func TestSecret_Engine_ListSecretsForRepo(t *testing.T) {
_repo.SetVisibility("public")
_repo.SetPipelineType("yaml")
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("bar")
@@ -36,9 +37,9 @@ func TestSecret_Engine_ListSecretsForRepo(t *testing.T) {
_secretOne.SetCreatedBy("user")
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretOne.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOne.SetAllowEvents(api.NewEventsFromMask(1))
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("foo")
_secretTwo.SetRepo("bar")
@@ -49,7 +50,7 @@ func TestSecret_Engine_ListSecretsForRepo(t *testing.T) {
_secretTwo.SetCreatedBy("user")
_secretTwo.SetUpdatedAt(1)
_secretTwo.SetUpdatedBy("user2")
- _secretTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretTwo.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -89,19 +90,19 @@ func TestSecret_Engine_ListSecretsForRepo(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Secret
+ want []*api.Secret
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
{
failure: false,
name: "sqlite",
database: _sqlite,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
}
diff --git a/database/secret/list_team.go b/database/secret/list_team.go
index 2e2a5773c..ae56a3da4 100644
--- a/database/secret/list_team.go
+++ b/database/secret/list_team.go
@@ -8,15 +8,15 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListSecretsForTeam gets a list of secrets by org and team name from the database.
//
//nolint:lll // ignore long line length due to variable names
-func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filters map[string]interface{}, page, perPage int) ([]*library.Secret, int64, error) {
+func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filters map[string]interface{}, page, perPage int) ([]*api.Secret, int64, error) {
e.logger.WithFields(logrus.Fields{
"org": org,
"team": team,
@@ -25,8 +25,8 @@ func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filte
// variables to store query results and return values
count := int64(0)
- s := new([]database.Secret)
- secrets := []*library.Secret{}
+ s := new([]types.Secret)
+ secrets := []*api.Secret{}
// count the results
count, err := e.CountSecretsForTeam(ctx, org, team, filters)
@@ -64,9 +64,6 @@ func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filte
// https://golang.org/doc/faq#closures_and_goroutines
tmp := secret
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = tmp.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -77,17 +74,14 @@ func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filte
e.logger.Errorf("unable to decrypt secret %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- secrets = append(secrets, tmp.ToLibrary())
+ secrets = append(secrets, tmp.ToAPI())
}
return secrets, count, nil
}
// ListSecretsForTeams gets a list of secrets by teams within an org from the database.
-func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []string, filters map[string]interface{}, page, perPage int) ([]*library.Secret, int64, error) {
+func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []string, filters map[string]interface{}, page, perPage int) ([]*api.Secret, int64, error) {
// iterate through the list of teams provided
for index, team := range teams {
// ensure the team name is lower case
@@ -102,8 +96,8 @@ func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []st
// variables to store query results and return values
count := int64(0)
- s := new([]database.Secret)
- secrets := []*library.Secret{}
+ s := new([]types.Secret)
+ secrets := []*api.Secret{}
// count the results
count, err := e.CountSecretsForTeams(ctx, org, teams, filters)
@@ -141,9 +135,6 @@ func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []st
// https://golang.org/doc/faq#closures_and_goroutines
tmp := secret
- // decrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Decrypt
err = tmp.Decrypt(e.config.EncryptionKey)
if err != nil {
// TODO: remove backwards compatibility before 1.x.x release
@@ -154,10 +145,7 @@ func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []st
e.logger.Errorf("unable to decrypt secret %d: %v", tmp.ID.Int64, err)
}
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.ToLibrary
- secrets = append(secrets, tmp.ToLibrary())
+ secrets = append(secrets, tmp.ToAPI())
}
return secrets, count, nil
diff --git a/database/secret/list_team_test.go b/database/secret/list_team_test.go
index 81708949a..382f6864c 100644
--- a/database/secret/list_team_test.go
+++ b/database/secret/list_team_test.go
@@ -9,13 +9,14 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_ListSecretsForTeam(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetTeam("bar")
@@ -26,9 +27,9 @@ func TestSecret_Engine_ListSecretsForTeam(t *testing.T) {
_secretOne.SetCreatedBy("user")
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretOne.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOne.SetAllowEvents(api.NewEventsFromMask(1))
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("foo")
_secretTwo.SetTeam("bar")
@@ -39,7 +40,7 @@ func TestSecret_Engine_ListSecretsForTeam(t *testing.T) {
_secretTwo.SetCreatedBy("user")
_secretTwo.SetUpdatedAt(1)
_secretTwo.SetUpdatedBy("user2")
- _secretTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretTwo.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -79,19 +80,19 @@ func TestSecret_Engine_ListSecretsForTeam(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Secret
+ want []*api.Secret
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
{
failure: false,
name: "sqlite",
database: _sqlite,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
}
@@ -123,7 +124,7 @@ func TestSecret_Engine_ListSecretsForTeam(t *testing.T) {
func TestSecret_Engine_ListSecretsForTeams(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetTeam("bar")
@@ -134,9 +135,9 @@ func TestSecret_Engine_ListSecretsForTeams(t *testing.T) {
_secretOne.SetCreatedBy("user")
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretOne.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOne.SetAllowEvents(api.NewEventsFromMask(1))
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("foo")
_secretTwo.SetTeam("bar")
@@ -147,7 +148,7 @@ func TestSecret_Engine_ListSecretsForTeams(t *testing.T) {
_secretTwo.SetCreatedBy("user")
_secretTwo.SetUpdatedAt(1)
_secretTwo.SetUpdatedBy("user2")
- _secretTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretTwo.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -187,19 +188,19 @@ func TestSecret_Engine_ListSecretsForTeams(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Secret
+ want []*api.Secret
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
{
failure: false,
name: "sqlite",
database: _sqlite,
- want: []*library.Secret{_secretTwo, _secretOne},
+ want: []*api.Secret{_secretTwo, _secretOne},
},
}
diff --git a/database/secret/list_test.go b/database/secret/list_test.go
index aa72d5baf..b744c434a 100644
--- a/database/secret/list_test.go
+++ b/database/secret/list_test.go
@@ -9,12 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/database/testutils"
)
func TestSecret_Engine_ListSecrets(t *testing.T) {
// setup types
- _secretOne := testSecret()
+ _secretOne := testutils.APISecret()
_secretOne.SetID(1)
_secretOne.SetOrg("foo")
_secretOne.SetRepo("bar")
@@ -25,9 +26,9 @@ func TestSecret_Engine_ListSecrets(t *testing.T) {
_secretOne.SetCreatedBy("user")
_secretOne.SetUpdatedAt(1)
_secretOne.SetUpdatedBy("user2")
- _secretOne.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOne.SetAllowEvents(api.NewEventsFromMask(1))
- _secretTwo := testSecret()
+ _secretTwo := testutils.APISecret()
_secretTwo.SetID(2)
_secretTwo.SetOrg("foo")
_secretTwo.SetRepo("bar")
@@ -38,7 +39,7 @@ func TestSecret_Engine_ListSecrets(t *testing.T) {
_secretTwo.SetCreatedBy("user")
_secretTwo.SetUpdatedAt(1)
_secretTwo.SetUpdatedBy("user2")
- _secretTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretTwo.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -76,19 +77,19 @@ func TestSecret_Engine_ListSecrets(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Secret
+ want []*api.Secret
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Secret{_secretOne, _secretTwo},
+ want: []*api.Secret{_secretOne, _secretTwo},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Secret{_secretOne, _secretTwo},
+ want: []*api.Secret{_secretOne, _secretTwo},
},
}
diff --git a/database/secret/secret.go b/database/secret/secret.go
index 4a7c772e8..b0119503f 100644
--- a/database/secret/secret.go
+++ b/database/secret/secret.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/secret/secret_test.go b/database/secret/secret_test.go
index 41bb4dd3a..968c48c7a 100644
--- a/database/secret/secret_test.go
+++ b/database/secret/secret_test.go
@@ -11,10 +11,6 @@ import (
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
-
- api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/library"
- "github.com/go-vela/types/library/actions"
)
func TestSecret_New(t *testing.T) {
@@ -174,78 +170,3 @@ func testSqlite(t *testing.T) *engine {
return _engine
}
-
-// testRepo is a test helper function to create a library
-// Repo type with all fields set to their zero values.
-func testRepo() *api.Repo {
- return &api.Repo{
- ID: new(int64),
- BuildLimit: new(int64),
- Timeout: new(int64),
- Counter: new(int),
- PipelineType: new(string),
- Hash: new(string),
- Org: new(string),
- Name: new(string),
- FullName: new(string),
- Link: new(string),
- Clone: new(string),
- Branch: new(string),
- Visibility: new(string),
- PreviousName: new(string),
- Private: new(bool),
- Trusted: new(bool),
- Active: new(bool),
- }
-}
-
-// testSecret is a test helper function to create a library
-// Secret type with all fields set to their zero values.
-func testSecret() *library.Secret {
- return &library.Secret{
- ID: new(int64),
- Org: new(string),
- Repo: new(string),
- Team: new(string),
- Name: new(string),
- Value: new(string),
- Type: new(string),
- Images: new([]string),
- AllowEvents: testEvents(),
- AllowCommand: new(bool),
- AllowSubstitution: new(bool),
- CreatedAt: new(int64),
- CreatedBy: new(string),
- UpdatedAt: new(int64),
- UpdatedBy: new(string),
- }
-}
-
-func testEvents() *library.Events {
- return &library.Events{
- Push: &actions.Push{
- Branch: new(bool),
- Tag: new(bool),
- DeleteBranch: new(bool),
- DeleteTag: new(bool),
- },
- PullRequest: &actions.Pull{
- Opened: new(bool),
- Edited: new(bool),
- Synchronize: new(bool),
- Reopened: new(bool),
- Labeled: new(bool),
- Unlabeled: new(bool),
- },
- Deployment: &actions.Deploy{
- Created: new(bool),
- },
- Comment: &actions.Comment{
- Created: new(bool),
- Edited: new(bool),
- },
- Schedule: &actions.Schedule{
- Run: new(bool),
- },
- }
-}
diff --git a/database/secret/table.go b/database/secret/table.go
index 650a3f3f4..f521459a2 100644
--- a/database/secret/table.go
+++ b/database/secret/table.go
@@ -5,7 +5,7 @@ package secret
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/secret/update.go b/database/secret/update.go
index c046d18ed..d512e7e33 100644
--- a/database/secret/update.go
+++ b/database/secret/update.go
@@ -9,13 +9,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// UpdateSecret updates an existing secret in the database.
-func (e *engine) UpdateSecret(ctx context.Context, s *library.Secret) (*library.Secret, error) {
+func (e *engine) UpdateSecret(ctx context.Context, s *api.Secret) (*api.Secret, error) {
// handle the secret based off the type
switch s.GetType() {
case constants.SecretShared:
@@ -34,22 +34,13 @@ func (e *engine) UpdateSecret(ctx context.Context, s *library.Secret) (*library.
}).Tracef("updating secret %s/%s/%s/%s", s.GetType(), s.GetOrg(), s.GetRepo(), s.GetName())
}
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#SecretFromLibrary
- secret := database.SecretFromLibrary(s)
+ secret := types.SecretFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Validate
err := secret.Validate()
if err != nil {
return nil, err
}
- // encrypt the fields for the secret
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Secret.Encrypt
err = secret.Encrypt(e.config.EncryptionKey)
if err != nil {
switch s.GetType() {
@@ -78,5 +69,5 @@ func (e *engine) UpdateSecret(ctx context.Context, s *library.Secret) (*library.
}
}
- return secret.ToLibrary(), nil
+ return secret.ToAPI(), nil
}
diff --git a/database/secret/update_test.go b/database/secret/update_test.go
index e53d43b4e..22a2c4dba 100644
--- a/database/secret/update_test.go
+++ b/database/secret/update_test.go
@@ -9,13 +9,13 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestSecret_Engine_UpdateSecret(t *testing.T) {
// setup types
- _secretRepo := testSecret()
+ _secretRepo := testutils.APISecret()
_secretRepo.SetID(1)
_secretRepo.SetOrg("foo")
_secretRepo.SetRepo("bar")
@@ -26,9 +26,9 @@ func TestSecret_Engine_UpdateSecret(t *testing.T) {
_secretRepo.SetCreatedBy("user")
_secretRepo.SetUpdatedAt(1)
_secretRepo.SetUpdatedBy("user2")
- _secretRepo.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretRepo.SetAllowEvents(api.NewEventsFromMask(1))
- _secretOrg := testSecret()
+ _secretOrg := testutils.APISecret()
_secretOrg.SetID(2)
_secretOrg.SetOrg("foo")
_secretOrg.SetRepo("*")
@@ -39,9 +39,9 @@ func TestSecret_Engine_UpdateSecret(t *testing.T) {
_secretOrg.SetCreatedBy("user")
_secretOrg.SetUpdatedAt(1)
_secretOrg.SetUpdatedBy("user2")
- _secretOrg.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretOrg.SetAllowEvents(api.NewEventsFromMask(1))
- _secretShared := testSecret()
+ _secretShared := testutils.APISecret()
_secretShared.SetID(3)
_secretShared.SetOrg("foo")
_secretShared.SetTeam("bar")
@@ -52,7 +52,7 @@ func TestSecret_Engine_UpdateSecret(t *testing.T) {
_secretShared.SetCreatedBy("user")
_secretShared.SetUpdatedAt(1)
_secretShared.SetUpdatedBy("user2")
- _secretShared.SetAllowEvents(library.NewEventsFromMask(1))
+ _secretShared.SetAllowEvents(api.NewEventsFromMask(1))
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
@@ -101,7 +101,7 @@ WHERE "id" = $15`).
failure bool
name string
database *engine
- secret *library.Secret
+ secret *api.Secret
}{
{
failure: false,
diff --git a/database/service/clean.go b/database/service/clean.go
index d234b4478..ac3bce1be 100644
--- a/database/service/clean.go
+++ b/database/service/clean.go
@@ -8,21 +8,21 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CleanServices updates services to an error with a created timestamp prior to a defined moment.
func (e *engine) CleanServices(ctx context.Context, msg string, before int64) (int64, error) {
logrus.Tracef("cleaning pending or running steps in the database created prior to %d", before)
- s := new(library.Service)
+ s := new(api.Service)
s.SetStatus(constants.StatusError)
s.SetError(msg)
s.SetFinished(time.Now().UTC().Unix())
- service := database.ServiceFromLibrary(s)
+ service := types.ServiceFromAPI(s)
// send query to the database
result := e.client.
diff --git a/database/service/count.go b/database/service/count.go
index 86e76cfe2..dabefecc2 100644
--- a/database/service/count.go
+++ b/database/service/count.go
@@ -5,7 +5,7 @@ package service
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountServices gets the count of all services from the database.
diff --git a/database/service/count_build.go b/database/service/count_build.go
index 0f00403e2..0bf016e6e 100644
--- a/database/service/count_build.go
+++ b/database/service/count_build.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountServicesForBuild gets the count of services by build ID from the database.
diff --git a/database/service/create.go b/database/service/create.go
index 3ecb96e04..dfe32683b 100644
--- a/database/service/create.go
+++ b/database/service/create.go
@@ -7,25 +7,19 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CreateService creates a new service in the database.
-func (e *engine) CreateService(ctx context.Context, s *library.Service) (*library.Service, error) {
+func (e *engine) CreateService(ctx context.Context, s *api.Service) (*api.Service, error) {
e.logger.WithFields(logrus.Fields{
"service": s.GetNumber(),
}).Tracef("creating service %s in the database", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary
- service := database.ServiceFromLibrary(s)
+ service := types.ServiceFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.Validate
err := service.Validate()
if err != nil {
return nil, err
@@ -37,5 +31,5 @@ func (e *engine) CreateService(ctx context.Context, s *library.Service) (*librar
Table(constants.TableService).
Create(service)
- return service.ToLibrary(), result.Error
+ return service.ToAPI(), result.Error
}
diff --git a/database/service/delete.go b/database/service/delete.go
index 835a25992..3fd77c9c7 100644
--- a/database/service/delete.go
+++ b/database/service/delete.go
@@ -7,21 +7,18 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// DeleteService deletes an existing service from the database.
-func (e *engine) DeleteService(ctx context.Context, s *library.Service) error {
+func (e *engine) DeleteService(ctx context.Context, s *api.Service) error {
e.logger.WithFields(logrus.Fields{
"service": s.GetNumber(),
}).Tracef("deleting service %s", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary
- service := database.ServiceFromLibrary(s)
+ service := types.ServiceFromAPI(s)
// send query to the database
return e.client.
diff --git a/database/service/get.go b/database/service/get.go
index 37cf9a5d0..fc5697405 100644
--- a/database/service/get.go
+++ b/database/service/get.go
@@ -5,17 +5,17 @@ package service
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetService gets a service by ID from the database.
-func (e *engine) GetService(ctx context.Context, id int64) (*library.Service, error) {
+func (e *engine) GetService(ctx context.Context, id int64) (*api.Service, error) {
e.logger.Tracef("getting service %d", id)
// variable to store query results
- s := new(database.Service)
+ s := new(types.Service)
// send query to the database and store result in variable
err := e.client.
@@ -28,8 +28,5 @@ func (e *engine) GetService(ctx context.Context, id int64) (*library.Service, er
return nil, err
}
- // return the service
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/service/get_build.go b/database/service/get_build.go
index e85ddc368..b6a77915d 100644
--- a/database/service/get_build.go
+++ b/database/service/get_build.go
@@ -8,20 +8,19 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetServiceForBuild gets a service by number and build ID from the database.
-func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number int) (*library.Service, error) {
+func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number int) (*api.Service, error) {
e.logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
"service": number,
}).Tracef("getting service %d", number)
// variable to store query results
- s := new(database.Service)
+ s := new(types.Service)
// send query to the database and store result in variable
err := e.client.
@@ -35,8 +34,5 @@ func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number in
return nil, err
}
- // return the service
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/service/get_build_test.go b/database/service/get_build_test.go
index da26e4ce9..8afa50390 100644
--- a/database/service/get_build_test.go
+++ b/database/service/get_build_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestService_Engine_GetServiceForBuild(t *testing.T) {
@@ -52,7 +52,7 @@ func TestService_Engine_GetServiceForBuild(t *testing.T) {
failure bool
name string
database *engine
- want *library.Service
+ want *api.Service
}{
{
failure: false,
diff --git a/database/service/get_test.go b/database/service/get_test.go
index 612811eed..a07d26c43 100644
--- a/database/service/get_test.go
+++ b/database/service/get_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestService_Engine_GetService(t *testing.T) {
@@ -47,7 +47,7 @@ func TestService_Engine_GetService(t *testing.T) {
failure bool
name string
database *engine
- want *library.Service
+ want *api.Service
}{
{
failure: false,
diff --git a/database/service/interface.go b/database/service/interface.go
index 40fc30293..161103d26 100644
--- a/database/service/interface.go
+++ b/database/service/interface.go
@@ -6,7 +6,6 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/library"
)
// ServiceInterface represents the Vela interface for service
@@ -32,21 +31,21 @@ type ServiceInterface interface {
// CountServicesForBuild defines a function that gets the count of services by build ID.
CountServicesForBuild(context.Context, *api.Build, map[string]interface{}) (int64, error)
// CreateService defines a function that creates a new service.
- CreateService(context.Context, *library.Service) (*library.Service, error)
+ CreateService(context.Context, *api.Service) (*api.Service, error)
// DeleteService defines a function that deletes an existing service.
- DeleteService(context.Context, *library.Service) error
+ DeleteService(context.Context, *api.Service) error
// GetService defines a function that gets a service by ID.
- GetService(context.Context, int64) (*library.Service, error)
+ GetService(context.Context, int64) (*api.Service, error)
// GetServiceForBuild defines a function that gets a service by number and build ID.
- GetServiceForBuild(context.Context, *api.Build, int) (*library.Service, error)
+ GetServiceForBuild(context.Context, *api.Build, int) (*api.Service, error)
// ListServices defines a function that gets a list of all services.
- ListServices(context.Context) ([]*library.Service, error)
+ ListServices(context.Context) ([]*api.Service, error)
// ListServicesForBuild defines a function that gets a list of services by build ID.
- ListServicesForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*library.Service, int64, error)
+ ListServicesForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*api.Service, int64, error)
// ListServiceImageCount defines a function that gets a list of all service images and the count of their occurrence.
ListServiceImageCount(context.Context) (map[string]float64, error)
// ListServiceStatusCount defines a function that gets a list of all service statuses and the count of their occurrence.
ListServiceStatusCount(context.Context) (map[string]float64, error)
// UpdateService defines a function that updates an existing service.
- UpdateService(context.Context, *library.Service) (*library.Service, error)
+ UpdateService(context.Context, *api.Service) (*api.Service, error)
}
diff --git a/database/service/list.go b/database/service/list.go
index 6dd70fdd1..6f09c6dcd 100644
--- a/database/service/list.go
+++ b/database/service/list.go
@@ -5,19 +5,19 @@ package service
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListServices gets a list of all services from the database.
-func (e *engine) ListServices(ctx context.Context) ([]*library.Service, error) {
+func (e *engine) ListServices(ctx context.Context) ([]*api.Service, error) {
e.logger.Trace("listing all services")
// variables to store query results and return value
count := int64(0)
- w := new([]database.Service)
- services := []*library.Service{}
+ w := new([]types.Service)
+ services := []*api.Service{}
// count the results
count, err := e.CountServices(ctx)
@@ -45,10 +45,7 @@ func (e *engine) ListServices(ctx context.Context) ([]*library.Service, error) {
// https://golang.org/doc/faq#closures_and_goroutines
tmp := service
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary
- services = append(services, tmp.ToLibrary())
+ services = append(services, tmp.ToAPI())
}
return services, nil
diff --git a/database/service/list_build.go b/database/service/list_build.go
index faf8c81fb..7aa897aa4 100644
--- a/database/service/list_build.go
+++ b/database/service/list_build.go
@@ -8,21 +8,20 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListServicesForBuild gets a list of all services from the database.
-func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*library.Service, int64, error) {
+func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*api.Service, int64, error) {
e.logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
}).Tracef("listing services for build %d", b.GetNumber())
// variables to store query results and return value
count := int64(0)
- s := new([]database.Service)
- services := []*library.Service{}
+ s := new([]types.Service)
+ services := []*api.Service{}
// count the results
count, err := e.CountServicesForBuild(ctx, b, filters)
@@ -58,10 +57,7 @@ func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters
// https://golang.org/doc/faq#closures_and_goroutines
tmp := service
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary
- services = append(services, tmp.ToLibrary())
+ services = append(services, tmp.ToAPI())
}
return services, count, nil
diff --git a/database/service/list_build_test.go b/database/service/list_build_test.go
index cd09061ee..cf00dbc54 100644
--- a/database/service/list_build_test.go
+++ b/database/service/list_build_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestService_Engine_ListServicesForBuild(t *testing.T) {
@@ -72,19 +72,19 @@ func TestService_Engine_ListServicesForBuild(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Service
+ want []*api.Service
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Service{_serviceTwo, _serviceOne},
+ want: []*api.Service{_serviceTwo, _serviceOne},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Service{_serviceTwo, _serviceOne},
+ want: []*api.Service{_serviceTwo, _serviceOne},
},
}
diff --git a/database/service/list_image.go b/database/service/list_image.go
index dbff3913c..cc17ec885 100644
--- a/database/service/list_image.go
+++ b/database/service/list_image.go
@@ -6,7 +6,7 @@ import (
"context"
"database/sql"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ListServiceImageCount gets a list of all service images and the count of their occurrence from the database.
diff --git a/database/service/list_status.go b/database/service/list_status.go
index b2570b55d..9593daa10 100644
--- a/database/service/list_status.go
+++ b/database/service/list_status.go
@@ -6,7 +6,7 @@ import (
"context"
"database/sql"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ListServiceStatusCount gets a list of all service statuses and the count of their occurrence from the database.
diff --git a/database/service/list_test.go b/database/service/list_test.go
index 462dae56c..7b6afa58e 100644
--- a/database/service/list_test.go
+++ b/database/service/list_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestService_Engine_ListServices(t *testing.T) {
@@ -67,19 +67,19 @@ func TestService_Engine_ListServices(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Service
+ want []*api.Service
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Service{_serviceOne, _serviceTwo},
+ want: []*api.Service{_serviceOne, _serviceTwo},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Service{_serviceOne, _serviceTwo},
+ want: []*api.Service{_serviceOne, _serviceTwo},
},
}
diff --git a/database/service/service.go b/database/service/service.go
index f02f6ae6b..a35b47bd3 100644
--- a/database/service/service.go
+++ b/database/service/service.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/service/table.go b/database/service/table.go
index 426eb2333..04b9e977a 100644
--- a/database/service/table.go
+++ b/database/service/table.go
@@ -5,7 +5,7 @@ package service
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/service/update.go b/database/service/update.go
index a53b9ae41..a3e4a38e8 100644
--- a/database/service/update.go
+++ b/database/service/update.go
@@ -7,25 +7,19 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// UpdateService updates an existing service in the database.
-func (e *engine) UpdateService(ctx context.Context, s *library.Service) (*library.Service, error) {
+func (e *engine) UpdateService(ctx context.Context, s *api.Service) (*api.Service, error) {
e.logger.WithFields(logrus.Fields{
"service": s.GetNumber(),
}).Tracef("updating service %s", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary
- service := database.ServiceFromLibrary(s)
+ service := types.ServiceFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Service.Validate
err := service.Validate()
if err != nil {
return nil, err
@@ -37,5 +31,5 @@ func (e *engine) UpdateService(ctx context.Context, s *library.Service) (*librar
Table(constants.TableService).
Save(service)
- return service.ToLibrary(), result.Error
+ return service.ToAPI(), result.Error
}
diff --git a/database/settings/table.go b/database/settings/table.go
index 3eba03cfe..3c1836a55 100644
--- a/database/settings/table.go
+++ b/database/settings/table.go
@@ -5,7 +5,7 @@ package settings
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/step/clean.go b/database/step/clean.go
index b7d8cb8f6..5ce04a1ed 100644
--- a/database/step/clean.go
+++ b/database/step/clean.go
@@ -8,21 +8,21 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CleanSteps updates steps to an error with a created timestamp prior to a defined moment.
func (e *engine) CleanSteps(ctx context.Context, msg string, before int64) (int64, error) {
logrus.Tracef("cleaning pending or running steps in the database created prior to %d", before)
- s := new(library.Step)
+ s := new(api.Step)
s.SetStatus(constants.StatusError)
s.SetError(msg)
s.SetFinished(time.Now().UTC().Unix())
- step := database.StepFromLibrary(s)
+ step := types.StepFromAPI(s)
// send query to the database
result := e.client.
diff --git a/database/step/count.go b/database/step/count.go
index bb9f0ce3a..0264283dc 100644
--- a/database/step/count.go
+++ b/database/step/count.go
@@ -5,7 +5,7 @@ package step
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountSteps gets the count of all steps from the database.
diff --git a/database/step/count_build.go b/database/step/count_build.go
index 4a0cefda5..cce1d20a7 100644
--- a/database/step/count_build.go
+++ b/database/step/count_build.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountStepsForBuild gets the count of steps by build ID from the database.
diff --git a/database/step/create.go b/database/step/create.go
index 9e46cf146..bb8b17396 100644
--- a/database/step/create.go
+++ b/database/step/create.go
@@ -7,25 +7,19 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// CreateStep creates a new step in the database.
-func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step, error) {
+func (e *engine) CreateStep(ctx context.Context, s *api.Step) (*api.Step, error) {
e.logger.WithFields(logrus.Fields{
"step": s.GetNumber(),
}).Tracef("creating step %s in the database", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary
- step := database.StepFromLibrary(s)
+ step := types.StepFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.Validate
err := step.Validate()
if err != nil {
return nil, err
@@ -37,5 +31,5 @@ func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step
Table(constants.TableStep).
Create(step)
- return step.ToLibrary(), result.Error
+ return step.ToAPI(), result.Error
}
diff --git a/database/step/delete.go b/database/step/delete.go
index 7c9139f6b..73398afc6 100644
--- a/database/step/delete.go
+++ b/database/step/delete.go
@@ -7,21 +7,19 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// DeleteStep deletes an existing step from the database.
-func (e *engine) DeleteStep(ctx context.Context, s *library.Step) error {
+func (e *engine) DeleteStep(ctx context.Context, s *api.Step) error {
e.logger.WithFields(logrus.Fields{
"step": s.GetNumber(),
}).Tracef("deleting step %s", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary
- step := database.StepFromLibrary(s)
+ // cast the API type to database type
+ step := types.StepFromAPI(s)
// send query to the database
return e.client.
diff --git a/database/step/get.go b/database/step/get.go
index a05a56fce..51a5778f7 100644
--- a/database/step/get.go
+++ b/database/step/get.go
@@ -5,17 +5,17 @@ package step
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetStep gets a step by ID from the database.
-func (e *engine) GetStep(ctx context.Context, id int64) (*library.Step, error) {
+func (e *engine) GetStep(ctx context.Context, id int64) (*api.Step, error) {
e.logger.Tracef("getting step %d", id)
// variable to store query results
- s := new(database.Step)
+ s := new(types.Step)
// send query to the database and store result in variable
err := e.client.
@@ -28,8 +28,5 @@ func (e *engine) GetStep(ctx context.Context, id int64) (*library.Step, error) {
return nil, err
}
- // return the step
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/step/get_build.go b/database/step/get_build.go
index de847a769..0f8d495c5 100644
--- a/database/step/get_build.go
+++ b/database/step/get_build.go
@@ -8,20 +8,19 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// GetStepForBuild gets a step by number and build ID from the database.
-func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) (*library.Step, error) {
+func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) (*api.Step, error) {
e.logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
"step": number,
}).Tracef("getting step %d", number)
// variable to store query results
- s := new(database.Step)
+ s := new(types.Step)
// send query to the database and store result in variable
err := e.client.
@@ -35,8 +34,5 @@ func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int)
return nil, err
}
- // return the step
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary
- return s.ToLibrary(), nil
+ return s.ToAPI(), nil
}
diff --git a/database/step/get_build_test.go b/database/step/get_build_test.go
index c5490aa58..e39ef5c6c 100644
--- a/database/step/get_build_test.go
+++ b/database/step/get_build_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/google/go-cmp/cmp"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestStep_Engine_GetStepForBuild(t *testing.T) {
@@ -54,7 +54,7 @@ func TestStep_Engine_GetStepForBuild(t *testing.T) {
failure bool
name string
database *engine
- want *library.Step
+ want *api.Step
}{
{
failure: false,
diff --git a/database/step/get_test.go b/database/step/get_test.go
index 4c05103ea..ef5acc816 100644
--- a/database/step/get_test.go
+++ b/database/step/get_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestStep_Engine_GetStep(t *testing.T) {
@@ -49,7 +49,7 @@ func TestStep_Engine_GetStep(t *testing.T) {
failure bool
name string
database *engine
- want *library.Step
+ want *api.Step
}{
{
failure: false,
diff --git a/database/step/interface.go b/database/step/interface.go
index 6de0cc168..ef74d05ea 100644
--- a/database/step/interface.go
+++ b/database/step/interface.go
@@ -6,7 +6,6 @@ import (
"context"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/library"
)
// StepInterface represents the Vela interface for step
@@ -32,21 +31,21 @@ type StepInterface interface {
// CountStepsForBuild defines a function that gets the count of steps by build ID.
CountStepsForBuild(context.Context, *api.Build, map[string]interface{}) (int64, error)
// CreateStep defines a function that creates a new step.
- CreateStep(context.Context, *library.Step) (*library.Step, error)
+ CreateStep(context.Context, *api.Step) (*api.Step, error)
// DeleteStep defines a function that deletes an existing step.
- DeleteStep(context.Context, *library.Step) error
+ DeleteStep(context.Context, *api.Step) error
// GetStep defines a function that gets a step by ID.
- GetStep(context.Context, int64) (*library.Step, error)
+ GetStep(context.Context, int64) (*api.Step, error)
// GetStepForBuild defines a function that gets a step by number and build ID.
- GetStepForBuild(context.Context, *api.Build, int) (*library.Step, error)
+ GetStepForBuild(context.Context, *api.Build, int) (*api.Step, error)
// ListSteps defines a function that gets a list of all steps.
- ListSteps(ctx context.Context) ([]*library.Step, error)
+ ListSteps(ctx context.Context) ([]*api.Step, error)
// ListStepsForBuild defines a function that gets a list of steps by build ID.
- ListStepsForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*library.Step, int64, error)
+ ListStepsForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*api.Step, int64, error)
// ListStepImageCount defines a function that gets a list of all step images and the count of their occurrence.
ListStepImageCount(context.Context) (map[string]float64, error)
// ListStepStatusCount defines a function that gets a list of all step statuses and the count of their occurrence.
ListStepStatusCount(context.Context) (map[string]float64, error)
// UpdateStep defines a function that updates an existing step.
- UpdateStep(context.Context, *library.Step) (*library.Step, error)
+ UpdateStep(context.Context, *api.Step) (*api.Step, error)
}
diff --git a/database/step/list.go b/database/step/list.go
index 9eb72996c..3904d9efa 100644
--- a/database/step/list.go
+++ b/database/step/list.go
@@ -5,19 +5,19 @@ package step
import (
"context"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListSteps gets a list of all steps from the database.
-func (e *engine) ListSteps(ctx context.Context) ([]*library.Step, error) {
+func (e *engine) ListSteps(ctx context.Context) ([]*api.Step, error) {
e.logger.Trace("listing all steps")
// variables to store query results and return value
count := int64(0)
- w := new([]database.Step)
- steps := []*library.Step{}
+ w := new([]types.Step)
+ steps := []*api.Step{}
// count the results
count, err := e.CountSteps(ctx)
@@ -45,10 +45,7 @@ func (e *engine) ListSteps(ctx context.Context) ([]*library.Step, error) {
// https://golang.org/doc/faq#closures_and_goroutines
tmp := step
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary
- steps = append(steps, tmp.ToLibrary())
+ steps = append(steps, tmp.ToAPI())
}
return steps, nil
diff --git a/database/step/list_build.go b/database/step/list_build.go
index 1ba16fdb0..819156746 100644
--- a/database/step/list_build.go
+++ b/database/step/list_build.go
@@ -8,21 +8,20 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// ListStepsForBuild gets a list of all steps from the database.
-func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*library.Step, int64, error) {
+func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*api.Step, int64, error) {
e.logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
}).Tracef("listing steps for build %d", b.GetNumber())
// variables to store query results and return value
count := int64(0)
- s := new([]database.Step)
- steps := []*library.Step{}
+ s := new([]types.Step)
+ steps := []*api.Step{}
// count the results
count, err := e.CountStepsForBuild(ctx, b, filters)
@@ -58,10 +57,7 @@ func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters ma
// https://golang.org/doc/faq#closures_and_goroutines
tmp := step
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary
- steps = append(steps, tmp.ToLibrary())
+ steps = append(steps, tmp.ToAPI())
}
return steps, count, nil
diff --git a/database/step/list_build_test.go b/database/step/list_build_test.go
index 327076fec..4bb43b044 100644
--- a/database/step/list_build_test.go
+++ b/database/step/list_build_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestStep_Engine_ListStepsForBuild(t *testing.T) {
@@ -75,19 +75,19 @@ func TestStep_Engine_ListStepsForBuild(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Step
+ want []*api.Step
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Step{_stepTwo, _stepOne},
+ want: []*api.Step{_stepTwo, _stepOne},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Step{_stepTwo, _stepOne},
+ want: []*api.Step{_stepTwo, _stepOne},
},
}
diff --git a/database/step/list_image.go b/database/step/list_image.go
index c485ec741..3a1b5b9be 100644
--- a/database/step/list_image.go
+++ b/database/step/list_image.go
@@ -6,7 +6,7 @@ import (
"context"
"database/sql"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ListStepImageCount gets a list of all step images and the count of their occurrence from the database.
diff --git a/database/step/list_status.go b/database/step/list_status.go
index 75c19a805..f11135e7f 100644
--- a/database/step/list_status.go
+++ b/database/step/list_status.go
@@ -6,7 +6,7 @@ import (
"context"
"database/sql"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// ListStepStatusCount gets a list of all step statuses and the count of their occurrence from the database.
diff --git a/database/step/list_test.go b/database/step/list_test.go
index 921a3f2f7..99819c59f 100644
--- a/database/step/list_test.go
+++ b/database/step/list_test.go
@@ -9,8 +9,8 @@ import (
"github.com/DATA-DOG/go-sqlmock"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/library"
)
func TestStep_Engine_ListSteps(t *testing.T) {
@@ -69,19 +69,19 @@ func TestStep_Engine_ListSteps(t *testing.T) {
failure bool
name string
database *engine
- want []*library.Step
+ want []*api.Step
}{
{
failure: false,
name: "postgres",
database: _postgres,
- want: []*library.Step{_stepOne, _stepTwo},
+ want: []*api.Step{_stepOne, _stepTwo},
},
{
failure: false,
name: "sqlite3",
database: _sqlite,
- want: []*library.Step{_stepOne, _stepTwo},
+ want: []*api.Step{_stepOne, _stepTwo},
},
}
diff --git a/database/step/step.go b/database/step/step.go
index edb3cb26e..a1465f778 100644
--- a/database/step/step.go
+++ b/database/step/step.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/step/table.go b/database/step/table.go
index c7560326d..af7431c70 100644
--- a/database/step/table.go
+++ b/database/step/table.go
@@ -5,7 +5,7 @@ package step
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/step/update.go b/database/step/update.go
index d467a2b65..524eea7f0 100644
--- a/database/step/update.go
+++ b/database/step/update.go
@@ -7,25 +7,19 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/database/types"
)
// UpdateStep updates an existing step in the database.
-func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.Step, error) {
+func (e *engine) UpdateStep(ctx context.Context, s *api.Step) (*api.Step, error) {
e.logger.WithFields(logrus.Fields{
"step": s.GetNumber(),
}).Tracef("updating step %s in the database", s.GetName())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary
- step := database.StepFromLibrary(s)
+ step := types.StepFromAPI(s)
- // validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Step.Validate
err := step.Validate()
if err != nil {
return nil, err
@@ -37,5 +31,5 @@ func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.Step
Table(constants.TableStep).
Save(step)
- return step.ToLibrary(), result.Error
+ return step.ToAPI(), result.Error
}
diff --git a/database/testutils/api_resources.go b/database/testutils/api_resources.go
index a183ada1f..18f619afd 100644
--- a/database/testutils/api_resources.go
+++ b/database/testutils/api_resources.go
@@ -12,7 +12,6 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/server/compiler/types/raw"
- "github.com/go-vela/types/library"
)
// API TEST RESOURCES
@@ -162,8 +161,8 @@ func APIHook() *api.Hook {
}
}
-func APILog() *library.Log {
- return &library.Log{
+func APILog() *api.Log {
+ return &api.Log{
ID: new(int64),
RepoID: new(int64),
BuildID: new(int64),
@@ -190,8 +189,28 @@ func APISchedule() *api.Schedule {
}
}
-func APIService() *library.Service {
- return &library.Service{
+func APISecret() *api.Secret {
+ return &api.Secret{
+ ID: new(int64),
+ Org: new(string),
+ Repo: new(string),
+ Team: new(string),
+ Name: new(string),
+ Value: new(string),
+ Type: new(string),
+ Images: new([]string),
+ AllowEvents: APIEvents(),
+ AllowCommand: new(bool),
+ AllowSubstitution: new(bool),
+ CreatedAt: new(int64),
+ CreatedBy: new(string),
+ UpdatedAt: new(int64),
+ UpdatedBy: new(string),
+ }
+}
+
+func APIService() *api.Service {
+ return &api.Service{
ID: new(int64),
BuildID: new(int64),
RepoID: new(int64),
@@ -210,8 +229,8 @@ func APIService() *library.Service {
}
}
-func APIStep() *library.Step {
- return &library.Step{
+func APIStep() *api.Step {
+ return &api.Step{
ID: new(int64),
BuildID: new(int64),
RepoID: new(int64),
diff --git a/database/types/build_executable.go b/database/types/build_executable.go
new file mode 100644
index 000000000..3448bde2e
--- /dev/null
+++ b/database/types/build_executable.go
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "encoding/base64"
+ "errors"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/util"
+)
+
+var (
+ // ErrEmptyBuildExecutableBuildID defines the error type when a
+ // BuildExecutable type has an empty BuildID field provided.
+ ErrEmptyBuildExecutableBuildID = errors.New("empty build_executable build_id provided")
+)
+
+// BuildExecutable is the database representation of a BuildExecutable.
+type BuildExecutable struct {
+ ID sql.NullInt64 `sql:"id"`
+ BuildID sql.NullInt64 `sql:"build_id"`
+ Data []byte `sql:"data"`
+}
+
+// Compress will manipulate the existing data for the
+// BuildExecutable by compressing that data. This produces
+// a significantly smaller amount of data that is
+// stored in the system.
+func (b *BuildExecutable) Compress(level int) error {
+ // compress the database BuildExecutable data
+ data, err := util.Compress(level, b.Data)
+ if err != nil {
+ return err
+ }
+
+ // overwrite database BuildExecutable data with compressed BuildExecutable data
+ b.Data = data
+
+ return nil
+}
+
+// Decompress will manipulate the existing data for the
+// BuildExecutable by decompressing that data. This allows us
+// to have a significantly smaller amount of data that
+// is stored in the system.
+func (b *BuildExecutable) Decompress() error {
+ // decompress the database BuildExecutable data
+ data, err := util.Decompress(b.Data)
+ if err != nil {
+ return err
+ }
+
+ // overwrite compressed BuildExecutable data with decompressed BuildExecutable data
+ b.Data = data
+
+ return nil
+}
+
+// Decrypt will manipulate the existing executable data by
+// base64 decoding that value. Then, a AES-256 cipher
+// block is created from the encryption key in order to
+// decrypt the base64 decoded secret value.
+func (b *BuildExecutable) Decrypt(key string) error {
+ dst := make([]byte, base64.StdEncoding.DecodedLen(len(b.Data)))
+
+ // base64 decode the encrypted repo hash
+ n, err := base64.StdEncoding.Decode(dst, b.Data)
+ if err != nil {
+ return err
+ }
+
+ dst = dst[:n]
+
+ // decrypt the base64 decoded executable data
+ decrypted, err := util.Decrypt(key, dst)
+ if err != nil {
+ return err
+ }
+
+ // set the decrypted executable
+ b.Data = decrypted
+
+ return nil
+}
+
+// Encrypt will manipulate the existing build executable by
+// creating a AES-256 cipher block from the encryption
+// key in order to encrypt the build executable. Then, the
+// build executable is base64 encoded for transport across
+// network boundaries.
+func (b *BuildExecutable) Encrypt(key string) error {
+ // encrypt the executable data
+ encrypted, err := util.Encrypt(key, b.Data)
+ if err != nil {
+ return err
+ }
+
+ // base64 encode the encrypted executable to make it network safe
+ dst := make([]byte, base64.StdEncoding.EncodedLen(len(encrypted)))
+ base64.StdEncoding.Encode(dst, encrypted)
+
+ b.Data = dst
+
+ return nil
+}
+
+// Nullify ensures the valid flag for
+// the sql.Null types are properly set.
+//
+// When a field within the BuildExecutable type is the zero
+// value for the field, the valid flag is set to
+// false causing it to be NULL in the database.
+func (b *BuildExecutable) Nullify() *BuildExecutable {
+ if b == nil {
+ return nil
+ }
+
+ // check if the ID field should be false
+ if b.ID.Int64 == 0 {
+ b.ID.Valid = false
+ }
+
+ // check if the BuildID field should be false
+ if b.BuildID.Int64 == 0 {
+ b.BuildID.Valid = false
+ }
+
+ return b
+}
+
+// ToAPI converts the BuildExecutable type
+// to a API BuildExecutable type.
+func (b *BuildExecutable) ToAPI() *api.BuildExecutable {
+ buildExecutable := new(api.BuildExecutable)
+
+ buildExecutable.SetID(b.ID.Int64)
+ buildExecutable.SetBuildID(b.BuildID.Int64)
+ buildExecutable.SetData(b.Data)
+
+ return buildExecutable
+}
+
+// Validate verifies the necessary fields for
+// the BuildExecutable type are populated correctly.
+func (b *BuildExecutable) Validate() error {
+ // verify the BuildID field is populated
+ if b.BuildID.Int64 <= 0 {
+ return ErrEmptyBuildExecutableBuildID
+ }
+
+ return nil
+}
+
+// BuildExecutableFromAPI converts the API BuildExecutable type
+// to a database BuildExecutable type.
+func BuildExecutableFromAPI(c *api.BuildExecutable) *BuildExecutable {
+ buildExecutable := &BuildExecutable{
+ ID: sql.NullInt64{Int64: c.GetID(), Valid: true},
+ BuildID: sql.NullInt64{Int64: c.GetBuildID(), Valid: true},
+ Data: c.GetData(),
+ }
+
+ return buildExecutable.Nullify()
+}
diff --git a/database/types/build_executable_test.go b/database/types/build_executable_test.go
new file mode 100644
index 000000000..1806e2951
--- /dev/null
+++ b/database/types/build_executable_test.go
@@ -0,0 +1,455 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "reflect"
+ "testing"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+)
+
+func TestDatabase_BuildExecutable_Compress(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ name string
+ failure bool
+ level int
+ buildExecutable *BuildExecutable
+ want []byte
+ }{
+ {
+ name: "compression level -1",
+ failure: false,
+ level: constants.CompressionNegOne,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 0",
+ failure: false,
+ level: constants.CompressionZero,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 1, 0, 108, 1, 147, 254, 10, 123, 32, 10, 32, 32, 32, 32, 34, 105, 100, 34, 58, 32, 34, 115, 116, 101, 112, 95, 110, 97, 109, 101, 34, 44, 10, 32, 32, 32, 32, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 34, 44, 10, 32, 32, 32, 32, 34, 109, 101, 116, 97, 100, 97, 116, 97, 34, 58, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 99, 108, 111, 110, 101, 34, 58, 116, 114, 117, 101, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 91, 34, 115, 116, 101, 112, 115, 34, 44, 34, 115, 101, 114, 118, 105, 99, 101, 115, 34, 44, 34, 115, 101, 99, 114, 101, 116, 115, 34, 93, 125, 44, 10, 32, 32, 32, 32, 34, 119, 111, 114, 107, 101, 114, 34, 58, 123, 125, 44, 10, 32, 32, 32, 32, 34, 115, 116, 101, 112, 115, 34, 58, 91, 10, 32, 32, 32, 32, 32, 32, 32, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 105, 100, 34, 58, 34, 115, 116, 101, 112, 95, 103, 105, 116, 104, 117, 98, 95, 111, 99, 116, 111, 99, 97, 116, 95, 49, 95, 105, 110, 105, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 100, 105, 114, 101, 99, 116, 111, 114, 121, 34, 58, 34, 47, 118, 101, 108, 97, 47, 115, 114, 99, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 103, 105, 116, 104, 117, 98, 47, 111, 99, 116, 111, 99, 97, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 32, 123, 34, 66, 85, 73, 76, 68, 95, 65, 85, 84, 72, 79, 82, 34, 58, 34, 79, 99, 116, 111, 99, 97, 116, 34, 125, 10, 32, 32, 32, 32, 32, 32, 32, 32, 125, 10, 32, 32, 32, 32, 93, 10, 125, 10, 1, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 1",
+ failure: false,
+ level: constants.CompressionOne,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 1, 92, 143, 65, 75, 3, 49, 16, 133, 239, 249, 21, 195, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 76, 7, 13, 118, 19, 153, 76, 87, 100, 217, 255, 46, 217, 236, 86, 244, 157, 134, 151, 121, 243, 190, 152, 145, 12, 17, 17, 226, 9, 150, 80, 148, 63, 93, 242, 61, 99, 211, 236, 129, 165, 196, 156, 234, 219, 118, 245, 122, 86, 127, 242, 234, 97, 199, 121, 169, 10, 225, 156, 19, 195, 170, 92, 184, 69, 171, 192, 105, 136, 146, 83, 207, 73, 97, 15, 243, 249, 130, 13, 10, 203, 16, 3, 183, 49, 8, 107, 193, 113, 106, 49, 124, 101, 249, 96, 129, 29, 87, 163, 50, 21, 216, 195, 181, 235, 183, 181, 106, 38, 159, 151, 220, 91, 212, 247, 203, 171, 203, 65, 115, 240, 234, 182, 46, 166, 168, 11, 245, 42, 156, 162, 112, 208, 44, 223, 176, 232, 6, 62, 251, 174, 72, 232, 90, 244, 38, 228, 126, 25, 187, 229, 202, 255, 248, 159, 31, 209, 136, 187, 253, 227, 211, 189, 187, 221, 191, 60, 236, 158, 97, 177, 107, 221, 152, 174, 180, 147, 33, 34, 58, 154, 201, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 2",
+ failure: false,
+ level: constants.CompressionTwo,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 146, 111, 222, 183, 205, 232, 26, 231, 156, 67, 238, 224, 29, 170, 210, 103, 40, 177, 39, 108, 172, 30, 72, 106, 230, 242, 251, 109, 123, 233, 122, 210, 216, 69, 141, 240, 227, 252, 211, 204, 167, 19, 23, 130, 87, 57, 147, 161, 115, 75, 101, 200, 194, 165, 167, 162, 240, 135, 249, 124, 197, 6, 149, 100, 200, 137, 44, 38, 33, 173, 56, 78, 203, 226, 23, 203, 7, 9, 252, 120, 41, 12, 242, 135, 117, 235, 111, 117, 53, 55, 241, 183, 172, 239, 231, 215, 192, 73, 57, 69, 13, 219, 144, 75, 214, 197, 122, 21, 237, 178, 80, 82, 150, 111, 120, 180, 3, 157, 98, 91, 37, 181, 134, 222, 36, 238, 151, 216, 46, 87, 174, 241, 127, 47, 114, 35, 238, 246, 143, 79, 247, 225, 118, 255, 242, 176, 123, 134, 199, 206, 182, 49, 173, 182, 150, 142, 205, 212, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 3",
+ failure: false,
+ level: constants.CompressionThree,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 118, 222, 123, 223, 54, 163, 107, 156, 115, 14, 185, 131, 119, 168, 74, 159, 161, 196, 158, 176, 49, 123, 32, 169, 153, 203, 239, 219, 246, 226, 245, 164, 177, 139, 26, 225, 199, 249, 104, 62, 76, 39, 46, 4, 175, 114, 38, 139, 206, 46, 149, 33, 11, 151, 158, 138, 194, 31, 230, 250, 138, 13, 42, 201, 144, 19, 153, 76, 66, 90, 113, 156, 150, 197, 47, 150, 15, 18, 248, 241, 98, 88, 200, 31, 214, 214, 191, 213, 149, 220, 192, 223, 178, 190, 159, 95, 3, 39, 229, 20, 53, 108, 67, 46, 89, 23, 234, 21, 169, 203, 66, 73, 89, 190, 225, 209, 14, 116, 138, 109, 149, 212, 90, 244, 38, 113, 191, 200, 118, 105, 185, 142, 255, 251, 145, 27, 113, 183, 127, 124, 186, 15, 183, 251, 151, 135, 221, 51, 60, 118, 182, 141, 105, 165, 53, 117, 108, 166, 230, 39, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 4",
+ failure: false,
+ level: constants.CompressionFour,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 204, 14, 26, 236, 102, 100, 50, 93, 145, 101, 255, 187, 52, 73, 87, 244, 54, 124, 51, 223, 203, 75, 55, 155, 206, 24, 99, 16, 7, 88, 131, 172, 244, 233, 146, 31, 9, 155, 138, 39, 146, 28, 57, 93, 118, 219, 43, 27, 73, 253, 224, 213, 195, 206, 5, 20, 24, 78, 156, 8, 86, 229, 76, 245, 172, 80, 74, 83, 20, 78, 35, 37, 133, 61, 148, 248, 140, 13, 50, 201, 20, 3, 213, 49, 8, 105, 198, 113, 105, 233, 95, 44, 31, 36, 176, 243, 21, 84, 201, 30, 214, 212, 223, 87, 203, 254, 210, 188, 22, 127, 139, 250, 126, 126, 117, 28, 148, 131, 87, 183, 117, 49, 69, 109, 173, 215, 243, 33, 10, 5, 101, 249, 134, 69, 63, 209, 201, 247, 89, 66, 95, 213, 155, 192, 99, 27, 251, 150, 242, 95, 255, 243, 35, 51, 227, 110, 255, 248, 116, 239, 110, 247, 47, 15, 187, 103, 88, 236, 154, 181, 172, 86, 157, 142, 221, 210, 253, 4, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 5",
+ failure: false,
+ level: constants.CompressionFive,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 6",
+ failure: false,
+ level: constants.CompressionSix,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 7",
+ failure: false,
+ level: constants.CompressionSeven,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 8",
+ failure: false,
+ level: constants.CompressionEight,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ {
+ name: "compression level 9",
+ failure: false,
+ level: constants.CompressionNine,
+ buildExecutable: &BuildExecutable{Data: testBuildExecutableData()},
+ want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105},
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ err := test.buildExecutable.Compress(test.level)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Compress for %s should have returned err", test.name)
+ }
+
+ return
+ }
+
+ if err != nil {
+ t.Errorf("Compress for %s returned err: %v", test.name, err)
+ }
+
+ if !reflect.DeepEqual(test.buildExecutable.Data, test.want) {
+ t.Errorf("Compress for %s is %v, want %v", test.name, test.buildExecutable.Data, string(test.want))
+ }
+ })
+ }
+}
+
+func TestDatabase_BuildExecutable_Decompress(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ name string
+ failure bool
+ buildExecutable *BuildExecutable
+ want []byte
+ }{
+ {
+ name: "compression level -1",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 0",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 1, 0, 108, 1, 147, 254, 10, 123, 32, 10, 32, 32, 32, 32, 34, 105, 100, 34, 58, 32, 34, 115, 116, 101, 112, 95, 110, 97, 109, 101, 34, 44, 10, 32, 32, 32, 32, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 34, 44, 10, 32, 32, 32, 32, 34, 109, 101, 116, 97, 100, 97, 116, 97, 34, 58, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 99, 108, 111, 110, 101, 34, 58, 116, 114, 117, 101, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 91, 34, 115, 116, 101, 112, 115, 34, 44, 34, 115, 101, 114, 118, 105, 99, 101, 115, 34, 44, 34, 115, 101, 99, 114, 101, 116, 115, 34, 93, 125, 44, 10, 32, 32, 32, 32, 34, 119, 111, 114, 107, 101, 114, 34, 58, 123, 125, 44, 10, 32, 32, 32, 32, 34, 115, 116, 101, 112, 115, 34, 58, 91, 10, 32, 32, 32, 32, 32, 32, 32, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 105, 100, 34, 58, 34, 115, 116, 101, 112, 95, 103, 105, 116, 104, 117, 98, 95, 111, 99, 116, 111, 99, 97, 116, 95, 49, 95, 105, 110, 105, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 100, 105, 114, 101, 99, 116, 111, 114, 121, 34, 58, 34, 47, 118, 101, 108, 97, 47, 115, 114, 99, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 103, 105, 116, 104, 117, 98, 47, 111, 99, 116, 111, 99, 97, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 32, 123, 34, 66, 85, 73, 76, 68, 95, 65, 85, 84, 72, 79, 82, 34, 58, 34, 79, 99, 116, 111, 99, 97, 116, 34, 125, 10, 32, 32, 32, 32, 32, 32, 32, 32, 125, 10, 32, 32, 32, 32, 93, 10, 125, 10, 1, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 1",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 1, 92, 143, 65, 75, 3, 49, 16, 133, 239, 249, 21, 195, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 76, 7, 13, 118, 19, 153, 76, 87, 100, 217, 255, 46, 217, 236, 86, 244, 157, 134, 151, 121, 243, 190, 152, 145, 12, 17, 17, 226, 9, 150, 80, 148, 63, 93, 242, 61, 99, 211, 236, 129, 165, 196, 156, 234, 219, 118, 245, 122, 86, 127, 242, 234, 97, 199, 121, 169, 10, 225, 156, 19, 195, 170, 92, 184, 69, 171, 192, 105, 136, 146, 83, 207, 73, 97, 15, 243, 249, 130, 13, 10, 203, 16, 3, 183, 49, 8, 107, 193, 113, 106, 49, 124, 101, 249, 96, 129, 29, 87, 163, 50, 21, 216, 195, 181, 235, 183, 181, 106, 38, 159, 151, 220, 91, 212, 247, 203, 171, 203, 65, 115, 240, 234, 182, 46, 166, 168, 11, 245, 42, 156, 162, 112, 208, 44, 223, 176, 232, 6, 62, 251, 174, 72, 232, 90, 244, 38, 228, 126, 25, 187, 229, 202, 255, 248, 159, 31, 209, 136, 187, 253, 227, 211, 189, 187, 221, 191, 60, 236, 158, 97, 177, 107, 221, 152, 174, 180, 147, 33, 34, 58, 154, 201, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 2",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 146, 111, 222, 183, 205, 232, 26, 231, 156, 67, 238, 224, 29, 170, 210, 103, 40, 177, 39, 108, 172, 30, 72, 106, 230, 242, 251, 109, 123, 233, 122, 210, 216, 69, 141, 240, 227, 252, 211, 204, 167, 19, 23, 130, 87, 57, 147, 161, 115, 75, 101, 200, 194, 165, 167, 162, 240, 135, 249, 124, 197, 6, 149, 100, 200, 137, 44, 38, 33, 173, 56, 78, 203, 226, 23, 203, 7, 9, 252, 120, 41, 12, 242, 135, 117, 235, 111, 117, 53, 55, 241, 183, 172, 239, 231, 215, 192, 73, 57, 69, 13, 219, 144, 75, 214, 197, 122, 21, 237, 178, 80, 82, 150, 111, 120, 180, 3, 157, 98, 91, 37, 181, 134, 222, 36, 238, 151, 216, 46, 87, 174, 241, 127, 47, 114, 35, 238, 246, 143, 79, 247, 225, 118, 255, 242, 176, 123, 134, 199, 206, 182, 49, 173, 182, 150, 142, 205, 212, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 3",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 118, 222, 123, 223, 54, 163, 107, 156, 115, 14, 185, 131, 119, 168, 74, 159, 161, 196, 158, 176, 49, 123, 32, 169, 153, 203, 239, 219, 246, 226, 245, 164, 177, 139, 26, 225, 199, 249, 104, 62, 76, 39, 46, 4, 175, 114, 38, 139, 206, 46, 149, 33, 11, 151, 158, 138, 194, 31, 230, 250, 138, 13, 42, 201, 144, 19, 153, 76, 66, 90, 113, 156, 150, 197, 47, 150, 15, 18, 248, 241, 98, 88, 200, 31, 214, 214, 191, 213, 149, 220, 192, 223, 178, 190, 159, 95, 3, 39, 229, 20, 53, 108, 67, 46, 89, 23, 234, 21, 169, 203, 66, 73, 89, 190, 225, 209, 14, 116, 138, 109, 149, 212, 90, 244, 38, 113, 191, 200, 118, 105, 185, 142, 255, 251, 145, 27, 113, 183, 127, 124, 186, 15, 183, 251, 151, 135, 221, 51, 60, 118, 182, 141, 105, 165, 53, 117, 108, 166, 230, 39, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 4",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 204, 14, 26, 236, 102, 100, 50, 93, 145, 101, 255, 187, 52, 73, 87, 244, 54, 124, 51, 223, 203, 75, 55, 155, 206, 24, 99, 16, 7, 88, 131, 172, 244, 233, 146, 31, 9, 155, 138, 39, 146, 28, 57, 93, 118, 219, 43, 27, 73, 253, 224, 213, 195, 206, 5, 20, 24, 78, 156, 8, 86, 229, 76, 245, 172, 80, 74, 83, 20, 78, 35, 37, 133, 61, 148, 248, 140, 13, 50, 201, 20, 3, 213, 49, 8, 105, 198, 113, 105, 233, 95, 44, 31, 36, 176, 243, 21, 84, 201, 30, 214, 212, 223, 87, 203, 254, 210, 188, 22, 127, 139, 250, 126, 126, 117, 28, 148, 131, 87, 183, 117, 49, 69, 109, 173, 215, 243, 33, 10, 5, 101, 249, 134, 69, 63, 209, 201, 247, 89, 66, 95, 213, 155, 192, 99, 27, 251, 150, 242, 95, 255, 243, 35, 51, 227, 110, 255, 248, 116, 239, 110, 247, 47, 15, 187, 103, 88, 236, 154, 181, 172, 86, 157, 142, 221, 210, 253, 4, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 5",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 6",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 7",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 8",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ {
+ name: "compression level 9",
+ failure: false,
+ buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}},
+ want: testBuildExecutableData(),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ err := test.buildExecutable.Decompress()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Decompress for %s should have returned err", test.name)
+ }
+
+ return
+ }
+
+ if err != nil {
+ t.Errorf("Decompress for %s returned err: %v", test.name, err)
+ }
+
+ if !reflect.DeepEqual(test.buildExecutable.Data, test.want) {
+ t.Errorf("Decompress for %s is %v, want %v", test.name, string(test.buildExecutable.Data), string(test.want))
+ }
+ })
+ }
+}
+
+func TestDatabase_BuildExecutable_Decrypt(t *testing.T) {
+ // setup types
+ key := "C639A572E14D5075C526FDDD43E4ECF6"
+ encrypted := testBuildExecutable()
+
+ err := encrypted.Encrypt(key)
+ if err != nil {
+ t.Errorf("unable to encrypt repo: %v", err)
+ }
+
+ // setup tests
+ tests := []struct {
+ failure bool
+ key string
+ executable BuildExecutable
+ }{
+ {
+ failure: false,
+ key: key,
+ executable: *encrypted,
+ },
+ {
+ failure: true,
+ key: "",
+ executable: *encrypted,
+ },
+ {
+ failure: true,
+ key: key,
+ executable: *testBuildExecutable(),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.executable.Decrypt(test.key)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Decrypt should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Decrypt returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_BuildExecutable_Encrypt(t *testing.T) {
+ // setup types
+ key := "C639A572E14D5075C526FDDD43E4ECF6"
+
+ // setup tests
+ tests := []struct {
+ failure bool
+ key string
+ executable *BuildExecutable
+ }{
+ {
+ failure: false,
+ key: key,
+ executable: testBuildExecutable(),
+ },
+ {
+ failure: true,
+ key: "",
+ executable: testBuildExecutable(),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.executable.Encrypt(test.key)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Encrypt should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Encrypt returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_BuildExecutable_Nullify(t *testing.T) {
+ // setup types
+ var p *BuildExecutable
+
+ want := &BuildExecutable{
+ ID: sql.NullInt64{Int64: 0, Valid: false},
+ BuildID: sql.NullInt64{Int64: 0, Valid: false},
+ }
+
+ // setup tests
+ tests := []struct {
+ buildExecutable *BuildExecutable
+ want *BuildExecutable
+ }{
+ {
+ buildExecutable: testBuildExecutable(),
+ want: testBuildExecutable(),
+ },
+ {
+ buildExecutable: p,
+ want: nil,
+ },
+ {
+ buildExecutable: new(BuildExecutable),
+ want: want,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.buildExecutable.Nullify()
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("Nullify is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestDatabase_BuildExecutable_ToAPI(t *testing.T) {
+ // setup types
+ want := new(api.BuildExecutable)
+
+ want.SetID(1)
+ want.SetBuildID(1)
+ want.SetData(testBuildExecutableData())
+
+ // run test
+ got := testBuildExecutable().ToAPI()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ToAPI is %v, want %v", got, want)
+ }
+}
+
+func TestDatabase_BuildExecutable_Validate(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ failure bool
+ buildExecutable *BuildExecutable
+ }{
+ {
+ failure: false,
+ buildExecutable: testBuildExecutable(),
+ },
+ { // no build_id set for buildExecutable
+ failure: true,
+ buildExecutable: &BuildExecutable{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ },
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.buildExecutable.Validate()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Validate should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Validate returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_BuildExecutableFromAPI(t *testing.T) {
+ // setup types
+ c := new(api.BuildExecutable)
+
+ c.SetID(1)
+ c.SetBuildID(1)
+ c.SetData(testBuildExecutableData())
+
+ want := testBuildExecutable()
+
+ // run test
+ got := BuildExecutableFromAPI(c)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("BuildExecutableFromAPI is %v, want %v", got, want)
+ }
+}
+
+// testBuildExecutable is a test helper function to create a BuildExecutable
+// type with all fields set to a fake value.
+func testBuildExecutable() *BuildExecutable {
+ return &BuildExecutable{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ Data: testBuildExecutableData(),
+ }
+}
+
+// testBuildExecutableData is a test helper function to create the
+// content for the Data field for the BuildExecutable type.
+func testBuildExecutableData() []byte {
+ return []byte(`
+{
+ "id": "step_name",
+ "version": "1",
+ "metadata":{
+ "clone":true,
+ "environment":["steps","services","secrets"]},
+ "worker":{},
+ "steps":[
+ {
+ "id":"step_github_octocat_1_init",
+ "directory":"/vela/src/github.com/github/octocat",
+ "environment": {"BUILD_AUTHOR":"Octocat"}
+ }
+ ]
+}
+`)
+}
diff --git a/database/types/deployment.go b/database/types/deployment.go
index df300d6be..965c8dbc6 100644
--- a/database/types/deployment.go
+++ b/database/types/deployment.go
@@ -11,8 +11,8 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/raw"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
var (
diff --git a/database/types/log.go b/database/types/log.go
new file mode 100644
index 000000000..0c208440f
--- /dev/null
+++ b/database/types/log.go
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "errors"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/util"
+)
+
+var (
+ // ErrEmptyLogBuildID defines the error type when a
+ // Log type has an empty BuildID field provided.
+ ErrEmptyLogBuildID = errors.New("empty log build_id provided")
+
+ // ErrEmptyLogRepoID defines the error type when a
+ // Log type has an empty RepoID field provided.
+ ErrEmptyLogRepoID = errors.New("empty log repo_id provided")
+
+ // ErrEmptyLogStepOrServiceID defines the error type when a
+ // Log type has an empty StepID or ServiceID field provided.
+ ErrEmptyLogStepOrServiceID = errors.New("empty log step_id or service_id not provided")
+)
+
+// Log is the database representation of a log for a step in a build.
+type Log struct {
+ ID sql.NullInt64 `sql:"id"`
+ BuildID sql.NullInt64 `sql:"build_id"`
+ RepoID sql.NullInt64 `sql:"repo_id"`
+ ServiceID sql.NullInt64 `sql:"service_id"`
+ StepID sql.NullInt64 `sql:"step_id"`
+ Data []byte `sql:"data"`
+}
+
+// Compress will manipulate the existing data for the
+// log entry by compressing that data. This produces
+// a significantly smaller amount of data that is
+// stored in the system.
+func (l *Log) Compress(level int) error {
+ // compress the database log data
+ data, err := util.Compress(level, l.Data)
+ if err != nil {
+ return err
+ }
+
+ // overwrite database log data with compressed log data
+ l.Data = data
+
+ return nil
+}
+
+// Decompress will manipulate the existing data for the
+// log entry by decompressing that data. This allows us
+// to have a significantly smaller amount of data that
+// is stored in the system.
+func (l *Log) Decompress() error {
+ // decompress the database log data
+ data, err := util.Decompress(l.Data)
+ if err != nil {
+ return err
+ }
+
+ // overwrite compressed log data with decompressed log data
+ l.Data = data
+
+ return nil
+}
+
+// Nullify ensures the valid flag for
+// the sql.Null types are properly set.
+//
+// When a field within the Log type is the zero
+// value for the field, the valid flag is set to
+// false causing it to be NULL in the database.
+func (l *Log) Nullify() *Log {
+ if l == nil {
+ return nil
+ }
+
+ // check if the ID field should be false
+ if l.ID.Int64 == 0 {
+ l.ID.Valid = false
+ }
+
+ // check if the BuildID field should be false
+ if l.BuildID.Int64 == 0 {
+ l.BuildID.Valid = false
+ }
+
+ // check if the RepoID field should be false
+ if l.RepoID.Int64 == 0 {
+ l.RepoID.Valid = false
+ }
+
+ // check if the ServiceID field should be false
+ if l.ServiceID.Int64 == 0 {
+ l.ServiceID.Valid = false
+ }
+
+ // check if the StepID field should be false
+ if l.StepID.Int64 == 0 {
+ l.StepID.Valid = false
+ }
+
+ return l
+}
+
+// ToAPI converts the Log type
+// to a API Log type.
+func (l *Log) ToAPI() *api.Log {
+ log := new(api.Log)
+
+ log.SetID(l.ID.Int64)
+ log.SetBuildID(l.BuildID.Int64)
+ log.SetRepoID(l.RepoID.Int64)
+ log.SetServiceID(l.ServiceID.Int64)
+ log.SetStepID(l.StepID.Int64)
+ log.SetData(l.Data)
+
+ return log
+}
+
+// Validate verifies the necessary fields for
+// the Log type are populated correctly.
+func (l *Log) Validate() error {
+ // verify the has StepID or ServiceID field populated
+ if l.StepID.Int64 <= 0 && l.ServiceID.Int64 <= 0 {
+ return ErrEmptyLogStepOrServiceID
+ }
+
+ // verify the BuildID field is populated
+ if l.BuildID.Int64 <= 0 {
+ return ErrEmptyLogBuildID
+ }
+
+ // verify the RepoID field is populated
+ if l.RepoID.Int64 <= 0 {
+ return ErrEmptyLogRepoID
+ }
+
+ return nil
+}
+
+// LogFromAPI converts the Log type
+// to a API Log type.
+func LogFromAPI(l *api.Log) *Log {
+ log := &Log{
+ ID: sql.NullInt64{Int64: l.GetID(), Valid: true},
+ BuildID: sql.NullInt64{Int64: l.GetBuildID(), Valid: true},
+ RepoID: sql.NullInt64{Int64: l.GetRepoID(), Valid: true},
+ ServiceID: sql.NullInt64{Int64: l.GetServiceID(), Valid: true},
+ StepID: sql.NullInt64{Int64: l.GetStepID(), Valid: true},
+ Data: l.GetData(),
+ }
+
+ return log.Nullify()
+}
diff --git a/database/types/log_test.go b/database/types/log_test.go
new file mode 100644
index 000000000..f45b15c4f
--- /dev/null
+++ b/database/types/log_test.go
@@ -0,0 +1,374 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "reflect"
+ "testing"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+)
+
+func TestDatabase_Log_Compress(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ name string
+ failure bool
+ level int
+ log *Log
+ want []byte
+ }{
+ {
+ name: "compression level -1",
+ failure: false,
+ level: constants.CompressionNegOne,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 156, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 0",
+ failure: false,
+ level: constants.CompressionZero,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 1, 0, 3, 0, 252, 255, 102, 111, 111, 1, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 1",
+ failure: false,
+ level: constants.CompressionOne,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 1, 0, 3, 0, 252, 255, 102, 111, 111, 1, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 2",
+ failure: false,
+ level: constants.CompressionTwo,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 3",
+ failure: false,
+ level: constants.CompressionThree,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 4",
+ failure: false,
+ level: constants.CompressionFour,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 5",
+ failure: false,
+ level: constants.CompressionFive,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 6",
+ failure: false,
+ level: constants.CompressionSix,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 156, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 7",
+ failure: false,
+ level: constants.CompressionSeven,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 8",
+ failure: false,
+ level: constants.CompressionEight,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ {
+ name: "compression level 9",
+ failure: false,
+ level: constants.CompressionNine,
+ log: &Log{Data: []byte("foo")},
+ want: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69},
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ err := test.log.Compress(test.level)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Compress for %s should have returned err", test.name)
+ }
+
+ return
+ }
+
+ if err != nil {
+ t.Errorf("Compress for %s returned err: %v", test.name, err)
+ }
+
+ if !reflect.DeepEqual(test.log.Data, test.want) {
+ t.Errorf("Compress for %s is %v, want %v", test.name, string(test.log.Data), string(test.want))
+ }
+ })
+ }
+}
+
+func TestDatabase_Log_Decompress(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ name string
+ failure bool
+ log *Log
+ want []byte
+ }{
+ {
+ name: "compression level -1",
+ failure: false,
+ log: &Log{Data: []byte{120, 156, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 0",
+ failure: false,
+ log: &Log{Data: []byte{120, 1, 0, 3, 0, 252, 255, 102, 111, 111, 1, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 1",
+ failure: false,
+ log: &Log{Data: []byte{120, 1, 0, 3, 0, 252, 255, 102, 111, 111, 1, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 2",
+ failure: false,
+ log: &Log{Data: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 3",
+ failure: false,
+ log: &Log{Data: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 4",
+ failure: false,
+ log: &Log{Data: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 5",
+ failure: false,
+ log: &Log{Data: []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 6",
+ failure: false,
+ log: &Log{Data: []byte{120, 156, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 7",
+ failure: false,
+ log: &Log{Data: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 8",
+ failure: false,
+ log: &Log{Data: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ {
+ name: "compression level 9",
+ failure: false,
+ log: &Log{Data: []byte{120, 218, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}},
+ want: []byte("foo"),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ err := test.log.Decompress()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Decompress for %s should have returned err", test.name)
+ }
+
+ return
+ }
+
+ if err != nil {
+ t.Errorf("Decompress for %s returned err: %v", test.name, err)
+ }
+
+ if !reflect.DeepEqual(test.log.Data, test.want) {
+ t.Errorf("Decompress for %s is %v, want %v", test.name, string(test.log.Data), string(test.want))
+ }
+ })
+ }
+}
+
+func TestDatabase_Log_Nullify(t *testing.T) {
+ // setup types
+ var l *Log
+
+ want := &Log{
+ ID: sql.NullInt64{Int64: 0, Valid: false},
+ BuildID: sql.NullInt64{Int64: 0, Valid: false},
+ RepoID: sql.NullInt64{Int64: 0, Valid: false},
+ ServiceID: sql.NullInt64{Int64: 0, Valid: false},
+ StepID: sql.NullInt64{Int64: 0, Valid: false},
+ }
+
+ // setup tests
+ tests := []struct {
+ log *Log
+ want *Log
+ }{
+ {
+ log: testLog(),
+ want: testLog(),
+ },
+ {
+ log: l,
+ want: nil,
+ },
+ {
+ log: new(Log),
+ want: want,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.log.Nullify()
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("Nullify is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestDatabase_Log_ToAPI(t *testing.T) {
+ // setup types
+ want := new(api.Log)
+
+ want.SetID(1)
+ want.SetServiceID(1)
+ want.SetStepID(1)
+ want.SetBuildID(1)
+ want.SetRepoID(1)
+ want.SetData([]byte("foo"))
+
+ // run test
+ got := testLog().ToAPI()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ToAPI is %v, want %v", got, want)
+ }
+}
+
+func TestDatabase_Log_Validate(t *testing.T) {
+ // setup tests
+ tests := []struct {
+ failure bool
+ log *Log
+ }{
+ {
+ failure: false,
+ log: testLog(),
+ },
+ { // no service_id or step_id set for log
+ failure: true,
+ log: &Log{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ },
+ },
+ { // no build_id set for log
+ failure: true,
+ log: &Log{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ ServiceID: sql.NullInt64{Int64: 1, Valid: true},
+ StepID: sql.NullInt64{Int64: 1, Valid: true},
+ },
+ },
+ { // no repo_id set for log
+ failure: true,
+ log: &Log{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ ServiceID: sql.NullInt64{Int64: 1, Valid: true},
+ StepID: sql.NullInt64{Int64: 1, Valid: true},
+ },
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.log.Validate()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Validate should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Validate returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_LogFromAPI(t *testing.T) {
+ // setup types
+ l := new(api.Log)
+
+ l.SetID(1)
+ l.SetServiceID(1)
+ l.SetStepID(1)
+ l.SetBuildID(1)
+ l.SetRepoID(1)
+ l.SetData([]byte("foo"))
+
+ want := testLog()
+
+ // run test
+ got := LogFromAPI(l)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("LogFromAPI is %v, want %v", got, want)
+ }
+}
+
+// testLog is a test helper function to create a Log
+// type with all fields set to a fake value.
+func testLog() *Log {
+ return &Log{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ ServiceID: sql.NullInt64{Int64: 1, Valid: true},
+ StepID: sql.NullInt64{Int64: 1, Valid: true},
+ Data: []byte("foo"),
+ }
+}
diff --git a/database/types/pipeline_test.go b/database/types/pipeline_test.go
index 63648acdf..659e3fb9c 100644
--- a/database/types/pipeline_test.go
+++ b/database/types/pipeline_test.go
@@ -8,7 +8,7 @@ import (
"testing"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestDatabase_Pipeline_Compress(t *testing.T) {
diff --git a/database/types/repo.go b/database/types/repo.go
index 584d12923..e406c0c5c 100644
--- a/database/types/repo.go
+++ b/database/types/repo.go
@@ -10,8 +10,8 @@ import (
"github.com/lib/pq"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
var (
diff --git a/database/types/repo_test.go b/database/types/repo_test.go
index d41ca7f8b..949985490 100644
--- a/database/types/repo_test.go
+++ b/database/types/repo_test.go
@@ -10,8 +10,8 @@ import (
"github.com/google/go-cmp/cmp"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestTypes_Repo_Decrypt(t *testing.T) {
diff --git a/database/types/schedule_test.go b/database/types/schedule_test.go
index aa7ad21be..10b4da233 100644
--- a/database/types/schedule_test.go
+++ b/database/types/schedule_test.go
@@ -11,8 +11,8 @@ import (
"github.com/adhocore/gronx"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/testutils"
- "github.com/go-vela/types/constants"
)
func TestTypes_Schedule_Nullify(t *testing.T) {
diff --git a/database/types/secret.go b/database/types/secret.go
new file mode 100644
index 000000000..1d4dc130e
--- /dev/null
+++ b/database/types/secret.go
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "encoding/base64"
+ "errors"
+ "strings"
+
+ "github.com/lib/pq"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ "github.com/go-vela/server/util"
+)
+
+var (
+ // ErrEmptySecretName defines the error type when a
+ // Secret type has an empty Name field provided.
+ ErrEmptySecretName = errors.New("empty secret name provided")
+
+ // ErrEmptySecretOrg defines the error type when a
+ // Secret type has an empty Org field provided.
+ ErrEmptySecretOrg = errors.New("empty secret org provided")
+
+ // ErrEmptySecretRepo defines the error type when a
+ // Secret type has an empty Repo field provided.
+ ErrEmptySecretRepo = errors.New("empty secret repo provided")
+
+ // ErrEmptySecretTeam defines the error type when a
+ // Secret type has an empty Team field provided.
+ ErrEmptySecretTeam = errors.New("empty secret team provided")
+
+ // ErrEmptySecretType defines the error type when a
+ // Secret type has an empty Type field provided.
+ ErrEmptySecretType = errors.New("empty secret type provided")
+
+ // ErrEmptySecretValue defines the error type when a
+ // Secret type has an empty Value field provided.
+ ErrEmptySecretValue = errors.New("empty secret value provided")
+)
+
+// Secret is the database representation of a secret.
+type Secret struct {
+ ID sql.NullInt64 `sql:"id"`
+ Org sql.NullString `sql:"org"`
+ Repo sql.NullString `sql:"repo"`
+ Team sql.NullString `sql:"team"`
+ Name sql.NullString `sql:"name"`
+ Value sql.NullString `sql:"value"`
+ Type sql.NullString `sql:"type"`
+ Images pq.StringArray `sql:"images" gorm:"type:varchar(1000)"`
+ AllowEvents sql.NullInt64 `sql:"allow_events"`
+ AllowCommand sql.NullBool `sql:"allow_command"`
+ AllowSubstitution sql.NullBool `sql:"allow_substitution"`
+ CreatedAt sql.NullInt64 `sql:"created_at"`
+ CreatedBy sql.NullString `sql:"created_by"`
+ UpdatedAt sql.NullInt64 `sql:"updated_at"`
+ UpdatedBy sql.NullString `sql:"updated_by"`
+}
+
+// Decrypt will manipulate the existing secret value by
+// base64 decoding that value. Then, a AES-256 cipher
+// block is created from the encryption key in order to
+// decrypt the base64 decoded secret value.
+func (s *Secret) Decrypt(key string) error {
+ // base64 decode the encrypted secret value
+ decoded, err := base64.StdEncoding.DecodeString(s.Value.String)
+ if err != nil {
+ return err
+ }
+
+ // decrypt the base64 decoded secret value
+ decrypted, err := util.Decrypt(key, decoded)
+ if err != nil {
+ return err
+ }
+
+ // set the decrypted secret value
+ s.Value = sql.NullString{
+ String: string(decrypted),
+ Valid: true,
+ }
+
+ return nil
+}
+
+// Encrypt will manipulate the existing secret value by
+// creating a AES-256 cipher block from the encryption
+// key in order to encrypt the secret value. Then, the
+// secret value is base64 encoded for transport across
+// network boundaries.
+func (s *Secret) Encrypt(key string) error {
+ // encrypt the secret value
+ encrypted, err := util.Encrypt(key, []byte(s.Value.String))
+ if err != nil {
+ return err
+ }
+
+ // base64 encode the encrypted secret data to make it network safe
+ s.Value = sql.NullString{
+ String: base64.StdEncoding.EncodeToString(encrypted),
+ Valid: true,
+ }
+
+ return nil
+}
+
+// Nullify ensures the valid flag for
+// the sql.Null types are properly set.
+//
+// When a field within the Secret type is the zero
+// value for the field, the valid flag is set to
+// false causing it to be NULL in the database.
+func (s *Secret) Nullify() *Secret {
+ if s == nil {
+ return nil
+ }
+
+ // check if the ID field should be false
+ if s.ID.Int64 == 0 {
+ s.ID.Valid = false
+ }
+
+ // check if the Org field should be false
+ if len(s.Org.String) == 0 {
+ s.Org.Valid = false
+ }
+
+ // check if the Repo field should be false
+ if len(s.Repo.String) == 0 {
+ s.Repo.Valid = false
+ }
+
+ // check if the Team field should be false
+ if len(s.Team.String) == 0 {
+ s.Team.Valid = false
+ }
+
+ // check if the Name field should be false
+ if len(s.Name.String) == 0 {
+ s.Name.Valid = false
+ }
+
+ // check if the Value field should be false
+ if len(s.Value.String) == 0 {
+ s.Value.Valid = false
+ }
+
+ // check if the Value should be false
+ if len(s.Type.String) == 0 {
+ s.Type.Valid = false
+ }
+
+ // check if the AllowEvents field should be false
+ if s.AllowEvents.Int64 == 0 {
+ s.AllowEvents.Valid = false
+ }
+
+ // check if the CreatedAt field should be false
+ if s.CreatedAt.Int64 == 0 {
+ s.CreatedAt.Valid = false
+ }
+
+ // check if the CreatedBy field should be false
+ if len(s.CreatedBy.String) == 0 {
+ s.CreatedBy.Valid = false
+ }
+
+ // check if the UpdatedAt field should be false
+ if s.UpdatedAt.Int64 == 0 {
+ s.UpdatedAt.Valid = false
+ }
+
+ // check if the UpdatedBy field should be false
+ if len(s.UpdatedBy.String) == 0 {
+ s.UpdatedBy.Valid = false
+ }
+
+ return s
+}
+
+// ToAPI converts the Secret type
+// to a API Secret type.
+func (s *Secret) ToAPI() *api.Secret {
+ secret := new(api.Secret)
+
+ secret.SetID(s.ID.Int64)
+ secret.SetOrg(s.Org.String)
+ secret.SetRepo(s.Repo.String)
+ secret.SetTeam(s.Team.String)
+ secret.SetName(s.Name.String)
+ secret.SetValue(s.Value.String)
+ secret.SetType(s.Type.String)
+ secret.SetImages(s.Images)
+ secret.SetAllowEvents(api.NewEventsFromMask(s.AllowEvents.Int64))
+ secret.SetAllowCommand(s.AllowCommand.Bool)
+ secret.SetAllowSubstitution(s.AllowSubstitution.Bool)
+ secret.SetCreatedAt(s.CreatedAt.Int64)
+ secret.SetCreatedBy(s.CreatedBy.String)
+ secret.SetUpdatedAt(s.UpdatedAt.Int64)
+ secret.SetUpdatedBy(s.UpdatedBy.String)
+
+ return secret
+}
+
+// Validate verifies the necessary fields for
+// the Secret type are populated correctly.
+func (s *Secret) Validate() error {
+ // verify the Type field is populated
+ if len(s.Type.String) == 0 {
+ return ErrEmptySecretType
+ }
+
+ // verify the Org field is populated
+ if len(s.Org.String) == 0 {
+ return ErrEmptySecretOrg
+ }
+
+ // check if an org or repo secret
+ if strings.EqualFold(s.Type.String, constants.SecretRepo) ||
+ strings.EqualFold(s.Type.String, constants.SecretOrg) {
+ // verify the Repo field is populated
+ if len(s.Repo.String) == 0 {
+ return ErrEmptySecretRepo
+ }
+ }
+
+ // check if a shared secret
+ if strings.EqualFold(s.Type.String, constants.SecretShared) {
+ // verify the Team field is populated
+ if len(s.Team.String) == 0 {
+ return ErrEmptySecretTeam
+ }
+ }
+
+ // verify the Name field is populated
+ if len(s.Name.String) == 0 {
+ return ErrEmptySecretName
+ }
+
+ // verify the Value field is populated
+ if len(s.Value.String) == 0 {
+ return ErrEmptySecretValue
+ }
+
+ // ensure that all Secret string fields
+ // that can be returned as JSON are sanitized
+ // to avoid unsafe HTML content
+ s.Org = sql.NullString{String: util.Sanitize(s.Org.String), Valid: s.Org.Valid}
+ s.Repo = sql.NullString{String: util.Sanitize(s.Repo.String), Valid: s.Repo.Valid}
+ s.Team = sql.NullString{String: util.Sanitize(s.Team.String), Valid: s.Team.Valid}
+ s.Name = sql.NullString{String: util.Sanitize(s.Name.String), Valid: s.Name.Valid}
+ s.Type = sql.NullString{String: util.Sanitize(s.Type.String), Valid: s.Type.Valid}
+
+ // ensure that all Images are sanitized
+ // to avoid unsafe HTML content
+ for i, v := range s.Images {
+ s.Images[i] = util.Sanitize(v)
+ }
+
+ return nil
+}
+
+// SecretFromAPI converts the API Secret type
+// to a database Secret type.
+func SecretFromAPI(s *api.Secret) *Secret {
+ secret := &Secret{
+ ID: sql.NullInt64{Int64: s.GetID(), Valid: true},
+ Org: sql.NullString{String: s.GetOrg(), Valid: true},
+ Repo: sql.NullString{String: s.GetRepo(), Valid: true},
+ Team: sql.NullString{String: s.GetTeam(), Valid: true},
+ Name: sql.NullString{String: s.GetName(), Valid: true},
+ Value: sql.NullString{String: s.GetValue(), Valid: true},
+ Type: sql.NullString{String: s.GetType(), Valid: true},
+ Images: pq.StringArray(s.GetImages()),
+ AllowEvents: sql.NullInt64{Int64: s.GetAllowEvents().ToDatabase(), Valid: true},
+ AllowCommand: sql.NullBool{Bool: s.GetAllowCommand(), Valid: true},
+ AllowSubstitution: sql.NullBool{Bool: s.GetAllowSubstitution(), Valid: true},
+ CreatedAt: sql.NullInt64{Int64: s.GetCreatedAt(), Valid: true},
+ CreatedBy: sql.NullString{String: s.GetCreatedBy(), Valid: true},
+ UpdatedAt: sql.NullInt64{Int64: s.GetUpdatedAt(), Valid: true},
+ UpdatedBy: sql.NullString{String: s.GetUpdatedBy(), Valid: true},
+ }
+
+ return secret.Nullify()
+}
diff --git a/database/types/secret_test.go b/database/types/secret_test.go
new file mode 100644
index 000000000..8ff5a55d5
--- /dev/null
+++ b/database/types/secret_test.go
@@ -0,0 +1,333 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "reflect"
+ "testing"
+ "time"
+
+ api "github.com/go-vela/server/api/types"
+)
+
+var (
+ currentTime = time.Now()
+ tsCreate = currentTime.UTC().Unix()
+ tsUpdate = currentTime.Add(time.Hour * 1).UTC().Unix()
+)
+
+func TestDatabase_Secret_Decrypt(t *testing.T) {
+ // setup types
+ key := "C639A572E14D5075C526FDDD43E4ECF6"
+ encrypted := testSecret()
+
+ err := encrypted.Encrypt(key)
+ if err != nil {
+ t.Errorf("unable to encrypt secret: %v", err)
+ }
+
+ // setup tests
+ tests := []struct {
+ failure bool
+ key string
+ secret Secret
+ }{
+ {
+ failure: false,
+ key: key,
+ secret: *encrypted,
+ },
+ {
+ failure: true,
+ key: "",
+ secret: *encrypted,
+ },
+ {
+ failure: true,
+ key: key,
+ secret: *testSecret(),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.secret.Decrypt(test.key)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Decrypt should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Decrypt returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_Secret_Encrypt(t *testing.T) {
+ // setup types
+ key := "C639A572E14D5075C526FDDD43E4ECF6"
+
+ // setup tests
+ tests := []struct {
+ failure bool
+ key string
+ secret *Secret
+ }{
+ {
+ failure: false,
+ key: key,
+ secret: testSecret(),
+ },
+ {
+ failure: true,
+ key: "",
+ secret: testSecret(),
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.secret.Encrypt(test.key)
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Encrypt should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Encrypt returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_Secret_Nullify(t *testing.T) {
+ // setup types
+ var s *Secret
+
+ want := &Secret{
+ ID: sql.NullInt64{Int64: 0, Valid: false},
+ Org: sql.NullString{String: "", Valid: false},
+ Repo: sql.NullString{String: "", Valid: false},
+ Team: sql.NullString{String: "", Valid: false},
+ Name: sql.NullString{String: "", Valid: false},
+ Value: sql.NullString{String: "", Valid: false},
+ Type: sql.NullString{String: "", Valid: false},
+ AllowEvents: sql.NullInt64{Int64: 0, Valid: false},
+ CreatedAt: sql.NullInt64{Int64: 0, Valid: false},
+ CreatedBy: sql.NullString{String: "", Valid: false},
+ UpdatedAt: sql.NullInt64{Int64: 0, Valid: false},
+ UpdatedBy: sql.NullString{String: "", Valid: false},
+ }
+
+ // setup tests
+ tests := []struct {
+ secret *Secret
+ want *Secret
+ }{
+ {
+ secret: testSecret(),
+ want: testSecret(),
+ },
+ {
+ secret: s,
+ want: nil,
+ },
+ {
+ secret: new(Secret),
+ want: want,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.secret.Nullify()
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("Nullify is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestDatabase_Secret_ToAPI(t *testing.T) {
+ // setup types
+ want := new(api.Secret)
+
+ want.SetID(1)
+ want.SetOrg("github")
+ want.SetRepo("octocat")
+ want.SetTeam("octokitties")
+ want.SetName("foo")
+ want.SetValue("bar")
+ want.SetType("repo")
+ want.SetImages([]string{"alpine"})
+ want.SetAllowEvents(api.NewEventsFromMask(1))
+ want.SetAllowCommand(true)
+ want.SetAllowSubstitution(true)
+ want.SetCreatedAt(tsCreate)
+ want.SetCreatedBy("octocat")
+ want.SetUpdatedAt(tsUpdate)
+ want.SetUpdatedBy("octocat2")
+
+ // run test
+ got := testSecret().ToAPI()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ToAPI is %v, want %v", got, want)
+ }
+}
+
+func TestDatabase_Secret_Validate(t *testing.T) {
+ // setup types
+ tests := []struct {
+ failure bool
+ secret *Secret
+ }{
+ {
+ failure: false,
+ secret: testSecret(),
+ },
+ { // no name set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ Type: sql.NullString{String: "repo", Valid: true},
+ },
+ },
+ { // no org set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ Type: sql.NullString{String: "repo", Valid: true},
+ },
+ },
+ { // no repo set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ Type: sql.NullString{String: "repo", Valid: true},
+ },
+ },
+ { // no team set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ Type: sql.NullString{String: "shared", Valid: true},
+ },
+ },
+ { // no type set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ },
+ },
+ { // no value set for secret
+ failure: true,
+ secret: &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Type: sql.NullString{String: "repo", Valid: true},
+ },
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.secret.Validate()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Validate should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Validate returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_SecretFromAPI(t *testing.T) {
+ // setup types
+ s := new(api.Secret)
+
+ s.SetID(1)
+ s.SetOrg("github")
+ s.SetRepo("octocat")
+ s.SetTeam("octokitties")
+ s.SetName("foo")
+ s.SetValue("bar")
+ s.SetType("repo")
+ s.SetImages([]string{"alpine"})
+ s.SetAllowEvents(api.NewEventsFromMask(1))
+ s.SetAllowCommand(true)
+ s.SetAllowSubstitution(true)
+ s.SetCreatedAt(tsCreate)
+ s.SetCreatedBy("octocat")
+ s.SetUpdatedAt(tsUpdate)
+ s.SetUpdatedBy("octocat2")
+
+ want := testSecret()
+
+ // run test
+ got := SecretFromAPI(s)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("SecretFromAPI is %v, want %v", got, want)
+ }
+}
+
+// testSecret is a test helper function to create a Secret
+// type with all fields set to a fake value.
+func testSecret() *Secret {
+ return &Secret{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ Org: sql.NullString{String: "github", Valid: true},
+ Repo: sql.NullString{String: "octocat", Valid: true},
+ Team: sql.NullString{String: "octokitties", Valid: true},
+ Name: sql.NullString{String: "foo", Valid: true},
+ Value: sql.NullString{String: "bar", Valid: true},
+ Type: sql.NullString{String: "repo", Valid: true},
+ Images: []string{"alpine"},
+ AllowEvents: sql.NullInt64{Int64: 1, Valid: true},
+ AllowCommand: sql.NullBool{Bool: true, Valid: true},
+ AllowSubstitution: sql.NullBool{Bool: true, Valid: true},
+ CreatedAt: sql.NullInt64{Int64: tsCreate, Valid: true},
+ CreatedBy: sql.NullString{String: "octocat", Valid: true},
+ UpdatedAt: sql.NullInt64{Int64: tsUpdate, Valid: true},
+ UpdatedBy: sql.NullString{String: "octocat2", Valid: true},
+ }
+}
diff --git a/database/types/service.go b/database/types/service.go
new file mode 100644
index 000000000..f3b508ed6
--- /dev/null
+++ b/database/types/service.go
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "errors"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/util"
+)
+
+var (
+ // ErrEmptyServiceBuildID defines the error type when a
+ // Service type has an empty BuildID field provided.
+ ErrEmptyServiceBuildID = errors.New("empty service build_id provided")
+
+ // ErrEmptyServiceName defines the error type when a
+ // Service type has an empty Name field provided.
+ ErrEmptyServiceName = errors.New("empty service name provided")
+
+ // ErrEmptyServiceImage defines the error type when a
+ // Service type has an empty Image field provided.
+ ErrEmptyServiceImage = errors.New("empty service image provided")
+
+ // ErrEmptyServiceNumber defines the error type when a
+ // Service type has an empty Number field provided.
+ ErrEmptyServiceNumber = errors.New("empty service number provided")
+
+ // ErrEmptyServiceRepoID defines the error type when a
+ // Service type has an empty RepoID field provided.
+ ErrEmptyServiceRepoID = errors.New("empty service repo_id provided")
+)
+
+// Service is the database representation of a service in a build.
+type Service struct {
+ ID sql.NullInt64 `sql:"id"`
+ BuildID sql.NullInt64 `sql:"build_id"`
+ RepoID sql.NullInt64 `sql:"repo_id"`
+ Number sql.NullInt32 `sql:"number"`
+ Name sql.NullString `sql:"name"`
+ Image sql.NullString `sql:"image"`
+ Status sql.NullString `sql:"status"`
+ Error sql.NullString `sql:"error"`
+ ExitCode sql.NullInt32 `sql:"exit_code"`
+ Created sql.NullInt64 `sql:"created"`
+ Started sql.NullInt64 `sql:"started"`
+ Finished sql.NullInt64 `sql:"finished"`
+ Host sql.NullString `sql:"host"`
+ Runtime sql.NullString `sql:"runtime"`
+ Distribution sql.NullString `sql:"distribution"`
+}
+
+// Nullify ensures the valid flag for
+// the sql.Null types are properly set.
+//
+// When a field within the Service type is the zero
+// value for the field, the valid flag is set to
+// false causing it to be NULL in the database.
+func (s *Service) Nullify() *Service {
+ if s == nil {
+ return nil
+ }
+
+ // check if the ID field should be false
+ if s.ID.Int64 == 0 {
+ s.ID.Valid = false
+ }
+
+ // check if the BuildID field should be false
+ if s.BuildID.Int64 == 0 {
+ s.BuildID.Valid = false
+ }
+
+ // check if the RepoID field should be false
+ if s.RepoID.Int64 == 0 {
+ s.RepoID.Valid = false
+ }
+
+ // check if the Number field should be false
+ if s.Number.Int32 == 0 {
+ s.Number.Valid = false
+ }
+
+ // check if the Name field should be false
+ if len(s.Name.String) == 0 {
+ s.Name.Valid = false
+ }
+
+ // check if the Image field should be false
+ if len(s.Image.String) == 0 {
+ s.Image.Valid = false
+ }
+
+ // check if the Status field should be false
+ if len(s.Status.String) == 0 {
+ s.Status.Valid = false
+ }
+
+ // check if the Error field should be false
+ if len(s.Error.String) == 0 {
+ s.Error.Valid = false
+ }
+
+ // check if the ExitCode field should be false
+ if s.ExitCode.Int32 == 0 {
+ s.ExitCode.Valid = false
+ }
+
+ // check if Created field should be false
+ if s.Created.Int64 == 0 {
+ s.Created.Valid = false
+ }
+
+ // check if Started field should be false
+ if s.Started.Int64 == 0 {
+ s.Started.Valid = false
+ }
+
+ // check if Finished field should be false
+ if s.Finished.Int64 == 0 {
+ s.Finished.Valid = false
+ }
+
+ // check if the Host field should be false
+ if len(s.Host.String) == 0 {
+ s.Host.Valid = false
+ }
+
+ // check if the Runtime field should be false
+ if len(s.Runtime.String) == 0 {
+ s.Runtime.Valid = false
+ }
+
+ // check if the Distribution field should be false
+ if len(s.Distribution.String) == 0 {
+ s.Distribution.Valid = false
+ }
+
+ return s
+}
+
+// ToAPI converts the Service type
+// to a API Service type.
+func (s *Service) ToAPI() *api.Service {
+ service := new(api.Service)
+
+ service.SetID(s.ID.Int64)
+ service.SetBuildID(s.BuildID.Int64)
+ service.SetRepoID(s.RepoID.Int64)
+ service.SetNumber(int(s.Number.Int32))
+ service.SetName(s.Name.String)
+ service.SetImage(s.Image.String)
+ service.SetStatus(s.Status.String)
+ service.SetError(s.Error.String)
+ service.SetExitCode(int(s.ExitCode.Int32))
+ service.SetCreated(s.Created.Int64)
+ service.SetStarted(s.Started.Int64)
+ service.SetFinished(s.Finished.Int64)
+ service.SetHost(s.Host.String)
+ service.SetRuntime(s.Runtime.String)
+ service.SetDistribution(s.Distribution.String)
+
+ return service
+}
+
+// Validate verifies the necessary fields for
+// the Service type are populated correctly.
+func (s *Service) Validate() error {
+ // verify the BuildID field is populated
+ if s.BuildID.Int64 <= 0 {
+ return ErrEmptyServiceBuildID
+ }
+
+ // verify the RepoID field is populated
+ if s.RepoID.Int64 <= 0 {
+ return ErrEmptyServiceRepoID
+ }
+
+ // verify the Number field is populated
+ if s.Number.Int32 <= 0 {
+ return ErrEmptyServiceNumber
+ }
+
+ // verify the Name field is populated
+ if len(s.Name.String) == 0 {
+ return ErrEmptyServiceName
+ }
+
+ // verify the Image field is populated
+ if len(s.Image.String) == 0 {
+ return ErrEmptyServiceImage
+ }
+
+ // ensure that all Service string fields
+ // that can be returned as JSON are sanitized
+ // to avoid unsafe HTML content
+ s.Name = sql.NullString{String: util.Sanitize(s.Name.String), Valid: s.Name.Valid}
+ s.Image = sql.NullString{String: util.Sanitize(s.Image.String), Valid: s.Image.Valid}
+ s.Status = sql.NullString{String: util.Sanitize(s.Status.String), Valid: s.Status.Valid}
+ s.Error = sql.NullString{String: util.Sanitize(s.Error.String), Valid: s.Error.Valid}
+ s.Host = sql.NullString{String: util.Sanitize(s.Host.String), Valid: s.Host.Valid}
+ s.Runtime = sql.NullString{String: util.Sanitize(s.Runtime.String), Valid: s.Runtime.Valid}
+ s.Distribution = sql.NullString{String: util.Sanitize(s.Distribution.String), Valid: s.Distribution.Valid}
+
+ return nil
+}
+
+// ServiceFromAPI converts the API Service type
+// to a database Service type.
+func ServiceFromAPI(s *api.Service) *Service {
+ service := &Service{
+ ID: sql.NullInt64{Int64: s.GetID(), Valid: true},
+ BuildID: sql.NullInt64{Int64: s.GetBuildID(), Valid: true},
+ RepoID: sql.NullInt64{Int64: s.GetRepoID(), Valid: true},
+ Number: sql.NullInt32{Int32: int32(s.GetNumber()), Valid: true},
+ Name: sql.NullString{String: s.GetName(), Valid: true},
+ Image: sql.NullString{String: s.GetImage(), Valid: true},
+ Status: sql.NullString{String: s.GetStatus(), Valid: true},
+ Error: sql.NullString{String: s.GetError(), Valid: true},
+ ExitCode: sql.NullInt32{Int32: int32(s.GetExitCode()), Valid: true},
+ Created: sql.NullInt64{Int64: s.GetCreated(), Valid: true},
+ Started: sql.NullInt64{Int64: s.GetStarted(), Valid: true},
+ Finished: sql.NullInt64{Int64: s.GetFinished(), Valid: true},
+ Host: sql.NullString{String: s.GetHost(), Valid: true},
+ Runtime: sql.NullString{String: s.GetRuntime(), Valid: true},
+ Distribution: sql.NullString{String: s.GetDistribution(), Valid: true},
+ }
+
+ return service.Nullify()
+}
diff --git a/database/types/service_test.go b/database/types/service_test.go
new file mode 100644
index 000000000..ce39d90db
--- /dev/null
+++ b/database/types/service_test.go
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "reflect"
+ "testing"
+
+ api "github.com/go-vela/server/api/types"
+)
+
+func TestDatabase_Service_Nullify(t *testing.T) {
+ // setup types
+ var s *Service
+
+ want := &Service{
+ ID: sql.NullInt64{Int64: 0, Valid: false},
+ BuildID: sql.NullInt64{Int64: 0, Valid: false},
+ RepoID: sql.NullInt64{Int64: 0, Valid: false},
+ Number: sql.NullInt32{Int32: 0, Valid: false},
+ Name: sql.NullString{String: "", Valid: false},
+ Image: sql.NullString{String: "", Valid: false},
+ Status: sql.NullString{String: "", Valid: false},
+ Error: sql.NullString{String: "", Valid: false},
+ ExitCode: sql.NullInt32{Int32: 0, Valid: false},
+ Created: sql.NullInt64{Int64: 0, Valid: false},
+ Started: sql.NullInt64{Int64: 0, Valid: false},
+ Finished: sql.NullInt64{Int64: 0, Valid: false},
+ Host: sql.NullString{String: "", Valid: false},
+ Runtime: sql.NullString{String: "", Valid: false},
+ Distribution: sql.NullString{String: "", Valid: false},
+ }
+
+ // setup tests
+ tests := []struct {
+ service *Service
+ want *Service
+ }{
+ {
+ service: testService(),
+ want: testService(),
+ },
+ {
+ service: s,
+ want: nil,
+ },
+ {
+ service: new(Service),
+ want: want,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.service.Nullify()
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("Nullify is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestDatabase_Service_ToAPI(t *testing.T) {
+ // setup types
+ want := new(api.Service)
+
+ want.SetID(1)
+ want.SetBuildID(1)
+ want.SetRepoID(1)
+ want.SetNumber(1)
+ want.SetName("postgres")
+ want.SetImage("postgres:12-alpine")
+ want.SetStatus("running")
+ want.SetError("")
+ want.SetExitCode(0)
+ want.SetCreated(1563474076)
+ want.SetStarted(1563474078)
+ want.SetFinished(1563474079)
+ want.SetHost("example.company.com")
+ want.SetRuntime("docker")
+ want.SetDistribution("linux")
+
+ // run test
+ got := testService().ToAPI()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ToAPI is %v, want %v", got, want)
+ }
+}
+
+func TestDatabase_Service_Validate(t *testing.T) {
+ tests := []struct {
+ failure bool
+ service *Service
+ }{
+ {
+ failure: false,
+ service: testService(),
+ },
+ { // no build_id set for service
+ failure: true,
+ service: &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "postgres", Valid: true},
+ Image: sql.NullString{String: "postgres:12-alpine", Valid: true},
+ },
+ },
+ { // no repo_id set for service
+ failure: true,
+ service: &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "postgres", Valid: true},
+ Image: sql.NullString{String: "postgres:12-alpine", Valid: true},
+ },
+ },
+ { // no number set for service
+ failure: true,
+ service: &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Name: sql.NullString{String: "postgres", Valid: true},
+ Image: sql.NullString{String: "postgres:12-alpine", Valid: true},
+ },
+ },
+ { // no name set for service
+ failure: true,
+ service: &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Image: sql.NullString{String: "postgres:12-alpine", Valid: true},
+ },
+ },
+ { // no image set for service
+ failure: true,
+ service: &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "postgres", Valid: true},
+ },
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.service.Validate()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Validate should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Validate returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_ServiceFromAPI(t *testing.T) {
+ // setup types
+ s := new(api.Service)
+
+ s.SetID(1)
+ s.SetBuildID(1)
+ s.SetRepoID(1)
+ s.SetNumber(1)
+ s.SetName("postgres")
+ s.SetImage("postgres:12-alpine")
+ s.SetStatus("running")
+ s.SetError("")
+ s.SetExitCode(0)
+ s.SetCreated(1563474076)
+ s.SetStarted(1563474078)
+ s.SetFinished(1563474079)
+ s.SetHost("example.company.com")
+ s.SetRuntime("docker")
+ s.SetDistribution("linux")
+
+ want := testService()
+
+ // run test
+ got := ServiceFromAPI(s)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ServiceFromAPI is %v, want %v", got, want)
+ }
+}
+
+// testService is a test helper function to create a Service
+// type with all fields set to a fake value.
+func testService() *Service {
+ return &Service{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "postgres", Valid: true},
+ Image: sql.NullString{String: "postgres:12-alpine", Valid: true},
+ Status: sql.NullString{String: "running", Valid: true},
+ Error: sql.NullString{String: "", Valid: false},
+ ExitCode: sql.NullInt32{Int32: 0, Valid: false},
+ Created: sql.NullInt64{Int64: 1563474076, Valid: true},
+ Started: sql.NullInt64{Int64: 1563474078, Valid: true},
+ Finished: sql.NullInt64{Int64: 1563474079, Valid: true},
+ Host: sql.NullString{String: "example.company.com", Valid: true},
+ Runtime: sql.NullString{String: "docker", Valid: true},
+ Distribution: sql.NullString{String: "linux", Valid: true},
+ }
+}
diff --git a/database/types/step.go b/database/types/step.go
new file mode 100644
index 000000000..4bd09c0b5
--- /dev/null
+++ b/database/types/step.go
@@ -0,0 +1,249 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "errors"
+
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/util"
+)
+
+var (
+ // ErrEmptyStepBuildID defines the error type when a
+ // Step type has an empty BuildID field provided.
+ ErrEmptyStepBuildID = errors.New("empty step build_id provided")
+
+ // ErrEmptyStepName defines the error type when a
+ // Step type has an empty Name field provided.
+ ErrEmptyStepName = errors.New("empty step name provided")
+
+ // ErrEmptyStepImage defines the error type when a
+ // Step type has an empty Image field provided.
+ ErrEmptyStepImage = errors.New("empty step image provided")
+
+ // ErrEmptyStepNumber defines the error type when a
+ // Step type has an empty Number field provided.
+ ErrEmptyStepNumber = errors.New("empty step number provided")
+
+ // ErrEmptyStepRepoID defines the error type when a
+ // Step type has an empty RepoID field provided.
+ ErrEmptyStepRepoID = errors.New("empty step repo_id provided")
+)
+
+// Step is the database representation of a step in a build.
+type Step struct {
+ ID sql.NullInt64 `sql:"id"`
+ BuildID sql.NullInt64 `sql:"build_id"`
+ RepoID sql.NullInt64 `sql:"repo_id"`
+ Number sql.NullInt32 `sql:"number"`
+ Name sql.NullString `sql:"name"`
+ Image sql.NullString `sql:"image"`
+ Stage sql.NullString `sql:"stage"`
+ Status sql.NullString `sql:"status"`
+ Error sql.NullString `sql:"error"`
+ ExitCode sql.NullInt32 `sql:"exit_code"`
+ Created sql.NullInt64 `sql:"created"`
+ Started sql.NullInt64 `sql:"started"`
+ Finished sql.NullInt64 `sql:"finished"`
+ Host sql.NullString `sql:"host"`
+ Runtime sql.NullString `sql:"runtime"`
+ Distribution sql.NullString `sql:"distribution"`
+ ReportAs sql.NullString `sql:"report_as"`
+}
+
+// Nullify ensures the valid flag for
+// the sql.Null types are properly set.
+//
+// When a field within the Step type is the zero
+// value for the field, the valid flag is set to
+// false causing it to be NULL in the database.
+func (s *Step) Nullify() *Step {
+ if s == nil {
+ return nil
+ }
+
+ // check if the ID field should be false
+ if s.ID.Int64 == 0 {
+ s.ID.Valid = false
+ }
+
+ // check if the BuildID field should be false
+ if s.BuildID.Int64 == 0 {
+ s.BuildID.Valid = false
+ }
+
+ // check if the RepoID field should be false
+ if s.RepoID.Int64 == 0 {
+ s.RepoID.Valid = false
+ }
+
+ // check if the Number field should be false
+ if s.Number.Int32 == 0 {
+ s.Number.Valid = false
+ }
+
+ // check if the Name field should be false
+ if len(s.Name.String) == 0 {
+ s.Name.Valid = false
+ }
+
+ // check if the Image field should be false
+ if len(s.Image.String) == 0 {
+ s.Image.Valid = false
+ }
+
+ // check if the Stage field should be false
+ if len(s.Stage.String) == 0 {
+ s.Stage.Valid = false
+ }
+
+ // check if the Status field should be false
+ if len(s.Status.String) == 0 {
+ s.Status.Valid = false
+ }
+
+ // check if the Error field should be false
+ if len(s.Error.String) == 0 {
+ s.Error.Valid = false
+ }
+
+ // check if the ExitCode field should be false
+ if s.ExitCode.Int32 == 0 {
+ s.ExitCode.Valid = false
+ }
+
+ // check if Created field should be false
+ if s.Created.Int64 == 0 {
+ s.Created.Valid = false
+ }
+
+ // check if Started field should be false
+ if s.Started.Int64 == 0 {
+ s.Started.Valid = false
+ }
+
+ // check if Finished field should be false
+ if s.Finished.Int64 == 0 {
+ s.Finished.Valid = false
+ }
+
+ // check if the Host field should be false
+ if len(s.Host.String) == 0 {
+ s.Host.Valid = false
+ }
+
+ // check if the Runtime field should be false
+ if len(s.Runtime.String) == 0 {
+ s.Runtime.Valid = false
+ }
+
+ // check if the Distribution field should be false
+ if len(s.Distribution.String) == 0 {
+ s.Distribution.Valid = false
+ }
+
+ // check if the ReportAs field should be false
+ if len(s.ReportAs.String) == 0 {
+ s.ReportAs.Valid = false
+ }
+
+ return s
+}
+
+// ToAPI converts the Step type
+// to a API Step type.
+func (s *Step) ToAPI() *api.Step {
+ step := new(api.Step)
+
+ step.SetID(s.ID.Int64)
+ step.SetBuildID(s.BuildID.Int64)
+ step.SetRepoID(s.RepoID.Int64)
+ step.SetNumber(int(s.Number.Int32))
+ step.SetName(s.Name.String)
+ step.SetImage(s.Image.String)
+ step.SetStage(s.Stage.String)
+ step.SetStatus(s.Status.String)
+ step.SetError(s.Error.String)
+ step.SetExitCode(int(s.ExitCode.Int32))
+ step.SetCreated(s.Created.Int64)
+ step.SetStarted(s.Started.Int64)
+ step.SetFinished(s.Finished.Int64)
+ step.SetHost(s.Host.String)
+ step.SetRuntime(s.Runtime.String)
+ step.SetDistribution(s.Distribution.String)
+ step.SetReportAs(s.ReportAs.String)
+
+ return step
+}
+
+// Validate verifies the necessary fields for
+// the Step type are populated correctly.
+func (s *Step) Validate() error {
+ // verify the BuildID field is populated
+ if s.BuildID.Int64 <= 0 {
+ return ErrEmptyStepBuildID
+ }
+
+ // verify the RepoID field is populated
+ if s.RepoID.Int64 <= 0 {
+ return ErrEmptyStepRepoID
+ }
+
+ // verify the Number field is populated
+ if s.Number.Int32 <= 0 {
+ return ErrEmptyStepNumber
+ }
+
+ // verify the Name field is populated
+ if len(s.Name.String) == 0 {
+ return ErrEmptyStepName
+ }
+
+ // verify the Image field is populated
+ if len(s.Image.String) == 0 {
+ return ErrEmptyStepImage
+ }
+
+ // ensure that all Step string fields
+ // that can be returned as JSON are sanitized
+ // to avoid unsafe HTML content
+ s.Name = sql.NullString{String: util.Sanitize(s.Name.String), Valid: s.Name.Valid}
+ s.Image = sql.NullString{String: util.Sanitize(s.Image.String), Valid: s.Image.Valid}
+ s.Stage = sql.NullString{String: util.Sanitize(s.Stage.String), Valid: s.Stage.Valid}
+ s.Status = sql.NullString{String: util.Sanitize(s.Status.String), Valid: s.Status.Valid}
+ s.Error = sql.NullString{String: util.Sanitize(s.Error.String), Valid: s.Error.Valid}
+ s.Host = sql.NullString{String: util.Sanitize(s.Host.String), Valid: s.Host.Valid}
+ s.Runtime = sql.NullString{String: util.Sanitize(s.Runtime.String), Valid: s.Runtime.Valid}
+ s.Distribution = sql.NullString{String: util.Sanitize(s.Distribution.String), Valid: s.Distribution.Valid}
+ s.ReportAs = sql.NullString{String: util.Sanitize(s.ReportAs.String), Valid: s.ReportAs.Valid}
+
+ return nil
+}
+
+// StepFromAPI converts the API Step type
+// to a database Step type.
+func StepFromAPI(s *api.Step) *Step {
+ step := &Step{
+ ID: sql.NullInt64{Int64: s.GetID(), Valid: true},
+ BuildID: sql.NullInt64{Int64: s.GetBuildID(), Valid: true},
+ RepoID: sql.NullInt64{Int64: s.GetRepoID(), Valid: true},
+ Number: sql.NullInt32{Int32: int32(s.GetNumber()), Valid: true},
+ Name: sql.NullString{String: s.GetName(), Valid: true},
+ Image: sql.NullString{String: s.GetImage(), Valid: true},
+ Stage: sql.NullString{String: s.GetStage(), Valid: true},
+ Status: sql.NullString{String: s.GetStatus(), Valid: true},
+ Error: sql.NullString{String: s.GetError(), Valid: true},
+ ExitCode: sql.NullInt32{Int32: int32(s.GetExitCode()), Valid: true},
+ Created: sql.NullInt64{Int64: s.GetCreated(), Valid: true},
+ Started: sql.NullInt64{Int64: s.GetStarted(), Valid: true},
+ Finished: sql.NullInt64{Int64: s.GetFinished(), Valid: true},
+ Host: sql.NullString{String: s.GetHost(), Valid: true},
+ Runtime: sql.NullString{String: s.GetRuntime(), Valid: true},
+ Distribution: sql.NullString{String: s.GetDistribution(), Valid: true},
+ ReportAs: sql.NullString{String: s.GetReportAs(), Valid: true},
+ }
+
+ return step.Nullify()
+}
diff --git a/database/types/step_test.go b/database/types/step_test.go
new file mode 100644
index 000000000..d2614effe
--- /dev/null
+++ b/database/types/step_test.go
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package types
+
+import (
+ "database/sql"
+ "reflect"
+ "testing"
+
+ api "github.com/go-vela/server/api/types"
+)
+
+func TestDatabase_Step_Nullify(t *testing.T) {
+ // setup types
+ var s *Step
+
+ want := &Step{
+ ID: sql.NullInt64{Int64: 0, Valid: false},
+ BuildID: sql.NullInt64{Int64: 0, Valid: false},
+ RepoID: sql.NullInt64{Int64: 0, Valid: false},
+ Number: sql.NullInt32{Int32: 0, Valid: false},
+ Name: sql.NullString{String: "", Valid: false},
+ Image: sql.NullString{String: "", Valid: false},
+ Stage: sql.NullString{String: "", Valid: false},
+ Status: sql.NullString{String: "", Valid: false},
+ Error: sql.NullString{String: "", Valid: false},
+ ExitCode: sql.NullInt32{Int32: 0, Valid: false},
+ Created: sql.NullInt64{Int64: 0, Valid: false},
+ Started: sql.NullInt64{Int64: 0, Valid: false},
+ Finished: sql.NullInt64{Int64: 0, Valid: false},
+ Host: sql.NullString{String: "", Valid: false},
+ Runtime: sql.NullString{String: "", Valid: false},
+ Distribution: sql.NullString{String: "", Valid: false},
+ ReportAs: sql.NullString{String: "", Valid: false},
+ }
+
+ // setup tests
+ tests := []struct {
+ step *Step
+ want *Step
+ }{
+ {
+ step: testStep(),
+ want: testStep(),
+ },
+ {
+ step: s,
+ want: nil,
+ },
+ {
+ step: new(Step),
+ want: want,
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ got := test.step.Nullify()
+
+ if !reflect.DeepEqual(got, test.want) {
+ t.Errorf("Nullify is %v, want %v", got, test.want)
+ }
+ }
+}
+
+func TestDatabase_Step_ToAPI(t *testing.T) {
+ // setup types
+ want := new(api.Step)
+
+ want.SetID(1)
+ want.SetBuildID(1)
+ want.SetRepoID(1)
+ want.SetNumber(1)
+ want.SetName("clone")
+ want.SetImage("target/vela-git:v0.3.0")
+ want.SetStage("")
+ want.SetStatus("running")
+ want.SetError("")
+ want.SetExitCode(0)
+ want.SetCreated(1563474076)
+ want.SetStarted(1563474078)
+ want.SetFinished(1563474079)
+ want.SetHost("example.company.com")
+ want.SetRuntime("docker")
+ want.SetDistribution("linux")
+ want.SetReportAs("test")
+
+ // run test
+ got := testStep().ToAPI()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("ToAPI is %v, want %v", got, want)
+ }
+}
+
+func TestDatabase_Step_Validate(t *testing.T) {
+ // setup types
+ tests := []struct {
+ failure bool
+ step *Step
+ }{
+ {
+ failure: false,
+ step: testStep(),
+ },
+ { // no build_id set for step
+ failure: true,
+ step: &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "clone", Valid: true},
+ Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true},
+ },
+ },
+ { // no repo_id set for step
+ failure: true,
+ step: &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "clone", Valid: true},
+ Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true},
+ },
+ },
+ { // no name set for step
+ failure: true,
+ step: &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true},
+ },
+ },
+ { // no number set for step
+ failure: true,
+ step: &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Name: sql.NullString{String: "clone", Valid: true},
+ Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true},
+ },
+ },
+ { // no image set for step
+ failure: true,
+ step: &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "clone", Valid: true},
+ },
+ },
+ }
+
+ // run tests
+ for _, test := range tests {
+ err := test.step.Validate()
+
+ if test.failure {
+ if err == nil {
+ t.Errorf("Validate should have returned err")
+ }
+
+ continue
+ }
+
+ if err != nil {
+ t.Errorf("Validate returned err: %v", err)
+ }
+ }
+}
+
+func TestDatabase_StepFromAPI(t *testing.T) {
+ // setup types
+ s := new(api.Step)
+
+ s.SetID(1)
+ s.SetBuildID(1)
+ s.SetRepoID(1)
+ s.SetNumber(1)
+ s.SetName("clone")
+ s.SetImage("target/vela-git:v0.3.0")
+ s.SetStage("")
+ s.SetStatus("running")
+ s.SetError("")
+ s.SetExitCode(0)
+ s.SetCreated(1563474076)
+ s.SetStarted(1563474078)
+ s.SetFinished(1563474079)
+ s.SetHost("example.company.com")
+ s.SetRuntime("docker")
+ s.SetDistribution("linux")
+ s.SetReportAs("test")
+
+ want := testStep()
+
+ // run test
+ got := StepFromAPI(s)
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("StepFromAPI is %v, want %v", got, want)
+ }
+}
+
+// testStep is a test helper function to create a Step
+// type with all fields set to a fake value.
+func testStep() *Step {
+ return &Step{
+ ID: sql.NullInt64{Int64: 1, Valid: true},
+ BuildID: sql.NullInt64{Int64: 1, Valid: true},
+ RepoID: sql.NullInt64{Int64: 1, Valid: true},
+ Number: sql.NullInt32{Int32: 1, Valid: true},
+ Name: sql.NullString{String: "clone", Valid: true},
+ Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true},
+ Stage: sql.NullString{String: "", Valid: false},
+ Status: sql.NullString{String: "running", Valid: true},
+ Error: sql.NullString{String: "", Valid: false},
+ ExitCode: sql.NullInt32{Int32: 0, Valid: false},
+ Created: sql.NullInt64{Int64: 1563474076, Valid: true},
+ Started: sql.NullInt64{Int64: 1563474078, Valid: true},
+ Finished: sql.NullInt64{Int64: 1563474079, Valid: true},
+ Host: sql.NullString{String: "example.company.com", Valid: true},
+ Runtime: sql.NullString{String: "docker", Valid: true},
+ Distribution: sql.NullString{String: "linux", Valid: true},
+ ReportAs: sql.NullString{String: "test", Valid: true},
+ }
+}
diff --git a/database/types/worker.go b/database/types/worker.go
index 16062e65b..7dfe1ffab 100644
--- a/database/types/worker.go
+++ b/database/types/worker.go
@@ -10,8 +10,8 @@ import (
"github.com/lib/pq"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
var (
diff --git a/database/types/worker_test.go b/database/types/worker_test.go
index ec835d1f1..44d676de9 100644
--- a/database/types/worker_test.go
+++ b/database/types/worker_test.go
@@ -171,7 +171,7 @@ func TestTypes_Worker_WorkerFromAPI(t *testing.T) {
got := WorkerFromAPI(w)
if !reflect.DeepEqual(got, want) {
- t.Errorf("WorkerFromLibrary is %v, want %v", got, want)
+ t.Errorf("WorkerFromAPI is %v, want %v", got, want)
}
}
diff --git a/database/user/count.go b/database/user/count.go
index b6b686fba..e8564bef8 100644
--- a/database/user/count.go
+++ b/database/user/count.go
@@ -5,7 +5,7 @@ package user
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountUsers gets the count of all users from the database.
diff --git a/database/user/create.go b/database/user/create.go
index c778349c4..ce2162d96 100644
--- a/database/user/create.go
+++ b/database/user/create.go
@@ -10,8 +10,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateUser creates a new user in the database.
@@ -24,16 +24,12 @@ func (e *engine) CreateUser(ctx context.Context, u *api.User) (*api.User, error)
user := types.UserFromAPI(u)
// validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#User.Validate
err := user.Validate()
if err != nil {
return nil, err
}
// encrypt the fields for the user
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#User.Encrypt
err = user.Encrypt(e.config.EncryptionKey)
if err != nil {
return nil, fmt.Errorf("unable to encrypt user %s: %w", u.GetName(), err)
diff --git a/database/user/delete.go b/database/user/delete.go
index 28547c07c..d42d804ad 100644
--- a/database/user/delete.go
+++ b/database/user/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteUser deletes an existing user from the database.
diff --git a/database/user/get.go b/database/user/get.go
index 30901c2ff..2a89f7836 100644
--- a/database/user/get.go
+++ b/database/user/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetUser gets a user by ID from the database.
diff --git a/database/user/get_name.go b/database/user/get_name.go
index fb9a90090..ee472a8d0 100644
--- a/database/user/get_name.go
+++ b/database/user/get_name.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetUserForName gets a user by name from the database.
diff --git a/database/user/list.go b/database/user/list.go
index 035699489..ae2858686 100644
--- a/database/user/list.go
+++ b/database/user/list.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListUsers gets a list of all users from the database.
diff --git a/database/user/list_lite.go b/database/user/list_lite.go
index c961fe483..f1719e0d5 100644
--- a/database/user/list_lite.go
+++ b/database/user/list_lite.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListLiteUsers gets a lite (only: id, name) list of users from the database.
diff --git a/database/user/table.go b/database/user/table.go
index de1f964a7..b39a04060 100644
--- a/database/user/table.go
+++ b/database/user/table.go
@@ -5,7 +5,7 @@ package user
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/user/update.go b/database/user/update.go
index d860e3293..bd8850502 100644
--- a/database/user/update.go
+++ b/database/user/update.go
@@ -10,8 +10,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateUser updates an existing user in the database.
@@ -20,7 +20,7 @@ func (e *engine) UpdateUser(ctx context.Context, u *api.User) (*api.User, error)
"user": u.GetName(),
}).Tracef("updating user %s", u.GetName())
- // cast the library type to database type
+ // cast the API type to database type
user := types.UserFromAPI(u)
// validate the necessary fields are populated
diff --git a/database/user/user.go b/database/user/user.go
index ad2e2bae5..552571525 100644
--- a/database/user/user.go
+++ b/database/user/user.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/validate.go b/database/validate.go
index 8025b325e..c7628f9a5 100644
--- a/database/validate.go
+++ b/database/validate.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Validate verifies the required fields from the provided configuration are populated correctly.
diff --git a/database/worker/count.go b/database/worker/count.go
index 6c440637c..2fac5cafc 100644
--- a/database/worker/count.go
+++ b/database/worker/count.go
@@ -5,7 +5,7 @@ package worker
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// CountWorkers gets the count of all workers from the database.
diff --git a/database/worker/create.go b/database/worker/create.go
index 180ee7ef6..efac2daa2 100644
--- a/database/worker/create.go
+++ b/database/worker/create.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// CreateWorker creates a new worker in the database.
@@ -18,14 +18,10 @@ func (e *engine) CreateWorker(ctx context.Context, w *api.Worker) (*api.Worker,
"worker": w.GetHostname(),
}).Tracef("creating worker %s", w.GetHostname())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
+ // cast the API type to database type
worker := types.WorkerFromAPI(w)
// validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Worker.Validate
err := worker.Validate()
if err != nil {
return nil, err
diff --git a/database/worker/delete.go b/database/worker/delete.go
index 252dd7831..bf2f813c3 100644
--- a/database/worker/delete.go
+++ b/database/worker/delete.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// DeleteWorker deletes an existing worker from the database.
@@ -18,9 +18,7 @@ func (e *engine) DeleteWorker(ctx context.Context, w *api.Worker) error {
"worker": w.GetHostname(),
}).Tracef("deleting worker %s", w.GetHostname())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
+ // cast the API type to database type
worker := types.WorkerFromAPI(w)
// send query to the database
diff --git a/database/worker/get.go b/database/worker/get.go
index 47be938a1..2a96be249 100644
--- a/database/worker/get.go
+++ b/database/worker/get.go
@@ -6,8 +6,8 @@ import (
"context"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetWorker gets a worker by ID from the database.
@@ -29,7 +29,5 @@ func (e *engine) GetWorker(ctx context.Context, id int64) (*api.Worker, error) {
}
// return the worker
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Worker.ToLibrary
return w.ToAPI(convertToBuilds(w.RunningBuildIDs)), nil
}
diff --git a/database/worker/get_hostname.go b/database/worker/get_hostname.go
index d1150f80d..b9192137a 100644
--- a/database/worker/get_hostname.go
+++ b/database/worker/get_hostname.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// GetWorkerForHostname gets a worker by hostname from the database.
@@ -33,7 +33,5 @@ func (e *engine) GetWorkerForHostname(ctx context.Context, hostname string) (*ap
}
// return the worker
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Worker.ToLibrary
return w.ToAPI(convertToBuilds(w.RunningBuildIDs)), nil
}
diff --git a/database/worker/list.go b/database/worker/list.go
index 34fc2ef79..26a7acf86 100644
--- a/database/worker/list.go
+++ b/database/worker/list.go
@@ -8,8 +8,8 @@ import (
"strconv"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// ListWorkers gets a list of all workers from the database.
@@ -49,9 +49,7 @@ func (e *engine) ListWorkers(ctx context.Context, active string, before, after i
// https://golang.org/doc/faq#closures_and_goroutines
tmp := worker
- // convert query result to library type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Worker.ToLibrary
+ // convert query result to API type
workers = append(workers, tmp.ToAPI(convertToBuilds(tmp.RunningBuildIDs)))
}
diff --git a/database/worker/table.go b/database/worker/table.go
index 921734f38..a1d871147 100644
--- a/database/worker/table.go
+++ b/database/worker/table.go
@@ -5,7 +5,7 @@ package worker
import (
"context"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
const (
diff --git a/database/worker/update.go b/database/worker/update.go
index 49c78e420..fa8a9deb2 100644
--- a/database/worker/update.go
+++ b/database/worker/update.go
@@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
- "github.com/go-vela/types/constants"
)
// UpdateWorker updates an existing worker in the database.
@@ -18,14 +18,10 @@ func (e *engine) UpdateWorker(ctx context.Context, w *api.Worker) (*api.Worker,
"worker": w.GetHostname(),
}).Tracef("updating worker %s", w.GetHostname())
- // cast the library type to database type
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
+ // cast the API type to database type
worker := types.WorkerFromAPI(w)
// validate the necessary fields are populated
- //
- // https://pkg.go.dev/github.com/go-vela/types/database#Worker.Validate
err := worker.Validate()
if err != nil {
return nil, err
diff --git a/database/worker/worker.go b/database/worker/worker.go
index 655a7dd2f..9869d4cd6 100644
--- a/database/worker/worker.go
+++ b/database/worker/worker.go
@@ -11,7 +11,7 @@ import (
"gorm.io/gorm"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
type (
diff --git a/database/worker/worker_test.go b/database/worker/worker_test.go
index bf54eb4da..976eb46f8 100644
--- a/database/worker/worker_test.go
+++ b/database/worker/worker_test.go
@@ -206,7 +206,7 @@ func testSqlite(t *testing.T) *engine {
return _engine
}
-// testWorker is a test helper function to create a library
+// testWorker is a test helper function to create a API
// Worker type with all fields set to their zero values.
func testWorker() *api.Worker {
b := new(api.Build)
diff --git a/go.mod b/go.mod
index a417873a3..290078d95 100644
--- a/go.mod
+++ b/go.mod
@@ -16,7 +16,6 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/assert/v2 v2.2.0
- github.com/go-vela/types v0.25.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v65 v65.0.0
diff --git a/go.sum b/go.sum
index b1c403b2a..1957fb598 100644
--- a/go.sum
+++ b/go.sum
@@ -102,8 +102,6 @@ github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
-github.com/go-vela/types v0.25.0 h1:5jSXgW8uf2ODbhOiWdVmKtbznF/CfNIzkZSYuNQIars=
-github.com/go-vela/types v0.25.0/go.mod h1:gyKVRQjNosAJy4AJ164CnEF6jIkwd1y6Cm5pZ6M20ZM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
diff --git a/internal/token/compose.go b/internal/token/compose.go
index 8fa0a1c8b..0bd685c11 100644
--- a/internal/token/compose.go
+++ b/internal/token/compose.go
@@ -9,8 +9,8 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
)
// Compose generates a refresh and access token pair unique
diff --git a/internal/token/compose_test.go b/internal/token/compose_test.go
index c6efd58ce..f87952ab3 100644
--- a/internal/token/compose_test.go
+++ b/internal/token/compose_test.go
@@ -12,8 +12,8 @@ import (
"github.com/golang-jwt/jwt/v5"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
)
func TestToken_Compose(t *testing.T) {
diff --git a/internal/token/parse_test.go b/internal/token/parse_test.go
index 600efe35e..0019aba6a 100644
--- a/internal/token/parse_test.go
+++ b/internal/token/parse_test.go
@@ -11,7 +11,7 @@ import (
jwt "github.com/golang-jwt/jwt/v5"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestTokenManager_ParseToken(t *testing.T) {
diff --git a/internal/token/refresh.go b/internal/token/refresh.go
index 257391230..f95d1b9c5 100644
--- a/internal/token/refresh.go
+++ b/internal/token/refresh.go
@@ -7,8 +7,8 @@ import (
"github.com/gin-gonic/gin"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/constants"
)
// Refresh returns a new access token, if the provided refreshToken is valid.
diff --git a/internal/token/refresh_test.go b/internal/token/refresh_test.go
index 49c809eb6..2478146e7 100644
--- a/internal/token/refresh_test.go
+++ b/internal/token/refresh_test.go
@@ -12,8 +12,8 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/constants"
)
func TestTokenManager_Refresh(t *testing.T) {
diff --git a/internal/webhook.go b/internal/webhook.go
index 3c6889a59..7edb365c2 100644
--- a/internal/webhook.go
+++ b/internal/webhook.go
@@ -6,7 +6,7 @@ import (
"strings"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
var (
diff --git a/internal/webhook_test.go b/internal/webhook_test.go
index 4e421854c..e374980d6 100644
--- a/internal/webhook_test.go
+++ b/internal/webhook_test.go
@@ -6,7 +6,7 @@ import (
"testing"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestWebhook_ShouldSkip(t *testing.T) {
diff --git a/mock/server/authentication.go b/mock/server/authentication.go
index 1d8ed2147..8d940934e 100644
--- a/mock/server/authentication.go
+++ b/mock/server/authentication.go
@@ -10,9 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
)
const (
@@ -67,7 +65,7 @@ const (
func getTokenRefresh(c *gin.Context) {
data := []byte(TokenRefreshResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -84,12 +82,12 @@ func getAuthenticate(c *gin.Context) {
err := "error"
if len(state) == 0 && len(code) == 0 {
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &err})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &err})
return
}
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.SetCookie(constants.RefreshTokenName, "refresh", 2, "/", "", true, true)
@@ -106,10 +104,10 @@ func getAuthenticateFromToken(c *gin.Context) {
token := c.Request.Header.Get("Token")
if len(token) == 0 {
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &err})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &err})
}
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -123,7 +121,7 @@ func validateToken(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
if len(token) == 0 {
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &err})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &err})
}
c.JSON(http.StatusOK, "vela-server")
@@ -137,7 +135,7 @@ func validateOAuthToken(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
if len(token) == 0 {
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &err})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &err})
}
c.JSON(http.StatusOK, "oauth token was created by vela")
diff --git a/mock/server/build.go b/mock/server/build.go
index ebbe44b88..786f26cb0 100644
--- a/mock/server/build.go
+++ b/mock/server/build.go
@@ -11,8 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
)
const (
@@ -245,7 +243,7 @@ func getBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -267,14 +265,14 @@ func getLogs(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(BuildLogsResp)
- var body []library.Log
+ var body []api.Log
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -300,7 +298,7 @@ func updateBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -323,7 +321,7 @@ func removeBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -340,7 +338,7 @@ func restartBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -362,7 +360,7 @@ func cancelBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("Build %s does not exist", b)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -379,7 +377,7 @@ func approveBuild(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := "user does not have admin permissions for the repo"
- c.AbortWithStatusJSON(http.StatusForbidden, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusForbidden, api.Error{Message: &msg})
return
}
@@ -428,7 +426,7 @@ func buildToken(c *gin.Context) {
data := []byte(BuildTokenResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -448,7 +446,7 @@ func idToken(c *gin.Context) {
data := []byte(IDTokenResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -468,7 +466,7 @@ func idTokenRequestToken(c *gin.Context) {
data := []byte(IDTokenRequestTokenResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -483,14 +481,14 @@ func buildExecutable(c *gin.Context) {
if strings.EqualFold(b, "0") {
msg := fmt.Sprintf("unable to get build executable for build %s", b)
- c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})
return
}
data := []byte(BuildExecutableResp)
- var body library.BuildExecutable
+ var body api.BuildExecutable
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
diff --git a/mock/server/dashboard.go b/mock/server/dashboard.go
index 2b89c3265..3b3fc5759 100644
--- a/mock/server/dashboard.go
+++ b/mock/server/dashboard.go
@@ -11,7 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
const (
@@ -221,7 +220,7 @@ func getDashboard(c *gin.Context) {
if strings.EqualFold(d, "0") {
msg := fmt.Sprintf("Dashboard %s does not exist", d)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/deployment.go b/mock/server/deployment.go
index 19323ec14..f6f0bd1c7 100644
--- a/mock/server/deployment.go
+++ b/mock/server/deployment.go
@@ -11,7 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
const (
@@ -438,7 +437,7 @@ func getDeployment(c *gin.Context) {
if strings.EqualFold(d, "0") {
msg := fmt.Sprintf("Deployment %s does not exist", d)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/hook.go b/mock/server/hook.go
index 84334bd42..0721a8a8f 100644
--- a/mock/server/hook.go
+++ b/mock/server/hook.go
@@ -12,7 +12,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
const (
@@ -298,7 +297,7 @@ func getHook(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Hook %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -331,7 +330,7 @@ func updateHook(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Hook %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -354,7 +353,7 @@ func removeHook(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Hook %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/log.go b/mock/server/log.go
index 98b359b57..d44c29fab 100644
--- a/mock/server/log.go
+++ b/mock/server/log.go
@@ -10,8 +10,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
const (
@@ -35,14 +34,14 @@ func getServiceLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(LogResp)
- var body library.Log
+ var body api.Log
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -62,7 +61,7 @@ func updateServiceLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -79,7 +78,7 @@ func removeServiceLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -96,14 +95,14 @@ func getStepLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(LogResp)
- var body library.Log
+ var body api.Log
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -123,7 +122,7 @@ func updateStepLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -140,7 +139,7 @@ func removeStepLog(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/log_test.go b/mock/server/log_test.go
index a77e55d55..28fbdc4a9 100644
--- a/mock/server/log_test.go
+++ b/mock/server/log_test.go
@@ -7,11 +7,11 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestLog_ActiveLogResp(t *testing.T) {
- testLog := library.Log{}
+ testLog := api.Log{}
err := json.Unmarshal([]byte(LogResp), &testLog)
if err != nil {
diff --git a/mock/server/pipeline.go b/mock/server/pipeline.go
index beb0b3b7a..f7eabde04 100644
--- a/mock/server/pipeline.go
+++ b/mock/server/pipeline.go
@@ -13,7 +13,6 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/yaml"
- "github.com/go-vela/types"
)
const (
@@ -343,7 +342,7 @@ func getPipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -376,7 +375,7 @@ func updatePipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -399,7 +398,7 @@ func removePipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -416,7 +415,7 @@ func compilePipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -438,7 +437,7 @@ func expandPipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -460,7 +459,7 @@ func getTemplates(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -482,7 +481,7 @@ func validatePipeline(c *gin.Context) {
if strings.EqualFold(p, "0") {
msg := fmt.Sprintf("Pipeline %s does not exist", p)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/repo.go b/mock/server/repo.go
index aba7cbaf9..9b156669e 100644
--- a/mock/server/repo.go
+++ b/mock/server/repo.go
@@ -11,7 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
const (
@@ -119,7 +118,7 @@ func getRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -152,7 +151,7 @@ func updateRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -175,7 +174,7 @@ func removeRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -192,7 +191,7 @@ func repairRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -209,7 +208,7 @@ func chownRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/rotate_keys.go b/mock/server/rotate_keys.go
index 3623f4c12..3e65133aa 100644
--- a/mock/server/rotate_keys.go
+++ b/mock/server/rotate_keys.go
@@ -8,8 +8,8 @@ import (
"github.com/gin-gonic/gin"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/router/middleware/auth"
- "github.com/go-vela/types"
)
// rotateKeys returns success message. Pass `invalid` to auth header to test 401 error.
@@ -18,7 +18,7 @@ func rotateKeys(c *gin.Context) {
if strings.EqualFold(tkn, "invalid") {
data := "unauthorized"
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &data})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &data})
return
}
diff --git a/mock/server/schedule.go b/mock/server/schedule.go
index 73882e4af..262e73cf9 100644
--- a/mock/server/schedule.go
+++ b/mock/server/schedule.go
@@ -11,7 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
const (
@@ -219,7 +218,7 @@ func getSchedule(c *gin.Context) {
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -252,7 +251,7 @@ func updateSchedule(c *gin.Context) {
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -275,7 +274,7 @@ func removeSchedule(c *gin.Context) {
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/scm.go b/mock/server/scm.go
index e191da268..6e70f2369 100644
--- a/mock/server/scm.go
+++ b/mock/server/scm.go
@@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types"
+ api "github.com/go-vela/server/api/types"
)
// syncRepo has a param :repo returns mock JSON for a http PATCH.
@@ -20,7 +20,7 @@ func syncRepo(c *gin.Context) {
if strings.Contains(r, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", r)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -36,7 +36,7 @@ func syncRepos(c *gin.Context) {
if strings.Contains(o, "not-found") {
msg := fmt.Sprintf("Repo %s does not exist", o)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/secret.go b/mock/server/secret.go
index 6cd45047f..5410a4a75 100644
--- a/mock/server/secret.go
+++ b/mock/server/secret.go
@@ -11,8 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
//nolint:gosec // these are mock responses
@@ -101,7 +100,7 @@ const (
func getSecrets(c *gin.Context) {
data := []byte(SecretsResp)
- var body []library.Secret
+ var body []api.Secret
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -116,14 +115,14 @@ func getSecret(c *gin.Context) {
if strings.Contains(n, "not-found") {
msg := fmt.Sprintf("Secret %s does not exist", n)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(SecretResp)
- var body library.Secret
+ var body api.Secret
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -133,7 +132,7 @@ func getSecret(c *gin.Context) {
func addSecret(c *gin.Context) {
data := []byte(SecretResp)
- var body library.Secret
+ var body api.Secret
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
@@ -149,7 +148,7 @@ func updateSecret(c *gin.Context) {
if strings.Contains(n, "not-found") {
msg := fmt.Sprintf("Repo or team %s does not exist for secret", n)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -157,7 +156,7 @@ func updateSecret(c *gin.Context) {
data := []byte(SecretResp)
- var body library.Secret
+ var body api.Secret
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -172,7 +171,7 @@ func removeSecret(c *gin.Context) {
if strings.Contains(n, "not-found") {
msg := fmt.Sprintf("Secret %s does not exist", n)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/secret_test.go b/mock/server/secret_test.go
index 502011c28..43e7098b1 100644
--- a/mock/server/secret_test.go
+++ b/mock/server/secret_test.go
@@ -7,11 +7,11 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestSecret_ActiveSecretResp(t *testing.T) {
- testSecret := library.Secret{}
+ testSecret := api.Secret{}
err := json.Unmarshal([]byte(SecretResp), &testSecret)
if err != nil {
diff --git a/mock/server/service.go b/mock/server/service.go
index c42e97dd6..bd241bf73 100644
--- a/mock/server/service.go
+++ b/mock/server/service.go
@@ -11,8 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
const (
@@ -70,7 +69,7 @@ const (
func getServices(c *gin.Context) {
data := []byte(ServicesResp)
- var body []library.Service
+ var body []api.Service
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -85,14 +84,14 @@ func getService(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Service %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(ServiceResp)
- var body library.Service
+ var body api.Service
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -102,7 +101,7 @@ func getService(c *gin.Context) {
func addService(c *gin.Context) {
data := []byte(ServiceResp)
- var body library.Service
+ var body api.Service
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
@@ -118,7 +117,7 @@ func updateService(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Service %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -126,7 +125,7 @@ func updateService(c *gin.Context) {
data := []byte(ServiceResp)
- var body library.Service
+ var body api.Service
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -141,7 +140,7 @@ func removeService(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Service %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/service_test.go b/mock/server/service_test.go
index 799dc64d6..70e1da0af 100644
--- a/mock/server/service_test.go
+++ b/mock/server/service_test.go
@@ -7,11 +7,11 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestService_ActiveServiceResp(t *testing.T) {
- testService := library.Service{}
+ testService := api.Service{}
err := json.Unmarshal([]byte(ServiceResp), &testService)
if err != nil {
diff --git a/mock/server/step.go b/mock/server/step.go
index ff4c32ce8..9b4a67e3f 100644
--- a/mock/server/step.go
+++ b/mock/server/step.go
@@ -11,8 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
const (
@@ -80,7 +79,7 @@ const (
func getSteps(c *gin.Context) {
data := []byte(StepsResp)
- var body []library.Step
+ var body []api.Step
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -95,14 +94,14 @@ func getStep(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Step %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(StepResp)
- var body library.Step
+ var body api.Step
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -112,7 +111,7 @@ func getStep(c *gin.Context) {
func addStep(c *gin.Context) {
data := []byte(StepResp)
- var body library.Step
+ var body api.Step
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
@@ -128,7 +127,7 @@ func updateStep(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Step %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -136,7 +135,7 @@ func updateStep(c *gin.Context) {
data := []byte(StepResp)
- var body library.Step
+ var body api.Step
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -151,7 +150,7 @@ func removeStep(c *gin.Context) {
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Step %s does not exist", s)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/step_test.go b/mock/server/step_test.go
index 9b4f6ef04..6b1952949 100644
--- a/mock/server/step_test.go
+++ b/mock/server/step_test.go
@@ -7,11 +7,11 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestStep_ActiveStepResp(t *testing.T) {
- testStep := library.Step{}
+ testStep := api.Step{}
err := json.Unmarshal([]byte(StepResp), &testStep)
if err != nil {
diff --git a/mock/server/user.go b/mock/server/user.go
index 9df1ef087..96537cfc7 100644
--- a/mock/server/user.go
+++ b/mock/server/user.go
@@ -12,7 +12,6 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/router/middleware/auth"
- "github.com/go-vela/types"
)
const (
@@ -69,7 +68,7 @@ func getUser(c *gin.Context) {
if strings.Contains(u, "not-found") {
msg := fmt.Sprintf("User %s does not exist", u)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -91,7 +90,7 @@ func currentUser(c *gin.Context) {
if strings.Contains(tkn, "invalid") {
msg := "unauthorized"
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &msg})
return
}
@@ -124,7 +123,7 @@ func updateUser(c *gin.Context) {
if strings.Contains(u, "not-found") {
msg := fmt.Sprintf("User %s does not exist", u)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -147,7 +146,7 @@ func removeUser(c *gin.Context) {
if strings.Contains(u, "not-found") {
msg := fmt.Sprintf("User %s does not exist", u)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
diff --git a/mock/server/worker.go b/mock/server/worker.go
index 6e5e6ac5e..c92b508ec 100644
--- a/mock/server/worker.go
+++ b/mock/server/worker.go
@@ -11,8 +11,6 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
- "github.com/go-vela/types/library"
)
const (
@@ -209,7 +207,7 @@ func getWorker(c *gin.Context) {
if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("Worker %s does not exist", w)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -226,7 +224,7 @@ func getWorker(c *gin.Context) {
func addWorker(c *gin.Context) {
data := []byte(AddWorkerResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
@@ -241,7 +239,7 @@ func updateWorker(c *gin.Context) {
if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("Worker %s does not exist", w)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -263,14 +261,14 @@ func refreshWorkerAuth(c *gin.Context) {
if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("Worker %s does not exist", w)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
data := []byte(RefreshWorkerAuthResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
@@ -285,7 +283,7 @@ func removeWorker(c *gin.Context) {
if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("Worker %s does not exist", w)
- c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusNotFound, api.Error{Message: &msg})
return
}
@@ -302,14 +300,14 @@ func registerToken(c *gin.Context) {
if strings.EqualFold(w, "0") {
msg := fmt.Sprintf("user %s is not a platform admin", w)
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &msg})
return
}
data := []byte(RegisterTokenResp)
- var body library.Token
+ var body api.Token
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
@@ -324,14 +322,14 @@ func getQueueCreds(c *gin.Context) {
if token == "" {
msg := "unable get queue credentials; invalid registration token"
- c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &msg})
+ c.AbortWithStatusJSON(http.StatusUnauthorized, api.Error{Message: &msg})
return
}
data := []byte(QueueInfoResp)
- var body library.QueueInfo
+ var body api.QueueInfo
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
diff --git a/queue/flags.go b/queue/flags.go
index 35e5745f5..6277226a8 100644
--- a/queue/flags.go
+++ b/queue/flags.go
@@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Flags represents all supported command line
diff --git a/queue/queue.go b/queue/queue.go
index fdff9b364..c6a48eb54 100644
--- a/queue/queue.go
+++ b/queue/queue.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// FromCLIContext helper function to setup the queue from the CLI arguments.
diff --git a/queue/redis/driver.go b/queue/redis/driver.go
index 5d5410bf9..90ba4b572 100644
--- a/queue/redis/driver.go
+++ b/queue/redis/driver.go
@@ -2,7 +2,7 @@
package redis
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Driver outputs the configured queue driver.
func (c *client) Driver() string {
diff --git a/queue/redis/driver_test.go b/queue/redis/driver_test.go
index 52894f1ba..f4434820a 100644
--- a/queue/redis/driver_test.go
+++ b/queue/redis/driver_test.go
@@ -10,7 +10,7 @@ import (
"github.com/alicebob/miniredis/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestRedis_Driver(t *testing.T) {
diff --git a/queue/redis/route.go b/queue/redis/route.go
index 5ee0d29a6..77de050c4 100644
--- a/queue/redis/route.go
+++ b/queue/redis/route.go
@@ -8,7 +8,7 @@ import (
"strings"
"github.com/go-vela/server/compiler/types/pipeline"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Route decides which route a build gets placed within the queue.
@@ -19,8 +19,6 @@ func (c *client) Route(w *pipeline.Worker) (string, error) {
buf := bytes.Buffer{}
// if pipline does not specify route information return default
- //
- // https://github.com/go-vela/types/blob/main/constants/queue.go#L10
if w.Empty() {
return constants.DefaultRoute, nil
}
diff --git a/queue/redis/route_test.go b/queue/redis/route_test.go
index 5750e9277..e4f802f0d 100644
--- a/queue/redis/route_test.go
+++ b/queue/redis/route_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"github.com/go-vela/server/compiler/types/pipeline"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestRedis_Client_Route(t *testing.T) {
diff --git a/queue/setup.go b/queue/setup.go
index c554c9238..8874aba95 100644
--- a/queue/setup.go
+++ b/queue/setup.go
@@ -9,8 +9,8 @@ import (
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/queue/redis"
- "github.com/go-vela/types/constants"
)
// Setup represents the configuration necessary for
diff --git a/router/middleware/auth/auth.go b/router/middleware/auth/auth.go
index 53ed6a8eb..3c6189100 100644
--- a/router/middleware/auth/auth.go
+++ b/router/middleware/auth/auth.go
@@ -8,7 +8,7 @@ import (
"github.com/golang-jwt/jwt/v5/request"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// RetrieveAccessToken gets the passed in access token from the header in the request.
diff --git a/router/middleware/auth/auth_test.go b/router/middleware/auth/auth_test.go
index 7a7993a98..f40e04e0f 100644
--- a/router/middleware/auth/auth_test.go
+++ b/router/middleware/auth/auth_test.go
@@ -9,7 +9,7 @@ import (
"strings"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestToken_Retrieve_Refresh(t *testing.T) {
diff --git a/router/middleware/claims/claims.go b/router/middleware/claims/claims.go
index e306f9e7e..4a20db604 100644
--- a/router/middleware/claims/claims.go
+++ b/router/middleware/claims/claims.go
@@ -9,10 +9,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/auth"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// Retrieve gets the claims in the given context.
diff --git a/router/middleware/claims/claims_test.go b/router/middleware/claims/claims_test.go
index 9d065df0f..8980deec1 100644
--- a/router/middleware/claims/claims_test.go
+++ b/router/middleware/claims/claims_test.go
@@ -17,9 +17,9 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
- "github.com/go-vela/types/constants"
)
func TestClaims_Retrieve(t *testing.T) {
diff --git a/router/middleware/claims/context_test.go b/router/middleware/claims/context_test.go
index b4f91baac..9a395166d 100644
--- a/router/middleware/claims/context_test.go
+++ b/router/middleware/claims/context_test.go
@@ -9,8 +9,8 @@ import (
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal/token"
- "github.com/go-vela/types/constants"
)
func TestClaims_FromContext(t *testing.T) {
diff --git a/router/middleware/default_repo_settings_test.go b/router/middleware/default_repo_settings_test.go
index 75cc7a02a..9a620c64c 100644
--- a/router/middleware/default_repo_settings_test.go
+++ b/router/middleware/default_repo_settings_test.go
@@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestMiddleware_DefaultRepoEvents(t *testing.T) {
diff --git a/router/middleware/executors/executors.go b/router/middleware/executors/executors.go
index 21616d64a..54a930ab1 100644
--- a/router/middleware/executors/executors.go
+++ b/router/middleware/executors/executors.go
@@ -14,11 +14,11 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// Retrieve gets the executors in the given context.
diff --git a/router/middleware/logger.go b/router/middleware/logger.go
index 5b8be89c9..2e6a518f8 100644
--- a/router/middleware/logger.go
+++ b/router/middleware/logger.go
@@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/dashboard"
@@ -21,7 +22,6 @@ import (
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/router/middleware/worker"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// This file, in part, reproduces portions of
diff --git a/router/middleware/logger_test.go b/router/middleware/logger_test.go
index 25e3dad14..bc17ea7bd 100644
--- a/router/middleware/logger_test.go
+++ b/router/middleware/logger_test.go
@@ -24,7 +24,6 @@ import (
"github.com/go-vela/server/router/middleware/step"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/router/middleware/worker"
- "github.com/go-vela/types/library"
)
func TestMiddleware_Logger(t *testing.T) {
@@ -41,14 +40,14 @@ func TestMiddleware_Logger(t *testing.T) {
b.SetRepo(r)
b.SetNumber(1)
- svc := new(library.Service)
+ svc := new(api.Service)
svc.SetID(1)
svc.SetRepoID(1)
svc.SetBuildID(1)
svc.SetNumber(1)
svc.SetName("foo")
- s := new(library.Step)
+ s := new(api.Step)
s.SetID(1)
s.SetRepoID(1)
s.SetBuildID(1)
diff --git a/router/middleware/pipeline/pipeline_test.go b/router/middleware/pipeline/pipeline_test.go
index bdc7d83f3..a12dd544b 100644
--- a/router/middleware/pipeline/pipeline_test.go
+++ b/router/middleware/pipeline/pipeline_test.go
@@ -20,6 +20,7 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/compiler/native"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/database/testutils"
"github.com/go-vela/server/internal"
@@ -30,7 +31,6 @@ import (
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/scm/github"
- "github.com/go-vela/types/constants"
)
func TestPipeline_Retrieve(t *testing.T) {
diff --git a/router/middleware/service/context.go b/router/middleware/service/context.go
index 7083879ea..4098cdea0 100644
--- a/router/middleware/service/context.go
+++ b/router/middleware/service/context.go
@@ -5,7 +5,7 @@ package service
import (
"context"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
const key = "service"
@@ -16,13 +16,13 @@ type Setter interface {
}
// FromContext returns the Service associated with this context.
-func FromContext(c context.Context) *library.Service {
+func FromContext(c context.Context) *api.Service {
value := c.Value(key)
if value == nil {
return nil
}
- s, ok := value.(*library.Service)
+ s, ok := value.(*api.Service)
if !ok {
return nil
}
@@ -32,6 +32,6 @@ func FromContext(c context.Context) *library.Service {
// ToContext adds the Service to this context if it supports
// the Setter interface.
-func ToContext(c Setter, s *library.Service) {
+func ToContext(c Setter, s *api.Service) {
c.Set(key, s)
}
diff --git a/router/middleware/service/context_test.go b/router/middleware/service/context_test.go
index 8c1cc74f4..41860657e 100644
--- a/router/middleware/service/context_test.go
+++ b/router/middleware/service/context_test.go
@@ -7,13 +7,13 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestService_FromContext(t *testing.T) {
// setup types
num := int64(1)
- want := &library.Service{ID: &num}
+ want := &api.Service{ID: &num}
// setup context
gin.SetMode(gin.TestMode)
@@ -72,7 +72,7 @@ func TestService_FromContext_Empty(t *testing.T) {
func TestService_ToContext(t *testing.T) {
// setup types
num := int64(1)
- want := &library.Service{ID: &num}
+ want := &api.Service{ID: &num}
// setup context
gin.SetMode(gin.TestMode)
diff --git a/router/middleware/service/service.go b/router/middleware/service/service.go
index 7089e22f7..2f9cabb7c 100644
--- a/router/middleware/service/service.go
+++ b/router/middleware/service/service.go
@@ -10,16 +10,16 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// Retrieve gets the service in the given context.
-func Retrieve(c *gin.Context) *library.Service {
+func Retrieve(c *gin.Context) *api.Service {
return FromContext(c)
}
diff --git a/router/middleware/service/service_test.go b/router/middleware/service/service_test.go
index 681975c36..f91bee81d 100644
--- a/router/middleware/service/service_test.go
+++ b/router/middleware/service/service_test.go
@@ -17,12 +17,11 @@ import (
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
- "github.com/go-vela/types/library"
)
func TestService_Retrieve(t *testing.T) {
// setup types
- want := new(library.Service)
+ want := new(api.Service)
want.SetID(1)
// setup context
@@ -57,7 +56,7 @@ func TestService_Establish(t *testing.T) {
b.SetRepo(r)
b.SetNumber(1)
- want := new(library.Service)
+ want := new(api.Service)
want.SetID(1)
want.SetRepoID(1)
want.SetBuildID(1)
@@ -74,7 +73,7 @@ func TestService_Establish(t *testing.T) {
want.SetRuntime("")
want.SetDistribution("")
- got := new(library.Service)
+ got := new(api.Service)
// setup database
db, err := database.NewTest()
diff --git a/router/middleware/step/context.go b/router/middleware/step/context.go
index f8c13740d..ae022c6b6 100644
--- a/router/middleware/step/context.go
+++ b/router/middleware/step/context.go
@@ -5,7 +5,7 @@ package step
import (
"context"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
const key = "step"
@@ -16,13 +16,13 @@ type Setter interface {
}
// FromContext returns the Step associated with this context.
-func FromContext(c context.Context) *library.Step {
+func FromContext(c context.Context) *api.Step {
value := c.Value(key)
if value == nil {
return nil
}
- s, ok := value.(*library.Step)
+ s, ok := value.(*api.Step)
if !ok {
return nil
}
@@ -32,6 +32,6 @@ func FromContext(c context.Context) *library.Step {
// ToContext adds the Step to this context if it supports
// the Setter interface.
-func ToContext(c Setter, s *library.Step) {
+func ToContext(c Setter, s *api.Step) {
c.Set(key, s)
}
diff --git a/router/middleware/step/context_test.go b/router/middleware/step/context_test.go
index c42feb41c..e111cffd2 100644
--- a/router/middleware/step/context_test.go
+++ b/router/middleware/step/context_test.go
@@ -7,13 +7,13 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestStep_FromContext(t *testing.T) {
// setup types
num := int64(1)
- want := &library.Step{ID: &num}
+ want := &api.Step{ID: &num}
// setup context
gin.SetMode(gin.TestMode)
@@ -72,7 +72,7 @@ func TestStep_FromContext_Empty(t *testing.T) {
func TestStep_ToContext(t *testing.T) {
// setup types
num := int64(1)
- want := &library.Step{ID: &num}
+ want := &api.Step{ID: &num}
// setup context
gin.SetMode(gin.TestMode)
diff --git a/router/middleware/step/step.go b/router/middleware/step/step.go
index c1e31cf43..1e9bb95d3 100644
--- a/router/middleware/step/step.go
+++ b/router/middleware/step/step.go
@@ -10,16 +10,16 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/library"
)
// Retrieve gets the step in the given context.
-func Retrieve(c *gin.Context) *library.Step {
+func Retrieve(c *gin.Context) *api.Step {
return FromContext(c)
}
diff --git a/router/middleware/step/step_test.go b/router/middleware/step/step_test.go
index 120170d04..77f4701a7 100644
--- a/router/middleware/step/step_test.go
+++ b/router/middleware/step/step_test.go
@@ -17,12 +17,11 @@ import (
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
- "github.com/go-vela/types/library"
)
func TestStep_Retrieve(t *testing.T) {
// setup types
- want := new(library.Step)
+ want := new(api.Step)
want.SetID(1)
// setup context
@@ -58,7 +57,7 @@ func TestStep_Establish(t *testing.T) {
b.SetRepo(r)
b.SetNumber(1)
- want := new(library.Step)
+ want := new(api.Step)
want.SetID(1)
want.SetRepoID(1)
want.SetBuildID(1)
@@ -77,7 +76,7 @@ func TestStep_Establish(t *testing.T) {
want.SetDistribution("")
want.SetReportAs("")
- got := new(library.Step)
+ got := new(api.Step)
// setup database
db, err := database.NewTest()
diff --git a/router/middleware/user/user.go b/router/middleware/user/user.go
index cc883fd41..a6936f96e 100644
--- a/router/middleware/user/user.go
+++ b/router/middleware/user/user.go
@@ -10,10 +10,10 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/util"
- "github.com/go-vela/types/constants"
)
// Retrieve gets the user in the given context.
diff --git a/router/middleware/user/user_test.go b/router/middleware/user/user_test.go
index 28d7f7a3d..5246ff701 100644
--- a/router/middleware/user/user_test.go
+++ b/router/middleware/user/user_test.go
@@ -15,12 +15,12 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/scm/github"
- "github.com/go-vela/types/constants"
)
func TestUser_Retrieve(t *testing.T) {
diff --git a/scm/flags.go b/scm/flags.go
index 2a64f7e14..0d95ebcb5 100644
--- a/scm/flags.go
+++ b/scm/flags.go
@@ -5,7 +5,7 @@ package scm
import (
"github.com/urfave/cli/v2"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Flags represents all supported command line
diff --git a/scm/github/deployment.go b/scm/github/deployment.go
index b4f89627b..e7f8ed0b4 100644
--- a/scm/github/deployment.go
+++ b/scm/github/deployment.go
@@ -135,7 +135,7 @@ func (c *client) GetDeploymentList(ctx context.Context, u *api.User, r *api.Repo
createdAt := deployment.CreatedAt.Unix()
- // convert query result to library type
+ // convert query result to API type
deployments = append(deployments, &api.Deployment{
ID: deployment.ID,
Repo: r,
diff --git a/scm/github/driver.go b/scm/github/driver.go
index 1a17f5f0f..f16f85f8a 100644
--- a/scm/github/driver.go
+++ b/scm/github/driver.go
@@ -2,7 +2,7 @@
package github
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Driver outputs the configured scm driver.
func (c *client) Driver() string {
diff --git a/scm/github/driver_test.go b/scm/github/driver_test.go
index 42b9f8f1e..7ea6656d8 100644
--- a/scm/github/driver_test.go
+++ b/scm/github/driver_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestGitHub_Driver(t *testing.T) {
diff --git a/scm/github/repo.go b/scm/github/repo.go
index f608b5199..31fa2b9e8 100644
--- a/scm/github/repo.go
+++ b/scm/github/repo.go
@@ -14,8 +14,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
)
// ConfigBackoff is a wrapper for Config that will retry five times if the function
@@ -401,7 +400,7 @@ func (c *client) Status(ctx context.Context, u *api.User, b *api.Build, org, nam
}
// StepStatus sends the commit status for the given SHA to the GitHub repo with the step as the context.
-func (c *client) StepStatus(ctx context.Context, u *api.User, b *api.Build, s *library.Step, org, name string) error {
+func (c *client) StepStatus(ctx context.Context, u *api.User, b *api.Build, s *api.Step, org, name string) error {
c.Logger.WithFields(logrus.Fields{
"build": b.GetNumber(),
"org": org,
@@ -486,7 +485,7 @@ func (c *client) GetRepo(ctx context.Context, u *api.User, r *api.Repo) (*api.Re
return nil, resp.StatusCode, err
}
- return toLibraryRepo(*repo), resp.StatusCode, nil
+ return toAPIRepo(*repo), resp.StatusCode, nil
}
// GetOrgAndRepoName returns the name of the org and the repository in the SCM.
@@ -557,14 +556,14 @@ func (c *client) ListUserRepos(ctx context.Context, u *api.User) ([]*api.Repo, e
continue
}
- f = append(f, toLibraryRepo(*repo))
+ f = append(f, toAPIRepo(*repo))
}
return f, nil
}
-// toLibraryRepo does a partial conversion of a github repo to a library repo.
-func toLibraryRepo(gr github.Repository) *api.Repo {
+// toAPIRepo does a partial conversion of a github repo to a API repo.
+func toAPIRepo(gr github.Repository) *api.Repo {
// setting the visbility to match the SCM visbility
var visibility string
if *gr.Private {
diff --git a/scm/github/repo_test.go b/scm/github/repo_test.go
index a1920e73d..502c1cc7c 100644
--- a/scm/github/repo_test.go
+++ b/scm/github/repo_test.go
@@ -15,8 +15,7 @@ import (
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
)
func TestGithub_Config_YML(t *testing.T) {
@@ -909,7 +908,7 @@ func TestGithub_Status_Running(t *testing.T) {
b.SetStatus(constants.StatusRunning)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
@@ -973,7 +972,7 @@ func TestGithub_Status_Success(t *testing.T) {
b.SetStatus(constants.StatusRunning)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
@@ -1037,7 +1036,7 @@ func TestGithub_Status_Failure(t *testing.T) {
b.SetStatus(constants.StatusRunning)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
@@ -1101,7 +1100,7 @@ func TestGithub_Status_Killed(t *testing.T) {
b.SetStatus(constants.StatusRunning)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
@@ -1165,7 +1164,7 @@ func TestGithub_Status_Skipped(t *testing.T) {
b.SetStatus(constants.StatusSkipped)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
@@ -1229,7 +1228,7 @@ func TestGithub_Status_Error(t *testing.T) {
b.SetStatus(constants.StatusRunning)
b.SetCommit("abcd1234")
- step := new(library.Step)
+ step := new(api.Step)
step.SetID(1)
step.SetNumber(1)
step.SetName("test")
diff --git a/scm/github/webhook.go b/scm/github/webhook.go
index d79deb718..b6f6556fe 100644
--- a/scm/github/webhook.go
+++ b/scm/github/webhook.go
@@ -17,8 +17,8 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
)
// ProcessWebhook parses the webhook from a repo.
@@ -139,7 +139,7 @@ func (c *client) processPushEvent(ctx context.Context, h *api.Hook, payload *git
repo := payload.GetRepo()
- // convert payload to library repo
+ // convert payload to API repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
@@ -150,7 +150,7 @@ func (c *client) processPushEvent(ctx context.Context, h *api.Hook, payload *git
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
- // convert payload to library build
+ // convert payload to API build
b := new(api.Build)
b.SetEvent(constants.EventPush)
b.SetClone(repo.GetCloneURL())
@@ -268,7 +268,7 @@ func (c *client) processPREvent(h *api.Hook, payload *github.PullRequestEvent) (
// capture the repo from the payload
repo := payload.GetRepo()
- // convert payload to library repo
+ // convert payload to API repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
@@ -355,7 +355,7 @@ func (c *client) processDeploymentEvent(h *api.Hook, payload *github.DeploymentE
// capture the repo from the payload
repo := payload.GetRepo()
- // convert payload to library repo
+ // convert payload to API repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
@@ -473,7 +473,7 @@ func (c *client) processIssueCommentEvent(h *api.Hook, payload *github.IssueComm
// capture the repo from the payload
repo := payload.GetRepo()
- // convert payload to library repo
+ // convert payload to API repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
@@ -484,7 +484,7 @@ func (c *client) processIssueCommentEvent(h *api.Hook, payload *github.IssueComm
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
- // convert payload to library build
+ // convert payload to API build
b := new(api.Build)
b.SetEvent(constants.EventComment)
b.SetEventAction(payload.GetAction())
@@ -516,7 +516,7 @@ func (c *client) processRepositoryEvent(h *api.Hook, payload *github.RepositoryE
repo := payload.GetRepo()
- // convert payload to library repo
+ // convert payload to API repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
diff --git a/scm/github/webhook_test.go b/scm/github/webhook_test.go
index 15fdb486d..1ef1685fe 100644
--- a/scm/github/webhook_test.go
+++ b/scm/github/webhook_test.go
@@ -17,8 +17,8 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/raw"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/constants"
)
func TestGithub_ProcessWebhook_Push(t *testing.T) {
diff --git a/scm/scm.go b/scm/scm.go
index e45b33576..b93bde906 100644
--- a/scm/scm.go
+++ b/scm/scm.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// New creates and returns a Vela service capable of
diff --git a/scm/service.go b/scm/service.go
index ca93ec1d5..bc917ce9a 100644
--- a/scm/service.go
+++ b/scm/service.go
@@ -8,7 +8,6 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/internal"
- "github.com/go-vela/types/library"
)
// Service represents the interface for Vela integrating
@@ -119,7 +118,7 @@ type Service interface {
Status(context.Context, *api.User, *api.Build, string, string) error
// StepStatus defines a function that sends the
// commit status for the given SHA for a specified step context.
- StepStatus(context.Context, *api.User, *api.Build, *library.Step, string, string) error
+ StepStatus(context.Context, *api.User, *api.Build, *api.Step, string, string) error
// ListUserRepos defines a function that retrieves
// all repos with admin rights for the user.
ListUserRepos(context.Context, *api.User) ([]*api.Repo, error)
diff --git a/scm/setup.go b/scm/setup.go
index c32a0cf66..dc3a3e698 100644
--- a/scm/setup.go
+++ b/scm/setup.go
@@ -8,9 +8,9 @@ import (
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/scm/github"
"github.com/go-vela/server/tracing"
- "github.com/go-vela/types/constants"
)
// Setup represents the configuration necessary for
diff --git a/secret/native/count.go b/secret/native/count.go
index 460ee077b..1931e4286 100644
--- a/secret/native/count.go
+++ b/secret/native/count.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Count counts a list of secrets.
diff --git a/secret/native/count_test.go b/secret/native/count_test.go
index e080ec03a..975b9b5df 100644
--- a/secret/native/count_test.go
+++ b/secret/native/count_test.go
@@ -6,13 +6,13 @@ import (
"context"
"testing"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_Count(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetID(1)
sec.SetOrg("foo")
sec.SetRepo("bar")
diff --git a/secret/native/create.go b/secret/native/create.go
index 698b25740..c374bacbd 100644
--- a/secret/native/create.go
+++ b/secret/native/create.go
@@ -8,12 +8,12 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
// Create creates a new secret.
-func (c *client) Create(ctx context.Context, sType, org, name string, s *library.Secret) (*library.Secret, error) {
+func (c *client) Create(ctx context.Context, sType, org, name string, s *api.Secret) (*api.Secret, error) {
// handle the secret based off the type
switch sType {
case constants.SecretOrg:
diff --git a/secret/native/create_test.go b/secret/native/create_test.go
index c7c44c22d..fb2aba6b2 100644
--- a/secret/native/create_test.go
+++ b/secret/native/create_test.go
@@ -7,13 +7,13 @@ import (
"reflect"
"testing"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_Create_Org(t *testing.T) {
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetID(1)
want.SetOrg("foo")
want.SetRepo("*")
@@ -22,7 +22,7 @@ func TestNative_Create_Org(t *testing.T) {
want.SetValue("baz")
want.SetType("org")
want.SetImages([]string{"foo", "bar"})
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetCreatedAt(1)
@@ -61,7 +61,7 @@ func TestNative_Create_Org(t *testing.T) {
func TestNative_Create_Repo(t *testing.T) {
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetID(1)
want.SetOrg("foo")
want.SetRepo("bar")
@@ -70,7 +70,7 @@ func TestNative_Create_Repo(t *testing.T) {
want.SetValue("foob")
want.SetType("repo")
want.SetImages([]string{"foo", "bar"})
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetCreatedAt(1)
@@ -109,7 +109,7 @@ func TestNative_Create_Repo(t *testing.T) {
func TestNative_Create_Shared(t *testing.T) {
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetID(1)
want.SetOrg("foo")
want.SetRepo("")
@@ -118,7 +118,7 @@ func TestNative_Create_Shared(t *testing.T) {
want.SetValue("foob")
want.SetType("shared")
want.SetImages([]string{"foo", "bar"})
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetCreatedAt(1)
@@ -157,7 +157,7 @@ func TestNative_Create_Shared(t *testing.T) {
func TestNative_Create_Invalid(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetID(1)
sec.SetOrg("foo")
sec.SetRepo("bar")
@@ -166,7 +166,7 @@ func TestNative_Create_Invalid(t *testing.T) {
sec.SetValue("foob")
sec.SetType("invalid")
sec.SetImages([]string{"foo", "bar"})
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
sec.SetCreatedAt(1)
diff --git a/secret/native/delete.go b/secret/native/delete.go
index d0fbdc458..a32b669a1 100644
--- a/secret/native/delete.go
+++ b/secret/native/delete.go
@@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Delete deletes a secret.
diff --git a/secret/native/delete_test.go b/secret/native/delete_test.go
index ad486b2a1..db6132260 100644
--- a/secret/native/delete_test.go
+++ b/secret/native/delete_test.go
@@ -6,13 +6,13 @@ import (
"context"
"testing"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_Delete(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetID(1)
sec.SetOrg("foo")
sec.SetRepo("bar")
diff --git a/secret/native/driver.go b/secret/native/driver.go
index 022967d53..26ba4f3dc 100644
--- a/secret/native/driver.go
+++ b/secret/native/driver.go
@@ -2,7 +2,7 @@
package native
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Driver outputs the configured secret driver.
func (c *client) Driver() string {
diff --git a/secret/native/driver_test.go b/secret/native/driver_test.go
index a18369e86..9f003bf94 100644
--- a/secret/native/driver_test.go
+++ b/secret/native/driver_test.go
@@ -6,8 +6,8 @@ import (
"reflect"
"testing"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/constants"
)
func TestNative_Driver(t *testing.T) {
diff --git a/secret/native/get.go b/secret/native/get.go
index da22376e6..fe9e0ddf4 100644
--- a/secret/native/get.go
+++ b/secret/native/get.go
@@ -9,12 +9,11 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
)
// Get captures a secret.
-func (c *client) Get(ctx context.Context, sType, org, name, path string) (*library.Secret, error) {
+func (c *client) Get(ctx context.Context, sType, org, name, path string) (*api.Secret, error) {
// handle the secret based off the type
switch sType {
case constants.SecretOrg:
diff --git a/secret/native/get_test.go b/secret/native/get_test.go
index f20dcdf5b..ad155ad44 100644
--- a/secret/native/get_test.go
+++ b/secret/native/get_test.go
@@ -7,13 +7,13 @@ import (
"reflect"
"testing"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_Get(t *testing.T) {
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetID(1)
want.SetOrg("foo")
want.SetRepo("bar")
@@ -22,7 +22,7 @@ func TestNative_Get(t *testing.T) {
want.SetValue("foob")
want.SetType("repo")
want.SetImages([]string{"foo", "bar"})
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetCreatedAt(1)
diff --git a/secret/native/list.go b/secret/native/list.go
index f1acfc069..1f6604f91 100644
--- a/secret/native/list.go
+++ b/secret/native/list.go
@@ -9,12 +9,11 @@ import (
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ "github.com/go-vela/server/constants"
)
// List captures a list of secrets.
-func (c *client) List(ctx context.Context, sType, org, name string, page, perPage int, teams []string) ([]*library.Secret, error) {
+func (c *client) List(ctx context.Context, sType, org, name string, page, perPage int, teams []string) ([]*api.Secret, error) {
// handle the secret based off the type
switch sType {
case constants.SecretOrg:
diff --git a/secret/native/list_test.go b/secret/native/list_test.go
index b201eda73..b332d42c6 100644
--- a/secret/native/list_test.go
+++ b/secret/native/list_test.go
@@ -7,13 +7,13 @@ import (
"reflect"
"testing"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_List(t *testing.T) {
// setup types
- sOne := new(library.Secret)
+ sOne := new(api.Secret)
sOne.SetID(1)
sOne.SetOrg("foo")
sOne.SetRepo("bar")
@@ -22,7 +22,7 @@ func TestNative_List(t *testing.T) {
sOne.SetValue("foob")
sOne.SetType("repo")
sOne.SetImages([]string{"foo", "bar"})
- sOne.SetAllowEvents(library.NewEventsFromMask(1))
+ sOne.SetAllowEvents(api.NewEventsFromMask(1))
sOne.SetAllowCommand(false)
sOne.SetAllowSubstitution(false)
sOne.SetCreatedAt(1)
@@ -30,7 +30,7 @@ func TestNative_List(t *testing.T) {
sOne.SetUpdatedAt(1)
sOne.SetUpdatedBy("user2")
- sTwo := new(library.Secret)
+ sTwo := new(api.Secret)
sTwo.SetID(2)
sTwo.SetOrg("foo")
sTwo.SetRepo("bar")
@@ -39,7 +39,7 @@ func TestNative_List(t *testing.T) {
sTwo.SetValue("baz")
sTwo.SetType("repo")
sTwo.SetImages([]string{"foo", "bar"})
- sTwo.SetAllowEvents(library.NewEventsFromMask(1))
+ sTwo.SetAllowEvents(api.NewEventsFromMask(1))
sTwo.SetAllowCommand(false)
sTwo.SetAllowSubstitution(false)
sTwo.SetCreatedAt(1)
@@ -47,7 +47,7 @@ func TestNative_List(t *testing.T) {
sTwo.SetUpdatedAt(1)
sTwo.SetUpdatedBy("user2")
- want := []*library.Secret{sTwo, sOne}
+ want := []*api.Secret{sTwo, sOne}
// setup database
db, err := database.NewTest()
diff --git a/secret/native/update.go b/secret/native/update.go
index 43bfcc011..12021d378 100644
--- a/secret/native/update.go
+++ b/secret/native/update.go
@@ -8,12 +8,12 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
// Update updates an existing secret.
-func (c *client) Update(ctx context.Context, sType, org, name string, s *library.Secret) (*library.Secret, error) {
+func (c *client) Update(ctx context.Context, sType, org, name string, s *api.Secret) (*api.Secret, error) {
// capture the secret from the native service
secret, err := c.Get(ctx, sType, org, name, s.GetName())
if err != nil {
diff --git a/secret/native/update_test.go b/secret/native/update_test.go
index 1ec2d597a..e134eec6b 100644
--- a/secret/native/update_test.go
+++ b/secret/native/update_test.go
@@ -8,13 +8,13 @@ import (
"testing"
"time"
+ api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
- "github.com/go-vela/types/library"
)
func TestNative_Update(t *testing.T) {
// setup types
- original := new(library.Secret)
+ original := new(api.Secret)
original.SetID(1)
original.SetOrg("foo")
original.SetRepo("bar")
@@ -23,7 +23,7 @@ func TestNative_Update(t *testing.T) {
original.SetValue("secretValue")
original.SetType("repo")
original.SetImages([]string{"foo", "baz"})
- original.SetAllowEvents(library.NewEventsFromMask(1))
+ original.SetAllowEvents(api.NewEventsFromMask(1))
original.SetAllowCommand(true)
original.SetAllowSubstitution(true)
original.SetCreatedAt(1)
@@ -31,7 +31,7 @@ func TestNative_Update(t *testing.T) {
original.SetUpdatedAt(time.Now().UTC().Unix())
original.SetUpdatedBy("user")
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetID(1)
want.SetOrg("foo")
want.SetRepo("bar")
@@ -40,7 +40,7 @@ func TestNative_Update(t *testing.T) {
want.SetValue("foob")
want.SetType("repo")
want.SetImages([]string{"foo", "bar"})
- want.SetAllowEvents(library.NewEventsFromMask(3))
+ want.SetAllowEvents(api.NewEventsFromMask(3))
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetCreatedAt(1)
@@ -81,7 +81,7 @@ func TestNative_Update(t *testing.T) {
func TestNative_Update_Invalid(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetName("baz")
sec.SetValue("foob")
diff --git a/secret/secret.go b/secret/secret.go
index 7dadc4b05..15dc307a8 100644
--- a/secret/secret.go
+++ b/secret/secret.go
@@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// New creates and returns a Vela service capable of
diff --git a/secret/service.go b/secret/service.go
index 6357dad05..e9183d299 100644
--- a/secret/service.go
+++ b/secret/service.go
@@ -5,7 +5,7 @@ package secret
import (
"context"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
// Service represents the interface for Vela integrating
@@ -18,15 +18,15 @@ type Service interface {
Driver() string
// Get defines a function that captures a secret.
- Get(context.Context, string, string, string, string) (*library.Secret, error)
+ Get(context.Context, string, string, string, string) (*api.Secret, error)
// List defines a function that captures a list of secrets.
- List(context.Context, string, string, string, int, int, []string) ([]*library.Secret, error)
+ List(context.Context, string, string, string, int, int, []string) ([]*api.Secret, error)
// Count defines a function that counts a list of secrets.
Count(context.Context, string, string, string, []string) (int64, error)
// Create defines a function that creates a new secret.
- Create(context.Context, string, string, string, *library.Secret) (*library.Secret, error)
+ Create(context.Context, string, string, string, *api.Secret) (*api.Secret, error)
// Update defines a function that updates an existing secret.
- Update(context.Context, string, string, string, *library.Secret) (*library.Secret, error)
+ Update(context.Context, string, string, string, *api.Secret) (*api.Secret, error)
// Delete defines a function that deletes a secret.
Delete(context.Context, string, string, string, string) error
diff --git a/secret/setup.go b/secret/setup.go
index 8a9917c0a..1f7c080d2 100644
--- a/secret/setup.go
+++ b/secret/setup.go
@@ -9,10 +9,10 @@ import (
"github.com/sirupsen/logrus"
+ "github.com/go-vela/server/constants"
"github.com/go-vela/server/database"
"github.com/go-vela/server/secret/native"
"github.com/go-vela/server/secret/vault"
- "github.com/go-vela/types/constants"
)
// Setup represents the configuration necessary for
diff --git a/secret/vault/count.go b/secret/vault/count.go
index 907165cea..927a1da85 100644
--- a/secret/vault/count.go
+++ b/secret/vault/count.go
@@ -10,7 +10,7 @@ import (
"github.com/hashicorp/vault/api"
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Count counts a list of secrets.
diff --git a/secret/vault/create.go b/secret/vault/create.go
index 6666d0f85..2a3e94a2b 100644
--- a/secret/vault/create.go
+++ b/secret/vault/create.go
@@ -9,13 +9,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ database "github.com/go-vela/server/database/types"
)
// Create creates a new secret.
-func (c *client) Create(ctx context.Context, sType, org, name string, s *library.Secret) (*library.Secret, error) {
+func (c *client) Create(ctx context.Context, sType, org, name string, s *api.Secret) (*api.Secret, error) {
// create log fields from secret metadata
fields := logrus.Fields{
"org": org,
@@ -38,7 +38,7 @@ func (c *client) Create(ctx context.Context, sType, org, name string, s *library
c.Logger.WithFields(fields).Tracef("creating vault %s secret %s for %s/%s", sType, s.GetName(), org, name)
// validate the secret
- err := database.SecretFromLibrary(s).Validate()
+ err := database.SecretFromAPI(s).Validate()
if err != nil {
return nil, err
}
@@ -61,25 +61,25 @@ func (c *client) Create(ctx context.Context, sType, org, name string, s *library
// createOrg is a helper function to create
// the org secret for the provided path.
-func (c *client) createOrg(org, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) createOrg(org, path string, data map[string]interface{}) (*api.Secret, error) {
return c.create(fmt.Sprintf("%s/org/%s/%s", c.config.Prefix, org, path), data)
}
// createRepo is a helper function to create
// the repo secret for the provided path.
-func (c *client) createRepo(org, repo, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) createRepo(org, repo, path string, data map[string]interface{}) (*api.Secret, error) {
return c.create(fmt.Sprintf("%s/repo/%s/%s/%s", c.config.Prefix, org, repo, path), data)
}
// createShared is a helper function to create
// the shared secret for the provided path.
-func (c *client) createShared(org, team, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) createShared(org, team, path string, data map[string]interface{}) (*api.Secret, error) {
return c.create(fmt.Sprintf("%s/shared/%s/%s/%s", c.config.Prefix, org, team, path), data)
}
// create is a helper function to create
// the secret for the provided path.
-func (c *client) create(path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) create(path string, data map[string]interface{}) (*api.Secret, error) {
if strings.HasPrefix("secret/data", c.config.Prefix) {
data = map[string]interface{}{
"data": data,
diff --git a/secret/vault/create_test.go b/secret/vault/create_test.go
index 1de42e2bf..f6eb60bff 100644
--- a/secret/vault/create_test.go
+++ b/secret/vault/create_test.go
@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestVault_Create_Org(t *testing.T) {
@@ -44,7 +44,7 @@ func TestVault_Create_Org(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("*")
sec.SetName("bar")
@@ -53,7 +53,7 @@ func TestVault_Create_Org(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -134,7 +134,7 @@ func TestVault_Create_Repo(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -143,7 +143,7 @@ func TestVault_Create_Repo(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(3))
+ sec.SetAllowEvents(api.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -225,7 +225,7 @@ func TestVault_Create_Shared(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetTeam("bar")
sec.SetName("baz")
@@ -234,7 +234,7 @@ func TestVault_Create_Shared(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -310,7 +310,7 @@ func TestVault_Create_InvalidSecret(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetTeam("")
@@ -364,7 +364,7 @@ func TestVault_Create_InvalidSecret(t *testing.T) {
func TestVault_Create_InvalidType(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetTeam("")
@@ -417,7 +417,7 @@ func TestVault_Create_InvalidType(t *testing.T) {
func TestVault_Create_ClosedServer(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetTeam("")
diff --git a/secret/vault/delete.go b/secret/vault/delete.go
index ef3521c54..246393764 100644
--- a/secret/vault/delete.go
+++ b/secret/vault/delete.go
@@ -9,7 +9,7 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
// Delete deletes a secret.
diff --git a/secret/vault/driver.go b/secret/vault/driver.go
index ad9a4858c..96dd0179d 100644
--- a/secret/vault/driver.go
+++ b/secret/vault/driver.go
@@ -2,7 +2,7 @@
package vault
-import "github.com/go-vela/types/constants"
+import "github.com/go-vela/server/constants"
// Driver outputs the configured secret driver.
func (c *client) Driver() string {
diff --git a/secret/vault/driver_test.go b/secret/vault/driver_test.go
index 4a0975766..22b3f0a18 100644
--- a/secret/vault/driver_test.go
+++ b/secret/vault/driver_test.go
@@ -8,7 +8,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestVault_Driver(t *testing.T) {
diff --git a/secret/vault/get.go b/secret/vault/get.go
index fcd083006..dd3b08591 100644
--- a/secret/vault/get.go
+++ b/secret/vault/get.go
@@ -10,12 +10,12 @@ import (
"github.com/hashicorp/vault/api"
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ velaAPI "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
// Get captures a secret.
-func (c *client) Get(ctx context.Context, sType, org, name, path string) (s *library.Secret, err error) {
+func (c *client) Get(ctx context.Context, sType, org, name, path string) (s *velaAPI.Secret, err error) {
// create log fields from secret metadata
fields := logrus.Fields{
"org": org,
diff --git a/secret/vault/get_test.go b/secret/vault/get_test.go
index 4b64b8ed7..b54c6e70f 100644
--- a/secret/vault/get_test.go
+++ b/secret/vault/get_test.go
@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestVault_Get_Org(t *testing.T) {
@@ -44,7 +44,8 @@ func TestVault_Get_Org(t *testing.T) {
defer fake.Close()
// setup types
- want := new(library.Secret)
+
+ want := new(api.Secret)
want.SetOrg("foo")
want.SetRepo("*")
want.SetName("bar")
@@ -53,7 +54,7 @@ func TestVault_Get_Org(t *testing.T) {
want.SetImages([]string{"foo", "bar"})
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
@@ -134,7 +135,7 @@ func TestVault_Get_Repo(t *testing.T) {
defer fake.Close()
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetOrg("foo")
want.SetRepo("bar")
want.SetName("baz")
@@ -143,7 +144,7 @@ func TestVault_Get_Repo(t *testing.T) {
want.SetImages([]string{"foo", "bar"})
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
- want.SetAllowEvents(library.NewEventsFromMask(3))
+ want.SetAllowEvents(api.NewEventsFromMask(3))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
@@ -224,7 +225,7 @@ func TestVault_Get_Shared(t *testing.T) {
defer fake.Close()
// setup types
- want := new(library.Secret)
+ want := new(api.Secret)
want.SetOrg("foo")
want.SetTeam("bar")
want.SetName("baz")
@@ -233,7 +234,7 @@ func TestVault_Get_Shared(t *testing.T) {
want.SetImages([]string{"foo", "bar"})
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
- want.SetAllowEvents(library.NewEventsFromMask(1))
+ want.SetAllowEvents(api.NewEventsFromMask(1))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
diff --git a/secret/vault/list.go b/secret/vault/list.go
index b42d00d66..b9bbfbfa0 100644
--- a/secret/vault/list.go
+++ b/secret/vault/list.go
@@ -10,8 +10,8 @@ import (
"github.com/hashicorp/vault/api"
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ velaAPI "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
// List captures a list of secrets.
@@ -19,7 +19,7 @@ import (
// We drop page and perPage as we are always returning all results.
// Vault API doesn't seem to support pagination. Might result in undesired
// behavior for fetching Vault secrets in paginated manner.
-func (c *client) List(ctx context.Context, sType, org, name string, _, _ int, _ []string) ([]*library.Secret, error) {
+func (c *client) List(ctx context.Context, sType, org, name string, _, _ int, _ []string) ([]*velaAPI.Secret, error) {
// create log fields from secret metadata
fields := logrus.Fields{
"org": org,
@@ -41,7 +41,7 @@ func (c *client) List(ctx context.Context, sType, org, name string, _, _ int, _
var err error
- s := []*library.Secret{}
+ s := []*velaAPI.Secret{}
vault := new(api.Secret)
diff --git a/secret/vault/list_test.go b/secret/vault/list_test.go
index 990c4f020..68c535888 100644
--- a/secret/vault/list_test.go
+++ b/secret/vault/list_test.go
@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestVault_List_Org(t *testing.T) {
@@ -59,7 +59,7 @@ func TestVault_List_Org(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("*")
sec.SetName("bar")
@@ -68,13 +68,13 @@ func TestVault_List_Org(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")
- want := []*library.Secret{sec}
+ want := []*api.Secret{sec}
type args struct {
version string
@@ -196,7 +196,7 @@ func TestVault_List_Repo(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -205,13 +205,13 @@ func TestVault_List_Repo(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(3))
+ sec.SetAllowEvents(api.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")
- want := []*library.Secret{sec}
+ want := []*api.Secret{sec}
type args struct {
version string
@@ -318,7 +318,7 @@ func TestVault_List_Shared(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetTeam("bar")
sec.SetName("baz")
@@ -327,13 +327,13 @@ func TestVault_List_Shared(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")
- want := []*library.Secret{sec}
+ want := []*api.Secret{sec}
type args struct {
version string
diff --git a/secret/vault/update.go b/secret/vault/update.go
index a269bd8f3..08ad3cda5 100644
--- a/secret/vault/update.go
+++ b/secret/vault/update.go
@@ -9,13 +9,13 @@ import (
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/database"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
+ database "github.com/go-vela/server/database/types"
)
// Update updates a secret.
-func (c *client) Update(ctx context.Context, sType, org, name string, s *library.Secret) (*library.Secret, error) {
+func (c *client) Update(ctx context.Context, sType, org, name string, s *api.Secret) (*api.Secret, error) {
// create log fields from secret metadata
fields := logrus.Fields{
"org": org,
@@ -67,7 +67,7 @@ func (c *client) Update(ctx context.Context, sType, org, name string, s *library
}
// validate the secret
- err = database.SecretFromLibrary(secretFromVault(vault)).Validate()
+ err = database.SecretFromAPI(secretFromVault(vault)).Validate()
if err != nil {
return nil, err
}
@@ -87,25 +87,25 @@ func (c *client) Update(ctx context.Context, sType, org, name string, s *library
// updateOrg is a helper function to update
// the org secret for the provided path.
-func (c *client) updateOrg(org, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) updateOrg(org, path string, data map[string]interface{}) (*api.Secret, error) {
return c.update(fmt.Sprintf("%s/%s/%s/%s", c.config.Prefix, constants.SecretOrg, org, path), data)
}
// updateRepo is a helper function to update
// the repo secret for the provided path.
-func (c *client) updateRepo(org, repo, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) updateRepo(org, repo, path string, data map[string]interface{}) (*api.Secret, error) {
return c.update(fmt.Sprintf("%s/%s/%s/%s/%s", c.config.Prefix, constants.SecretRepo, org, repo, path), data)
}
// updateShared is a helper function to update
// the shared secret for the provided path.
-func (c *client) updateShared(org, team, path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) updateShared(org, team, path string, data map[string]interface{}) (*api.Secret, error) {
return c.update(fmt.Sprintf("%s/%s/%s/%s/%s", c.config.Prefix, constants.SecretShared, org, team, path), data)
}
// update is a helper function to update
// the secret for the provided path.
-func (c *client) update(path string, data map[string]interface{}) (*library.Secret, error) {
+func (c *client) update(path string, data map[string]interface{}) (*api.Secret, error) {
if strings.HasPrefix("secret/data", c.config.Prefix) {
data = map[string]interface{}{
"data": data,
diff --git a/secret/vault/update_test.go b/secret/vault/update_test.go
index 39fea7d41..fa245f6cb 100644
--- a/secret/vault/update_test.go
+++ b/secret/vault/update_test.go
@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
- "github.com/go-vela/types/library"
+ api "github.com/go-vela/server/api/types"
)
func TestVault_Update_Org(t *testing.T) {
@@ -59,7 +59,7 @@ func TestVault_Update_Org(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("*")
sec.SetName("bar")
@@ -68,7 +68,7 @@ func TestVault_Update_Org(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -165,7 +165,7 @@ func TestVault_Update_Repo(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -174,7 +174,7 @@ func TestVault_Update_Repo(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
- sec.SetAllowEvents(library.NewEventsFromMask(3))
+ sec.SetAllowEvents(api.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -271,7 +271,7 @@ func TestVault_Update_Shared(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetTeam("bar")
sec.SetName("baz")
@@ -280,7 +280,7 @@ func TestVault_Update_Shared(t *testing.T) {
sec.SetImages([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
- sec.SetAllowEvents(library.NewEventsFromMask(1))
+ sec.SetAllowEvents(api.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
@@ -362,7 +362,7 @@ func TestVault_Update_InvalidSecret(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -415,7 +415,7 @@ func TestVault_Update_InvalidSecret(t *testing.T) {
func TestVault_Update_InvalidType(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -466,7 +466,7 @@ func TestVault_Update_InvalidType(t *testing.T) {
func TestVault_Update_ClosedServer(t *testing.T) {
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
@@ -539,7 +539,7 @@ func TestVault_Update_NoWrite(t *testing.T) {
defer fake.Close()
// setup types
- sec := new(library.Secret)
+ sec := new(api.Secret)
sec.SetOrg("foo")
sec.SetRepo("bar")
sec.SetName("baz")
diff --git a/secret/vault/vault.go b/secret/vault/vault.go
index 63745833f..9cf2a7161 100644
--- a/secret/vault/vault.go
+++ b/secret/vault/vault.go
@@ -12,8 +12,8 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/go-vela/types/constants"
- "github.com/go-vela/types/library"
+ velaAPI "github.com/go-vela/server/api/types"
+ "github.com/go-vela/server/constants"
)
const (
@@ -134,8 +134,8 @@ func New(opts ...ClientOpt) (*client, error) {
// secretFromVault is a helper function to convert a HashiCorp Vault secret to a Vela secret.
//
//nolint:gocyclo,funlen // ignore cyclomatic complexity and function length due to conditionals
-func secretFromVault(vault *api.Secret) *library.Secret {
- s := new(library.Secret)
+func secretFromVault(vault *api.Secret) *velaAPI.Secret {
+ s := new(velaAPI.Secret)
var data map[string]interface{}
// handle k/v v2
@@ -152,7 +152,7 @@ func secretFromVault(vault *api.Secret) *library.Secret {
if ok {
mask, err := maskJSON.Int64()
if err == nil {
- s.SetAllowEvents(library.NewEventsFromMask(mask))
+ s.SetAllowEvents(velaAPI.NewEventsFromMask(mask))
}
}
} else {
@@ -182,7 +182,7 @@ func secretFromVault(vault *api.Secret) *library.Secret {
}
}
- s.SetAllowEvents(library.NewEventsFromMask(allowEventsMask))
+ s.SetAllowEvents(velaAPI.NewEventsFromMask(allowEventsMask))
}
}
@@ -327,7 +327,7 @@ func secretFromVault(vault *api.Secret) *library.Secret {
}
// vaultFromSecret is a helper function to convert a Vela secret to a HashiCorp Vault secret.
-func vaultFromSecret(s *library.Secret) *api.Secret {
+func vaultFromSecret(s *velaAPI.Secret) *api.Secret {
data := make(map[string]interface{})
vault := new(api.Secret)
vault.Data = data
diff --git a/secret/vault/vault_test.go b/secret/vault/vault_test.go
index a60d7bd75..a566c0db1 100644
--- a/secret/vault/vault_test.go
+++ b/secret/vault/vault_test.go
@@ -13,7 +13,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/vault/api"
- "github.com/go-vela/types/library"
+ velaAPI "github.com/go-vela/server/api/types"
)
func TestVault_New(t *testing.T) {
@@ -127,14 +127,14 @@ func TestVault_secretFromVault(t *testing.T) {
},
}
- want := new(library.Secret)
+ want := new(velaAPI.Secret)
want.SetOrg("foo")
want.SetRepo("*")
want.SetTeam("foob")
want.SetName("bar")
want.SetValue("baz")
want.SetType("org")
- want.SetAllowEvents(library.NewEventsFromMask(8195))
+ want.SetAllowEvents(velaAPI.NewEventsFromMask(8195))
want.SetImages([]string{"foo", "bar"})
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
@@ -169,14 +169,14 @@ func TestVault_secretFromVault(t *testing.T) {
func TestVault_vaultFromSecret(t *testing.T) {
// setup types
- s := new(library.Secret)
+ s := new(velaAPI.Secret)
s.SetOrg("foo")
s.SetRepo("*")
s.SetTeam("foob")
s.SetName("bar")
s.SetValue("baz")
s.SetType("org")
- s.SetAllowEvents(library.NewEventsFromMask(1))
+ s.SetAllowEvents(velaAPI.NewEventsFromMask(1))
s.SetImages([]string{"foo", "bar"})
s.SetAllowCommand(true)
s.SetAllowSubstitution(true)
@@ -213,7 +213,7 @@ func TestVault_vaultFromSecret(t *testing.T) {
}
func TestVault_AccurateSecretFields(t *testing.T) {
- testSecret := library.Secret{}
+ testSecret := velaAPI.Secret{}
tSecret := reflect.TypeOf(testSecret)
diff --git a/util/compression_test.go b/util/compression_test.go
index 4328b61a3..5492a9750 100644
--- a/util/compression_test.go
+++ b/util/compression_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- "github.com/go-vela/types/constants"
+ "github.com/go-vela/server/constants"
)
func TestDatabase_compress(t *testing.T) {
diff --git a/util/util.go b/util/util.go
index 864fad7b3..f56b7670f 100644
--- a/util/util.go
+++ b/util/util.go
@@ -12,7 +12,6 @@ import (
"github.com/microcosm-cc/bluemonday"
api "github.com/go-vela/server/api/types"
- "github.com/go-vela/types"
)
// HandleError appends the error to the handler chain for logging and outputs it.
@@ -23,7 +22,7 @@ func HandleError(c context.Context, status int, err error) {
case *gin.Context:
//nolint:errcheck // ignore checking error
ctx.Error(err)
- ctx.AbortWithStatusJSON(status, types.Error{Message: &msg})
+ ctx.AbortWithStatusJSON(status, api.Error{Message: &msg})
return
default:
diff --git a/version/metadata.go b/version/metadata.go
new file mode 100644
index 000000000..3cb7fcfba
--- /dev/null
+++ b/version/metadata.go
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package version
+
+import "fmt"
+
+const metaFormat = `{
+ Architecture: %s,
+ BuildDate: %s,
+ Compiler: %s,
+ GitCommit: %s,
+ GoVersion: %s,
+ OperatingSystem: %s,
+}`
+
+// Metadata represents extra information surrounding the application version.
+type Metadata struct {
+ // Architecture represents the architecture information for the application.
+ Architecture string `json:"architecture,omitempty"`
+ // BuildDate represents the build date information for the application.
+ BuildDate string `json:"build_date,omitempty"`
+ // Compiler represents the compiler information for the application.
+ Compiler string `json:"compiler,omitempty"`
+ // GitCommit represents the git commit information for the application.
+ GitCommit string `json:"git_commit,omitempty"`
+ // GoVersion represents the golang version information for the application.
+ GoVersion string `json:"go_version,omitempty"`
+ // OperatingSystem represents the operating system information for the application.
+ OperatingSystem string `json:"operating_system,omitempty"`
+}
+
+// String implements the Stringer interface for the Metadata type.
+func (m *Metadata) String() string {
+ return fmt.Sprintf(
+ metaFormat,
+ m.Architecture,
+ m.BuildDate,
+ m.Compiler,
+ m.GitCommit,
+ m.GoVersion,
+ m.OperatingSystem,
+ )
+}
diff --git a/version/metadata_test.go b/version/metadata_test.go
new file mode 100644
index 000000000..831e2c321
--- /dev/null
+++ b/version/metadata_test.go
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package version
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestVersion_Metadata_String(t *testing.T) {
+ // setup types
+ m := &Metadata{
+ Architecture: "amd64",
+ BuildDate: "1970-1-1T00:00:00Z",
+ Compiler: "gc",
+ GitCommit: "abcdef123456789",
+ GoVersion: "1.19.0",
+ OperatingSystem: "linux",
+ }
+
+ want := fmt.Sprintf(
+ metaFormat,
+ m.Architecture,
+ m.BuildDate,
+ m.Compiler,
+ m.GitCommit,
+ m.GoVersion,
+ m.OperatingSystem,
+ )
+
+ // run test
+ got := m.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
diff --git a/version/version.go b/version/version.go
index f363d79b4..efc7a68ae 100644
--- a/version/version.go
+++ b/version/version.go
@@ -8,10 +8,72 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/sirupsen/logrus"
-
- "github.com/go-vela/types/version"
)
+const versionFormat = `{
+ Canonical: %s,
+ Major: %d,
+ Minor: %d,
+ Patch: %d,
+ PreRelease: %s,
+ Metadata: {
+ Architecture: %s,
+ BuildDate: %s,
+ Compiler: %s,
+ GitCommit: %s,
+ GoVersion: %s,
+ OperatingSystem: %s,
+ }
+}`
+
+// Version represents application information that
+// follows semantic version guidelines from
+// https://semver.org/.
+//
+// swagger:model Version
+type Version struct {
+ // Canonical represents a canonical semantic version for the application.
+ Canonical string `json:"canonical"`
+ // Major represents incompatible API changes.
+ Major uint64 `json:"major"`
+ // Minor represents added functionality in a backwards compatible manner.
+ Minor uint64 `json:"minor"`
+ // Patch represents backwards compatible bug fixes.
+ Patch uint64 `json:"patch"`
+ // PreRelease represents unstable changes that might not be compatible.
+ PreRelease string `json:"pre_release,omitempty"`
+ // Metadata represents extra information surrounding the application version.
+ Metadata Metadata `json:"metadata,omitempty"`
+}
+
+// Meta implements a formatted string containing only metadata for the Version type.
+func (v *Version) Meta() string {
+ return v.Metadata.String()
+}
+
+// Semantic implements a formatted string containing a formal semantic version for the Version type.
+func (v *Version) Semantic() string {
+ return v.Canonical
+}
+
+// String implements the Stringer interface for the Version type.
+func (v *Version) String() string {
+ return fmt.Sprintf(
+ versionFormat,
+ v.Canonical,
+ v.Major,
+ v.Minor,
+ v.Patch,
+ v.PreRelease,
+ v.Metadata.Architecture,
+ v.Metadata.BuildDate,
+ v.Metadata.Compiler,
+ v.Metadata.GitCommit,
+ v.Metadata.GoVersion,
+ v.Metadata.OperatingSystem,
+ )
+}
+
var (
// Arch represents the architecture information for the package.
Arch = runtime.GOARCH
@@ -30,7 +92,7 @@ var (
)
// New creates a new version object for Vela that is used throughout the application.
-func New() *version.Version {
+func New() *Version {
// check if a semantic tag was provided
if len(Tag) == 0 {
logrus.Warning("no semantic tag provided - defaulting to v0.0.0")
@@ -44,13 +106,13 @@ func New() *version.Version {
fmt.Println(fmt.Errorf("unable to parse semantic version for %s: %w", Tag, err))
}
- return &version.Version{
+ return &Version{
Canonical: Tag,
Major: v.Major(),
Minor: v.Minor(),
Patch: v.Patch(),
PreRelease: v.Prerelease(),
- Metadata: version.Metadata{
+ Metadata: Metadata{
Architecture: Arch,
BuildDate: Date,
Compiler: Compiler,
diff --git a/version/version_test.go b/version/version_test.go
new file mode 100644
index 000000000..620ad5267
--- /dev/null
+++ b/version/version_test.go
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package version
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestVersion_Version_Meta(t *testing.T) {
+ // setup types
+ v := &Version{
+ Canonical: "v1.2.3",
+ Major: 1,
+ Minor: 2,
+ Patch: 3,
+ PreRelease: "",
+ Metadata: Metadata{
+ Architecture: "amd64",
+ BuildDate: "1970-1-1T00:00:00Z",
+ Compiler: "gc",
+ GitCommit: "abcdef123456789",
+ GoVersion: "1.19.0",
+ OperatingSystem: "linux",
+ },
+ }
+
+ want := v.Metadata.String()
+
+ // run test
+ got := v.Meta()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+func TestVersion_Version_Semantic(t *testing.T) {
+ // setup types
+ v := &Version{
+ Canonical: "v1.2.3",
+ Major: 1,
+ Minor: 2,
+ Patch: 3,
+ PreRelease: "",
+ Metadata: Metadata{
+ Architecture: "amd64",
+ BuildDate: "1970-1-1T00:00:00Z",
+ Compiler: "gc",
+ GitCommit: "abcdef123456789",
+ GoVersion: "1.19.0",
+ OperatingSystem: "linux",
+ },
+ }
+
+ want := v.Canonical
+
+ // run test
+ got := v.Semantic()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}
+
+func TestVersion_Version_String(t *testing.T) {
+ // setup types
+ v := &Version{
+ Canonical: "v1.2.3",
+ Major: 1,
+ Minor: 2,
+ Patch: 3,
+ PreRelease: "",
+ Metadata: Metadata{
+ Architecture: "amd64",
+ BuildDate: "1970-1-1T00:00:00Z",
+ Compiler: "gc",
+ GitCommit: "abcdef123456789",
+ GoVersion: "1.19.0",
+ OperatingSystem: "linux",
+ },
+ }
+
+ want := fmt.Sprintf(
+ versionFormat,
+ v.Canonical,
+ v.Major,
+ v.Minor,
+ v.Patch,
+ v.PreRelease,
+ v.Metadata.Architecture,
+ v.Metadata.BuildDate,
+ v.Metadata.Compiler,
+ v.Metadata.GitCommit,
+ v.Metadata.GoVersion,
+ v.Metadata.OperatingSystem,
+ )
+
+ // run test
+ got := v.String()
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("String is %v, want %v", got, want)
+ }
+}