@adobe/aio-cli-plugin-api-mesh 1.0.1-beta → 1.0.4-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,20 +11,47 @@ governing permissions and limitations under the License.
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
13
  const { readFile } = require('fs/promises');
14
- const { initSdk, initRequestId } = require('../../helpers');
14
+
15
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
15
16
  const logger = require('../../classes/logger');
17
+ const CONSTANTS = require('../../constants');
18
+ const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
19
+ const {
20
+ createMesh,
21
+ createAPIMeshCredentials,
22
+ subscribeCredentialToMeshService,
23
+ } = require('../../lib/devConsole');
24
+
25
+ require('dotenv').config();
26
+
27
+ const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
16
28
 
17
29
  class CreateCommand extends Command {
18
30
  static args = [{ name: 'file' }];
31
+ static flags = {
32
+ ignoreCache: ignoreCacheFlag,
33
+ autoConfirmAction: autoConfirmActionFlag,
34
+ };
19
35
 
20
36
  async run() {
21
37
  await initRequestId();
22
38
 
23
39
  logger.info(`RequestId: ${global.requestId}`);
24
40
 
25
- const { args } = this.parse(CreateCommand);
41
+ const { args, flags } = await this.parse(CreateCommand);
42
+
43
+ if (!args.file) {
44
+ this.error('Missing file path. Run aio api-mesh create --help for more info.');
45
+
46
+ return;
47
+ }
48
+
49
+ const ignoreCache = await flags.ignoreCache;
50
+ const autoConfirmAction = await flags.autoConfirmAction;
26
51
 
27
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
52
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
53
+ ignoreCache,
54
+ });
28
55
 
29
56
  let data;
30
57
 
@@ -39,25 +66,78 @@ class CreateCommand extends Command {
39
66
  );
40
67
  }
41
68
 
42
- try {
43
- const mesh = await schemaServiceClient.createMesh(imsOrgId, projectId, workspaceId, data);
69
+ let shouldContinue = true;
70
+
71
+ if (!autoConfirmAction) {
72
+ shouldContinue = await promptConfirm(`Are you sure you want to create a mesh?`);
73
+ }
44
74
 
45
- if (mesh) {
46
- this.log('Successfully created mesh %s', mesh.meshId);
47
- this.log(JSON.stringify(mesh, null, 2));
75
+ if (shouldContinue) {
76
+ try {
77
+ const mesh = await createMesh(imsOrgId, projectId, workspaceId, data);
78
+ let sdkList = [];
48
79
 
49
- return mesh;
50
- } else {
51
- this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
52
- exit: false,
53
- });
80
+ if (mesh) {
81
+ this.log('Successfully created mesh %s', mesh.meshId);
82
+ this.log(JSON.stringify(mesh, null, 2));
83
+ // create API key credential
84
+ const adobeIdIntegrationsForWorkspace = await createAPIMeshCredentials(
85
+ imsOrgId,
86
+ projectId,
87
+ workspaceId,
88
+ );
89
+
90
+ if (adobeIdIntegrationsForWorkspace) {
91
+ this.log('Successfully created API Key %s', adobeIdIntegrationsForWorkspace.apiKey);
92
+ // subscribe the credential to API mesh service
93
+ sdkList = await subscribeCredentialToMeshService(
94
+ imsOrgId,
95
+ projectId,
96
+ workspaceId,
97
+ adobeIdIntegrationsForWorkspace.id,
98
+ );
99
+
100
+ if (sdkList) {
101
+ this.log(
102
+ 'Successfully subscribed API Key %s to API Mesh service',
103
+ adobeIdIntegrationsForWorkspace.apiKey,
104
+ );
105
+
106
+ this.log(
107
+ 'Mesh Endpoint: %s\n',
108
+ `${MULTITENANT_GRAPHQL_SERVER_BASE_URL}/${mesh.meshId}/graphql?api_key=${adobeIdIntegrationsForWorkspace.apiKey}`,
109
+ );
110
+ } else {
111
+ this.log(
112
+ 'Unable to subscribe API Key %s to API Mesh service',
113
+ adobeIdIntegrationsForWorkspace.apiKey,
114
+ );
115
+ }
116
+ } else {
117
+ this.log('Unable to create API Key');
118
+ }
119
+
120
+ return {
121
+ adobeIdIntegrationsForWorkspace,
122
+ sdkList,
123
+ mesh,
124
+ };
125
+ } else {
126
+ this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
127
+ exit: false,
128
+ });
129
+ }
130
+ } catch (error) {
131
+ this.log(error.message);
132
+
133
+ this.error(
134
+ `Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
135
+ );
54
136
  }
55
- } catch (error) {
56
- this.log(error.message);
137
+ } else {
138
+ this.log('Create cancelled');
57
139
 
58
- this.error(
59
- `Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
60
- );
140
+ return 'Create cancelled';
61
141
  }
