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