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:
@@ -47,6 +47,7 @@ func (hs *HTTPServer) GetAPIKeys(c *contextmodel.ReqContext) response.Response {
|
|||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
Role: t.Role,
|
Role: t.Role,
|
||||||
Expiration: expiration,
|
Expiration: expiration,
|
||||||
|
LastUsedAt: t.LastUsedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ type ApiKeyDTO struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Role org.RoleType `json:"role"`
|
Role org.RoleType `json:"role"`
|
||||||
Expiration *time.Time `json:"expiration,omitempty"`
|
Expiration *time.Time `json:"expiration,omitempty"`
|
||||||
|
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
|
||||||
AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"`
|
AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export const ApiKeysTable: FC<Props> = ({ apiKeys, timeZone, onDelete, onMigrate
|
|||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Role</th>
|
<th>Role</th>
|
||||||
<th>Expires</th>
|
<th>Expires</th>
|
||||||
|
<th>Last used at</th>
|
||||||
<th style={{ width: '34px' }} />
|
<th style={{ width: '34px' }} />
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -47,6 +48,7 @@ export const ApiKeysTable: FC<Props> = ({ apiKeys, timeZone, onDelete, onMigrate
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
<td>{formatLastUsedAtDate(timeZone, key.lastUsedAt)}</td>
|
||||||
<td>
|
<td>
|
||||||
<HorizontalGroup justify="flex-end">
|
<HorizontalGroup justify="flex-end">
|
||||||
<Button size="sm" onClick={() => onMigrate(key)}>
|
<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 {
|
function formatDate(expiration: string | undefined, timeZone: TimeZone): string {
|
||||||
if (!expiration) {
|
if (!expiration) {
|
||||||
return 'No expiration date';
|
return 'No expiration date';
|
||||||
|
|||||||
@@ -26,8 +26,11 @@ export const MigrateToServiceAccountsCard = ({ onMigrate, apikeysCount, disabled
|
|||||||
);
|
);
|
||||||
const migrationBoxDesc = (
|
const migrationBoxDesc = (
|
||||||
<span>
|
<span>
|
||||||
Are you sure you want to migrate all API keys to service accounts? {docsLink}
|
Migrating all API keys will hide the API keys tab.
|
||||||
<br>This hides the API keys tab.</br>
|
<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>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ export const MigrateToServiceAccountsCard = ({ onMigrate, apikeysCount, disabled
|
|||||||
Migrate all service accounts
|
Migrate all service accounts
|
||||||
</Button>
|
</Button>
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
title={'Migrate API keys to service accounts'}
|
title={'Migrate API keys to Service accounts'}
|
||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
body={migrationBoxDesc}
|
body={migrationBoxDesc}
|
||||||
confirmText={'Yes, migrate now'}
|
confirmText={'Yes, migrate now'}
|
||||||
|
|||||||
Reference in New Issue
Block a user