@itentialopensource/adapter-db_oracle 0.3.9 → 0.4.0

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 CHANGED
@@ -9,6 +9,7 @@ module.exports = {
9
9
  'json'
10
10
  ],
11
11
  parserOptions: {
12
+ ecmaVersion: 2020,
12
13
  sourceType: 'module'
13
14
  },
14
15
  rules: {
package/AUTH.md CHANGED
@@ -1,13 +1,13 @@
1
1
  ## Authenticating Oracle SQL Adapter
2
2
 
3
- This document will go through the steps for authenticating the Oracle SQL adapter with. Properly configuring the properties for an adapter in IAP is critical for getting the adapter online. You can read more about adapter authentication <a href="https://docs.itential.com/opensource/docs/authentication" target="_blank">HERE</a>.
3
+ This document will go through the steps for authenticating the Oracle SQL adapter with. Properly configuring the properties for an adapter in Itential Platform is critical for getting the adapter online. You can read more about adapter authentication <a href="https://docs.itential.com/opensource/docs/authentication" target="_blank">HERE</a>.
4
4
 
5
5
  ### Database Library Authentication
6
6
  The Oracle SQL adapter requires Database Library Authentication. If you change authentication methods, you should change this section accordingly and merge it back into the adapter repository.
7
7
 
8
8
  STEPS
9
9
  1. Ensure you have access to a Oracle SQL server and that it is running
10
- 2. Follow the steps in the README.md to import the adapter into IAP if you have not already done so
10
+ 2. Follow the steps in the README.md to import the adapter into Itential Platform if you have not already done so
11
11
  3. Use the properties below for the ```properties.authentication``` field
12
12
  ```json
13
13
  "authentication": {
@@ -19,6 +19,6 @@ STEPS
19
19
 
20
20
  ### Troubleshooting
21
21
  - Make sure you copied over the correct username and password.
22
- - Turn on debug level logs for the adapter in IAP Admin Essentials.
22
+ - Turn on debug level logs for the adapter in Itential Platform Admin Essentials.
23
23
  - Investigate the logs
24
24
  - Credentials should be ** masked ** by the adapter so make sure you verify the username and password - including that there are erroneous spaces at the front or end.
package/CALLS.md CHANGED
@@ -4,7 +4,7 @@ The `adapter.js` file contains the calls the adapter makes available to the rest
4
4
 
5
5
  ### Generic Adapter Calls
6
6
 
7
- These are adapter methods that IAP or you might use. There are some other methods not shown here that might be used for internal adapter functionality.
7
+ These are adapter methods that Itential Platform or you might use. There are some other methods not shown here that might be used for internal adapter functionality.
8
8
 
9
9
  <table border="1" class="bordered-table">
10
10
  <tr>
package/ENHANCE.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  ### Adding a Second Instance of an Adapter
4
4
 
5
- You can add a second instance of this adapter without adding new code on the file system. To do this go into the IAP Admin Essentials and add a new service config for this adapter. The two instances of the adapter should have unique ids. In addition, they should point to different instances (unique host and port) of the other system.
5
+ You can add a second instance of this adapter without adding new code on the file system. To do this go into the Itential Platform Admin Essentials and add a new service config for this adapter. The two instances of the adapter should have unique ids. In addition, they should point to different instances (unique host and port) of the other system.
6
6
 
7
7
  ### Adding Adapter Properties
8
8
 
9
- While changing adapter properties is done in the service instance configuration section of IAP, adding properties has to be done in the adapter. To add a property you should edit the propertiesSchema.json with the proper information for the property. In addition, you should modify the sampleProperties to have the new property in it.
9
+ While changing adapter properties is done in the service instance configuration section of Itential Platform, adding properties has to be done in the adapter. To add a property you should edit the propertiesSchema.json with the proper information for the property. In addition, you should modify the sampleProperties to have the new property in it.
10
10
 
11
11
  ```text
12
12
  Files to update
package/PROPERTIES.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Configuration
2
2
 
3
- This section defines **all** the properties that are available for the adapter, including detailed information on what each property is for. If you are not using certain capabilities with this adapter, you do not need to define all of the properties. An example of how the properties for this adapter can be used with tests or IAP are provided in the sampleProperties.
3
+ This section defines **all** the properties that are available for the adapter, including detailed information on what each property is for. If you are not using certain capabilities with this adapter, you do not need to define all of the properties. An example of how the properties for this adapter can be used with tests or Itential Platform are provided in the sampleProperties.
4
4
 
5
5
  ```json
6
6
  {
@@ -28,7 +28,7 @@ This section defines **all** the properties that are available for the adapter,
28
28
 
29
29
  ### Connection Properties
30
30
 
31
- These base properties are used to connect to MicrosoftSQL upon the adapter initially coming up. It is important to set these properties appropriately.
31
+ These base properties are used to connect to Oracle upon the adapter initially coming up. It is important to set these properties appropriately.
32
32
 
33
33
  <table border="1" class="bordered-table">
34
34
  <tr>
@@ -54,13 +54,13 @@ These base properties are used to connect to MicrosoftSQL upon the adapter initi
54
54
  </table>
55
55
  <br>
56
56
 
57
- A connectivity check tells IAP the adapter has loaded successfully.
57
+ A connectivity check tells Itential Platform the adapter has loaded successfully.
58
58
 
59
59
  ### Authentication Properties
60
60
 
61
- The following properties are used to define the authentication process to MicrosoftSQL.
61
+ The following properties are used to define the authentication process to Oracle.
62
62
 
63
- >**Note**: Depending on the method that is used to authenticate with MicrosoftSQL, you may not need to set all of the authentication properties.
63
+ >**Note**: Depending on the method that is used to authenticate with Oracle, you may not need to set all of the authentication properties.
64
64
 
65
65
  <table border="1" class="bordered-table">
66
66
  <tr>
@@ -73,11 +73,11 @@ The following properties are used to define the authentication process to Micros
73
73
  </tr>
74
74
  <tr>
75
75
  <td style="padding:15px">username</td>
76
- <td style="padding:15px">Used to authenticate with MicrosoftSQL on every request or when pulling a token that will be used in subsequent requests.</td>
76
+ <td style="padding:15px">Used to authenticate with Oracle on every request or when pulling a token that will be used in subsequent requests.</td>
77
77
  </tr>
78
78
  <tr>
79
79
  <td style="padding:15px">password</td>
80
- <td style="padding:15px">Used to authenticate with MicrosoftSQL on every request or when pulling a token that will be used in subsequent requests.</td>
80
+ <td style="padding:15px">Used to authenticate with Oracle on every request or when pulling a token that will be used in subsequent requests.</td>
81
81
  </tr>
82
82
  <tr>
83
83
  <td style="padding:15px">domain</td>
@@ -88,7 +88,7 @@ The following properties are used to define the authentication process to Micros
88
88
 
89
89
  ### SSL Properties
90
90
 
91
- The SSL section defines the properties utilized for ssl authentication with MicrosoftSQL. SSL can work two different ways: set the `accept\_invalid\_certs` flag to true (only recommended for lab environments), or provide a `ca\_file`.
91
+ The SSL section defines the properties utilized for ssl authentication with Oracle. SSL can work two different ways: set the `accept\_invalid\_certs` flag to true (only recommended for lab environments), or provide a `ca\_file`.
92
92
 
93
93
  <table border="1" class="bordered-table">
94
94
  <tr>
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Oracle Adapter
2
2
  ===========
3
3
 
4
- This adapter allows interaction with a Oracle server. For efficiency, this adapter should only be used in IAP workflow calls. Calling the adapter from Applications instead of using the npm oracledb pacakges will be less efficient!
4
+ This adapter allows interaction with a Oracle server. For efficiency, this adapter should only be used in Itential Platform workflow calls. Calling the adapter from Applications instead of using the npm oracledb pacakges will be less efficient!
5
5
 
6
6
  License & Maintainers
7
7
  ---
package/SUMMARY.md CHANGED
@@ -1,9 +1,9 @@
1
1
  ## Overview
2
2
 
3
- This adapter is used to integrate the Itential Automation Platform (IAP) with the Oracle System. The API that was used to build the adapter for Oracle is usually available in the report directory of this adapter. The adapter utilizes the Oracle API to provide the integrations that are deemed pertinent to IAP. The ReadMe file is intended to provide information on this adapter it is generated from various other Markdown files.
3
+ This adapter is used to integrate the Itential Platform with the Oracle System. The API that was used to build the adapter for Oracle is usually available in the report directory of this adapter. The adapter utilizes the Oracle API to provide the integrations that are deemed pertinent to Itential Platform. The ReadMe file is intended to provide information on this adapter it is generated from various other Markdown files.
4
4
 
5
5
  >**Note**: It is possible that some integrations will be supported through the Oracle adapter while other integrations will not. If you need additional API calls, you can use the Update capabilities provided by the Adapter Builder or request Itential to add them if the Adapter is an Itential opensourced adapter.
6
6
 
7
7
  Itential provides information on all of its product adapters in the Customer Knowledge Base. Information in the <a href="https://itential.atlassian.net/servicedesk/customer/portals" target="_blank">Customer Knowledge Base</a> is consistently maintained and goes through documentation reviews. As a result, it should be the first place to go for information.
8
8
 
9
- For opensourced and custom built adapters, the ReadMe is a starting point to understand what you have built, provide the information for you to be able to update the adapter, and assist you with deploying the adapter into IAP.
9
+ For opensourced and custom built adapters, the ReadMe is a starting point to understand what you have built, provide the information for you to be able to update the adapter, and assist you with deploying the adapter into Itential Platform.
package/SYSTEMINFO.md CHANGED
@@ -15,7 +15,7 @@ We classify Oracle Database into the Data Storage domaina as Oracle Database is
15
15
  "Lower operational costs with a resource-efficient relational database server"
16
16
 
17
17
  ## Why Integrate
18
- The Oracle Database adapter from Itential is used to integrate the Itential Automation Platform (IAP) with Oracle Database. With this adapter you have the ability to perform operations with Oracle Database on items such as:
18
+ The Oracle Database adapter from Itential is used to integrate the Itential Platform with Oracle Database. With this adapter you have the ability to perform operations with Oracle Database on items such as:
19
19
 
20
20
  - Storage of Information
21
21
  - Retrieval of Information
package/TAB1.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Overview
2
2
 
3
- This adapter is used to integrate the Itential Automation Platform (IAP) with the Oracle System. The API that was used to build the adapter for Oracle is usually available in the report directory of this adapter. The adapter utilizes the Oracle API to provide the integrations that are deemed pertinent to IAP. The ReadMe file is intended to provide information on this adapter it is generated from various other Markdown files.
3
+ This adapter is used to integrate the Itential Platform with the Oracle System. The API that was used to build the adapter for Oracle is usually available in the report directory of this adapter. The adapter utilizes the Oracle API to provide the integrations that are deemed pertinent to Itential Platform. The ReadMe file is intended to provide information on this adapter it is generated from various other Markdown files.
4
4
 
5
5
  ## Details
6
- The Oracle Database adapter from Itential is used to integrate the Itential Automation Platform (IAP) with Oracle Database. With this adapter you have the ability to perform operations with Oracle Database on items such as:
6
+ The Oracle Database adapter from Itential is used to integrate the Itential Platform with Oracle Database. With this adapter you have the ability to perform operations with Oracle Database on items such as:
7
7
 
8
8
  - Storage of Information
9
9
  - Retrieval of Information
package/TAB2.md CHANGED
@@ -11,14 +11,14 @@
11
11
  ## Specific Adapter Information
12
12
  ### Authentication
13
13
 
14
- This document will go through the steps for authenticating the Oracle SQL adapter with. Properly configuring the properties for an adapter in IAP is critical for getting the adapter online. You can read more about adapter authentication <a href="https://docs.itential.com/opensource/docs/authentication" target="_blank">HERE</a>.
14
+ This document will go through the steps for authenticating the Oracle SQL adapter with. Properly configuring the properties for an adapter in Itential Platform is critical for getting the adapter online. You can read more about adapter authentication <a href="https://docs.itential.com/opensource/docs/authentication" target="_blank">HERE</a>.
15
15
 
16
16
  #### Database Library Authentication
17
17
  The Oracle SQL adapter requires Database Library Authentication. If you change authentication methods, you should change this section accordingly and merge it back into the adapter repository.
18
18
 
19
19
  STEPS
20
20
  1. Ensure you have access to a Oracle SQL server and that it is running
21
- 2. Follow the steps in the README.md to import the adapter into IAP if you have not already done so
21
+ 2. Follow the steps in the README.md to import the adapter into Itential Platform if you have not already done so
22
22
  3. Use the properties below for the ```properties.authentication``` field
23
23
  ```json
24
24
  "authentication": {
@@ -30,12 +30,12 @@ STEPS
30
30
 
31
31
  #### Troubleshooting
32
32
  - Make sure you copied over the correct username and password.
33
- - Turn on debug level logs for the adapter in IAP Admin Essentials.
33
+ - Turn on debug level logs for the adapter in Itential Platform Admin Essentials.
34
34
  - Investigate the logs
35
35
  - Credentials should be ** masked ** by the adapter so make sure you verify the username and password - including that there are erroneous spaces at the front or end.
36
36
  ### Sample Properties
37
37
 
38
- Sample Properties can be used to help you configure the adapter in the Itential Automation Platform. You will need to update connectivity information such as the host, port, protocol and credentials.
38
+ Sample Properties can be used to help you configure the adapter in the Itential Platform. You will need to update connectivity information such as the host, port, protocol and credentials.
39
39
 
40
40
  ```json
41
41
  "properties": {
package/TROUBLESHOOT.md CHANGED
@@ -8,18 +8,18 @@
8
8
  Go into the Itential Platform GUI and verify/update the properties
9
9
  ```
10
10
 
11
- 2. Verify there is connectivity between the Itential Platform Server and MicrosoftSQL Server.
11
+ 2. Verify there is connectivity between the Itential Platform Server and Oracle Server.
12
12
 
13
13
  ```text
14
- ping the ip address of MicrosoftSQL server
15
- try telnet to the ip address port of MicrosoftSQL
14
+ ping the ip address of Oracle server
15
+ try telnet to the ip address port of Oracle
16
16
  execute a curl command to the other system
17
17
  ```
18
18
 
19
- 3. Verify the credentials provided for MicrosoftSQL.
19
+ 3. Verify the credentials provided for Oracle.
20
20
 
21
21
  ```text
22
- login to MicrosoftSQL using the provided credentials
22
+ login to Oracle using the provided credentials
23
23
  ```
24
24
 
25
25
 
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-db_oracle",
3
- "version": "0.3.9",
3
+ "version": "0.4.0",
4
4
  "description": "Itential adapter to connect to oracle",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.44.7",
7
- "engineVersion": "1.67.14",
7
+ "engineVersion": "1.69.14",
8
8
  "adapterType": "http",
9
9
  "scripts": {
10
- "artifactize": "npm i && node utils/packModificationScript.js",
11
10
  "preinstall": "node utils/setup.js",
12
11
  "deinstall": "node utils/removeHooks.js",
13
12
  "lint": "node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js",
@@ -20,10 +19,9 @@
20
19
  },
21
20
  "keywords": [
22
21
  "Itential",
23
- "IAP",
22
+ "Itential Platform",
24
23
  "Automation",
25
24
  "Integration",
26
- "App-Artifacts",
27
25
  "Adapter",
28
26
  "Persistence",
29
27
  "Oracle",
@@ -41,21 +39,21 @@
41
39
  "author": "Itential",
42
40
  "homepage": "https://gitlab.com/itentialopensource/adapters/adapter-db_oracle#readme",
43
41
  "dependencies": {
44
- "ajv": "^8.17.1",
45
- "fs-extra": "^11.2.0",
42
+ "ajv": "8.17.1",
43
+ "fs-extra": "11.3.0",
46
44
  "oracledb": "6.6.0",
47
- "readline-sync": "^1.4.10",
48
- "uuid": "^3.1.0"
45
+ "readline-sync": "1.4.10",
46
+ "uuid": "3.1.0",
47
+ "mocha": "10.8.2",
48
+ "winston": "3.17.0"
49
49
  },
50
50
  "devDependencies": {
51
- "chai": "^4.3.7",
52
- "eslint": "^8.44.0",
53
- "eslint-config-airbnb-base": "^15.0.0",
54
- "eslint-plugin-import": "^2.27.5",
55
- "eslint-plugin-json": "^3.1.0",
56
- "mocha": "^10.7.0",
57
- "testdouble": "^3.18.0",
58
- "winston": "^3.13.1"
51
+ "chai": "4.5.0",
52
+ "eslint": "8.57.0",
53
+ "eslint-config-airbnb-base": "15.0.0",
54
+ "eslint-plugin-import": "2.31.0",
55
+ "eslint-plugin-json": "3.1.0",
56
+ "testdouble": "^3.18.0"
59
57
  },
60
58
  "private": false
61
59
  }
@@ -13,9 +13,9 @@ const path = require('path');
13
13
  const winston = require('winston');
14
14
  const { expect } = require('chai');
15
15
  const { use } = require('chai');
16
+ const log = require('../../utils/logger');
16
17
 
17
18
  // stub and attemptTimeout are used throughout the code so set them here
18
- let logLevel = 'none';
19
19
  const stub = true;
20
20
  const isRapidFail = false;
21
21
  const isSaveMockData = false;
@@ -64,43 +64,6 @@ global.pronghornProps = {
64
64
 
65
65
  global.$HOME = `${__dirname}/../..`;
66
66
 
67
- // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
68
- // this you may error on log.trace calls.
69
- const myCustomLevels = {
70
- levels: {
71
- spam: 6,
72
- trace: 5,
73
- debug: 4,
74
- info: 3,
75
- warn: 2,
76
- error: 1,
77
- none: 0
78
- }
79
- };
80
-
81
- // need to see if there is a log level passed in
82
- process.argv.forEach((val) => {
83
- // is there a log level defined to be passed in?
84
- if (val.indexOf('--LOG') === 0) {
85
- // get the desired log level
86
- const inputVal = val.split('=')[1];
87
-
88
- // validate the log level is supported, if so set it
89
- if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
90
- logLevel = inputVal;
91
- }
92
- }
93
- });
94
-
95
- // need to set global logging
96
- global.log = winston.createLogger({
97
- level: logLevel,
98
- levels: myCustomLevels.levels,
99
- transports: [
100
- new winston.transports.Console()
101
- ]
102
- });
103
-
104
67
  /**
105
68
  * Runs the common asserts for test
106
69
  */
@@ -17,12 +17,12 @@ const { expect } = require('chai');
17
17
  const { use } = require('chai');
18
18
  const td = require('testdouble');
19
19
  const Ajv = require('ajv');
20
+ const log = require('../../utils/logger');
20
21
 
21
22
  const ajv = new Ajv({ strictSchema: false, allErrors: true, allowUnionTypes: true });
22
23
  const anything = td.matchers.anything();
23
24
 
24
25
  // stub and attemptTimeout are used throughout the code so set them here
25
- let logLevel = 'none';
26
26
  const stub = true;
27
27
  const isRapidFail = false;
28
28
  const attemptTimeout = 120000;
@@ -70,43 +70,6 @@ global.pronghornProps = {
70
70
 
71
71
  global.$HOME = `${__dirname}/../..`;
72
72
 
73
- // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
74
- // this you may error on log.trace calls.
75
- const myCustomLevels = {
76
- levels: {
77
- spam: 6,
78
- trace: 5,
79
- debug: 4,
80
- info: 3,
81
- warn: 2,
82
- error: 1,
83
- none: 0
84
- }
85
- };
86
-
87
- // need to see if there is a log level passed in
88
- process.argv.forEach((val) => {
89
- // is there a log level defined to be passed in?
90
- if (val.indexOf('--LOG') === 0) {
91
- // get the desired log level
92
- const inputVal = val.split('=')[1];
93
-
94
- // validate the log level is supported, if so set it
95
- if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
96
- logLevel = inputVal;
97
- }
98
- }
99
- });
100
-
101
- // need to set global logging
102
- global.log = winston.createLogger({
103
- level: logLevel,
104
- levels: myCustomLevels.levels,
105
- transports: [
106
- new winston.transports.Console()
107
- ]
108
- });
109
-
110
73
  /**
111
74
  * Runs the error asserts for the test
112
75
  */
@@ -1,20 +1,94 @@
1
1
  #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
2
+ /* @copyright Itential, LLC 2025 */
3
+
3
4
  /* eslint global-require:warn */
4
5
  /* eslint import/no-dynamic-require:warn */
5
6
  /* eslint prefer-destructuring:warn */
6
7
 
8
+ /**
9
+ * This script will determine the information about the adapter and store
10
+ * it into a file in the adapter. This is self contained and only depends on
11
+ * finding files within the adapter to gather information.
12
+ *
13
+ * This utility is used when adapters are committed and pushed. It is not used by
14
+ * any customers nor is it references in any scripts.
15
+ */
16
+
7
17
  const path = require('path');
8
18
  const fs = require('fs-extra');
9
19
 
10
20
  /**
11
- * This script will determine the information about the adapter and store
12
- * it into a file in the adapter.
21
+ * @summary Count the number of lines in a file
22
+ * @param {string} filePath - The path to the file
23
+ * @returns {number} The total number of lines in the file
24
+ */
25
+ function countLinesInFile(filePath) {
26
+ if (fs.existsSync(filePath)) {
27
+ const cFile = fs.readFileSync(filePath, 'utf8');
28
+ return cFile.split('\n').length;
29
+ }
30
+ console.log(`Missing - ${path.basename(filePath)}`);
31
+ return 0;
32
+ }
33
+
34
+ /**
35
+ * @summary Count the number of lines across multiple files
36
+ * @param {array} filePaths - An array of file paths
37
+ * @returns {number} The total number of lines across all files
38
+ */
39
+ function countLinesInFiles(filePaths) {
40
+ return filePaths.reduce((total, filePath) => total + countLinesInFile(filePath), 0);
41
+ }
42
+
43
+ /**
44
+ * @summary Count the number of lines in all json files within an entity directory
45
+ * @param {string} entityDir - The entity directory
46
+ * @returns {number} The total number of lines across all JSON files in the entity directory
47
+ */
48
+ function countEntityLines(entityDir) {
49
+ let totalLines = 0;
50
+
51
+ if (!fs.existsSync(entityDir)) {
52
+ console.log('Could not find the entities directory');
53
+ return totalLines;
54
+ }
55
+ const entities = fs.readdirSync(entityDir);
56
+ for (let e = 0; e < entities.length; e += 1) {
57
+ const entityPath = path.join(entityDir, entities[e]);
58
+ if (fs.statSync(entityPath).isDirectory()) {
59
+ const jsonFiles = fs.readdirSync(entityPath).filter((f) => f.endsWith('.json'));
60
+ for (let j = 0; j < jsonFiles.length; j += 1) {
61
+ totalLines += countLinesInFile(path.join(entityPath, jsonFiles[j]));
62
+ }
63
+ }
64
+ }
65
+ return totalLines;
66
+ }
67
+
68
+ /**
69
+ * @summary Count the number of test cases in a file
70
+ * @param {string} filePath - The path to the test file
71
+ * @returns {number} The total number of test cases in the file
13
72
  */
73
+ function countTestsInFile(filePath) {
74
+ if (fs.existsSync(filePath)) {
75
+ const tFile = fs.readFileSync(filePath, 'utf8');
76
+ const ttestCount = tFile.split('it(\'').length;
77
+ return ttestCount;
78
+ }
79
+ console.log(`Missing - ${path.basename(filePath)}`);
80
+ return 0;
81
+ }
14
82
 
15
83
  /**
16
- * get adapter information
84
+ * @summary Count the number of test cases across multiple files
85
+ * @param {array} filePaths - An array of test file paths
86
+ * @returns {number} The total number of test cases across all files
17
87
  */
88
+ function countTestsInFiles(filePaths) {
89
+ return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
90
+ }
91
+
18
92
  function adapterInfo() {
19
93
  // set the base pase of the adapter - tool shoud be one level up in utils
20
94
  let adaptdir = __dirname;
@@ -23,172 +97,43 @@ function adapterInfo() {
23
97
  if (adaptdir.endsWith('/utils')) {
24
98
  adaptdir = adaptdir.substring(0, adaptdir.length - 6);
25
99
  }
100
+
101
+ // if no package.json then not in right place - end with error
102
+ if (!fs.existsSync(`${adaptdir}/package.json`)) {
103
+ throw new Error('Missing - package.json');
104
+ }
26
105
  const pack = require(`${adaptdir}/package.json`);
27
106
  infoRes.version = pack.version;
28
107
 
29
108
  let configCount = 0;
30
- if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
31
- const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
32
- configCount += cFile.split('\n').length;
33
- } else {
34
- console.log('Missing - pronghorn.json');
35
- }
36
- if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
37
- const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
38
- configCount += cFile.split('\n').length;
39
- } else {
40
- console.log('Missing - propertiesSchema.json');
41
- }
42
- if (fs.existsSync(`${adaptdir}/error.json`)) {
43
- const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
44
- configCount += cFile.split('\n').length;
45
- } else {
46
- console.log('Missing - error.json');
47
- }
48
- const entitydir = path.join(adaptdir, '/entities');
49
- if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
50
- const entities = fs.readdirSync(entitydir);
51
- // need to go through each entity in the entities directory
52
- for (let e = 0; e < entities.length; e += 1) {
53
- if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
54
- const cfiles = fs.readdirSync(entitydir);
55
- for (let c = 0; c < cfiles.length; c += 1) {
56
- if (cfiles[c].endsWith('.json')) {
57
- const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
58
- configCount += ccFile.split('\n').length;
59
- }
60
- }
61
- }
62
- }
63
- } else {
64
- console.log('Could not find the entities directory');
65
- }
109
+ const configFiles = ['pronghorn.json', 'propertiesSchema.json', 'error.json'].map((f) => path.join(adaptdir, f));
110
+ configCount = countLinesInFiles(configFiles);
111
+
112
+ const entityDir = path.join(adaptdir, '/entities');
113
+ configCount += countEntityLines(entityDir);
114
+
66
115
  infoRes.configLines = configCount;
