mirror of
https://github.com/unraid/api.git
synced 2026-05-02 21:22:04 -05:00
674323fd87
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * API Key Authorization flow with consent screen, callback support, and a Tools page. * Schema-driven API Key creation UI with permission presets, templates, and Developer Authorization Link. * Effective Permissions preview and a new multi-select permission control. * **UI Improvements** * Mask/toggle API keys, copy-to-clipboard with toasts, improved select labels, new label styles, tab wrapping, and accordionized color controls. * **Documentation** * Public guide for the API Key authorization flow and scopes added. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
111 lines
2.7 KiB
TypeScript
111 lines
2.7 KiB
TypeScript
import type { Resource } from '~/composables/gql/graphql.js';
|
|
import { AuthAction } from '~/composables/gql/graphql.js';
|
|
|
|
export interface PermissionPreset {
|
|
resources: Resource[];
|
|
actions: AuthAction[];
|
|
}
|
|
|
|
/**
|
|
* Permission preset definitions matching the backend form schema
|
|
*/
|
|
export const PERMISSION_PRESETS: Record<string, PermissionPreset> = {
|
|
docker_manager: {
|
|
resources: ['DOCKER' as Resource],
|
|
actions: [
|
|
AuthAction.CREATE_ANY,
|
|
AuthAction.READ_ANY,
|
|
AuthAction.UPDATE_ANY,
|
|
AuthAction.DELETE_ANY,
|
|
],
|
|
},
|
|
vm_manager: {
|
|
resources: ['VMS' as Resource],
|
|
actions: [
|
|
AuthAction.CREATE_ANY,
|
|
AuthAction.READ_ANY,
|
|
AuthAction.UPDATE_ANY,
|
|
AuthAction.DELETE_ANY,
|
|
],
|
|
},
|
|
monitoring: {
|
|
resources: ['INFO', 'DASHBOARD', 'LOGS', 'ARRAY', 'DISK', 'NETWORK'] as Resource[],
|
|
actions: [AuthAction.READ_ANY],
|
|
},
|
|
backup_manager: {
|
|
resources: ['FLASH', 'SHARE'] as Resource[],
|
|
actions: [
|
|
AuthAction.CREATE_ANY,
|
|
AuthAction.READ_ANY,
|
|
AuthAction.UPDATE_ANY,
|
|
AuthAction.DELETE_ANY,
|
|
],
|
|
},
|
|
network_admin: {
|
|
resources: ['NETWORK', 'SERVICES'] as Resource[],
|
|
actions: [
|
|
AuthAction.CREATE_ANY,
|
|
AuthAction.READ_ANY,
|
|
AuthAction.UPDATE_ANY,
|
|
AuthAction.DELETE_ANY,
|
|
],
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Composable for working with API key permission presets
|
|
*/
|
|
export function useApiKeyPermissionPresets() {
|
|
/**
|
|
* Get a specific preset by ID
|
|
*/
|
|
const getPreset = (presetId: string): PermissionPreset | undefined => {
|
|
return PERMISSION_PRESETS[presetId];
|
|
};
|
|
|
|
/**
|
|
* Apply a preset to custom permissions array
|
|
*/
|
|
const applyPreset = (
|
|
presetId: string,
|
|
existingPermissions: Array<{ resources: Resource[]; actions: AuthAction[] }> = []
|
|
): Array<{ resources: Resource[]; actions: AuthAction[] }> => {
|
|
const preset = getPreset(presetId);
|
|
if (!preset) return existingPermissions;
|
|
|
|
return [...existingPermissions, {
|
|
resources: preset.resources,
|
|
actions: preset.actions,
|
|
}];
|
|
};
|
|
|
|
/**
|
|
* Get all available preset IDs
|
|
*/
|
|
const getPresetIds = (): string[] => {
|
|
return Object.keys(PERMISSION_PRESETS);
|
|
};
|
|
|
|
/**
|
|
* Get a human-readable label for a preset
|
|
*/
|
|
const getPresetLabel = (presetId: string): string => {
|
|
const labels: Record<string, string> = {
|
|
docker_manager: 'Docker Manager',
|
|
vm_manager: 'VM Manager',
|
|
monitoring: 'Monitoring (Read Only)',
|
|
backup_manager: 'Backup Manager',
|
|
network_admin: 'Network Administrator',
|
|
};
|
|
return labels[presetId] || presetId;
|
|
};
|
|
|
|
return {
|
|
getPreset,
|
|
applyPreset,
|
|
getPresetIds,
|
|
getPresetLabel,
|
|
PERMISSION_PRESETS,
|
|
};
|
|
}
|