API: Optionally list expired keys (#20468)
* API: Optionally list expired keys * Update docs
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func GetAPIKeys(c *models.ReqContext) Response {
|
||||
query := models.GetApiKeysQuery{OrgId: c.OrgId}
|
||||
query := models.GetApiKeysQuery{OrgId: c.OrgId, IncludeExpired: c.QueryBool("includeExpired")}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return Error(500, "Failed to list api keys", err)
|
||||
|
||||
@@ -50,7 +50,7 @@ type DeleteApiKeyCommand struct {
|
||||
|
||||
type GetApiKeysQuery struct {
|
||||
OrgId int64
|
||||
IncludeInvalid bool
|
||||
IncludeExpired bool
|
||||
Result []*ApiKey
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func init() {
|
||||
func GetApiKeys(query *models.GetApiKeysQuery) error {
|
||||
sess := x.Limit(100, 0).Where("org_id=? and ( expires IS NULL or expires >= ?)",
|
||||
query.OrgId, timeNow().Unix()).Asc("name")
|
||||
if query.IncludeInvalid {
|
||||
if query.IncludeExpired {
|
||||
sess = x.Limit(100, 0).Where("org_id=?", query.OrgId).Asc("name")
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestApiKeyDataAccess(t *testing.T) {
|
||||
// advance mocked getTime by 1s
|
||||
timeNow()
|
||||
|
||||
query := models.GetApiKeysQuery{OrgId: 1, IncludeInvalid: false}
|
||||
query := models.GetApiKeysQuery{OrgId: 1, IncludeExpired: false}
|
||||
err = GetApiKeys(&query)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestApiKeyDataAccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
query = models.GetApiKeysQuery{OrgId: 1, IncludeInvalid: true}
|
||||
query = models.GetApiKeysQuery{OrgId: 1, IncludeExpired: true}
|
||||
err = GetApiKeys(&query)
|
||||
assert.Nil(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user