+50
-8
@@ -13,6 +13,7 @@ import {
|
||||
import { mockOn, mocked, rawFetch, request } from './request'
|
||||
import type {
|
||||
AuditEventsResult,
|
||||
CreatedApiKey,
|
||||
IamUser,
|
||||
IdentityDomain,
|
||||
IamUserDetail,
|
||||
@@ -26,6 +27,7 @@ import type {
|
||||
SignOnRule,
|
||||
SubscriptionDetail,
|
||||
SubscriptionSummary,
|
||||
UserApiKey,
|
||||
} from '@/types/api'
|
||||
|
||||
// ---- 配额 ----
|
||||
@@ -169,15 +171,55 @@ export function clearUserMfa(id: number, userId: string, domainId?: string): Pro
|
||||
return request(`/oci-configs/${id}/users/${userId}/mfa-devices`, { method: 'DELETE', query: { domainId } })
|
||||
}
|
||||
|
||||
export function deleteUserApiKeys(
|
||||
id: number,
|
||||
userId: string,
|
||||
includeCurrent = false,
|
||||
): Promise<{ deletedApiKeys: number }> {
|
||||
if (mockOn) return mocked({ deletedApiKeys: 1 })
|
||||
return request(`/oci-configs/${id}/users/${userId}/api-keys`, {
|
||||
// ---- 用户 API 签名 Key ----
|
||||
|
||||
const mockCreatedKey: CreatedApiKey = {
|
||||
fingerprint: '11:22:33:44:55:66:77:88:99:00:aa:bb:cc:dd:ee:ff',
|
||||
privateKey: '-----BEGIN RSA PRIVATE KEY-----\nMOCKMOCKMOCK\n-----END RSA PRIVATE KEY-----\n',
|
||||
configIni:
|
||||
'[DEFAULT]\nuser=ocid1.user.oc1..mock\nfingerprint=11:22:33:44:55:66:77:88:99:00:aa:bb:cc:dd:ee:ff\ntenancy=ocid1.tenancy.oc1..mock\nregion=ap-tokyo-1\nkey_file=~/.oci/oci_api_key.pem\n',
|
||||
}
|
||||
|
||||
export function listUserApiKeys(id: number, userId: string): Promise<{ items: UserApiKey[] }> {
|
||||
if (mockOn)
|
||||
return mocked({
|
||||
items: [
|
||||
{
|
||||
fingerprint: 'aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99',
|
||||
timeCreated: '2026-07-01T08:00:00Z',
|
||||
isCurrent: true,
|
||||
configIni: mockCreatedKey.configIni,
|
||||
},
|
||||
{
|
||||
fingerprint: '99:88:77:66:55:44:33:22:11:00:ff:ee:dd:cc:bb:aa',
|
||||
timeCreated: '2026-07-10T08:00:00Z',
|
||||
isCurrent: false,
|
||||
configIni: mockCreatedKey.configIni,
|
||||
},
|
||||
],
|
||||
})
|
||||
return request(`/oci-configs/${id}/users/${userId}/api-keys`)
|
||||
}
|
||||
|
||||
/** 后端生成密钥对并上传公钥;私钥仅本次返回 */
|
||||
export function addUserApiKey(id: number, userId: string): Promise<CreatedApiKey> {
|
||||
if (mockOn) return mocked({ ...mockCreatedKey })
|
||||
return request(`/oci-configs/${id}/users/${userId}/api-keys`, { method: 'POST' })
|
||||
}
|
||||
|
||||
export function deleteUserApiKey(id: number, userId: string, fingerprint: string): Promise<void> {
|
||||
if (mockOn) return mocked(undefined)
|
||||
return request(`/oci-configs/${id}/users/${userId}/api-keys/${encodeURIComponent(fingerprint)}`, {
|
||||
method: 'DELETE',
|
||||
query: { includeCurrent },
|
||||
})
|
||||
}
|
||||
|
||||
/** 把刚创建的 key 设为本配置签名凭据(验证可用后落库,不删旧 key);私钥为创建时下发的那份回传 */
|
||||
export function activateApiKey(id: number, fingerprint: string, privateKey: string): Promise<void> {
|
||||
if (mockOn) return mocked(undefined)
|
||||
return request(`/oci-configs/${id}/activate-api-key`, {
|
||||
method: 'POST',
|
||||
body: { fingerprint, privateKey },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user