67
116
 
68
- let scodeCount = 0;
69
- if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
70
- const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
71
- scodeCount += sFile.split('\n').length;
72
- } else {
73
- console.log('Missing - utils/artifactize.js');
74
- }
75
- if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
76
- const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
77
- scodeCount += sFile.split('\n').length;
78
- } else {
79
- console.log('Missing - utils/basicGet.js');
80
- }
81
- if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
82
- const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
83
- scodeCount += sFile.split('\n').length;
84
- } else {
85
- console.log('Missing - utils/checkMigrate.js');
86
- }
87
- if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
88
- const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
89
- scodeCount += sFile.split('\n').length;
90
- } else {
91
- console.log('Missing - utils/findPath.js');
92
- }
93
- if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
94
- const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
95
- scodeCount += sFile.split('\n').length;
96
- } else {
97
- console.log('Missing - utils/modify.js');
98
- }
99
- if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
100
- const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
101
- scodeCount += sFile.split('\n').length;
102
- } else {
103
- console.log('Missing - utils/packModificationScript.js');
104
- }
105
- if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
106
- const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
107
- scodeCount += sFile.split('\n').length;
108
- } else {
109
- console.log('Missing - utils/setup.js');
110
- }
111
- if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
112
- const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
113
- scodeCount += sFile.split('\n').length;
114
- } else {
115
- console.log('Missing - utils/tbScript.js');
116
- }
117
- if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
118
- const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
119
- scodeCount += sFile.split('\n').length;
120
- } else {
121
- console.log('Missing - utils/tbUtils.js');
122
- }
123
- if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
124
- const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
125
- scodeCount += sFile.split('\n').length;
126
- } else {
127
- console.log('Missing - utils/testRunner.js');
128
- }
129
- if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
130
- const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
131
- scodeCount += sFile.split('\n').length;
132
- } else {
133
- console.log('Missing - utils/troubleshootingAdapter.js');
134
- }
135
- infoRes.scriptLines = scodeCount;
117
+ const utilFiles = ['argParser', 'checkMigrate.js', 'entitiesToDB.js', 'findPath.js', 'logger.js', 'methodDocumentor.js', 'modify.js', 'mongoDbConnection.js',
118
+ 'mongoUtils.js', 'setup.js', 'taskMover.js', 'tbScript.js', 'tbUtils.js', 'testRunner.js', 'troubleshootingAdapter.js', 'updateAdapterConfig.js'
119
+ ].map((f) => path.join(adaptdir, 'utils', f));
136
120
 
