1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export interface Resource {
9 modifiedByClientUuid: string;
10 modifiedByUserUuid: string;
17 export interface EditableResource extends Resource {
21 export interface TrashableResource extends Resource {
27 export enum ResourceKind {
28 API_CLIENT_AUTHORIZATION = "arvados#apiClientAuthorization",
29 COLLECTION = "arvados#collection",
30 CONTAINER = "arvados#container",
31 CONTAINER_REQUEST = "arvados#containerRequest",
32 GROUP = "arvados#group",
33 LINK = "arvados#link",
35 NODE = "arvados#node",
36 PROCESS = "arvados#containerRequest",
37 PROJECT = "arvados#group",
38 REPOSITORY = "arvados#repository",
39 SSH_KEY = "arvados#authorizedKeys",
40 KEEP_SERVICE = "arvados#keepService",
41 USER = "arvados#user",
42 VIRTUAL_MACHINE = "arvados#virtualMachine",
43 WORKFLOW = "arvados#workflow",
47 export enum ResourceObjectType {
48 API_CLIENT_AUTHORIZATION = 'gj3su',
51 CONTAINER_REQUEST = 'xvhdp',
57 VIRTUAL_MACHINE = '2x53u',
60 KEEP_SERVICE = 'bi6l4',
64 export const RESOURCE_UUID_PATTERN = '[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}';
65 export const PORTABLE_DATA_HASH_PATTERN = '[a-f0-9]{32}\\+\\d+';
66 export const RESOURCE_UUID_REGEX = new RegExp("^" + RESOURCE_UUID_PATTERN + "$");
67 export const COLLECTION_PDH_REGEX = new RegExp("^" + PORTABLE_DATA_HASH_PATTERN + "$");
69 export const isResourceUuid = (uuid: string) =>
70 RESOURCE_UUID_REGEX.test(uuid);
72 export const extractUuidObjectType = (uuid: string) => {
73 const match = RESOURCE_UUID_REGEX.exec(uuid);
75 ? match[0].split('-')[1]
79 export const extractUuidKind = (uuid: string = '') => {
80 const objectType = extractUuidObjectType(uuid);
82 case ResourceObjectType.USER:
83 return ResourceKind.USER;
84 case ResourceObjectType.GROUP:
85 return ResourceKind.GROUP;
86 case ResourceObjectType.COLLECTION:
87 return ResourceKind.COLLECTION;
88 case ResourceObjectType.CONTAINER_REQUEST:
89 return ResourceKind.CONTAINER_REQUEST;
90 case ResourceObjectType.CONTAINER:
91 return ResourceKind.CONTAINER;
92 case ResourceObjectType.LOG:
93 return ResourceKind.LOG;
94 case ResourceObjectType.WORKFLOW:
95 return ResourceKind.WORKFLOW;
96 case ResourceObjectType.VIRTUAL_MACHINE:
97 return ResourceKind.VIRTUAL_MACHINE;
98 case ResourceObjectType.REPOSITORY:
99 return ResourceKind.REPOSITORY;
100 case ResourceObjectType.SSH_KEY:
101 return ResourceKind.SSH_KEY;
102 case ResourceObjectType.KEEP_SERVICE:
103 return ResourceKind.KEEP_SERVICE;
104 case ResourceObjectType.NODE:
105 return ResourceKind.NODE;
106 case ResourceObjectType.API_CLIENT_AUTHORIZATION:
107 return ResourceKind.API_CLIENT_AUTHORIZATION;
108 case ResourceObjectType.LINK:
109 return ResourceKind.LINK;
111 const match = COLLECTION_PDH_REGEX.exec(uuid);
112 return match ? ResourceKind.COLLECTION : undefined;