@rockcarver/frodo-lib 0.16.2-2 → 0.16.2-3

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/cjs/api/AgentApi.js +221 -0
  3. package/cjs/api/AgentApi.js.map +1 -0
  4. package/cjs/api/AgentApi.test.js.map +1 -0
  5. package/cjs/api/ApiTypes.js.map +1 -1
  6. package/cjs/api/BaseApi.js +15 -11
  7. package/cjs/api/BaseApi.js.map +1 -1
  8. package/cjs/index.js +5 -1
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/ops/AgentOps.js +805 -0
  11. package/cjs/ops/AgentOps.js.map +1 -0
  12. package/cjs/ops/AgentOps.test.js.map +1 -0
  13. package/cjs/ops/AuthenticateOps.js +8 -8
  14. package/cjs/ops/AuthenticateOps.js.map +1 -1
  15. package/cjs/ops/JourneyOps.test.js.map +1 -1
  16. package/cjs/ops/OpsTypes.js.map +1 -1
  17. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +22 -0
  18. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  19. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  20. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +32 -0
  21. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/J2EEAgent/javaAgent.json +623 -0
  22. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/J2EEAgent/tomcatagent.json +630 -0
  23. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/WebAgent/apacheagent.json +456 -0
  24. package/cjs/test/mocks/AgentApi/deleteAgentByTypeAndId/WebAgent/webserver.json +455 -0
  25. package/cjs/test/mocks/AgentApi/findAgentById/ajays_client.json +19 -0
  26. package/cjs/test/mocks/AgentApi/findAgentById/apacheagent.json +142 -0
  27. package/cjs/test/mocks/AgentApi/findAgentById/api_client.json +19 -0
  28. package/cjs/test/mocks/AgentApi/findAgentById/ig_chico.json +19 -0
  29. package/cjs/test/mocks/AgentApi/findAgentById/ig_mytestrun_com.json +29 -0
  30. package/cjs/test/mocks/AgentApi/findAgentById/javaAgent.json +190 -0
  31. package/cjs/test/mocks/AgentApi/findAgentById/tomcatagent.json +191 -0
  32. package/cjs/test/mocks/AgentApi/findAgentById/webserver.json +144 -0
  33. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +23 -0
  34. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  35. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  36. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +33 -0
  37. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/J2EEAgent/javaAgent.json +193 -0
  38. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/J2EEAgent/tomcatagent.json +195 -0
  39. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/WebAgent/apacheagent.json +145 -0
  40. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/WebAgent/webserver.json +148 -0
  41. package/cjs/test/mocks/AgentApi/findAgentByTypeAndId/not_found.json +8 -0
  42. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +22 -0
  43. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  44. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  45. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +32 -0
  46. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/javaAgent.json +623 -0
  47. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/tomcatagent.json +630 -0
  48. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/apacheagent.json +456 -0
  49. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/webserver.json +455 -0
  50. package/cjs/test/mocks/AgentApi/getAgentTypes/agentTypes.json +54 -0
  51. package/cjs/test/mocks/AgentApi/getAgents/agents.json +3862 -0
  52. package/cjs/test/mocks/AgentApi/getAgentsByType/IdentityGatewayAgents.json +73 -0
  53. package/cjs/test/mocks/AgentApi/getAgentsByType/J2EEAgents.json +379 -0
  54. package/cjs/test/mocks/AgentApi/getAgentsByType/WebAgents.json +284 -0
  55. package/cjs/test/mocks/ForgeRockApiMockEngine.js +147 -20
  56. package/cjs/test/mocks/ForgeRockApiMockEngine.js.map +1 -1
  57. package/esm/api/AgentApi.mjs +164 -0
  58. package/esm/api/AgentApi.test.mjs +267 -0
  59. package/esm/api/BaseApi.mjs +16 -4
  60. package/esm/index.mjs +2 -0
  61. package/esm/ops/AgentOps.mjs +576 -0
  62. package/esm/ops/AgentOps.test.mjs +1212 -0
  63. package/esm/ops/AuthenticateOps.mjs +8 -8
  64. package/esm/ops/JourneyOps.test.mjs +4 -8
  65. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +22 -0
  66. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  67. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  68. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +32 -0
  69. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/J2EEAgent/javaAgent.json +623 -0
  70. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/J2EEAgent/tomcatagent.json +630 -0
  71. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/WebAgent/apacheagent.json +456 -0
  72. package/esm/test/mocks/AgentApi/deleteAgentByTypeAndId/WebAgent/webserver.json +455 -0
  73. package/esm/test/mocks/AgentApi/findAgentById/ajays_client.json +19 -0
  74. package/esm/test/mocks/AgentApi/findAgentById/apacheagent.json +142 -0
  75. package/esm/test/mocks/AgentApi/findAgentById/api_client.json +19 -0
  76. package/esm/test/mocks/AgentApi/findAgentById/ig_chico.json +19 -0
  77. package/esm/test/mocks/AgentApi/findAgentById/ig_mytestrun_com.json +29 -0
  78. package/esm/test/mocks/AgentApi/findAgentById/javaAgent.json +190 -0
  79. package/esm/test/mocks/AgentApi/findAgentById/tomcatagent.json +191 -0
  80. package/esm/test/mocks/AgentApi/findAgentById/webserver.json +144 -0
  81. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +23 -0
  82. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  83. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  84. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +33 -0
  85. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/J2EEAgent/javaAgent.json +193 -0
  86. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/J2EEAgent/tomcatagent.json +195 -0
  87. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/WebAgent/apacheagent.json +145 -0
  88. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/WebAgent/webserver.json +148 -0
  89. package/esm/test/mocks/AgentApi/findAgentByTypeAndId/not_found.json +8 -0
  90. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +22 -0
  91. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/api_client.json +22 -0
  92. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json +22 -0
  93. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json +32 -0
  94. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/javaAgent.json +623 -0
  95. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/tomcatagent.json +630 -0
  96. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/apacheagent.json +456 -0
  97. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/webserver.json +455 -0
  98. package/esm/test/mocks/AgentApi/getAgentTypes/agentTypes.json +54 -0
  99. package/esm/test/mocks/AgentApi/getAgents/agents.json +3862 -0
  100. package/esm/test/mocks/AgentApi/getAgentsByType/IdentityGatewayAgents.json +73 -0
  101. package/esm/test/mocks/AgentApi/getAgentsByType/J2EEAgents.json +379 -0
  102. package/esm/test/mocks/AgentApi/getAgentsByType/WebAgents.json +284 -0
  103. package/esm/test/mocks/ForgeRockApiMockEngine.mjs +136 -20
  104. package/package.json +2 -2
  105. package/types/api/AgentApi.d.ts +51 -0
  106. package/types/api/AgentApi.d.ts.map +1 -0
  107. package/types/api/ApiTypes.d.ts +3 -0
  108. package/types/api/ApiTypes.d.ts.map +1 -1
  109. package/types/api/BaseApi.d.ts.map +1 -1
  110. package/types/index.d.ts +2 -0
  111. package/types/index.d.ts.map +1 -1
  112. package/types/ops/AgentOps.d.ts +210 -0
  113. package/types/ops/AgentOps.d.ts.map +1 -0
  114. package/types/ops/AuthenticateOps.d.ts.map +1 -1
  115. package/types/ops/OpsTypes.d.ts +5 -1
  116. package/types/ops/OpsTypes.d.ts.map +1 -1
  117. package/types/test/mocks/ForgeRockApiMockEngine.d.ts +35 -2
  118. package/types/test/mocks/ForgeRockApiMockEngine.d.ts.map +1 -1