137
- let codeCount = 0;
138
- if (fs.existsSync(`${adaptdir}/adapter.js`)) {
139
- const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
140
- codeCount += aFile.split('\n').length;
141
- } else {
142
- console.log('Missing - utils/adapter.js');
143
- }
144
- if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
145
- const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
146
- codeCount += aFile.split('\n').length;
147
- } else {
148
- console.log('Missing - utils/adapterBase.js');
149
- }
150
- infoRes.codeLines = codeCount;
151
-
152
- let tcodeCount = 0;
153
- let ttestCount = 0;
154
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
155
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
156
- tcodeCount += tFile.split('\n').length;
157
- ttestCount += tFile.split('it(\'').length;
158
- } else {
159
- console.log('Missing - test/integration/adapterTestBasicGet.js');
160
- }
161
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
162
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
163
- tcodeCount += tFile.split('\n').length;
164
- ttestCount += tFile.split('it(\'').length;
165
- } else {
166
- console.log('Missing - test/integration/adapterTestConnectivity.js');
167
- }
168
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
169
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
170
- tcodeCount += tFile.split('\n').length;
171
- ttestCount += tFile.split('it(\'').length;
172
- } else {
173
- console.log('Missing - test/integration/adapterTestIntegration.js');
174
- }
175
- if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
176
- const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
177
- tcodeCount += tFile.split('\n').length;
178
- ttestCount += tFile.split('it(\'').length;
179
- } else {
180
- console.log('Missing - test/unit/adapterBaseTestUnit.js');
181
- }
182
- if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
183
- const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
184
- tcodeCount += tFile.split('\n').length;
185
- ttestCount += tFile.split('it(\'').length;
186
- } else {
187
- console.log('Missing - test/unit/adapterTestUnit.js');
188
- }
189
- infoRes.testLines = tcodeCount;
190
- infoRes.testCases = ttestCount;
191
- infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
121
+ infoRes.scriptLines = countLinesInFiles(utilFiles);
122
+
123
+ const adapterFiles = ['adapter.js', 'adapterBase.js'].map((f) => path.join(adaptdir, f));
124
+ infoRes.codeLines = countLinesInFiles(adapterFiles);
125
+
126
+ const testFiles = [
127
+ 'test/integration/adapterTestBasicGet.js',
128
+ 'test/integration/adapterTestConnectivity.js',
129
+ 'test/integration/adapterTestIntegration.js',
130
+ 'test/unit/adapterBaseTestUnit.js',
131
+ 'test/unit/adapterTestUnit.js'
132
+ ].map((f) => path.join(adaptdir, f));
133
+ infoRes.testLines = countLinesInFiles(testFiles);
134
+ infoRes.testCases = countTestsInFiles(testFiles);
135
+
136
+ infoRes.totalCodeLines = infoRes.scriptLines + infoRes.codeLines + infoRes.testLines;
192
137
 