62
142
  }
63
143
  }
@@ -10,39 +10,103 @@ governing permissions and limitations under the License.
10
10
  */
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
+
13
14
  const logger = require('../../classes/logger');
14
- const { initSdk, initRequestId } = require('../../helpers');
15
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
16
+ const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
17
+ const {
18
+ getMeshId,
19
+ deleteMesh,
20
+ getApiKeyCredential,
21
+ unsubscribeCredentialFromMeshService,
22
+ } = require('../../lib/devConsole');
15
23
 
16
24
  require('dotenv').config();
17
25
 
18
26
  class DeleteCommand extends Command {
19
- static args = [{ name: 'meshId' }];
27
+ static flags = {
28
+ ignoreCache: ignoreCacheFlag,
29
+ autoConfirmAction: autoConfirmActionFlag,
30
+ };
20
31
 
21
32
  async run() {
22
33
  await initRequestId();
23
34
 
24
35
  logger.info(`RequestId: ${global.requestId}`);
25
36
 
26
- const { args } = this.parse(DeleteCommand);
37
+ const { flags } = await this.parse(DeleteCommand);
38
+
39
+ const ignoreCache = await flags.ignoreCache;
40
+ const autoConfirmAction = await flags.autoConfirmAction;
41
+
42
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
43
+ ignoreCache,
44
+ });
27
45
 
28
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
46
+ let meshId = null;
29
47
 
30
48
  try {
31
- const response = await schemaServiceClient.deleteMesh(
32
- imsOrgId,
33
- projectId,
34
- workspaceId,
35
- args.meshId,
49
+ meshId = await getMeshId(imsOrgId, projectId, workspaceId);
50
+ } catch (err) {
51
+ this.error(
52
+ `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
36
53
  );
54
+ }
55
+
56
+ if (meshId) {
57
+ let shouldContinue = true;
58
+
59
+ if (!autoConfirmAction) {
60
+ shouldContinue = await promptConfirm(
61
+ `Are you sure you want to delete the mesh: ${meshId}?`,
62
+ );
63
+ }
64
+
65
+ if (shouldContinue) {
66
+ try {
67
+ const deleteMeshResponse = await deleteMesh(imsOrgId, projectId, workspaceId, meshId);
68
+
69
+ if (deleteMeshResponse) {
70
+ this.log('Successfully deleted mesh %s', meshId);
71
+
72
+ const credential = await getApiKeyCredential(imsOrgId, projectId, workspaceId);
73
+
74
+ if (credential) {
75
+ const newSDKList = await unsubscribeCredentialFromMeshService(
76
+ imsOrgId,
77
+ projectId,
78
+ workspaceId,
79
+ credential.id_integration,
80
+ );
81
+
82
+ if (newSDKList) {
83
+ this.log('Successfully unsubscribed API Key %s', credential.client_id);
84
+ } else {
85
+ this.log('Unable to unsubscribe API Key %s', credential.client_id);
86
+ }
87
+ } else {
88
+ this.log('No API Key found to unsubscribe');
89
+ }
37
90
 
38
- this.log('Successfully deleted mesh %s', args.meshId);
91
+ return deleteMeshResponse;
92
+ } else {
93
+ throw new Error('Unable to delete mesh');
94
+ }
95
+ } catch (error) {
96
+ this.log(error.message);
39
97
 
40
- return response;
41
- } catch (error) {
42
- this.log(error.message);
98
+ this.error(
99
+ `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
100
+ );
101
+ }
102
+ } else {
103
+ this.log('Delete cancelled');
43
104
 
105
+ return 'Delete cancelled';
106
+ }
107
+ } else {
44
108
  this.error(
45
- `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
109
+ `Unable to delete. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
46
110
  );
47
111
  }
48
112
  }
