@itentialopensource/adapter-tufin_secureapp 0.5.8 → 0.6.1
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.
- package/.eslintrc.js +1 -0
- package/AUTH.md +4 -4
- package/BROKER.md +4 -4
- package/CALLS.md +9 -9
- package/ENHANCE.md +3 -3
- package/PROPERTIES.md +24 -9
- package/README.md +25 -24
- package/SUMMARY.md +2 -2
- package/SYSTEMINFO.md +1 -1
- package/TAB1.md +2 -2
- package/TAB2.md +10 -6
- package/TROUBLESHOOT.md +10 -1
- package/UTILITIES.md +473 -0
- package/adapter.js +5 -5
- package/adapterBase.js +52 -16
- package/package.json +24 -28
- package/pronghorn.json +15 -13
- package/propertiesSchema.json +68 -7
- package/report/adapterInfo.json +7 -7
- package/report/updateReport1748556165444.json +120 -0
- package/sampleProperties.json +5 -1
- package/test/integration/adapterTestBasicGet.js +88 -54
- package/test/integration/adapterTestConnectivity.js +15 -16
- package/test/integration/adapterTestIntegration.js +1 -38
- package/test/unit/adapterBaseTestUnit.js +641 -39
- package/test/unit/adapterTestUnit.js +17 -54
- package/utils/adapterInfo.js +114 -164
- package/utils/argParser.js +44 -0
- package/utils/checkMigrate.js +77 -38
- package/utils/entitiesToDB.js +53 -42
- package/utils/logger.js +26 -0
- package/utils/modify.js +56 -55
- package/utils/mongoDbConnection.js +79 -0
- package/utils/mongoUtils.js +162 -0
- package/utils/taskMover.js +31 -32
- package/utils/tbScript.js +36 -172
- package/utils/tbUtils.js +84 -226
- package/utils/troubleshootingAdapter.js +68 -84
- package/utils/updateAdapterConfig.js +158 -0
- package/npm-shrinkwrap.json +0 -11224
- package/package-temp.json +0 -11224
- package/utils/addAuth.js +0 -94
- package/utils/artifactize.js +0 -146
- package/utils/basicGet.js +0 -50
- package/utils/packModificationScript.js +0 -35
- package/utils/patches2bundledDeps.js +0 -90
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2025 */
|
|
2
|
+
|
|
3
|
+
// Set globals
|
|
4
|
+
/* global log */
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
|
9
|
+
const MongoDBConnection = require('./mongoDbConnection');
|
|
10
|
+
|
|
11
|
+
const propUtil = new PropUtilCl();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Updates action configuration in the document
|
|
15
|
+
* @param {Object} doc - Document to update
|
|
16
|
+
* @param {string} action - Action name
|
|
17
|
+
* @param {Object} changes - Changes to apply
|
|
18
|
+
* @returns {Object} Updated document
|
|
19
|
+
*/
|
|
20
|
+
function updateActionConfig(doc, action, changes) {
|
|
21
|
+
const updateDoc = { ...doc };
|
|
22
|
+
if (!updateDoc.actions) updateDoc.actions = [];
|
|
23
|
+
const actionIndex = updateDoc.actions.findIndex((a) => a.name === action);
|
|
24
|
+
if (actionIndex >= 0) {
|
|
25
|
+
updateDoc.actions[actionIndex] = propUtil.mergeProperties(changes, updateDoc.actions[actionIndex]);
|
|
26
|
+
} else {
|
|
27
|
+
updateDoc.actions.push({ name: action, ...changes });
|
|
28
|
+
}
|
|
29
|
+
return updateDoc;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Updates schema configuration in the document
|
|
34
|
+
* @param {Object} doc - Document to update
|
|
35
|
+
* @param {string} configFile - Configuration file name
|
|
36
|
+
* @param {Object} changes - Changes to apply
|
|
37
|
+
* @returns {Object} Updated document
|
|
38
|
+
*/
|
|
39
|
+
function updateSchemaConfig(doc, configFile, changes) {
|
|
40
|
+
const updateDoc = { ...doc };
|
|
41
|
+
if (!updateDoc.schema) updateDoc.schema = [];
|
|
42
|
+
const schemaIndex = updateDoc.schema.findIndex((s) => s.name === configFile);
|
|
43
|
+
if (schemaIndex >= 0) {
|
|
44
|
+
updateDoc.schema[schemaIndex].schema = propUtil.mergeProperties(changes, updateDoc.schema[schemaIndex].schema);
|
|
45
|
+
} else {
|
|
46
|
+
updateDoc.schema.push({ name: configFile, schema: changes });
|
|
47
|
+
}
|
|
48
|
+
return updateDoc;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Updates mock data configuration in the document
|
|
53
|
+
* @param {Object} doc - Document to update
|
|
54
|
+
* @param {string} configFile - Configuration file name
|
|
55
|
+
* @param {Object} changes - Changes to apply
|
|
56
|
+
* @param {boolean} replace - Whether to replace or merge
|
|
57
|
+
* @returns {Object} Updated document
|
|
58
|
+
*/
|
|
59
|
+
function updateMockConfig(doc, configFile, changes, replace) {
|
|
60
|
+
const updateDoc = { ...doc };
|
|
61
|
+
if (!updateDoc.mockdatafiles) updateDoc.mockdatafiles = {};
|
|
62
|
+
updateDoc.mockdatafiles[configFile] = replace ? changes : propUtil.mergeProperties(changes, updateDoc.mockdatafiles[configFile] || {});
|
|
63
|
+
return updateDoc;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Configuration update strategies for different types
|
|
68
|
+
*/
|
|
69
|
+
const updateStrategies = {
|
|
70
|
+
action: (doc, configFile, changes, action) => (!action ? doc : updateActionConfig(doc, action, changes)),
|
|
71
|
+
schema: (doc, configFile, changes) => updateSchemaConfig(doc, configFile, changes),
|
|
72
|
+
mock: (doc, configFile, changes, replace) => updateMockConfig(doc, configFile, changes, replace)
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Updates MongoDB configuration for an adapter entity
|
|
77
|
+
* @param {Object} options - Configuration options
|
|
78
|
+
* @param {string} options.id - Adapter ID
|
|
79
|
+
* @param {Object} options.mongoProps - MongoDB connection properties
|
|
80
|
+
* @param {string} options.entity - Entity name
|
|
81
|
+
* @param {string} options.type - Update type (action/schema/mock)
|
|
82
|
+
* @param {string} options.configFile - Configuration file name
|
|
83
|
+
* @param {Object} options.changes - Changes to apply
|
|
84
|
+
* @param {string} options.action - Action name (for action type updates)
|
|
85
|
+
* @param {boolean} options.replace - Whether to replace or merge (for mock type updates)
|
|
86
|
+
* @returns {Promise<void>}
|
|
87
|
+
*/
|
|
88
|
+
async function updateMongoDBConfig(options) {
|
|
89
|
+
const {
|
|
90
|
+
id,
|
|
91
|
+
mongoProps,
|
|
92
|
+
entity,
|
|
93
|
+
type,
|
|
94
|
+
configFile,
|
|
95
|
+
changes,
|
|
96
|
+
action,
|
|
97
|
+
replace
|
|
98
|
+
} = options;
|
|
99
|
+
|
|
100
|
+
if (!mongoProps) {
|
|
101
|
+
log.error('MongoDB properties not found');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let mongoConnection = null;
|
|
106
|
+
try {
|
|
107
|
+
// Get adapter type from pronghorn.json
|
|
108
|
+
const pronghornPath = path.join(__dirname, '../pronghorn.json');
|
|
109
|
+
const pronghornData = JSON.parse(fs.readFileSync(pronghornPath, 'utf8'));
|
|
110
|
+
const adapterType = pronghornData.id;
|
|
111
|
+
|
|
112
|
+
mongoConnection = new MongoDBConnection(mongoProps);
|
|
113
|
+
await mongoConnection.connect();
|
|
114
|
+
|
|
115
|
+
const collection = mongoConnection.db.collection('adapter_configs');
|
|
116
|
+
const query = {
|
|
117
|
+
id,
|
|
118
|
+
type: adapterType,
|
|
119
|
+
entity
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const existingConfig = await collection.findOne(query);
|
|
123
|
+
if (!existingConfig) {
|
|
124
|
+
log.debug(`No existing configuration found for entity ${entity}`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Update the configuration based on type
|
|
129
|
+
const updateStrategy = updateStrategies[type];
|
|
130
|
+
if (!updateStrategy) {
|
|
131
|
+
log.error(`Unsupported update type: ${type}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const updatedDoc = updateStrategy(existingConfig, configFile, changes, action || replace);
|
|
136
|
+
|
|
137
|
+
// Remove _id from updateDoc as it can't be modified
|
|
138
|
+
const { _id, ...updateDocWithoutId } = updatedDoc;
|
|
139
|
+
const updateResult = await collection.updateOne(
|
|
140
|
+
{ id, type: adapterType, entity },
|
|
141
|
+
{ $set: updateDocWithoutId }
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (updateResult.modifiedCount === 0) {
|
|
145
|
+
log.warn(`No documents were modified for entity ${entity}`);
|
|
146
|
+
}
|
|
147
|
+
log.info(`Successfully updated MongoDB configuration for entity ${entity}`);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
log.error(`Error updating MongoDB configuration: ${error.message}`);
|
|
150
|
+
throw error;
|
|
151
|
+
} finally {
|
|
152
|
+
if (mongoConnection) {
|
|
153
|
+
await mongoConnection.closeConnection();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { updateMongoDBConfig };
|