1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export interface Resource {
9 modifiedByUserUuid: string;
16 export interface ResourceWithProperties extends Resource {
20 export interface EditableResource extends Resource {
24 export interface TrashableResource extends Resource {
30 export enum ResourceKind {
31 API_CLIENT_AUTHORIZATION = "arvados#apiClientAuthorization",
32 COLLECTION = "arvados#collection",
33 CONTAINER = "arvados#container",
34 CONTAINER_REQUEST = "arvados#containerRequest",
35 GROUP = "arvados#group",
36 LINK = "arvados#link",
38 PROCESS = "arvados#containerRequest",
39 PROJECT = "arvados#group",
40 REPOSITORY = "arvados#repository",
41 SSH_KEY = "arvados#authorizedKeys",
42 KEEP_SERVICE = "arvados#keepService",
43 USER = "arvados#user",
44 VIRTUAL_MACHINE = "arvados#virtualMachine",
45 WORKFLOW = "arvados#workflow",
49 export enum ResourceObjectType {
50 API_CLIENT_AUTHORIZATION = 'gj3su',
53 CONTAINER_REQUEST = 'xvhdp',
59 VIRTUAL_MACHINE = '2x53u',
62 KEEP_SERVICE = 'bi6l4'
65 export const RESOURCE_UUID_PATTERN = '[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}';
66 export const PORTABLE_DATA_HASH_PATTERN = '[a-f0-9]{32}\\+\\d+';
67 export const RESOURCE_UUID_REGEX = new RegExp("^" + RESOURCE_UUID_PATTERN + "$");
68 export const COLLECTION_PDH_REGEX = new RegExp("^" + PORTABLE_DATA_HASH_PATTERN + "$");
69 export const KEEP_URL_REGEX = new RegExp("^(keep:)?" + 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;