From f6cb8b4d1705f649843b291579dc1b872f2fa9bb Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 19 Nov 2024 09:10:55 -0500 Subject: [PATCH] fixes --- pkg/auth/jwt.go | 4 +-- pkg/database/mocks/Store.go | 32 +++++++++++----------- pkg/database/models.go | 4 +-- pkg/database/querier.go | 4 +-- pkg/database/users.sql.go | 4 +-- pkg/sinks/relay.go | 8 +++--- sql/postgres/migrations/001_initial.up.sql | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pkg/auth/jwt.go b/pkg/auth/jwt.go index d85bbb8..c915c29 100644 --- a/pkg/auth/jwt.go +++ b/pkg/auth/jwt.go @@ -98,7 +98,7 @@ func (a *Auth) Login(ctx context.Context, username, password string) (token stri return a.newToken(found.ID), nil } -func (a *Auth) newToken(uid int32) string { +func (a *Auth) newToken(uid int) string { claims := claims{ "sub": strconv.Itoa(int(uid)), } @@ -134,7 +134,7 @@ func (a *Auth) routeRefresh(w http.ResponseWriter, r *http.Request) { return } - tok := a.newToken(int32(uid)) + tok := a.newToken(uid) cookie := &http.Cookie{ Name: "jwt", diff --git a/pkg/database/mocks/Store.go b/pkg/database/mocks/Store.go index 5ea8209..2c769a4 100644 --- a/pkg/database/mocks/Store.go +++ b/pkg/database/mocks/Store.go @@ -1293,7 +1293,7 @@ func (_c *Store_GetTalkgroupsWithLearnedBySystem_Call) RunAndReturn(run func(con } // GetUserByID provides a mock function with given fields: ctx, id -func (_m *Store) GetUserByID(ctx context.Context, id int32) (database.User, error) { +func (_m *Store) GetUserByID(ctx context.Context, id int) (database.User, error) { ret := _m.Called(ctx, id) if len(ret) == 0 { @@ -1302,16 +1302,16 @@ func (_m *Store) GetUserByID(ctx context.Context, id int32) (database.User, erro var r0 database.User var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, int) (database.User, error)); ok { return rf(ctx, id) } - if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { + if rf, ok := ret.Get(0).(func(context.Context, int) database.User); ok { r0 = rf(ctx, id) } else { r0 = ret.Get(0).(database.User) } - if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { r1 = rf(ctx, id) } else { r1 = ret.Error(1) @@ -1327,14 +1327,14 @@ type Store_GetUserByID_Call struct { // GetUserByID is a helper method to define mock.On call // - ctx context.Context -// - id int32 +// - id int func (_e *Store_Expecter) GetUserByID(ctx interface{}, id interface{}) *Store_GetUserByID_Call { return &Store_GetUserByID_Call{Call: _e.mock.On("GetUserByID", ctx, id)} } -func (_c *Store_GetUserByID_Call) Run(run func(ctx context.Context, id int32)) *Store_GetUserByID_Call { +func (_c *Store_GetUserByID_Call) Run(run func(ctx context.Context, id int)) *Store_GetUserByID_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32)) + run(args[0].(context.Context), args[1].(int)) }) return _c } @@ -1344,13 +1344,13 @@ func (_c *Store_GetUserByID_Call) Return(_a0 database.User, _a1 error) *Store_Ge return _c } -func (_c *Store_GetUserByID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByID_Call { +func (_c *Store_GetUserByID_Call) RunAndReturn(run func(context.Context, int) (database.User, error)) *Store_GetUserByID_Call { _c.Call.Return(run) return _c } // GetUserByUID provides a mock function with given fields: ctx, id -func (_m *Store) GetUserByUID(ctx context.Context, id int32) (database.User, error) { +func (_m *Store) GetUserByUID(ctx context.Context, id int) (database.User, error) { ret := _m.Called(ctx, id) if len(ret) == 0 { @@ -1359,16 +1359,16 @@ func (_m *Store) GetUserByUID(ctx context.Context, id int32) (database.User, err var r0 database.User var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int32) (database.User, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, int) (database.User, error)); ok { return rf(ctx, id) } - if rf, ok := ret.Get(0).(func(context.Context, int32) database.User); ok { + if rf, ok := ret.Get(0).(func(context.Context, int) database.User); ok { r0 = rf(ctx, id) } else { r0 = ret.Get(0).(database.User) } - if rf, ok := ret.Get(1).(func(context.Context, int32) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { r1 = rf(ctx, id) } else { r1 = ret.Error(1) @@ -1384,14 +1384,14 @@ type Store_GetUserByUID_Call struct { // GetUserByUID is a helper method to define mock.On call // - ctx context.Context -// - id int32 +// - id int func (_e *Store_Expecter) GetUserByUID(ctx interface{}, id interface{}) *Store_GetUserByUID_Call { return &Store_GetUserByUID_Call{Call: _e.mock.On("GetUserByUID", ctx, id)} } -func (_c *Store_GetUserByUID_Call) Run(run func(ctx context.Context, id int32)) *Store_GetUserByUID_Call { +func (_c *Store_GetUserByUID_Call) Run(run func(ctx context.Context, id int)) *Store_GetUserByUID_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int32)) + run(args[0].(context.Context), args[1].(int)) }) return _c } @@ -1401,7 +1401,7 @@ func (_c *Store_GetUserByUID_Call) Return(_a0 database.User, _a1 error) *Store_G return _c } -func (_c *Store_GetUserByUID_Call) RunAndReturn(run func(context.Context, int32) (database.User, error)) *Store_GetUserByUID_Call { +func (_c *Store_GetUserByUID_Call) RunAndReturn(run func(context.Context, int) (database.User, error)) *Store_GetUserByUID_Call { _c.Call.Return(run) return _c } diff --git a/pkg/database/models.go b/pkg/database/models.go index 987df9c..f756897 100644 --- a/pkg/database/models.go +++ b/pkg/database/models.go @@ -26,7 +26,7 @@ type Alert struct { } type ApiKey struct { - ID int32 `json:"id"` + ID int `json:"id"` Owner int `json:"owner"` CreatedAt time.Time `json:"created_at"` Expires pgtype.Timestamp `json:"expires"` @@ -109,7 +109,7 @@ type TalkgroupsLearned struct { } type User struct { - ID int32 `json:"id"` + ID int `json:"id"` Username string `json:"username"` Password string `json:"password"` Email string `json:"email"` diff --git a/pkg/database/querier.go b/pkg/database/querier.go index d1358a4..aa42757 100644 --- a/pkg/database/querier.go +++ b/pkg/database/querier.go @@ -31,8 +31,8 @@ type Querier interface { GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroupsWithLearnedRow, error) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error) - GetUserByID(ctx context.Context, id int32) (User, error) - GetUserByUID(ctx context.Context, id int32) (User, error) + GetUserByID(ctx context.Context, id int) (User, error) + GetUserByUID(ctx context.Context, id int) (User, error) GetUserByUsername(ctx context.Context, username string) (User, error) GetUsers(ctx context.Context) ([]User, error) SetCallTranscript(ctx context.Context, iD uuid.UUID, transcript *string) error diff --git a/pkg/database/users.sql.go b/pkg/database/users.sql.go index 479cbc8..fa05dff 100644 --- a/pkg/database/users.sql.go +++ b/pkg/database/users.sql.go @@ -113,7 +113,7 @@ SELECT id, username, password, email, is_admin, prefs FROM users WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetUserByID(ctx context.Context, id int32) (User, error) { +func (q *Queries) GetUserByID(ctx context.Context, id int) (User, error) { row := q.db.QueryRow(ctx, getUserByID, id) var i User err := row.Scan( @@ -132,7 +132,7 @@ SELECT id, username, password, email, is_admin, prefs FROM users WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetUserByUID(ctx context.Context, id int32) (User, error) { +func (q *Queries) GetUserByUID(ctx context.Context, id int) (User, error) { row := q.db.QueryRow(ctx, getUserByUID, id) var i User err := row.Scan( diff --git a/pkg/sinks/relay.go b/pkg/sinks/relay.go index 1f3bb97..a481764 100644 --- a/pkg/sinks/relay.go +++ b/pkg/sinks/relay.go @@ -44,21 +44,20 @@ func NewRelayManager(s Sinks, cfgs []config.Relay) (*RelayManager, error) { } for i, cfg := range cfgs { - rs, err := rm.newRelay(cfg) + rs, err := rm.newRelay(i, cfg) if err != nil { return nil, err } rm.relays = append(rm.relays, rs) - sinkName := fmt.Sprintf("relay%d:%s", i, rs.url.Host) - s.Register(sinkName, rs, cfg.Required) + s.Register(rs.Name, rs, cfg.Required) } return rm, nil } -func (rs *RelayManager) newRelay(cfg config.Relay) (*Relay, error) { +func (rs *RelayManager) newRelay(idx int, cfg config.Relay) (*Relay, error) { u, err := url.Parse(cfg.URL) if err != nil { return nil, err @@ -71,6 +70,7 @@ func (rs *RelayManager) newRelay(cfg config.Relay) (*Relay, error) { u = u.JoinPath("/api/call-upload") return &Relay{ + Name: fmt.Sprintf("relay%d:%s", idx, u.Host), Relay: cfg, url: u, mgr: rs, diff --git a/sql/postgres/migrations/001_initial.up.sql b/sql/postgres/migrations/001_initial.up.sql index 445fa4f..59aa9ec 100644 --- a/sql/postgres/migrations/001_initial.up.sql +++ b/sql/postgres/migrations/001_initial.up.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS talkgroups( alert BOOLEAN NOT NULL DEFAULT 'true', alert_config JSONB, weight REAL NOT NULL DEFAULT 1.0, - learned BOOLEAN, + learned BOOLEAN NOT NULL DEFAULT FALSE, UNIQUE (system_id, tgid) );