From 7882348ee5392076b52d43b9b04771a10238a35a Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Tue, 14 Jul 2020 21:37:20 -0700 Subject: [PATCH] stuff --- Readme.md | 4 ++-- authentication/{authenticationapihttp.go => api.go} | 0 .../{authenticationapihttp_test.go => api_test.go} | 2 +- .../{authenticationmiddleware.go => middleware.go} | 0 ...ticationmiddleware_test.go => middleware_test.go} | 0 authentication/{authenticationui.go => ui.go} | 0 .../{authenticationui_test.go => ui_test.go} | 0 common/error.go | 1 - common/query.go | 3 +++ models/job.go | 2 +- models/node.go | 4 ++-- models/task.go | 2 +- task/agent.go | 12 ++---------- 13 files changed, 12 insertions(+), 18 deletions(-) rename authentication/{authenticationapihttp.go => api.go} (100%) rename authentication/{authenticationapihttp_test.go => api_test.go} (96%) rename authentication/{authenticationmiddleware.go => middleware.go} (100%) rename authentication/{authenticationmiddleware_test.go => middleware_test.go} (100%) rename authentication/{authenticationui.go => ui.go} (100%) rename authentication/{authenticationui_test.go => ui_test.go} (100%) diff --git a/Readme.md b/Readme.md index a75983d..b6e34af 100644 --- a/Readme.md +++ b/Readme.md @@ -57,9 +57,9 @@ Covey has, and will gain (in the coming weeks/months) a variety of features, inc * [x] ~~Evaluate designing a very basic framework (for keeping things cleaner)~~ * [x] ~~Evaluate GraphQL for the API~~ * [x] Redesign DB using Gorm -* [ ] Fully implement (and test) the API +* [x] Fully implement (and test) the API * [x] Swagger (OpenAPI) -* [ ] Fully document the API +* [x] Fully document the API #### V0.6 Alpha diff --git a/authentication/authenticationapihttp.go b/authentication/api.go similarity index 100% rename from authentication/authenticationapihttp.go rename to authentication/api.go diff --git a/authentication/authenticationapihttp_test.go b/authentication/api_test.go similarity index 96% rename from authentication/authenticationapihttp_test.go rename to authentication/api_test.go index 6e49db2..f558792 100644 --- a/authentication/authenticationapihttp_test.go +++ b/authentication/api_test.go @@ -9,7 +9,7 @@ import ( ) //revive:disable:cognitive-complexity -func Test_tokenGetAPI(t *testing.T) { +func TestTokenGetAPI(t *testing.T) { var tests = []struct { userid string want string diff --git a/authentication/authenticationmiddleware.go b/authentication/middleware.go similarity index 100% rename from authentication/authenticationmiddleware.go rename to authentication/middleware.go diff --git a/authentication/authenticationmiddleware_test.go b/authentication/middleware_test.go similarity index 100% rename from authentication/authenticationmiddleware_test.go rename to authentication/middleware_test.go diff --git a/authentication/authenticationui.go b/authentication/ui.go similarity index 100% rename from authentication/authenticationui.go rename to authentication/ui.go diff --git a/authentication/authenticationui_test.go b/authentication/ui_test.go similarity index 100% rename from authentication/authenticationui_test.go rename to authentication/ui_test.go diff --git a/common/error.go b/common/error.go index 2644074..a598605 100644 --- a/common/error.go +++ b/common/error.go @@ -22,5 +22,4 @@ func Recover() { } panic(fmt.Errorf("r: %v, type: %T", r, r)) } - } diff --git a/common/query.go b/common/query.go index 38092a0..9765e82 100644 --- a/common/query.go +++ b/common/query.go @@ -10,6 +10,7 @@ import ( "gorm.io/gorm" ) +// QueryParams parses a URL query and gets the items from the database based on it. type QueryParams struct { Limit int `form:"limit" validate:"min=0,max=50"` Offset int `form:"offset"` @@ -18,6 +19,7 @@ type QueryParams struct { Expand bool `form:"expand"` } +// Query runs a query against the database. func (q *QueryParams) Query(table string, model interface{}, db *gorm.DB) error { v := validator.New() err := v.Struct(q) @@ -44,6 +46,7 @@ func (q *QueryParams) Query(table string, model interface{}, db *gorm.DB) error return nil } +// Setup parses a url query. func (q *QueryParams) Setup(r *http.Request) error { q.Limit = 20 q.Offset = 0 diff --git a/models/job.go b/models/job.go index 22dcd13..c35bbb8 100644 --- a/models/job.go +++ b/models/job.go @@ -65,7 +65,7 @@ type Job struct { func (j *Job) GetIDShort() string { x, _ := hex.DecodeString(j.ID); return hex.EncodeToString(x[:8]) } // BeforeCreate generates the job ID before saving. -func (j *Job) BeforeCreate(tx *gorm.DB) (err error) { +func (j *Job) BeforeCreate(_ *gorm.DB) (err error) { j.ID = common.GenerateID(j) j.IDShort = j.GetIDShort() return nil diff --git a/models/node.go b/models/node.go index dad2c64..86656f4 100644 --- a/models/node.go +++ b/models/node.go @@ -29,13 +29,13 @@ type Node struct { func (n *Node) GetIDShort() string { x, _ := hex.DecodeString(n.ID); return hex.EncodeToString(x[:8]) } // BeforeCreate gets the short ID before saving. -func (n *Node) BeforeCreate(tx *gorm.DB) (err error) { +func (n *Node) BeforeCreate(_ *gorm.DB) (err error) { n.IDShort = n.GetIDShort() return nil } // AfterFind runs the setup for a node -func (n *Node) AfterFind(tx *gorm.DB) (err error) { +func (n *Node) AfterFind(_ *gorm.DB) (err error) { return n.Setup() } diff --git a/models/task.go b/models/task.go index b8386b8..8d20601 100644 --- a/models/task.go +++ b/models/task.go @@ -54,7 +54,7 @@ type Task struct { func (t *Task) GetIDShort() string { x, _ := hex.DecodeString(t.ID); return hex.EncodeToString(x[:8]) } // BeforeCreate initializes the default values for a Task. -func (t *Task) BeforeCreate(tx *gorm.DB) (err error) { +func (t *Task) BeforeCreate(_ *gorm.DB) (err error) { t.ExitCode = 258 t.State = StateQueued t.ID = common.GenerateID(t) diff --git a/task/agent.go b/task/agent.go index e2e8e66..51e5315 100644 --- a/task/agent.go +++ b/task/agent.go @@ -111,11 +111,7 @@ func initAgent(agent string) error { return result.Error } - if err := initQueues(t); err != nil { - return err - } - - return nil + return initQueues(t) } // Init initializes the agent queues. @@ -128,11 +124,7 @@ func Init() error { return result.Error } - if err := initQueues(t); err != nil { - return err - } - - return nil + return initQueues(t) } // RegisterAgentHandlers registers the handler for receiving information from agents.