API keys: Add last_used_at and docs changes for migration (#64293)

* feat: last_used_at for apikeys

* add: docs and copy changes

* refactor: use br correctly

* remove docs

* removed more docs
This commit is contained in:
Eric Leijonmarck 2023-03-09 14:16:42 +00:00 committed by GitHub
parent 4c0571be3a
commit 17537b033d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -47,6 +47,7 @@ func (hs *HTTPServer) GetAPIKeys(c *contextmodel.ReqContext) response.Response {
Name: t.Name,
Role: t.Role,
Expiration: expiration,
LastUsedAt: t.LastUsedAt,
}
}

View File

@ -22,5 +22,6 @@ type ApiKeyDTO struct {
Name string `json:"name"`
Role org.RoleType `json:"role"`
Expiration *time.Time `json:"expiration,omitempty"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"`
}

View File

@ -26,6 +26,7 @@ export const ApiKeysTable: FC<Props> = ({ apiKeys, timeZone, onDelete, onMigrate
<th>Name</th>
<th>Role</th>
<th>Expires</th>
<th>Last used at</th>
<th style={{ width: '34px' }} />
</tr>
</thead>
@ -47,6 +48,7 @@ export const ApiKeysTable: FC<Props> = ({ apiKeys, timeZone, onDelete, onMigrate
</span>
)}
</td>
<td>{formatLastUsedAtDate(timeZone, key.lastUsedAt)}</td>
<td>
<HorizontalGroup justify="flex-end">
<Button size="sm" onClick={() => onMigrate(key)}>
@ -69,6 +71,13 @@ export const ApiKeysTable: FC<Props> = ({ apiKeys, timeZone, onDelete, onMigrate
);
};
function formatLastUsedAtDate(timeZone: TimeZone, lastUsedAt?: string): string {
if (!lastUsedAt) {
return 'Never';
}
return dateTimeFormat(lastUsedAt, { timeZone });
}
function formatDate(expiration: string | undefined, timeZone: TimeZone): string {
if (!expiration) {
return 'No expiration date';

View File

@ -26,8 +26,11 @@ export const MigrateToServiceAccountsCard = ({ onMigrate, apikeysCount, disabled
);
const migrationBoxDesc = (
<span>
Are you sure you want to migrate all API keys to service accounts? {docsLink}
<br>This hides the API keys tab.</br>
Migrating all API keys will hide the API keys tab.
<br></br>
<br></br>
The API keys API will remain available for you to create new API keys, but we strongly encourage you to use
Service accounts instead.
</span>
);
@ -44,7 +47,7 @@ export const MigrateToServiceAccountsCard = ({ onMigrate, apikeysCount, disabled
Migrate all service accounts
</Button>
<ConfirmModal
title={'Migrate API keys to service accounts'}
title={'Migrate API keys to Service accounts'}
isOpen={isModalOpen}
body={migrationBoxDesc}
confirmText={'Yes, migrate now'}