Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57e5162
Merge branch 'master' of github.com:go-vela/server
jbrockopp Feb 23, 2022
b6b840c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 10, 2022
858c818
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 16, 2022
ceddb11
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 28, 2022
331b2a2
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 11, 2022
c4ec5fb
Merge branches 'master' and 'master' of github.com:go-vela/server
jbrockopp Apr 18, 2022
30c1151
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 20, 2022
0ddc31c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 27, 2022
890f9fa
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 9, 2022
cf4ca0e
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 20, 2022
175e5c5
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 31, 2022
1728dce
Merge branch 'master' of github.com:go-vela/server
jbrockopp Jun 12, 2022
88d3974
Merge branch 'master' of github.com:go-vela/server
jbrockopp Jun 22, 2022
de5ac75
feat(database): add user engine
jbrockopp Jun 22, 2022
8f2fce6
chore(database): remove old user logic
jbrockopp Jun 22, 2022
736a0e9
refactor(database): restructure DDL functions
jbrockopp Jun 22, 2022
c28ca23
chore: updates for database user engine
jbrockopp Jun 22, 2022
b2350a9
Merge branch 'master' into refactor/database/user
jbrockopp Jun 28, 2022
ad08516
Merge branch 'refactor/database/user' of github.com:go-vela/server in…
jbrockopp Jun 28, 2022
a3798c3
chore: address linter feedback
jbrockopp Jun 28, 2022
ce66bd7
chore: address review feedback
jbrockopp Jun 29, 2022
ab1577e
Merge branch 'master' into refactor/database/user
wass3r Jul 31, 2022
b38840a
Merge branch 'master' into refactor/database/user
jbrockopp Aug 8, 2022
9445022
Merge branch 'master' into refactor/database/user
wass3r Aug 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func AllUsers(c *gin.Context) {
logrus.Info("Admin: reading all users")

// send API call to capture all users
u, err := database.FromContext(c).GetUserList()
u, err := database.FromContext(c).ListUsers()
if err != nil {
retErr := fmt.Errorf("unable to capture all users: %w", err)

Expand Down
4 changes: 2 additions & 2 deletions api/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Authenticate(c *gin.Context) {
}

// send API call to capture the user logging in
u, err := database.FromContext(c).GetUserName(newUser.GetName())
u, err := database.FromContext(c).GetUserForName(newUser.GetName())
// create a new user account
if len(u.GetName()) == 0 || err != nil {
// create unique id for the user
Expand Down Expand Up @@ -314,7 +314,7 @@ func AuthenticateToken(c *gin.Context) {
}

// check if the user exists
u, err = database.FromContext(c).GetUserName(u.GetName())
u, err = database.FromContext(c).GetUserForName(u.GetName())
if err != nil {
retErr := fmt.Errorf("user %s not found", u.GetName())

Expand Down
2 changes: 1 addition & 1 deletion api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func CustomMetrics(c *gin.Context) {
// helper function to get the totals of resource types.
func recordGauges(c *gin.Context) {
// send API call to capture the total number of users
u, err := database.FromContext(c).GetUserCount()
u, err := database.FromContext(c).CountUsers()
if err != nil {
logrus.Errorf("unable to get count of all users: %v", err)
}
Expand Down
26 changes: 8 additions & 18 deletions api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func CreateUser(c *gin.Context) {
}

// send API call to capture the created user
user, _ := database.FromContext(c).GetUserName(input.GetName())
user, _ := database.FromContext(c).GetUserForName(input.GetName())

c.JSON(http.StatusCreated, user)
}
Expand Down Expand Up @@ -172,18 +172,8 @@ func GetUsers(c *gin.Context) {
// ensure per_page isn't above or below allowed values
perPage = util.MaxInt(1, util.MinInt(100, perPage))

// send API call to capture the total number of users
t, err := database.FromContext(c).GetUserCount()
if err != nil {
retErr := fmt.Errorf("unable to get users count: %w", err)

util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

// send API call to capture the list of users
users, err := database.FromContext(c).GetUserLiteList(page, perPage)
users, t, err := database.FromContext(c).ListLiteUsers(page, perPage)
if err != nil {
retErr := fmt.Errorf("unable to get users: %w", err)

Expand Down Expand Up @@ -311,7 +301,7 @@ func UpdateCurrentUser(c *gin.Context) {
}

// send API call to capture the updated user
u, err = database.FromContext(c).GetUserName(u.GetName())
u, err = database.FromContext(c).GetUserForName(u.GetName())
if err != nil {
retErr := fmt.Errorf("unable to get updated user %s: %w", u.GetName(), err)

Expand Down Expand Up @@ -363,7 +353,7 @@ func GetUser(c *gin.Context) {
}).Infof("reading user %s", user)

// send API call to capture the user
u, err := database.FromContext(c).GetUserName(user)
u, err := database.FromContext(c).GetUserForName(user)
if err != nil {
retErr := fmt.Errorf("unable to get user %s: %w", user, err)

Expand Down Expand Up @@ -548,7 +538,7 @@ func UpdateUser(c *gin.Context) {
}

// send API call to capture the user
u, err = database.FromContext(c).GetUserName(user)
u, err = database.FromContext(c).GetUserForName(user)
if err != nil {
retErr := fmt.Errorf("unable to get user %s: %w", user, err)

Expand Down Expand Up @@ -584,7 +574,7 @@ func UpdateUser(c *gin.Context) {
}

// send API call to capture the updated user
u, _ = database.FromContext(c).GetUserName(user)
u, _ = database.FromContext(c).GetUserForName(user)

c.JSON(http.StatusOK, u)
}
Expand Down Expand Up @@ -633,7 +623,7 @@ func DeleteUser(c *gin.Context) {
}).Infof("deleting user %s", user)

// send API call to capture the user
u, err := database.FromContext(c).GetUserName(user)
u, err := database.FromContext(c).GetUserForName(user)
if err != nil {
retErr := fmt.Errorf("unable to get user %s: %w", user, err)

Expand All @@ -643,7 +633,7 @@ func DeleteUser(c *gin.Context) {
}

// send API call to remove the user
err = database.FromContext(c).DeleteUser(u.GetID())
err = database.FromContext(c).DeleteUser(u)
if err != nil {
retErr := fmt.Errorf("unable to delete user %s: %w", u.GetName(), err)

Expand Down
4 changes: 2 additions & 2 deletions database/pipeline/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ ON pipelines (repo_id);
`
)

// CreateIndexes creates the indexes for the pipelines table in the database.
func (e *engine) CreateIndexes() error {
// CreatePipelineIndexes creates the indexes for the pipelines table in the database.
func (e *engine) CreatePipelineIndexes() error {
e.logger.Tracef("creating indexes for pipelines table in the database")

// create the repo_id column index for the pipelines table
Expand Down
8 changes: 4 additions & 4 deletions database/pipeline/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
)

func TestPipeline_Engine_CreateIndexes(t *testing.T) {
func TestPipeline_Engine_CreatePipelineIndexes(t *testing.T) {
// setup types
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
Expand Down Expand Up @@ -41,18 +41,18 @@ func TestPipeline_Engine_CreateIndexes(t *testing.T) {
// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := test.database.CreateIndexes()
err := test.database.CreatePipelineIndexes()

if test.failure {
if err == nil {
t.Errorf("CreateIndexes for %s should have returned err", test.name)
t.Errorf("CreatePipelineIndexes for %s should have returned err", test.name)
}

return
}

if err != nil {
t.Errorf("CreateIndexes for %s returned err: %v", test.name, err)
t.Errorf("CreatePipelineIndexes for %s returned err: %v", test.name, err)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions database/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func New(opts ...EngineOpt) (*engine, error) {
}

// create the pipelines table
err := e.CreateTable(e.client.Config.Dialector.Name())
err := e.CreatePipelineTable(e.client.Config.Dialector.Name())
if err != nil {
return nil, fmt.Errorf("unable to create %s table: %w", constants.TablePipeline, err)
}

// create the indexes for the pipelines table
err = e.CreateIndexes()
err = e.CreatePipelineIndexes()
if err != nil {
return nil, fmt.Errorf("unable to create indexes for %s table: %w", constants.TablePipeline, err)
}
Expand Down
8 changes: 4 additions & 4 deletions database/pipeline/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type PipelineService interface {
//
// https://en.wikipedia.org/wiki/Data_definition_language

// CreateIndexes creates the indexes for the pipelines table.
CreateIndexes() error
// CreateTable defines a function that creates the pipelines table.
CreateTable(string) error
// CreatePipelineIndexes defines a function that creates the indexes for the pipelines table.
CreatePipelineIndexes() error
// CreatePipelineTable defines a function that creates the pipelines table.
CreatePipelineTable(string) error

// Pipeline Data Manipulation Language Functions
//
Expand Down
4 changes: 2 additions & 2 deletions database/pipeline/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pipelines (
`
)

// CreateTable creates the pipelines table in the database.
func (e *engine) CreateTable(driver string) error {
// CreatePipelineTable creates the pipelines table in the database.
func (e *engine) CreatePipelineTable(driver string) error {
e.logger.Tracef("creating pipelines table in the database")

// handle the driver provided to create the table
Expand Down
8 changes: 4 additions & 4 deletions database/pipeline/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
)

func TestPipeline_Engine_CreateTable(t *testing.T) {
func TestPipeline_Engine_CreatePipelineTable(t *testing.T) {
// setup types
_postgres, _mock := testPostgres(t)
defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }()
Expand Down Expand Up @@ -41,18 +41,18 @@ func TestPipeline_Engine_CreateTable(t *testing.T) {
// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := test.database.CreateTable(test.name)
err := test.database.CreatePipelineTable(test.name)

if test.failure {
if err == nil {
t.Errorf("CreateTable for %s should have returned err", test.name)
t.Errorf("CreatePipelineTable for %s should have returned err", test.name)
}

return
}

if err != nil {
t.Errorf("CreateTable for %s returned err: %v", test.name, err)
t.Errorf("CreatePipelineTable for %s returned err: %v", test.name, err)
}
})
}
Expand Down
34 changes: 0 additions & 34 deletions database/postgres/ddl/user.go

This file was deleted.

68 changes: 0 additions & 68 deletions database/postgres/dml/user.go

This file was deleted.

Loading