satellite/satellitedb: select user_agent in apikeys method GetPagedByProjectID

The user_agent column was missing from the SQL query in
apikeys.GetPagedByProjectID. Add it.

Change-Id: I2201b0ecd1767194a6d2339dba25a0b58e1ee30a
This commit is contained in:
Cameron Ayer 2022-01-03 11:58:22 -05:00
parent c58a81e7c2
commit 2a4ff6f469
2 changed files with 6 additions and 2 deletions

View File

@ -28,6 +28,8 @@ func TestApiKeysRepository(t *testing.T) {
assert.NotNil(t, project)
assert.NoError(t, err)
userAgent := []byte("testUserAgent")
t.Run("Creation success", func(t *testing.T) {
for i := 0; i < 10; i++ {
key, err := macaroon.NewAPIKey([]byte("testSecret"))
@ -37,6 +39,7 @@ func TestApiKeysRepository(t *testing.T) {
Name: fmt.Sprintf("key %d", i),
ProjectID: project.ID,
Secret: []byte("testSecret"),
UserAgent: userAgent,
}
createdKey, err := apikeys.Create(ctx, key.Head(), keyInfo)
@ -87,6 +90,7 @@ func TestApiKeysRepository(t *testing.T) {
key, err := apikeys.Get(ctx, page.APIKeys[0].ID)
assert.NotNil(t, key)
assert.Equal(t, page.APIKeys[0].ID, key.ID)
assert.Equal(t, page.APIKeys[0].UserAgent, userAgent)
assert.NoError(t, err)
})

View File

@ -70,7 +70,7 @@ func (keys *apikeys) GetPagedByProjectID(ctx context.Context, projectID uuid.UUI
}
repoundQuery := keys.db.Rebind(`
SELECT ak.id, ak.project_id, ak.name, ak.partner_id, ak.created_at
SELECT ak.id, ak.project_id, ak.name, ak.partner_id, ak.user_agent, ak.created_at
FROM api_keys ak
WHERE ak.project_id = ?
AND lower(ak.name) LIKE ?
@ -95,7 +95,7 @@ func (keys *apikeys) GetPagedByProjectID(ctx context.Context, projectID uuid.UUI
ak := console.APIKeyInfo{}
var partnerID uuid.NullUUID
err = rows.Scan(&ak.ID, &ak.ProjectID, &ak.Name, &partnerID, &ak.CreatedAt)
err = rows.Scan(&ak.ID, &ak.ProjectID, &ak.Name, &partnerID, &ak.UserAgent, &ak.CreatedAt)
if err != nil {
return nil, err
}