@@ -0,0 +1,85 @@
1
+ /*
2
+ Copyright 2021 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
10
+ */
11
+
12
+ const { Command } = require('@oclif/command');
13
+
14
+ const logger = require('../../classes/logger');
15
+ const { initSdk, initRequestId } = require('../../helpers');
16
+ const CONSTANTS = require('../../constants');
17
+ const { ignoreCacheFlag } = require('../../utils');
18
+ const { describeMesh } = require('../../lib/devConsole');
19
+
20
+ require('dotenv').config();
21
+
22
+ const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
23
+
24
+ class DescribeCommand extends Command {
25
+ static flags = {
26
+ ignoreCache: ignoreCacheFlag,
27
+ };
28
+
29
+ async run() {
30
+ await initRequestId();
31
+
32
+ logger.info(`RequestId: ${global.requestId}`);
33
+
34
+ const { flags } = await this.parse(DescribeCommand);
35
+
36
+ const ignoreCache = await flags.ignoreCache;
37
+
38
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
39
+ ignoreCache,
40
+ });
41
+
42
+ try {
43
+ const meshDetails = await describeMesh(imsOrgId, projectId, workspaceId);
44
+
45
+ if (meshDetails) {
46
+ const { meshId, apiKey } = meshDetails;
47
+
48
+ if (meshId) {
49
+ this.log('Successfully retrieved mesh details \n');
50
+ this.log('Org ID: %s', imsOrgId);
51
+ this.log('Project ID: %s', projectId);
52
+ this.log('Workspace ID: %s', workspaceId);
53
+ this.log('Mesh ID: %s', meshId);
54
+
55
+ if (apiKey) {
56
+ this.log('API Key: %s', apiKey);
57
+ this.log(
58
+ 'Mesh Endpoint: %s\n',
59
+ `${MULTITENANT_GRAPHQL_SERVER_BASE_URL}/${meshId}/graphql?api_key=${apiKey}`,
60
+ );
61
+ }
62
+
63
+ return meshDetails;
64
+ } else {
65
+ this.error(
66
+ `Unable to get mesh details. Please check the details and try again. RequestId: ${global.requestId}`,
67
+ { exit: false },
68
+ );
69
+ }
70
+ } else {
71
+ throw new Error(`Unable to get mesh details`);
72
+ }
73
+ } catch (error) {
74
+ this.log(error.message);
75
+
76
+ this.error(
77
+ `Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
78
+ );
79
+ }
80
+ }
81
+ }
82
+
83
+ DescribeCommand.description = 'Get details of a mesh';
84
+
85
+ module.exports = DescribeCommand;
@@ -11,54 +11,80 @@ governing permissions and limitations under the License.
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
13
  const { writeFile } = require('fs/promises');
14
+
14
15
  const logger = require('../../classes/logger');
15
16
  const { initSdk, initRequestId } = require('../../helpers');
17
+ const { ignoreCacheFlag } = require('../../utils');
18
+ const { getMeshId, getMesh } = require('../../lib/devConsole');
16
19
 
17
20
  require('dotenv').config();
18
21
 
19
22
  class GetCommand extends Command {
20
- static args = [{ name: 'meshId' }, { name: 'file' }];
23
+ static args = [{ name: 'file' }];
24
+ static flags = {
25
+ ignoreCache: ignoreCacheFlag,
26
+ };
21
27
 
22
28
  async run() {
23
29
  await initRequestId();
24
30
 
25
31
  logger.info(`RequestId: ${global.requestId}`);
26
32
 
27
- const { args } = this.parse(GetCommand);
33
+ const { args, flags } = await this.parse(GetCommand);
34
+
35
+ const ignoreCache = await flags.ignoreCache;
36
+
37
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
38
+ ignoreCache,
39
+ });
28
40
 
29
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
41
+ let meshId = null;
30
42
 
31
43
  try {
32
- const mesh = await schemaServiceClient.getMesh(imsOrgId, projectId, workspaceId, args.meshId);
44
+ meshId = await getMeshId(imsOrgId, projectId, workspaceId);
45
+ } catch (err) {
46
+ this.error(
47
+ `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
48
+ );
49
+ }
50
+
51
+ if (meshId) {
52
+ try {
53
+ const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
33
54
 
34
- if (mesh) {
35
- this.log('Successfully retrieved mesh %s', JSON.stringify(mesh, null, 2));
55
+ if (mesh) {
56
+ this.log('Successfully retrieved mesh %s', JSON.stringify(mesh, null, 2));
36
57
 
37
- if (args.file) {
38
- try {
39
- const { meshConfig } = mesh;
40
- await writeFile(args.file, JSON.stringify({ meshConfig }, null, 2));
58
+ if (args.file) {
59
+ try {
60
+ const { meshConfig } = mesh;
61
+ await writeFile(args.file, JSON.stringify({ meshConfig }, null, 2));
41
62
 
42
- this.log('Successfully wrote mesh to file %s', args.file);
43
- } catch (error) {
44
- this.log('Unable to write mesh to file %s', args.file);
63
+ this.log('Successfully wrote mesh to file %s', args.file);
64
+ } catch (error) {
65
+ this.log('Unable to write mesh to file %s', args.file);
45
66
 
46
- logger.error(error);
67
+ logger.error(error);
68
+ }
47
69
  }
70
+
71
+ return mesh;
72
+ } else {
73
+ this.error(
74
+ `Unable to get mesh with the ID ${meshId}. Please check the mesh ID and try again. RequestId: ${global.requestId}`,
75
+ { exit: false },
76
+ );
48
77
  }
78
+ } catch (error) {
79
+ this.log(error.message);
49
80
 
50
- return mesh;
51
- } else {
52
81
  this.error(
53
- `Unable to get mesh with the ID ${args.meshId}. Please check the mesh ID and try again. RequestId: ${global.requestId}`,
54
- { exit: false },
82
+ `Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
55
83
  );
56
84
  }
57
- } catch (error) {
58
- this.log(error.message);
59
-
85
+ } else {
60
86
  this.error(
61
- `Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
87
+ `Unable to get mesh config. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
62
88
  );
63
89
  }
64
90
  }
@@ -11,20 +11,41 @@ governing permissions and limitations under the License.
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
13
  const { readFile } = require('fs/promises');
14
+
14
15
  const logger = require('../../classes/logger');
15
- const { initSdk, initRequestId } = require('../../helpers');
16
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
17
+ const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
18
+ const { getMeshId, updateMesh } = require('../../lib/devConsole');
19
+
20
+ require('dotenv').config();
16
21
 
17
22
  class UpdateCommand extends Command {
18
- static args = [{ name: 'meshId' }, { name: 'file' }];
23
+ static args = [{ name: 'file' }];
24
+ static flags = {
25
+ ignoreCache: ignoreCacheFlag,
26
+ autoConfirmAction: autoConfirmActionFlag,
27
+ };
19
28
 
20
29
  async run() {
21
30
  await initRequestId();
22
31
 
23
32
  logger.info(`RequestId: ${global.requestId}`);
24
33
 
25
- const { args } = this.parse(UpdateCommand);
34
+ const { args, flags } = await this.parse(UpdateCommand);
35
+
36
+ if (!args.file) {
37
+ this.error('Missing required args. Run aio api-mesh update --help for more info.');
38
+
39
+ return;
40
+ }
41
+
42
+ const ignoreCache = await flags.ignoreCache;
43
+ const autoConfirmAction = await flags.autoConfirmAction;
44
+
45
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
46
+ ignoreCache,
47
+ });
26
48
 
27
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
28
49
  let data;
29
50
 
30
51
  try {
@@ -38,23 +59,47 @@ class UpdateCommand extends Command {
38
59
  );
39
60
  }
40
61
 
62
+ let meshId = null;
63
+
41
64
  try {
42
- const response = await schemaServiceClient.updateMesh(
43
- imsOrgId,
44
- projectId,
45
- workspaceId,
46
- args.meshId,
47
- data,
65
+ meshId = await getMeshId(imsOrgId, projectId, workspaceId);
66
+ } catch (err) {
67
+ this.error(
68
+ `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
48
69
  );
70
+ }
49
71
 
50
- this.log('Successfully updated the mesh with the id: %s', args.meshId);
72
+ if (meshId) {
73
+ let shouldContinue = true;
51
74
 
52
- return response;
53
- } catch (error) {
54
- this.log(error.message);
75
+ if (!autoConfirmAction) {
76
+ shouldContinue = await promptConfirm(
77
+ `Are you sure you want to update the mesh: ${meshId}?`,
78
+ );
79
+ }
80
+
81
+ if (shouldContinue) {
82
+ try {
83
+ const response = await updateMesh(imsOrgId, projectId, workspaceId, meshId, data);
84
+
85
+ this.log('Successfully updated the mesh with the id: %s', meshId);
86
+
87
+ return response;
88
+ } catch (error) {
89
+ this.log(error.message);
90
+
91
+ this.error(
92
+ `Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
93
+ );
94
+ }
95
+ } else {
96
+ this.log('Update cancelled');
55
97
 
98
+ return 'Update cancelled';
99
+ }
100
+ } else {
56
101
  this.error(
57
- `Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
102
+ `Unable to update. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
58
103
  );
59
104
  }
60
105
  }
@@ -0,0 +1,21 @@
1
+ const { getCliEnv } = require('@adobe/aio-lib-env');
2
+
3
+ const clientEnv = getCliEnv();
4
+
5
+ const StageConstants = {
6
+ MULTITENANT_GRAPHQL_SERVER_BASE_URL: 'https://graph-stage.adobe.io/api',
7
+ DEV_CONSOLE_BASE_URL: 'https://developers-stage.adobe.io/console',
8
+ DEV_CONSOLE_API_KEY: 'adobe-api-manager-sms-stage',
9
+ DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
10
+ AIO_CLI_API_KEY: 'aio-cli-console-auth-stage',
11
+ };
12
+
13
+ const ProdConstants = {
14
+ MULTITENANT_GRAPHQL_SERVER_BASE_URL: 'https://graph.adobe.io/api',
15
+ DEV_CONSOLE_BASE_URL: 'https://developers.adobe.io/console',
16
+ DEV_CONSOLE_API_KEY: 'adobe-graph-prod',
17
+ DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
18
+ AIO_CLI_API_KEY: 'aio-cli-console-auth',
19
+ };
20
+
21
+ module.exports = clientEnv === 'stage' ? StageConstants : ProdConstants;