@itentialopensource/adapter-db_mssql 1.0.6 → 1.1.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,15 @@
1
1
  ## Authenticating Microsoft SQL Adapter
2
2
 
3
- This document will go through the steps for authenticating the Microsoft 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 Microsoft 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
+
5
+ If Itential Platform is running in docker, and MicrosoftSQL server is running in the local machine, host in adapter properties should be 'host.docker.internal' instead of 'localhost' or '127.0.0.1'.
4
6
 
5
7
  ### Database Library Authentication
6
8
  The Microsoft 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
9
 
8
10
  STEPS
9
11
  1. Ensure you have access to a Microsoft 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
12
+ 2. Follow the steps in the README.md to import the adapter into Itential Platform if you have not already done so
11
13
  3. Use the properties below for the ```properties.authentication``` field
12
14
  ```json
13
15
  "authentication": {
@@ -21,6 +23,6 @@ STEPS
21
23
 
22
24
  ### Troubleshooting
23
25
  - Make sure you copied over the correct username and password.
24
- - Turn on debug level logs for the adapter in IAP Admin Essentials.
26
+ - Turn on debug level logs for the adapter in Itential Platform Admin Essentials.
25
27
  - Investigate the logs
26
28
  - 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
  {
@@ -54,7 +54,7 @@ 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
 
package/README.md CHANGED
@@ -1,20 +1,296 @@
1
- MicrosoftSQL Adapter
2
- ===========
1
+ # Adapter for MicrosoftSQL
3
2
 
4
- This adapter allows interaction with a MicrosoftSQL server. For efficiency, this adapter should only be used in IAP workflow calls. Calling the adapter from Applications instead of using the npm mssql pacakge will be less efficient!
3
+ ## Table of Contents
5
4
 
6
- Notes:
7
- 1. If IAP is running in docker, and MicrosoftSQL server is running in the local machine, host in adapter properties should be 'host.docker.internal' instead of 'localhost' or '127.0.0.1'.
5
+ Some of the page links in this document and links to other GitLab files do not work in Confluence however, the information is available in other sections of the Confluence material.
8
6
 
9
- License & Maintainers
10
- ---
7
+ - [Specific to this Adapter](#specific-to-this-adapter)
8
+ - [Authentication](./AUTH.md)
9
+ - [Sample Properties](./sampleProperties.json)
10
+ - [Available Calls](./CALLS.md)
11
+ - [Swagger](./report/adapter-openapi.json)
12
+ - [Generic Adapter Information](#generic-adapter-information)
13
+ - [Overview](./SUMMARY.md)
14
+ - [Versioning](#versioning)
15
+ - [Supported Platform Versions](#supported-platform-versions)
16
+ - [Getting Started](#getting-started)
17
+ - [Helpful Background Information](#helpful-background-information)
18
+ - [Prerequisites](#prerequisites)
19
+ - [How to Install](#how-to-install)
20
+ - [Testing](#testing)
21
+ - [Configuration](./PROPERTIES.md)
22
+ - [Utilities](./UTILITIES.md)
23
+ - [Additional Information](#additional-information)
24
+ - [Enhancements](./ENHANCE.md)
25
+ - [Contributing](./CONTRIBUTING.md)
26
+ - [Helpful Links](#helpful-links)
27
+ - [Node Scripts](#node-scripts)
28
+ - [Troubleshoot](./TROUBLESHOOT.md)
29
+ - [License and Maintainers](#license-and-maintainers)
30
+ - [Product License](#product-license)
11
31
 
12
- ### Maintained by:
13
32
 
14
- Itential Adapter Team (<product_team@itential.com>)
33
+ ## Specific to this Adapter
15
34
 
16
- Check the [changelog](CHANGELOG.md) for the latest changes.
35
+ ### [Authentication](./AUTH.md)
17
36
 
18
- ### License
37
+ ### [Sample Properties](./sampleProperties.json)
19
38
 
20
- Itential, LLC proprietary
39
+ <a href="./sampleProperties.json" target="_blank">Sample Properties</a> 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.
40
+
41
+ ### [Available Calls](./CALLS.md)
42
+
43
+ ### [Swagger](./report/adapter-openapi.json)
44
+
45
+
46
+ ## Generic Adapter Information
47
+
48
+ ### [Overview](./SUMMARY.md)
49
+
50
+ ### Versioning
51
+
52
+ Itential Product and opensource adapters utilize SemVer for versioning. The current version of the adapter can be found in the `package.json` file or viewed in the Platform GUI on the System page. All Itential opensource adapters can be found in the <a href="https://gitlab.com/itentialopensource/adapters" target="_blank">Itential OpenSource Repository</a>.
53
+
54
+ Any release prior to 1.0.0 is a pre-release. Initial builds of adapters are generally set up as pre-releases as there is often work that needs to be done to configure the adapter and make sure the authentication process to MicrosoftSQL works appropriately.
55
+
56
+ Release notes can be viewed in CHANGELOG.md.
57
+
58
+ ### Supported Platform Versions
59
+
60
+ Itential Product adapters are built for particular versions of Platform and packaged with the versions they work with.
61
+
62
+ Itential opensource adapter as well as custom adapters built with the Itential Adapter Builder work acoss many releases of Platform. As a result, it is not often necessary to modify an adapter when upgrading Platform. If Platform has changes that impact the pronghorn.json, like adding a new required section, this will most likely require changes to all adapters when upgrading Platform.
63
+
64
+ Many of the scripts that come with all adapters built using the Itential Adapter Builder do have some dependencies on Platform or the Platform database schema and so it is possible these scripts could stop working in different versions of Platform. If you notify Itential of any issues, the Adapter Team will attempt to fix the scripts for newer releases of Platform.
65
+
66
+ ### Getting Started
67
+
68
+ These instructions will help you get a copy of the project on your local machine for development and testing. Reading this section is also helpful for deployments as it provides you with pertinent information on prerequisites and properties.
69
+
70
+ #### Helpful Background Information
71
+
72
+ There is <a href="https://docs.itential.com/opensource/docs/adapters" target="_blank">Adapter documentation available on the Itential Documentation Site</a>. This documentation includes information and examples that are helpful for:
73
+
74
+ ```text
75
+ Authentication
76
+ Platform Service Instance Configuration
77
+ Code Files
78
+ Endpoint Configuration (Action & Schema)
79
+ Mock Data
80
+ Adapter Generic Methods
81
+ Headers
82
+ Security
83
+ Linting and Testing
84
+ Build an Adapter
85
+ Troubleshooting an Adapter
86
+ ```
87
+
88
+ Others will be added over time.
89
+ Want to build a new adapter? Use the <a href="https://adapters.itential.io" target="_blank">Itential Adapter Builder</a>
90
+
91
+ #### Prerequisites
92
+
93
+ The following is a list of required packages for installation on the system the adapter will run on:
94
+
95
+ ```text
96
+ Node.js
97
+ npm
98
+ Git
99
+ ```
100
+
101
+ The following list of packages are required for Itential opensource adapters or custom adapters that have been built utilizing the Itential Adapter Builder. You can install these packages by running npm install inside the adapter directory.
102
+
103
+ <table border="1" class="bordered-table">
104
+ <tr>
105
+ <th bgcolor="lightgrey" style="padding:15px"><span style="font-size:12.0pt">Package</span></th>
106
+ <th bgcolor="lightgrey" style="padding:15px"><span style="font-size:12.0pt">Description</span></th>
107
+ </tr>
108
+ <tr>
109
+ <td style="padding:15px">@itentialopensource/adapter-utils</td>
110
+ <td style="padding:15px">Runtime library classes for all adapters; includes request handling, connection, authentication throttling, and translation.</td>
111
+ </tr>
112
+ <tr>
113
+ <td style="padding:15px">ajv</td>
114
+ <td style="padding:15px">Required for validation of adapter properties to integrate with MicrosoftSQL.</td>
115
+ </tr>
116
+ <tr>
117
+ <td style="padding:15px">axios</td>
118
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
119
+ </tr>
120
+ <tr>
121
+ <td style="padding:15px">commander</td>
122
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
123
+ </tr>
124
+ <tr>
125
+ <td style="padding:15px">fs-extra</td>
126
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
127
+ </tr>
128
+ <tr>
129
+ <td style="padding:15px">mocha</td>
130
+ <td style="padding:15px">Testing library that is utilized by some of the node scripts that are included with the adapter.</td>
131
+ </tr>
132
+ <tr>
133
+ <td style="padding:15px">mocha-param</td>
134
+ <td style="padding:15px">Testing library that is utilized by some of the node scripts that are included with the adapter.</td>
135
+ </tr>
136
+ <tr>
137
+ <td style="padding:15px">mongodb</td>
138
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
139
+ </tr>
140
+ <tr>
141
+ <td style="padding:15px">nyc</td>
142
+ <td style="padding:15px">Testing coverage library that is utilized by some of the node scripts that are included with the adapter.</td>
143
+ </tr>
144
+ <tr>
145
+ <td style="padding:15px">ping</td>
146
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
147
+ </tr>
148
+ <tr>
149
+ <td style="padding:15px">readline-sync</td>
150
+ <td style="padding:15px">Utilized by the node script that comes with the adapter; helps to test unit and integration functionality.</td>
151
+ </tr>
152
+ <tr>
153
+ <td style="padding:15px">semver</td>
154
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
155
+ </tr>
156
+ <tr>
157
+ <td style="padding:15px">winston</td>
158
+ <td style="padding:15px">Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality.</td>
159
+ </tr>
160
+ </table>
161
+ <br>
162
+
163
+ If you are developing and testing a custom adapter, or have testing capabilities on an Itential opensource adapter, you will need to install these packages as well.
164
+
165
+ ```text
166
+ chai
167
+ eslint
168
+ eslint-config-airbnb-base
169
+ eslint-plugin-import
170
+ eslint-plugin-json
171
+ testdouble
172
+ ```
173
+
174
+ #### How to Install
175
+
176
+ 1a. If you are working on Itential Platform 2023.2 or earlier versions, set up the name space location in your Itential Platform node_modules.
177
+
178
+ ```bash
179
+ cd /opt/pronghorn/current/node_modules (* could be in a different place)
180
+ if the @itentialopensource directory does not exist, create it:
181
+ mkdir @itentialopensource
182
+ cd @itentialopensource
183
+ ```
184
+
185
+ 1b. If you are working on Platform 6, you need to install the adapter in the services directory.
186
+
187
+ ```bash
188
+ cd /opt/itential/platform/services (* you may have configured it to be in a different place)
189
+ ```
190
+
191
+ 2. Clone/unzip/tar the adapter into your Platform environment.
192
+
193
+ ```bash
194
+ git clone git@gitlab.com:@itentialopensource/adapters/adapter-db_mssql
195
+ or
196
+ unzip adapter-db_mssql.zip
197
+ or
198
+ tar -xvf adapter-db_mssql.tar
199
+ ```
200
+
201
+ 3. install the adapter dependencies.
202
+
203
+ ```bash
204
+ cd adapter-db_mssql
205
+ npm install
206
+ npm run lint:errors
207
+ npm run test
208
+ ```
209
+
210
+ 4. Restart Platform
211
+
212
+ ```bash
213
+ systemctl restart pronghorn
214
+ ```
215
+
216
+ 5. Create an adapter service instance configuration in Platform Admin Essentials GUI
217
+
218
+ 6. Copy the properties from the sampleProperties.json and paste them into the service instance configuration in the inner/second properties field.
219
+
220
+ 7. Change the adapter service instance configuration (host, port, credentials, etc) in Platform Admin Essentials GUI
221
+
222
+ #### Testing
223
+
224
+ Mocha is generally used to test all Itential Opensource Adapters. There are unit tests as well as integration tests performed. Integration tests can generally be run as standalone using mock data and running the adapter in stub mode, or as integrated. When running integrated, every effort is made to prevent environmental failures, however there is still a possibility.
225
+
226
+ ##### Unit Testing
227
+
228
+ Unit Testing includes testing basic adapter functionality as well as error conditions that are triggered in the adapter prior to any integration. There are two ways to run unit tests. The prefered method is to use the testRunner script; however, both methods are provided here.
229
+
230
+ ```bash
231
+ node utils/testRunner --unit
232
+
233
+ npm run test:unit
234
+ npm run test:baseunit
235
+ ```
236
+
237
+ To add new unit tests, edit the `test/unit/adapterTestUnit.js` file. The tests that are already in this file should provide guidance for adding additional tests.
238
+
239
+ ##### Integration Testing - Standalone
240
+
241
+ Standalone Integration Testing requires mock data to be provided with the entities. If this data is not provided, standalone integration testing will fail. When the adapter is set to run in stub mode (setting the stub property to true), the adapter will run through its code up to the point of making the request. It will then retrieve the mock data and return that as if it had received that data as the response from MicrosoftSQL. It will then translate the data so that the adapter can return the expected response to the rest of the Itential software. Standalone is the default integration test.
242
+
243
+ Similar to unit testing, there are two ways to run integration tests. Using the testRunner script is better because it prevents you from having to edit the test script; it will also resets information after testing is complete so that credentials are not saved in the file.
244
+
245
+ ```bash
246
+ node utils/testRunner
247
+ answer no at the first prompt
248
+
249
+ npm run test:integration
250
+ ```
251
+
252
+ To add new integration tests, edit the `test/integration/adapterTestIntegration.js` file. The tests that are already in this file should provide guidance for adding additional tests.
253
+
254
+ ##### Integration Testing
255
+
256
+ Integration Testing requires connectivity to MicrosoftSQL. By using the testRunner script it prevents you from having to edit the integration test. It also resets the integration test after the test is complete so that credentials are not saved in the file.
257
+
258
+ > **Note**: These tests have been written as a best effort to make them work in most environments. However, the Adapter Builder often does not have the necessary information that is required to set up valid integration tests. For example, the order of the requests can be very important and data is often required for `creates` and `updates`. Hence, integration tests may have to be enhanced before they will work (integrate) with MicrosoftSQL. Even after tests have been set up properly, it is possible there are environmental constraints that could result in test failures. Some examples of possible environmental issues are customizations that have been made within MicrosoftSQL which change order dependencies or required data.
259
+
260
+ ```bash
261
+ node utils/testRunner
262
+ answer yes at the first prompt
263
+ answer all other questions on connectivity and credentials
264
+ ```
265
+
266
+ Test should also be written to clean up after themselves. However, it is important to understand that in some cases this may not be possible. In addition, whenever exceptions occur, test execution may be stopped, which will prevent cleanup actions from running. It is recommended that tests be utilized in dev and test labs only.
267
+
268
+ > **Reminder**: Do not check in code with actual credentials to systems.
269
+
270
+ ### [Configuration](./PROPERTIES.md)
271
+
272
+ ### [Utilities](./UTILITIES.md)
273
+
274
+ ### Additional Information
275
+
276
+ #### [Enhancements](./ENHANCE.md)
277
+
278
+ #### [Contributing](./CONTRIBUTING.md)
279
+
280
+ #### Helpful Links
281
+
282
+ <a href="https://docs.itential.com/opensource/docs/adapters" target="_blank">Adapter Technical Resources</a>
283
+
284
+ ### [Troubleshoot](./TROUBLESHOOT.md)
285
+
286
+ ### License and Maintainers
287
+
288
+ ```text
289
+ Itential Product Adapters are maintained by the Itential Product Team.
290
+ Itential OpenSource Adapters are maintained by the Itential Adapter Team and the community at large.
291
+ Custom Adapters are maintained by other sources.
292
+ ```
293
+
294
+ ### Product License
295
+
296
+ [Apache 2.0](./LICENSE)
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 MicrosoftSQL System. The API that was used to build the adapter for MicrosoftSQL is usually available in the report directory of this adapter. The adapter utilizes the MicrosoftSQL 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 MicrosoftSQL System. The API that was used to build the adapter for MicrosoftSQL is usually available in the report directory of this adapter. The adapter utilizes the MicrosoftSQL 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 MicrosoftSQL 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
@@ -14,7 +14,7 @@ We classify MSSQL into the Data Storage domaina as MSSQL is a database which pro
14
14
  "Industry-leading performance and availability"
15
15
 
16
16
  ## Why Integrate
17
- The MSSQL adapter from Itential is used to integrate the Itential Automation Platform (IAP) with Microsoft MSSQL. With this adapter you have the ability to perform operations with MSSQL on items such as:
17
+ The MSSQL adapter from Itential is used to integrate the Itential Platform with Microsoft MSSQL. With this adapter you have the ability to perform operations with MSSQL on items such as:
18
18
 
19
19
  - Storage of Information
20
20
  - 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 MicrosoftSQL System. The API that was used to build the adapter for MicrosoftSQL is usually available in the report directory of this adapter. The adapter utilizes the MicrosoftSQL 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 MicrosoftSQL System. The API that was used to build the adapter for MicrosoftSQL is usually available in the report directory of this adapter. The adapter utilizes the MicrosoftSQL 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 MSSQL adapter from Itential is used to integrate the Itential Automation Platform (IAP) with Microsoft MSSQL. With this adapter you have the ability to perform operations with MSSQL on items such as:
6
+ The MSSQL adapter from Itential is used to integrate the Itential Platform with Microsoft MSSQL. With this adapter you have the ability to perform operations with MSSQL on items such as:
7
7
 
8
8
  - Storage of Information
9
9
  - Retrieval of Information
package/TAB2.md CHANGED
@@ -11,14 +11,16 @@
11
11
  ## Specific Adapter Information
12
12
  ### Authentication
13
13
 
14
- This document will go through the steps for authenticating the Microsoft 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 Microsoft 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
+
16
+ If Itential Platform is running in docker, and MicrosoftSQL server is running in the local machine, host in adapter properties should be 'host.docker.internal' instead of 'localhost' or '127.0.0.1'.
15
17
 
16
18
  #### Database Library Authentication
17
19
  The Microsoft 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
20
 
19
21
  STEPS
20
22
  1. Ensure you have access to a Microsoft 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
23
+ 2. Follow the steps in the README.md to import the adapter into Itential Platform if you have not already done so
22
24
  3. Use the properties below for the ```properties.authentication``` field
23
25
  ```json
