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 + "$");
71 export const isResourceUuid = (uuid: string) =>
72 RESOURCE_UUID_REGEX.test(uuid);
74 export const extractUuidObjectType = (uuid: string) => {
75 const match = RESOURCE_UUID_REGEX.exec(uuid);
77 ? match[0].split('-')[1]
81 export const extractUuidKind = (uuid: string = '') => {
82 const objectType = extractUuidObjectType(uuid);
84 case ResourceObjectType.USER:
85 return ResourceKind.USER;
86 case ResourceObjectType.GROUP:
87 return ResourceKind.GROUP;
88 case ResourceObjectType.COLLECTION:
89 return ResourceKind.COLLECTION;
90 case ResourceObjectType.CONTAINER_REQUEST:
91 return ResourceKind.CONTAINER_REQUEST;
92 case ResourceObjectType.CONTAINER:
93 return ResourceKind.CONTAINER;
94 case ResourceObjectType.LOG:
95 return ResourceKind.LOG;
96 case ResourceObjectType.WORKFLOW:
97 return ResourceKind.WORKFLOW;
98 case ResourceObjectType.VIRTUAL_MACHINE:
99 return ResourceKind.VIRTUAL_MACHINE;
100 case ResourceObjectType.REPOSITORY:
101 return ResourceKind.REPOSITORY;
102 case ResourceObjectType.SSH_KEY:
103 return ResourceKind.SSH_KEY;
104 case ResourceObjectType.KEEP_SERVICE:
105 return ResourceKind.KEEP_SERVICE;
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;