package/esm/index.mjs CHANGED
@@ -2,6 +2,7 @@ import Color from 'colors';
2
2
  Color.enable();
3
3
 
4
4
  // Api Layer
5
+ export * as AgentRaw from './api/AgentApi';
5
6
  export * as EmailTemplateRaw from './api/EmailTemplateApi';
6
7
  export * as NodeRaw from './api/NodeApi';
7
8
  export * as SecretsRaw from './api/SecretsApi';
@@ -13,6 +14,7 @@ export * as VariablesRaw from './api/VariablesApi';
13
14
 
14
15
  // Ops Layer
15
16
  export * as Admin from './ops/AdminOps';
17
+ export * as Agent from './ops/AgentOps';
16
18
  export * as Authenticate from './ops/AuthenticateOps';
17
19
  export * as CirclesOfTrust from './ops/CirclesOfTrustOps';
18
20
  export * as ConnectionProfile from './ops/ConnectionProfileOps';
@@ -0,0 +1,576 @@
1
+ import { debugMessage, printMessage } from './utils/Console';
2
+ import { getAgentsByType, getAgentByTypeAndId as _getAgentByTypeAndId, putAgentByTypeAndId, findAgentById, deleteAgentByTypeAndId, findAgentByTypeAndId } from '../api/AgentApi';
3
+ import { validateImport } from './utils/ExportImportUtils';
4
+ export const AGENT_TYPE_IG = 'IdentityGatewayAgent';
5
+ export const AGENT_TYPE_JAVA = 'J2EEAgent';
6
+ export const AGENT_TYPE_WEB = 'WebAgent';
7
+
8
+ /**
9
+ * Create an empty single tree export template
10
+ * @returns {SingleTreeExportInterface} an empty single tree export template
11
+ */
12
+ export function createAgentExportTemplate() {
13
+ return {
14
+ meta: {},
15
+ agents: {}
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Get all agents. Results are sorted aphabetically.
21
+ * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects
22
+ */
23
+ export async function getAgents() {
24
+ debugMessage(`AgentOps.getAgents: start`);
25
+ let agents = [];
26
+ try {
27
+ const resolved = await Promise.all([getAgentsByType('IdentityGatewayAgent'), getAgentsByType('J2EEAgent'), getAgentsByType('WebAgent')]);
28
+ agents = agents.concat(resolved[0].result);
29
+ agents = agents.concat(resolved[1].result);
30
+ agents = agents.concat(resolved[2].result);
31
+ } catch (error) {
32
+ printMessage(`${error.message}`, 'error');
33
+ printMessage(error.response.data, 'error');
34
+ }
35
+ agents.sort((a, b) => a._id.localeCompare(b._id));
36
+ debugMessage(`AgentOps.getAgents: end`);
37
+ return agents;
38
+ }
39
+
40
+ /**
41
+ * Get agent
42
+ * @param {string} agentId agent id/name
43
+ * @returns {Promise} a promise that resolves to an agent object
44
+ */
45
+ export async function getAgent(agentId) {
46
+ debugMessage(`AgentOps.getAgent: start`);
47
+ const agents = await findAgentById(agentId);
48
+ if (agents.length === 1) {
49
+ const result = await _getAgentByTypeAndId(agents[0]._type, agents[0]._id);
50
+ debugMessage(`AgentOps.getAgent: end`);
51
+ return result;
52
+ } else if (agents.length === 0) {
53
+ throw new Error(`Agent '${agentId}' not found`);
54
+ } else {
55
+ throw new Error(`${agents.length} agents '${agentId}' found`);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Get agent by type and id
61
+ * @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)
62
+ * @param {string} agentId agent id/name
63
+ * @returns {Promise} a promise that resolves to an agent object
64
+ */
65
+ export async function getAgentByTypeAndId(agentType, agentId) {
66
+ debugMessage(`AgentOps.getAgentByTypeAndId: start`);
67
+ const result = await _getAgentByTypeAndId(agentType, agentId);
68
+ debugMessage(`AgentOps.getAgentByTypeAndId: start`);
69
+ return result;
70
+ }
71
+
72
+ /**
73
+ * Get identity gateway agents
74
+ * @returns {Promise} a promise that resolves to an array of IdentityGatewayAgent objects
75
+ */
76
+ export async function getIdentityGatewayAgents() {
77
+ debugMessage(`AgentOps.getIdentityGatewayAgents: start`);
78
+ const {
79
+ result
80
+ } = await getAgentsByType(AGENT_TYPE_IG);
81
+ debugMessage(`AgentOps.getIdentityGatewayAgents: end`);
82
+ return result;
83
+ }
84
+
85
+ /**
86
+ * Get identity gateway agent
87
+ * @param {string} gatewayId gateway id
88
+ * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object
89
+ */
90
+ export async function getIdentityGatewayAgent(gatewayId) {
91
+ debugMessage(`AgentOps.getIdentityGatewayAgent: start`);
92
+ const result = await getAgentByTypeAndId(AGENT_TYPE_IG, gatewayId);
93
+ debugMessage(`AgentOps.getIdentityGatewayAgent: end`);
94
+ return result;
95
+ }
96
+
97
+ /**
98
+ * Put identity gateway agent
99
+ * @param {string} gatewayId gateway id
100
+ * @param {Object} gatewayData IdentityGatewayAgent object
101
+ * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object
102
+ */
103
+ export async function putIdentityGatewayAgent(gatewayId, gatewayData) {
104
+ debugMessage(`AgentOps.putIdentityGatewayAgent: start`);
105
+ const result = await putAgentByTypeAndId(AGENT_TYPE_IG, gatewayId, gatewayData);
106
+ debugMessage(`AgentOps.putIdentityGatewayAgent: end`);
107
+ return result;
108
+ }
109
+
110
+ /**
111
+ * Get java agents
112
+ * @returns {Promise} a promise that resolves to an array of J2EEAgent objects
113
+ */
114
+ export async function getJavaAgents() {
115
+ debugMessage(`AgentOps.getJavaAgents: start`);
116
+ const {
117
+ result
118
+ } = await getAgentsByType(AGENT_TYPE_JAVA);
119
+ debugMessage(`AgentOps.getJavaAgents: end`);
120
+ return result;
121
+ }
122
+
123
+ /**
124
+ * Get java agent
125
+ * @param {string} agentId java agent id
126
+ * @returns {Promise} a promise that resolves to an object containing an J2EEAgent object
127
+ */
128
+ export async function getJavaAgent(agentId) {
129
+ debugMessage(`AgentOps.getJavaAgent: start`);
130
+ const result = await getAgentByTypeAndId(AGENT_TYPE_JAVA, agentId);
131
+ debugMessage(`AgentOps.getJavaAgent: end`);
132
+ return result;
133
+ }
134
+
135
+ /**
136
+ * Put java agent
137
+ * @param {string} agentId java agent id
138
+ * @param {Object} agentData java agent object
139
+ * @returns {Promise} a promise that resolves to an object containing an java agent object
140
+ */
141
+ export async function putJavaAgent(agentId, agentData) {
142
+ debugMessage(`AgentOps.putJavaAgent: start`);
143
+ const result = await putAgentByTypeAndId(AGENT_TYPE_JAVA, agentId, agentData);
144
+ debugMessage(`AgentOps.putJavaAgent: end`);
145
+ return result;
146
+ }
147
+
148
+ /**
149
+ * Get web agents
150
+ * @returns {Promise} a promise that resolves to an array of WebAgent objects
151
+ */
152
+ export async function getWebAgents() {
153
+ debugMessage(`AgentOps.getWebAgents: start`);
154
+ const {
155
+ result
156
+ } = await getAgentsByType(AGENT_TYPE_WEB);
157
+ debugMessage(`AgentOps.getWebAgents: end`);
158
+ return result;
159
+ }
160
+
161
+ /**
162
+ * Get web agent
163
+ * @param {string} agentId web agent id
164
+ * @returns {Promise} a promise that resolves to an object containing an WebAgent object
165
+ */
166
+ export async function getWebAgent(agentId) {
167
+ debugMessage(`AgentOps.getWebAgent: start`);
168
+ const result = await getAgentByTypeAndId(AGENT_TYPE_WEB, agentId);
169
+ debugMessage(`AgentOps.getWebAgent: end`);
170
+ return result;
171
+ }
172
+
173
+ /**
174
+ * Put web agent
175
+ * @param {string} agentId web agent id
176
+ * @param {Object} agentData WebAgent object
177
+ * @returns {Promise} a promise that resolves to an object containing an WebAgent object
178
+ */
179
+ export async function putWebAgent(agentId, agentData) {
180
+ debugMessage(`AgentOps.putWebAgent: start`);
181
+ const result = await putAgentByTypeAndId(AGENT_TYPE_WEB, agentId, agentData);
182
+ debugMessage(`AgentOps.putWebAgent: end`);
183
+ return result;
184
+ }
185
+
186
+ /**
187
+ * Export all agents. The response can be saved to file as is.
188
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
189
+ */
190
+ export async function exportAgents() {
191
+ debugMessage(`AgentOps.exportAgents: start`);
192
+ const exportData = createAgentExportTemplate();
193
+ const agents = await getAgents();
194
+ for (const agent of agents) {
195
+ exportData.agents[agent._id] = agent;
196
+ }
197
+ debugMessage(`AgentOps.exportAgents: end`);
198
+ return exportData;
199
+ }
200
+
201
+ /**
202
+ * Export all identity gateway agents. The response can be saved to file as is.
203
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
204
+ */
205
+ export async function exportIdentityGatewayAgents() {
206
+ debugMessage(`AgentOps.exportIdentityGatewayAgents: start`);
207
+ const exportData = createAgentExportTemplate();
208
+ const agents = await getIdentityGatewayAgents();
209
+ for (const agent of agents) {
210
+ exportData.agents[agent._id] = agent;
211
+ }
212
+ debugMessage(`AgentOps.exportIdentityGatewayAgents: end`);
213
+ return exportData;
214
+ }
215
+
216
+ /**
217
+ * Export all java agents. The response can be saved to file as is.
218
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
219
+ */
220
+ export async function exportJavaAgents() {
221
+ debugMessage(`AgentOps.exportJavaAgents: start`);
222
+ const exportData = createAgentExportTemplate();
223
+ const agents = await getJavaAgents();
224
+ for (const agent of agents) {
225
+ exportData.agents[agent._id] = agent;
226
+ }
227
+ debugMessage(`AgentOps.exportJavaAgents: end`);
228
+ return exportData;
229
+ }
230
+
231
+ /**
232
+ * Export all web agents. The response can be saved to file as is.
233
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
234
+ */
235
+ export async function exportWebAgents() {
236
+ debugMessage(`AgentOps.exportWebAgents: start`);
237
+ const exportData = createAgentExportTemplate();
238
+ const agents = await getWebAgents();
239
+ for (const agent of agents) {
240
+ exportData.agents[agent._id] = agent;
241
+ }
242
+ debugMessage(`AgentOps.exportWebAgents: end`);
243
+ return exportData;
244
+ }
245
+
246
+ /**
247
+ * Export agent. The response can be saved to file as is.
248
+ * @param agentId agent id/name
249
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
250
+ */
251
+ export async function exportAgent(agentId) {
252
+ debugMessage(`AgentOps.exportAgent: start`);
253
+ const exportData = createAgentExportTemplate();
254
+ const agentObject = await getAgent(agentId);
255
+ exportData.agents[agentId] = agentObject;
256
+ debugMessage(`AgentOps.exportAgent: end`);
257
+ return exportData;
258
+ }
259
+
260
+ /**
261
+ * Export identity gateway agent. The response can be saved to file as is.
262
+ * @param agentId agent id/name
263
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
264
+ */
265
+ export async function exportIdentityGatewayAgent(agentId) {
266
+ debugMessage(`AgentOps.exportIdentityGatewayAgent: start`);
267
+ const exportData = createAgentExportTemplate();
268
+ const agentObject = await getIdentityGatewayAgent(agentId);
269
+ exportData.agents[agentId] = agentObject;
270
+ debugMessage(`AgentOps.exportIdentityGatewayAgent: end`);
271
+ return exportData;
272
+ }
273
+
274
+ /**
275
+ * Export java agent. The response can be saved to file as is.
276
+ * @param agentId agent id/name
277
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
278
+ */
279
+ export async function exportJavaAgent(agentId) {
280
+ debugMessage(`AgentOps.exportJavaAgent: start`);
281
+ const exportData = createAgentExportTemplate();
282
+ const agentObject = await getJavaAgent(agentId);
283
+ exportData.agents[agentId] = agentObject;
284
+ debugMessage(`AgentOps.exportJavaAgent: end`);
285
+ return exportData;
286
+ }
287
+
288
+ /**
289
+ * Export web agent. The response can be saved to file as is.
290
+ * @param agentId agent id/name
291
+ * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.
292
+ */
293
+ export async function exportWebAgent(agentId) {
294
+ debugMessage(`AgentOps.exportWebAgent: start`);
295
+ const exportData = createAgentExportTemplate();
296
+ const agentObject = await getWebAgent(agentId);
297
+ exportData.agents[agentId] = agentObject;
298
+ debugMessage(`AgentOps.exportWebAgent: end`);
299
+ return exportData;
300
+ }
301
+
302
+ /**
303
+ * Import agents. The import data is usually read from an agent export file.
304
+ * @param {AgentExportInterface} importData agent import data.
305
+ */
306
+ export async function importAgents(importData) {
307
+ debugMessage(`AgentOps.importAgents: start`);
308
+ if (validateImport(importData.meta)) {
309
+ for (const agentId of Object.keys(importData.agents)) {
310
+ const agentType = importData.agents[agentId]._type._id;
311
+ debugMessage(`AgentOps.importAgents: ${agentId} [${agentType}]`);
312
+ await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
313
+ }
314
+ } else {
315
+ throw new Error('Invalid meta data.');
316
+ }
317
+ debugMessage(`AgentOps.importAgents: end`);
318
+ }
319
+
320
+ /**
321
+ * Import identity gateway agents. The import data is usually read from an agent export file.
322
+ * @param {AgentExportInterface} importData agent import data.
323
+ */
324
+ export async function importIdentityGatewayAgents(importData) {
325
+ debugMessage(`AgentOps.importIdentityGatewayAgents: start`);
326
+ if (validateImport(importData.meta)) {
327
+ for (const agentId of Object.keys(importData.agents)) {
328
+ const agentType = importData.agents[agentId]._type._id;
329
+ if (agentType !== AGENT_TYPE_IG) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_IG}' but got '${agentType}'.`);
330
+ await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
331
+ }
332
+ } else {
333
+ throw new Error('Invalid meta data.');
334
+ }
335
+ debugMessage(`AgentOps.importIdentityGatewayAgents: end`);
336
+ }
337
+
338
+ /**
339
+ * Import java agents. The import data is usually read from an agent export file.
340
+ * @param {AgentExportInterface} importData agent import data.
341
+ */
342
+ export async function importJavaAgents(importData) {
343
+ debugMessage(`AgentOps.importJavaAgents: start`);
344
+ if (validateImport(importData.meta)) {
345
+ for (const agentId of Object.keys(importData.agents)) {
346
+ const agentType = importData.agents[agentId]._type._id;
347
+ if (agentType !== AGENT_TYPE_JAVA) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_JAVA}' but got '${agentType}'.`);
348
+ await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
349
+ }
350
+ } else {
351
+ throw new Error('Invalid meta data.');
352
+ }
353
+ debugMessage(`AgentOps.importJavaAgents: end`);
354
+ }
355
+
356
+ /**
357
+ * Import web agents. The import data is usually read from an agent export file.
358
+ * @param {AgentExportInterface} importData agent import data.
359
+ */
360
+ export async function importWebAgents(importData) {
361
+ debugMessage(`AgentOps.importWebAgents: start`);
362
+ if (validateImport(importData.meta)) {
363
+ for (const agentId of Object.keys(importData.agents)) {
364
+ const agentType = importData.agents[agentId]._type._id;
365
+ if (agentType !== AGENT_TYPE_WEB) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_WEB}' but got '${agentType}'.`);
366
+ await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
367
+ }
368
+ } else {
369
+ throw new Error('Invalid meta data.');
370
+ }
371
+ debugMessage(`AgentOps.importWebAgents: end`);
372
+ }
373
+
374
+ /**
375
+ * Import agent. The import data is usually read from an agent export file.
376
+ * @param {string} agentId agent id/name
377
+ * @param {AgentExportInterface} importData agent import data.
378
+ * @returns {Promise} Promise resolving to an agent object.
379
+ */
380
+ export async function importAgent(agentId, importData) {
381
+ debugMessage(`AgentOps.importAgent: start`);
382
+ if (validateImport(importData.meta)) {
383
+ var _importData$agents$ag;
384
+ const agentType = (_importData$agents$ag = importData.agents[agentId]) === null || _importData$agents$ag === void 0 ? void 0 : _importData$agents$ag._type._id;
385
+ const result = await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
386
+ debugMessage(`AgentOps.importAgent: end`);
387
+ return result;
388
+ } else {
389
+ throw new Error('Invalid meta data.');
390
+ }
391
+ }
392
+
393
+ /**
394
+ * Import identity gateway agent. The import data is usually read from an agent export file.
395
+ * @param {string} agentId agent id/name
396
+ * @param {AgentExportInterface} importData agent import data.
397
+ * @returns {Promise} Promise resolving to an agent object.
398
+ */
399
+ export async function importIdentityGatewayAgent(agentId, importData) {
400
+ debugMessage(`AgentOps.importIdentityGatewayAgent: start`);
401
+ if (validateImport(importData.meta)) {
402
+ var _importData$agents$ag2;
403
+ const agentType = (_importData$agents$ag2 = importData.agents[agentId]) === null || _importData$agents$ag2 === void 0 ? void 0 : _importData$agents$ag2._type._id;
404
+ if (agentType !== AGENT_TYPE_IG) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_IG}' but got '${agentType}'.`);
405
+ const result = await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
406
+ debugMessage(`AgentOps.importIdentityGatewayAgent: end`);
407
+ return result;
408
+ } else {
409
+ throw new Error('Invalid meta data.');
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Import java agent. The import data is usually read from an agent export file.
415
+ * @param {string} agentId agent id/name
416
+ * @param {AgentExportInterface} importData agent import data.
417
+ * @returns {Promise} Promise resolving to an agent object.
418
+ */
419
+ export async function importJavaAgent(agentId, importData) {
420
+ debugMessage(`AgentOps.importJavaAgent: start`);
421
+ if (validateImport(importData.meta)) {
422
+ var _importData$agents$ag3;
423
+ const agentType = (_importData$agents$ag3 = importData.agents[agentId]) === null || _importData$agents$ag3 === void 0 ? void 0 : _importData$agents$ag3._type._id;
424
+ if (agentType !== AGENT_TYPE_JAVA) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_JAVA}' but got '${agentType}'.`);
425
+ const result = await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
426
+ debugMessage(`AgentOps.importJavaAgent: end`);
427
+ return result;
428
+ } else {
429
+ throw new Error('Invalid meta data.');
430
+ }
431
+ }
432
+
433
+ /**
434
+ * Import java agent. The import data is usually read from an agent export file.
435
+ * @param {string} agentId agent id/name
436
+ * @param {AgentExportInterface} importData agent import data.
437
+ * @returns {Promise} Promise resolving to an agent object.
438
+ */
439
+ export async function importWebAgent(agentId, importData) {
440
+ debugMessage(`AgentOps.importWebAgent: start`);
441
+ if (validateImport(importData.meta)) {
442
+ var _importData$agents$ag4;
443
+ const agentType = (_importData$agents$ag4 = importData.agents[agentId]) === null || _importData$agents$ag4 === void 0 ? void 0 : _importData$agents$ag4._type._id;
444
+ if (agentType !== AGENT_TYPE_WEB) throw new Error(`Wrong agent type! Expected '${AGENT_TYPE_WEB}' but got '${agentType}'.`);
445
+ const result = await putAgentByTypeAndId(agentType, agentId, importData.agents[agentId]);
446
+ debugMessage(`AgentOps.importWebAgent: end`);
447
+ return result;
448
+ } else {
449
+ throw new Error('Invalid meta data.');
450
+ }
451
+ }
452
+
453
+ /**
454
+ * Delete all agents
455
+ */
456
+ export async function deleteAgents() {
457
+ debugMessage(`AgentOps.deleteAgents: start`);
458
+ const agents = await getAgents();
459
+ for (const agent of agents) {
460
+ debugMessage(`AgentOps.deleteAgent: '${agent['_id']}'`);
461
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
462
+ }
463
+ debugMessage(`AgentOps.deleteAgents: end`);
464
+ }
465
+
466
+ /**
467
+ * Delete agent
468
+ * @param agentId agent id/name
469
+ */
470
+ export async function deleteAgent(agentId) {
471
+ debugMessage(`AgentOps.deleteAgent: start`);
472
+ const agents = await findAgentById(agentId);
473
+ if (agents.length) {
474
+ for (const agent of agents) {
475
+ debugMessage(`AgentOps.deleteAgent: '${agent['_id']}'`);
476
+ await deleteAgentByTypeAndId(agent['_type'], agent['_id']);
477
+ }
478
+ } else {
479
+ throw new Error(`Agent '${agentId}' not found!`);
480
+ }
481
+ debugMessage(`AgentOps.deleteAgent: end`);
482
+ }
483
+
484
+ /**
485
+ * Delete all identity gateway agents
486
+ */
487
+ export async function deleteIdentityGatewayAgents() {
488
+ debugMessage(`AgentOps.deleteIdentityGatewayAgents: start`);
489
+ const agents = await getIdentityGatewayAgents();
490
+ for (const agent of agents) {
491
+ debugMessage(`AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`);
492
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
493
+ }
494
+ debugMessage(`AgentOps.deleteIdentityGatewayAgents: end`);
495
+ }
496
+
497
+ /**
498
+ * Delete identity gateway agent
499
+ * @param agentId agent id/name
500
+ */
501
+ export async function deleteIdentityGatewayAgent(agentId) {
502
+ debugMessage(`AgentOps.deleteIdentityGatewayAgent: start`);
503
+ const agents = await findAgentByTypeAndId(AGENT_TYPE_IG, agentId);
504
+ if (agents.length) {
505
+ for (const agent of agents) {
506
+ debugMessage(`AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`);
507
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
508
+ }
509
+ } else {
510
+ throw new Error(`Identity gateway agent '${agentId}' not found!`);
511
+ }
512
+ debugMessage(`AgentOps.deleteIdentityGatewayAgent: end`);
513
+ }
514
+
515
+ /**
516
+ * Delete all java agents
517
+ */
518
+ export async function deleteJavaAgents() {
519
+ debugMessage(`AgentOps.deleteJavaAgents: start`);
520
+ const agents = await getJavaAgents();
521
+ for (const agent of agents) {
522
+ debugMessage(`AgentOps.deleteJavaAgent: '${agent['_id']}'`);
523
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
524
+ }
525
+ debugMessage(`AgentOps.deleteJavaAgents: end`);
526
+ }
527
+
528
+ /**
529
+ * Delete java agent
530
+ * @param agentId agent id/name
531
+ */
532
+ export async function deleteJavaAgent(agentId) {
533
+ debugMessage(`AgentOps.deleteJavaAgent: start`);
534
+ const agents = await findAgentByTypeAndId(AGENT_TYPE_JAVA, agentId);
535
+ if (agents.length) {
536
+ for (const agent of agents) {
537
+ debugMessage(`AgentOps.deleteJavaAgent: '${agent['_id']}'`);
538
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
539
+ }
540
+ } else {
541
+ throw new Error(`Java agent '${agentId}' not found!`);
542
+ }
543
+ debugMessage(`AgentOps.deleteJavaAgent: end`);
544
+ }
545
+
546
+ /**
547
+ * Delete all web agents
548
+ */
549
+ export async function deleteWebAgents() {
550
+ debugMessage(`AgentOps.deleteWebAgents: start`);
551
+ const agents = await getWebAgents();
552
+ for (const agent of agents) {
553
+ debugMessage(`AgentOps.deleteWebAgent: '${agent['_id']}'`);
554
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
555
+ }
556
+ debugMessage(`AgentOps.deleteWebAgents: end`);
557
+ }
558
+
559
+ /**
560
+ * Delete web agent
561
+ * @param agentId agent id/name
562
+ */
563
+ export async function deleteWebAgent(agentId) {
564
+ debugMessage(`AgentOps.deleteWebAgent: start`);
565
+ const agents = await findAgentByTypeAndId(AGENT_TYPE_WEB, agentId);
566
+ if (agents.length) {
567
+ for (const agent of agents) {
568
+ debugMessage(`AgentOps.deleteWebAgent: '${agent['_id']}'`);
569
+ await deleteAgentByTypeAndId(agent['_type']['_id'], agent['_id']);
570
+ }
571
+ } else {
572
+ throw new Error(`Web agent '${agentId}' not found!`);
573
+ }
574
+ debugMessage(`AgentOps.deleteWebAgent: end`);
575
+ }
576
+ //# sourceMappingURL=AgentOps.js.map