24
26
  "authentication": {
@@ -32,12 +34,12 @@ STEPS
32
34
 
33
35
  #### Troubleshooting
34
36
  - Make sure you copied over the correct username and password.
35
- - Turn on debug level logs for the adapter in IAP Admin Essentials.
37
+ - Turn on debug level logs for the adapter in Itential Platform Admin Essentials.
36
38
  - Investigate the logs
37
39
  - 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.
38
40
  ### Sample Properties
39
41
 
40
- 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.
42
+ 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.
41
43
 
42
44
  ```json
43
45
  "properties": {
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-db_mssql",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "Itential adapter to connect to mssql",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.44.7",
7
- "engineVersion": "1.67.14",
7
+ "engineVersion": "1.69.14",
8
8
  "adapterType": "library",
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
  "MicrosoftSQL",
@@ -41,20 +39,20 @@
41
39
  "author": "Itential",
42
40
  "homepage": "https://gitlab.com/itentialopensource/adapters/adapter-db_mssql#readme",
43
41
  "dependencies": {
44
- "ajv": "^8.17.1",
45
- "fs-extra": "^11.2.0",
46
- "mssql": "^10.0.1",
47
- "readline-sync": "^1.4.10"
42
+ "ajv": "8.17.1",
43
+ "fs-extra": "11.3.0",
44
+ "mssql": "10.0.1",
45
+ "readline-sync": "1.4.10",
46
+ "mocha": "10.8.2",
47
+ "winston": "3.17.0"
48
48
  },
49
49
  "devDependencies": {
50
- "chai": "^4.3.7",
51
- "eslint": "^8.44.0",
52
- "eslint-config-airbnb-base": "^15.0.0",
53
- "eslint-plugin-import": "^2.27.5",
54
- "eslint-plugin-json": "^3.1.0",
55
- "mocha": "^10.7.0",
56
- "testdouble": "^3.18.0",
57
- "winston": "^3.13.1"
50
+ "chai": "4.5.0",
51
+ "eslint": "8.57.0",
52
+ "eslint-config-airbnb-base": "15.0.0",
53
+ "eslint-plugin-import": "2.31.0",
54
+ "eslint-plugin-json": "3.1.0",
55
+ "testdouble": "3.18.0"
58
56
  },
59
57
  "private": false
60
58
  }
@@ -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;
Binary file
@@ -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
- });