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 ResourceWithProperties extends Resource {
21 export interface EditableResource extends Resource {
25 export interface TrashableResource extends Resource {
31 export enum ResourceKind {
32 API_CLIENT_AUTHORIZATION = "arvados#apiClientAuthorization",
33 COLLECTION = "arvados#collection",
34 CONTAINER = "arvados#container",
35 CONTAINER_REQUEST = "arvados#containerRequest",
36 GROUP = "arvados#group",
37 LINK = "arvados#link",
39 PROCESS = "arvados#containerRequest",
40 PROJECT = "arvados#group",
41 REPOSITORY = "arvados#repository",
42 SSH_KEY = "arvados#authorizedKeys",
43 KEEP_SERVICE = "arvados#keepService",
44 USER = "arvados#user",
45 VIRTUAL_MACHINE = "arvados#virtualMachine",
46 WORKFLOW = "arvados#workflow",
50 export enum ResourceObjectType {
51 API_CLIENT_AUTHORIZATION = 'gj3su',
54 CONTAINER_REQUEST = 'xvhdp',
60 VIRTUAL_MACHINE = '2x53u',
63 KEEP_SERVICE = 'bi6l4'
66 export const RESOURCE_UUID_PATTERN = '[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}';
67 export const PORTABLE_DATA_HASH_PATTERN = '[a-f0-9]{32}\\+\\d+';
68 export const RESOURCE_UUID_REGEX = new RegExp("^" + RESOURCE_UUID_PATTERN + "$");
69 export const COLLECTION_PDH_REGEX = new RegExp("^" + PORTABLE_DATA_HASH_PATTERN + "$");
70 export const KEEP_URL_REGEX = new RegExp("^(keep:)?" + PORTABLE_DATA_HASH_PATTERN);
72 export const isResourceUuid = (uuid: string) =>
73 RESOURCE_UUID_REGEX.test(uuid);
75 export const extractUuidObjectType = (uuid: string) => {
76 const match = RESOURCE_UUID_REGEX.exec(uuid);
78 ? match[0].split('-')[1]
82 export const extractUuidKind = (uuid: string = '') => {
83 const objectType = extractUuidObjectType(uuid);
85 case ResourceObjectType.USER:
86 return ResourceKind.USER;
87 case ResourceObjectType.GROUP:
88 return ResourceKind.GROUP;
89 case ResourceObjectType.COLLECTION:
90 return ResourceKind.COLLECTION;
91 case ResourceObjectType.CONTAINER_REQUEST:
92 return ResourceKind.CONTAINER_REQUEST;
93 case ResourceObjectType.CONTAINER:
94 return ResourceKind.CONTAINER;
95 case ResourceObjectType.LOG:
96 return ResourceKind.LOG;
97 case ResourceObjectType.WORKFLOW:
98 return ResourceKind.WORKFLOW;
99 case ResourceObjectType.VIRTUAL_MACHINE:
100 return ResourceKind.VIRTUAL_MACHINE;
101 case ResourceObjectType.REPOSITORY:
102 return ResourceKind.REPOSITORY;
103 case ResourceObjectType.SSH_KEY:
104 return ResourceKind.SSH_KEY;
105 case ResourceObjectType.KEEP_SERVICE:
106 return ResourceKind.KEEP_SERVICE;
107 case ResourceObjectType.API_CLIENT_AUTHORIZATION:
108 return ResourceKind.API_CLIENT_AUTHORIZATION;
109 case ResourceObjectType.LINK:
110 return ResourceKind.LINK;
112 const match = COLLECTION_PDH_REGEX.exec(uuid);
113 return match ? ResourceKind.COLLECTION : undefined;