193
138
  if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
194
139
  // Read the entity schema from the file system
@@ -203,4 +148,9 @@ function adapterInfo() {
203
148
  fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
204
149
  }
205
150
 
206
- adapterInfo();
151
+ try {
152
+ adapterInfo();
153
+ } catch (err) {
154
+ console.error(err.message);
155
+ process.exit();
156
+ }
@@ -0,0 +1,44 @@
1
+ const customLevels = {
2
+ spam: 6,
3
+ trace: 5,
4
+ debug: 4,
5
+ info: 3,
6
+ warn: 2,
7
+ error: 1,
8
+ none: 0
9
+ };
10
+
11
+ function parseArgs(argv = process.argv) {
12
+ let properties = null;
13
+ let logLevel = 'none';
14
+ let maxCalls = 5;
15
+ let host = null;
16
+
17
+ argv.forEach((val) => {
18
+ if (val.startsWith('--PROPS=')) {
19
+ // get the properties
20
+ const inputVal = val.split('=')[1];
21
+ properties = JSON.parse(inputVal);
22
+ } else if (val.startsWith('--LOG=')) {
23
+ // get the desired log level
24
+ const level = val.split('=')[1];
25
+ // validate the log level is supported, if so set it
26
+ if (Object.hasOwnProperty.call(customLevels, level)) {
27
+ logLevel = level;
28
+ }
29
+ } else if (val.startsWith('--MAXCALLS=')) {
30
+ const override = parseInt(val.split('=')[1], 10);
31
+ if (!Number.isNaN(override) && override > 0) {
32
+ maxCalls = override;
33
+ }
34
+ } else if (val.startsWith('--HOST=')) {
35
+ [, host] = val.split('=');
36
+ }
37
+ });
38
+
39
+ return {
40
+ properties, logLevel, maxCalls, host
41
+ };
42
+ }
43
+
44
+ module.exports = { parseArgs };
@@ -0,0 +1,26 @@
1
+ // utils/logger.js
2
+ const winston = require('winston');
3
+ const { parseArgs } = require('./argParser');
4
+
5
+ const customLevels = {
6
+ spam: 6,
7
+ trace: 5,
8
+ debug: 4,
9
+ info: 3,
10
+ warn: 2,
11
+ error: 1,
12
+ none: 0
13
+ };
14
+
15
+ // Only set global logger if it doesn't already exist (i.e., not provided by app)
16
+ if (!global.log) {
17
+ const { logLevel = 'info' } = parseArgs();
18
+
19
+ global.log = winston.createLogger({
20
+ level: logLevel,
21
+ levels: customLevels,
22
+ transports: [new winston.transports.Console()]
23
+ });
24
+ }
25
+
26
+ module.exports = global.log;
@@ -1,146 +0,0 @@
1
- #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
3
-
4
- const path = require('path');
5
- const fs = require('fs-extra');
6
-
7
- async function createBundle(adapterOldDir) {
8
- // set directories
9
- const artifactDir = path.join(adapterOldDir, '../artifactTemp');
10
- const workflowsDir = path.join(adapterOldDir, 'workflows');
11
-
12
- // read adapter's package and set names
13
- const adapterPackage = fs.readJSONSync(path.join(adapterOldDir, 'package.json'));
14
- const originalName = adapterPackage.name.substring(adapterPackage.name.lastIndexOf('/') + 1);
15
- const shortenedName = originalName.replace('adapter-', '');
16
- const artifactName = originalName.replace('adapter', 'bundled-adapter');
17
-
18
- const adapterNewDir = path.join(artifactDir, 'bundles', 'adapters', originalName);
19
- fs.ensureDirSync(adapterNewDir);
20
-
21
- const ops = [];
22
-
23
- // copy old adapterDir to bundled hierarchy location
24
- ops.push(() => fs.copySync(adapterOldDir, adapterNewDir));
25
-
26
- // copy readme
27
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'README.md'), path.join(artifactDir, 'README.md')));
28
-
29
- // copy changelog
30
- if (fs.existsSync(path.join(adapterOldDir, 'CHANGELOG.md'))) {
31
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'CHANGELOG.md'), path.join(artifactDir, 'CHANGELOG.md')));
32
- }
33
-
34
- // copy license
35
- if (fs.existsSync(path.join(adapterOldDir, 'LICENSE'))) {
36
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'LICENSE'), path.join(artifactDir, 'LICENSE')));
37
- }
38
-
39
- // create package
40
- const artifactPackage = {
41
- name: artifactName,
42
- version: adapterPackage.version,
43
- description: `A bundled version of the ${originalName} to be used in adapter-artifacts for easy installation`,
44
- scripts: {
45
- test: 'echo "Error: no test specified" && exit 1',
46
- deploy: 'npm publish --registry=http://registry.npmjs.org'
47
- },
48
- keywords: [
49
- 'IAP',
50
- 'artifacts',
51
- 'Itential',
52
- 'Pronghorn',
53
- 'Adapter',
54
- 'Adapter-Artifacts',
55
- shortenedName
56
- ],
57
- author: 'Itential Artifacts',
58
- license: 'Apache-2.0',
59
- repository: adapterPackage.repository,
60
- private: false,
61
- devDependencies: {
62
- r2: '^2.0.1',
63
- ajv: '6.10.0',
64
- 'better-ajv-errors': '^0.6.1',
65
- 'fs-extra': '^7.0.1'
66
- }
67
- };
68
-
69
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'package.json'), artifactPackage, { spaces: 2 }));
70
-
71
- // create manifest
72
- const manifest = {
73
- bundleName: originalName,
74
- version: adapterPackage.version,
75
- fingerprint: 'Some verifiable token',
76
- createdEpoch: '1554836984020',
77
- artifacts: [
78
- {
79
- id: `${shortenedName}-adapter`,
80
- name: `${shortenedName}-adapter`,
81
- type: 'adapter',
82
- location: `/bundles/adapters/${originalName}`,
83
- description: artifactPackage.description,
84
- properties: {
85
- entryPoint: false
86
- }
87
- }
88
- ]
89
- };
90
-
91
- // add workflows into artifact
92
- if (fs.existsSync(workflowsDir)) {
93
- const workflowFileNames = fs.readdirSync(workflowsDir);
94
-
95
- // if folder isnt empty and only file is not readme
96
- if (workflowFileNames.length !== 0 && (!(workflowFileNames.length === 1 && workflowFileNames[0].split('.')[1] === 'md'))) {
97
- // add workflows to correct location in bundle
98
- ops.push(() => fs.copySync(workflowsDir, path.join(artifactDir, 'bundles', 'workflows')));
99
-
100
- // add workflows to manifest
101
- workflowFileNames.forEach((filename) => {
102
- const [filenameNoExt, ext] = filename.split('.');
103
- if (ext === 'json') {
104
- manifest.artifacts.push({
105
- id: `workflow-${filenameNoExt}`,
106
- name: filenameNoExt,
107
- type: 'workflow',
108
- location: `/bundles/workflows/${filename}`,
109
- description: 'Main entry point to artifact',
110
- properties: {
111
- entryPoint: false
112
- }
113
- });
114
- }
115
- });
116
- }
117
- }
118
-
119
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'manifest.json'), manifest, { spaces: 2 }));
120
-
121
- // Run the commands in parallel
122
- try {
123
- await Promise.all(ops.map(async (op) => op()));
124
- } catch (e) {
125
- throw new Error(e);
126
- }
127
-
128
- const pathObj = {
129
- bundlePath: artifactDir,
130
- bundledAdapterPath: path.join(artifactDir, 'bundles', 'adapters', originalName)
131
- };
132
- return pathObj;
133
- }
134
-
135
- async function artifactize(entryPathToAdapter) {
136
- const truePath = path.resolve(entryPathToAdapter);
137
- const packagePath = path.join(truePath, 'package');
138
- // remove adapter from package and move bundle in
139
- const pathObj = await createBundle(packagePath);
140
- const { bundlePath } = pathObj;
141
- fs.removeSync(packagePath);
142
- fs.moveSync(bundlePath, packagePath);
143
- return 'Bundle successfully created and old folder system removed';
144
- }
145
-
146
- module.exports = { createBundle, artifactize };
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
3
-
4
- const path = require('path');
5
- const { spawnSync } = require('child_process');
6
- const fs = require('fs-extra');
7
- const { createBundle } = require('./artifactize');
8
-
9
- const nodeEntryPath = path.resolve('.');
10
- createBundle(nodeEntryPath).then((pathObj) => {
11
- const { bundlePath, bundledAdapterPath } = pathObj;
12
- const npmIgnorePath = path.join(bundledAdapterPath, '.npmignore');
13
- const adapterPackagePath = path.join(bundledAdapterPath, 'package.json');
14
- const artifactPackagePath = path.join(bundlePath, 'package.json');
15
-
16
- // remove node_modules from .npmIgnore so that node_modules are included in the resulting tar from npm pack
17
- let npmIgnoreString;
18
- if (fs.existsSync(npmIgnorePath)) {
19
- npmIgnoreString = fs.readFileSync(npmIgnorePath, 'utf8');
20
- npmIgnoreString = npmIgnoreString.replace('node_modules', '');
21
- npmIgnoreString = npmIgnoreString.replace('\n\n', '\n');
22
- fs.writeFileSync(npmIgnorePath, npmIgnoreString);
23
- }
24
-
25
- // add files to package so that node_modules are included in the resulting tar from npm pack
26
- const adapterPackage = fs.readJSONSync(adapterPackagePath);
27
- adapterPackage.files = ['*'];
28
- fs.writeJSONSync(artifactPackagePath, adapterPackage, { spaces: 2 });
29
- const npmResult = spawnSync('npm', ['pack', '-q', bundlePath], { cwd: path.resolve(bundlePath, '..') });
30
- if (npmResult.status === 0) {
31
- fs.removeSync(bundlePath);
32
- console.log('Bundle folder removed');
33
- }
34
- console.log('Script successful');
35
- });