Merge branch '14841-link-workbench1' refs #14841 refs #14720
[arvados.git] / src / store / advanced-tab / advanced-tab.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from 'redux';
6 import { dialogActions } from '~/store/dialog/dialog-actions';
7 import { RootState } from '~/store/store';
8 import { ResourceKind, extractUuidKind } from '~/models/resource';
9 import { getResource } from '~/store/resources/resources';
10 import { GroupContentsResourcePrefix } from '~/services/groups-service/groups-service';
11 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
12 import { ContainerRequestResource } from '~/models/container-request';
13 import { CollectionResource } from '~/models/collection';
14 import { ProjectResource } from '~/models/project';
15 import { ServiceRepository } from '~/services/services';
16 import { FilterBuilder } from '~/services/api/filter-builder';
17 import { ListResults } from '~/services/common-service/common-service';
18 import { RepositoryResource } from '~/models/repositories';
19 import { SshKeyResource } from '~/models/ssh-key';
20 import { VirtualMachinesResource } from '~/models/virtual-machines';
21 import { UserResource } from '~/models/user';
22 import { LinkResource } from '~/models/link';
23 import { KeepServiceResource } from '~/models/keep-services';
24 import { NodeResource } from '~/models/node';
25 import { ApiClientAuthorization } from '~/models/api-client-authorization';
26 import * as React from 'react';
27
28 export const ADVANCED_TAB_DIALOG = 'advancedTabDialog';
29
30 interface AdvancedTabDialogData {
31     apiResponse: any;
32     metadata: ListResults<LinkResource> | string;
33     user: UserResource | string;
34     pythonHeader: string;
35     pythonExample: string;
36     cliGetHeader: string;
37     cliGetExample: string;
38     cliUpdateHeader: string;
39     cliUpdateExample: string;
40     curlHeader: string;
41     curlExample: string;
42 }
43
44 enum CollectionData {
45     COLLECTION = 'collection',
46     STORAGE_CLASSES_CONFIRMED = 'storage_classes_confirmed'
47 }
48
49 enum ProcessData {
50     CONTAINER_REQUEST = 'container_request',
51     OUTPUT_NAME = 'output_name'
52 }
53
54 enum ProjectData {
55     GROUP = 'group',
56     DELETE_AT = 'delete_at'
57 }
58
59 enum RepositoryData {
60     REPOSITORY = 'repository',
61     CREATED_AT = 'created_at'
62 }
63
64 enum SshKeyData {
65     SSH_KEY = 'authorized_key',
66     CREATED_AT = 'created_at'
67 }
68
69 enum VirtualMachineData {
70     VIRTUAL_MACHINE = 'virtual_machine',
71     CREATED_AT = 'created_at'
72 }
73
74 enum ResourcePrefix {
75     REPOSITORIES = 'repositories',
76     AUTORIZED_KEYS = 'authorized_keys',
77     VIRTUAL_MACHINES = 'virtual_machines',
78     KEEP_SERVICES = 'keep_services',
79     COMPUTE_NODES = 'nodes',
80     USERS = 'users',
81     API_CLIENT_AUTHORIZATIONS = 'api_client_authorizations',
82     LINKS = 'links'
83 }
84
85 enum KeepServiceData {
86     KEEP_SERVICE = 'keep_services',
87     CREATED_AT = 'created_at'
88 }
89
90 enum UserData {
91     USER = 'user',
92     USERNAME = 'username'
93 }
94
95 enum ComputeNodeData {
96     COMPUTE_NODE = 'node',
97     PROPERTIES = 'properties'
98 }
99
100 enum ApiClientAuthorizationsData {
101     API_CLIENT_AUTHORIZATION = 'api_client_authorization',
102     DEFAULT_OWNER_UUID = 'default_owner_uuid'
103 }
104
105 enum LinkData {
106     LINK = 'link',
107     PROPERTIES = 'properties'
108 }
109
110 type AdvanceResourceKind = CollectionData | ProcessData | ProjectData | RepositoryData | SshKeyData | VirtualMachineData | KeepServiceData | ComputeNodeData | ApiClientAuthorizationsData | UserData | LinkData;
111 type AdvanceResourcePrefix = GroupContentsResourcePrefix | ResourcePrefix;
112 type AdvanceResponseData = ContainerRequestResource | ProjectResource | CollectionResource | RepositoryResource | SshKeyResource | VirtualMachinesResource | KeepServiceResource | NodeResource | ApiClientAuthorization | UserResource | LinkResource | undefined;
113
114 export const openAdvancedTabDialog = (uuid: string) =>
115     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
116         const kind = extractUuidKind(uuid);
117         switch (kind) {
118             case ResourceKind.COLLECTION:
119                 const { data: dataCollection, metadata: metaCollection, user: userCollection } = await dispatch<any>(getDataForAdvancedTab(uuid));
120                 const advanceDataCollection = advancedTabData({
121                     uuid,
122                     metadata: metaCollection,
123                     user: userCollection,
124                     apiResponseKind: collectionApiResponse,
125                     data: dataCollection,
126                     resourceKind: CollectionData.COLLECTION,
127                     resourcePrefix: GroupContentsResourcePrefix.COLLECTION,
128                     resourceKindProperty: CollectionData.STORAGE_CLASSES_CONFIRMED,
129                     property: dataCollection.storageClassesConfirmed
130                 });
131                 dispatch<any>(initAdvancedTabDialog(advanceDataCollection));
132                 break;
133             case ResourceKind.PROCESS:
134                 const { data: dataProcess, metadata: metaProcess, user: userProcess } = await dispatch<any>(getDataForAdvancedTab(uuid));
135                 const advancedDataProcess = advancedTabData({
136                     uuid,
137                     metadata: metaProcess,
138                     user: userProcess,
139                     apiResponseKind: containerRequestApiResponse,
140                     data: dataProcess,
141                     resourceKind: ProcessData.CONTAINER_REQUEST,
142                     resourcePrefix: GroupContentsResourcePrefix.PROCESS,
143                     resourceKindProperty: ProcessData.OUTPUT_NAME,
144                     property: dataProcess.outputName
145                 });
146                 dispatch<any>(initAdvancedTabDialog(advancedDataProcess));
147                 break;
148             case ResourceKind.PROJECT:
149                 const { data: dataProject, metadata: metaProject, user: userProject } = await dispatch<any>(getDataForAdvancedTab(uuid));
150                 const advanceDataProject = advancedTabData({
151                     uuid,
152                     metadata: metaProject,
153                     user: userProject,
154                     apiResponseKind: groupRequestApiResponse,
155                     data: dataProject,
156                     resourceKind: ProjectData.GROUP,
157                     resourcePrefix: GroupContentsResourcePrefix.PROJECT,
158                     resourceKindProperty: ProjectData.DELETE_AT,
159                     property: dataProject.deleteAt
160                 });
161                 dispatch<any>(initAdvancedTabDialog(advanceDataProject));
162                 break;
163             case ResourceKind.REPOSITORY:
164                 const dataRepository = getState().repositories.items.find(it => it.uuid === uuid);
165                 const advanceDataRepository = advancedTabData({
166                     uuid,
167                     metadata: '',
168                     user: '',
169                     apiResponseKind: repositoryApiResponse,
170                     data: dataRepository,
171                     resourceKind: RepositoryData.REPOSITORY,
172                     resourcePrefix: ResourcePrefix.REPOSITORIES,
173                     resourceKindProperty: RepositoryData.CREATED_AT,
174                     property: dataRepository!.createdAt
175                 });
176                 dispatch<any>(initAdvancedTabDialog(advanceDataRepository));
177                 break;
178             case ResourceKind.SSH_KEY:
179                 const dataSshKey = getState().auth.sshKeys.find(it => it.uuid === uuid);
180                 const advanceDataSshKey = advancedTabData({
181                     uuid,
182                     metadata: '',
183                     user: '',
184                     apiResponseKind: sshKeyApiResponse,
185                     data: dataSshKey,
186                     resourceKind: SshKeyData.SSH_KEY,
187                     resourcePrefix: ResourcePrefix.AUTORIZED_KEYS,
188                     resourceKindProperty: SshKeyData.CREATED_AT,
189                     property: dataSshKey!.createdAt
190                 });
191                 dispatch<any>(initAdvancedTabDialog(advanceDataSshKey));
192                 break;
193             case ResourceKind.VIRTUAL_MACHINE:
194                 const dataVirtualMachine = getState().virtualMachines.virtualMachines.items.find(it => it.uuid === uuid);
195                 const advanceDataVirtualMachine = advancedTabData({
196                     uuid,
197                     metadata: '',
198                     user: '',
199                     apiResponseKind: virtualMachineApiResponse,
200                     data: dataVirtualMachine,
201                     resourceKind: VirtualMachineData.VIRTUAL_MACHINE,
202                     resourcePrefix: ResourcePrefix.VIRTUAL_MACHINES,
203                     resourceKindProperty: VirtualMachineData.CREATED_AT,
204                     property: dataVirtualMachine.createdAt
205                 });
206                 dispatch<any>(initAdvancedTabDialog(advanceDataVirtualMachine));
207                 break;
208             case ResourceKind.KEEP_SERVICE:
209                 const dataKeepService = getState().keepServices.find(it => it.uuid === uuid);
210                 const advanceDataKeepService = advancedTabData({
211                     uuid,
212                     metadata: '',
213                     user: '',
214                     apiResponseKind: keepServiceApiResponse,
215                     data: dataKeepService,
216                     resourceKind: KeepServiceData.KEEP_SERVICE,
217                     resourcePrefix: ResourcePrefix.KEEP_SERVICES,
218                     resourceKindProperty: KeepServiceData.CREATED_AT,
219                     property: dataKeepService!.createdAt
220                 });
221                 dispatch<any>(initAdvancedTabDialog(advanceDataKeepService));
222                 break;
223             case ResourceKind.USER:
224                 const { resources } = getState();
225                 const data = getResource<UserResource>(uuid)(resources);
226                 const metadata = await services.linkService.list({
227                     filters: new FilterBuilder()
228                         .addEqual('headUuid', uuid)
229                         .getFilters()
230                 });
231                 const advanceDataUser = advancedTabData({
232                     uuid,
233                     metadata,
234                     user: '',
235                     apiResponseKind: userApiResponse,
236                     data,
237                     resourceKind: UserData.USER,
238                     resourcePrefix: ResourcePrefix.USERS,
239                     resourceKindProperty: UserData.USERNAME,
240                     property: data!.username
241                 });
242                 dispatch<any>(initAdvancedTabDialog(advanceDataUser));
243                 break;
244             case ResourceKind.NODE:
245                 const computeNodeResources = getState().resources;
246                 const dataComputeNode = getResource<NodeResource>(uuid)(computeNodeResources);
247                 const advanceDataComputeNode = advancedTabData({
248                     uuid,
249                     metadata: '',
250                     user: '',
251                     apiResponseKind: computeNodeApiResponse,
252                     data: dataComputeNode,
253                     resourceKind: ComputeNodeData.COMPUTE_NODE,
254                     resourcePrefix: ResourcePrefix.COMPUTE_NODES,
255                     resourceKindProperty: ComputeNodeData.PROPERTIES,
256                     property: dataComputeNode ? dataComputeNode.properties : {}
257                 });
258                 dispatch<any>(initAdvancedTabDialog(advanceDataComputeNode));
259                 break;
260             case ResourceKind.API_CLIENT_AUTHORIZATION:
261                 const apiClientAuthorizationResources = getState().resources;
262                 const dataApiClientAuthorization = getResource<ApiClientAuthorization>(uuid)(apiClientAuthorizationResources);
263                 const advanceDataApiClientAuthorization = advancedTabData({
264                     uuid,
265                     metadata: '',
266                     user: '',
267                     apiResponseKind: apiClientAuthorizationApiResponse,
268                     data: dataApiClientAuthorization,
269                     resourceKind: ApiClientAuthorizationsData.API_CLIENT_AUTHORIZATION,
270                     resourcePrefix: ResourcePrefix.API_CLIENT_AUTHORIZATIONS,
271                     resourceKindProperty: ApiClientAuthorizationsData.DEFAULT_OWNER_UUID,
272                     property: dataApiClientAuthorization!.defaultOwnerUuid
273                 });
274                 dispatch<any>(initAdvancedTabDialog(advanceDataApiClientAuthorization));
275                 break;
276             case ResourceKind.LINK:
277                 const linkResources = getState().resources;
278                 const dataLink = getResource<LinkResource>(uuid)(linkResources);
279                 const advanceDataLink = advancedTabData({
280                     uuid,
281                     metadata: '',
282                     user: '',
283                     apiResponseKind: linkApiResponse,
284                     data: dataLink,
285                     resourceKind: LinkData.LINK,
286                     resourcePrefix: ResourcePrefix.LINKS,
287                     resourceKindProperty: LinkData.PROPERTIES,
288                     property: dataLink!.properties
289                 });
290                 dispatch<any>(initAdvancedTabDialog(advanceDataLink));
291                 break;
292             default:
293                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Could not open advanced tab for this resource.", hideDuration: 2000, kind: SnackbarKind.ERROR }));
294         }
295     };
296
297 const getDataForAdvancedTab = (uuid: string) =>
298     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
299         const { resources } = getState();
300         const data = getResource<any>(uuid)(resources);
301         const metadata = await services.linkService.list({
302             filters: new FilterBuilder()
303                 .addEqual('headUuid', uuid)
304                 .getFilters()
305         });
306         const user = metadata.itemsAvailable && await services.userService.get(metadata.items[0].tailUuid || '');
307         return { data, metadata, user };
308     };
309
310 const initAdvancedTabDialog = (data: AdvancedTabDialogData) => dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data });
311
312 interface AdvancedTabData {
313     uuid: string;
314     metadata: ListResults<LinkResource> | string;
315     user: UserResource | string;
316     apiResponseKind: any;
317     data: AdvanceResponseData;
318     resourceKind: AdvanceResourceKind;
319     resourcePrefix: AdvanceResourcePrefix;
320     resourceKindProperty: AdvanceResourceKind;
321     property: any;
322 }
323
324 const advancedTabData = ({ uuid, user, metadata, apiResponseKind, data, resourceKind, resourcePrefix, resourceKindProperty, property }: AdvancedTabData) => {
325     return {
326         uuid,
327         user,
328         metadata,
329         apiResponse: apiResponseKind(data),
330         pythonHeader: pythonHeader(resourceKind),
331         pythonExample: pythonExample(uuid, resourcePrefix),
332         cliGetHeader: cliGetHeader(resourceKind),
333         cliGetExample: cliGetExample(uuid, resourceKind),
334         cliUpdateHeader: cliUpdateHeader(resourceKind, resourceKindProperty),
335         cliUpdateExample: cliUpdateExample(uuid, resourceKind, property, resourceKindProperty),
336         curlHeader: curlHeader(resourceKind, resourceKindProperty),
337         curlExample: curlExample(uuid, resourcePrefix, property, resourceKind, resourceKindProperty),
338     };
339 };
340
341 const pythonHeader = (resourceKind: string) =>
342     `An example python command to get a ${resourceKind} using its uuid:`;
343
344 const pythonExample = (uuid: string, resourcePrefix: string) => {
345     const pythonExample = `import arvados
346
347 x = arvados.api().${resourcePrefix}().get(uuid='${uuid}').execute()`;
348
349     return pythonExample;
350 };
351
352 const cliGetHeader = (resourceKind: string) =>
353     `An example arv command to get a ${resourceKind} using its uuid:`;
354
355 const cliGetExample = (uuid: string, resourceKind: string) => {
356     const cliGetExample = `arv ${resourceKind} get \\
357   --uuid ${uuid}`;
358
359     return cliGetExample;
360 };
361
362 const cliUpdateHeader = (resourceKind: string, resourceName: string) =>
363     `An example arv command to update the "${resourceName}" attribute for the current ${resourceKind}:`;
364
365 const cliUpdateExample = (uuid: string, resourceKind: string, resource: string | string[], resourceName: string) => {
366     const CLIUpdateCollectionExample = `arv ${resourceKind} update \\
367   --uuid ${uuid} \\
368   --${resourceKind} '{"${resourceName}":${JSON.stringify(resource)}}'`;
369
370     return CLIUpdateCollectionExample;
371 };
372
373 const curlHeader = (resourceKind: string, resource: string) =>
374     `An example curl command to update the "${resource}" attribute for the current ${resourceKind}:`;
375
376 const curlExample = (uuid: string, resourcePrefix: string, resource: string | string[], resourceKind: string, resourceName: string) => {
377     const curlExample = `curl -X PUT \\
378   -H "Authorization: OAuth2 $ARVADOS_API_TOKEN" \\
379   --data-urlencode ${resourceKind}@/dev/stdin \\
380   https://$ARVADOS_API_HOST/arvados/v1/${resourcePrefix}/${uuid} \\
381   <<EOF
382 {
383   "${resourceName}": ${JSON.stringify(resource, null, 4)}
384 }
385 EOF`;
386
387     return curlExample;
388 };
389
390 const stringify = (item: string | null | number | boolean) =>
391     JSON.stringify(item) || 'null';
392
393 const stringifyObject = (item: any) =>
394     JSON.stringify(item, null, 2) || 'null';
395
396 const containerRequestApiResponse = (apiResponse: ContainerRequestResource) => {
397     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, properties, state, requestingContainerUuid, containerUuid,
398         containerCountMax, mounts, runtimeConstraints, containerImage, environment, cwd, command, outputPath, priority, expiresAt, filters, containerCount,
399         useExisting, schedulingParameters, outputUuid, logUuid, outputName, outputTtl } = apiResponse;
400     const response = `
401 "uuid": "${uuid}",
402 "owner_uuid": "${ownerUuid}",
403 "created_at": "${createdAt}",
404 "modified_at": ${stringify(modifiedAt)},
405 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
406 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
407 "name": ${stringify(name)},
408 "description": ${stringify(description)},
409 "properties": ${stringifyObject(properties)},
410 "state": ${stringify(state)},
411 "requesting_container_uuid": ${stringify(requestingContainerUuid)},
412 "container_uuid": ${stringify(containerUuid)},
413 "container_count_max": ${stringify(containerCountMax)},
414 "mounts": ${stringifyObject(mounts)},
415 "runtime_constraints": ${stringifyObject(runtimeConstraints)},
416 "container_image": "${stringify(containerImage)}",
417 "environment": ${stringifyObject(environment)},
418 "cwd": ${stringify(cwd)},
419 "command": ${stringifyObject(command)},
420 "output_path": ${stringify(outputPath)},
421 "priority": ${stringify(priority)},
422 "expires_at": ${stringify(expiresAt)},
423 "filters": ${stringify(filters)},
424 "container_count": ${stringify(containerCount)},
425 "use_existing": ${stringify(useExisting)},
426 "scheduling_parameters": ${stringifyObject(schedulingParameters)},
427 "output_uuid": ${stringify(outputUuid)},
428 "log_uuid": ${stringify(logUuid)},
429 "output_name": ${stringify(outputName)},
430 "output_ttl": ${stringify(outputTtl)}`;
431
432     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
433 };
434
435 const collectionApiResponse = (apiResponse: CollectionResource) => {
436     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, properties, portableDataHash, replicationDesired,
437         replicationConfirmedAt, replicationConfirmed, manifestText, deleteAt, trashAt, isTrashed, storageClassesDesired,
438         storageClassesConfirmed, storageClassesConfirmedAt, currentVersionUuid, version, preserveVersion } = apiResponse;
439     const response = `
440 "uuid": "${uuid}",
441 "owner_uuid": "${ownerUuid}",
442 "created_at": "${createdAt}",
443 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
444 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
445 "modified_at": ${stringify(modifiedAt)},
446 "portable_data_hash": ${stringify(portableDataHash)},
447 "replication_desired": ${stringify(replicationDesired)},
448 "replication_confirmed_at": ${stringify(replicationConfirmedAt)},
449 "replication_confirmed": ${stringify(replicationConfirmed)},
450 "manifest_text": ${stringify(manifestText)},
451 "name": ${stringify(name)},
452 "description": ${stringify(description)},
453 "properties": ${stringifyObject(properties)},
454 "delete_at": ${stringify(deleteAt)},
455 "trash_at": ${stringify(trashAt)},
456 "is_trashed": ${stringify(isTrashed)},
457 "storage_classes_desired": ${JSON.stringify(storageClassesDesired, null, 2)},
458 "storage_classes_confirmed": ${JSON.stringify(storageClassesConfirmed, null, 2)},
459 "storage_classes_confirmed_at": ${stringify(storageClassesConfirmedAt)},
460 "currentVersionUuid": ${stringify(currentVersionUuid)},
461 "version": ${version},
462 "preserveVersion": ${preserveVersion}`;
463
464     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
465 };
466
467 const groupRequestApiResponse = (apiResponse: ProjectResource) => {
468     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, groupClass, trashAt, isTrashed, deleteAt, properties, writeableBy } = apiResponse;
469     const response = `
470 "uuid": "${uuid}",
471 "owner_uuid": "${ownerUuid}",
472 "created_at": "${createdAt}",
473 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
474 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
475 "modified_at": ${stringify(modifiedAt)},
476 "name": ${stringify(name)},
477 "description": ${stringify(description)},
478 "group_class": ${stringify(groupClass)},
479 "trash_at": ${stringify(trashAt)},
480 "is_trashed": ${stringify(isTrashed)},
481 "delete_at": ${stringify(deleteAt)},
482 "properties": ${stringifyObject(properties)},
483 "witable_by": ${stringifyObject(writeableBy)}`;
484
485     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
486 };
487
488 const repositoryApiResponse = (apiResponse: RepositoryResource) => {
489     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, cloneUrls } = apiResponse;
490     const response = `
491 "uuid": "${uuid}",
492 "owner_uuid": "${ownerUuid}",
493 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
494 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
495 "modified_at": ${stringify(modifiedAt)},
496 "name": ${stringify(name)},
497 "created_at": "${createdAt}",
498 "clone_urls": ${stringifyObject(cloneUrls)}`;
499
500     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
501 };
502
503 const sshKeyApiResponse = (apiResponse: SshKeyResource) => {
504     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, authorizedUserUuid, expiresAt } = apiResponse;
505     const response = `
506 "uuid": "${uuid}",
507 "owner_uuid": "${ownerUuid}",
508 "authorized_user_uuid": "${authorizedUserUuid}",
509 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
510 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
511 "modified_at": ${stringify(modifiedAt)},
512 "name": ${stringify(name)},
513 "created_at": "${createdAt}",
514 "expires_at": "${expiresAt}"`;
515     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
516 };
517
518 const virtualMachineApiResponse = (apiResponse: VirtualMachinesResource) => {
519     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, hostname } = apiResponse;
520     const response = `
521 "hostname": ${stringify(hostname)},
522 "uuid": "${uuid}",
523 "owner_uuid": "${ownerUuid}",
524 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
525 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
526 "modified_at": ${stringify(modifiedAt)},
527 "modified_at": ${stringify(modifiedAt)},
528 "created_at": "${createdAt}"`;
529
530     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
531 };
532
533 const keepServiceApiResponse = (apiResponse: KeepServiceResource) => {
534     const {
535         uuid, readOnly, serviceHost, servicePort, serviceSslFlag, serviceType,
536         ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid
537     } = apiResponse;
538     const response = `
539 "uuid": "${uuid}",
540 "owner_uuid": "${ownerUuid}",
541 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
542 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
543 "modified_at": ${stringify(modifiedAt)},
544 "service_host": "${serviceHost}",
545 "service_port": "${servicePort}",
546 "service_ssl_flag": "${stringify(serviceSslFlag)}",
547 "service_type": "${serviceType}",
548 "created_at": "${createdAt}",
549 "read_only": "${stringify(readOnly)}"`;
550
551     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
552 };
553
554 const userApiResponse = (apiResponse: UserResource) => {
555     const {
556         uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid,
557         email, firstName, lastName, username, isActive, isAdmin, prefs, defaultOwnerUuid,
558     } = apiResponse;
559     const response = `
560 "uuid": "${uuid}",
561 "owner_uuid": "${ownerUuid}",
562 "created_at": "${createdAt}",
563 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
564 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
565 "modified_at": ${stringify(modifiedAt)},
566 "email": "${email}",
567 "first_name": "${firstName}",
568 "last_name": "${stringify(lastName)}",
569 "username": "${username}",
570 "is_active": "${isActive},
571 "is_admin": "${isAdmin},
572 "prefs": "${stringifyObject(prefs)},
573 "default_owner_uuid": "${defaultOwnerUuid},
574 "username": "${username}"`;
575
576     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
577 };
578
579 const computeNodeApiResponse = (apiResponse: NodeResource) => {
580     const {
581         uuid, slotNumber, hostname, domain, ipAddress, firstPingAt, lastPingAt, jobUuid,
582         ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid,
583         properties, info
584     } = apiResponse;
585     const response = `
586 "uuid": "${uuid}",
587 "owner_uuid": "${ownerUuid}",
588 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
589 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
590 "modified_at": ${stringify(modifiedAt)},
591 "created_at": "${createdAt}",
592 "slot_number": "${stringify(slotNumber)}",
593 "hostname": "${stringify(hostname)}",
594 "domain": "${stringify(domain)}",
595 "ip_address": "${stringify(ipAddress)}",
596 "first_ping_at": "${stringify(firstPingAt)}",
597 "last_ping_at": "${stringify(lastPingAt)}",
598 "job_uuid": "${stringify(jobUuid)}",
599 "properties": "${JSON.stringify(properties, null, 2)}",
600 "info": "${JSON.stringify(info, null, 2)}"`;
601
602     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
603 };
604
605 const apiClientAuthorizationApiResponse = (apiResponse: ApiClientAuthorization) => {
606     const {
607         uuid, ownerUuid, apiToken, apiClientId, userId, createdByIpAddress, lastUsedByIpAddress,
608         lastUsedAt, expiresAt, defaultOwnerUuid, scopes, updatedAt, createdAt
609     } = apiResponse;
610     const response = `
611 "uuid": "${uuid}",
612 "owner_uuid": "${ownerUuid}",
613 "api_token": "${stringify(apiToken)}",
614 "api_client_id": "${stringify(apiClientId)}",
615 "user_id": "${stringify(userId)}",
616 "created_by_ip_address": "${stringify(createdByIpAddress)}",
617 "last_used_by_ip_address": "${stringify(lastUsedByIpAddress)}",
618 "last_used_at": "${stringify(lastUsedAt)}",
619 "expires_at": "${stringify(expiresAt)}",
620 "created_at": "${stringify(createdAt)}",
621 "updated_at": "${stringify(updatedAt)}",
622 "default_owner_uuid": "${stringify(defaultOwnerUuid)}",
623 "scopes": "${JSON.stringify(scopes, null, 2)}"`;
624
625     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
626 };
627
628 const linkApiResponse = (apiResponse: LinkResource) => {
629     const {
630         uuid, name, headUuid, properties, headKind, tailUuid, tailKind, linkClass,
631         ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid
632     } = apiResponse;
633     const response = `
634 "uuid": "${uuid}",
635 "name": "${name}",
636 "head_uuid": "${headUuid}",
637 "head_kind": "${headKind}",
638 "tail_uuid": "${tailUuid}",
639 "tail_kind": "${tailKind}",
640 "link_class": "${linkClass}",
641 "owner_uuid": "${ownerUuid}",
642 "created_at": "${stringify(createdAt)}",
643 "modified_at": ${stringify(modifiedAt)},
644 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
645 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
646 "properties": "${JSON.stringify(properties, null, 2)}"`;
647
648     return <span style={{ marginLeft: '-15px' }}>{'{'} {response} {'\n'} <span style={{ marginLeft: '-15px' }}>{'}'}</span></span>;
649 };