Skip to content

Commit

Permalink
chore: Fix smoke tests node 20 (#1745)
Browse files Browse the repository at this point in the history
Co-authored-by: Maurice Rickard <maurice@mauricerickard.com>
  • Loading branch information
bizob2828 and mrickard committed Aug 3, 2023
1 parent 8f2e11a commit 8c053e0
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 173 deletions.
36 changes: 18 additions & 18 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic

* [@newrelic/eslint-config](#newreliceslint-config)
* [@newrelic/newrelic-oss-cli](#newrelicnewrelic-oss-cli)
* [@newrelic/proxy](#newrelicproxy)
* [@newrelic/test-utilities](#newrelictest-utilities)
* [@octokit/rest](#octokitrest)
* [@slack/bolt](#slackbolt)
Expand Down Expand Up @@ -66,6 +65,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
* [memcached](#memcached)
* [nock](#nock)
* [prettier](#prettier)
* [proxy](#proxy)
* [proxyquire](#proxyquire)
* [q](#q)
* [rimraf](#rimraf)
Expand Down Expand Up @@ -1273,7 +1273,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### https-proxy-agent

This product includes source derived from [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) ([v5.0.1](https://github.com/TooTallNate/node-https-proxy-agent/tree/v5.0.1)), distributed under the [MIT License](https://github.com/TooTallNate/node-https-proxy-agent/blob/v5.0.1/README.md):
This product includes source derived from [https-proxy-agent](https://github.com/TooTallNate/proxy-agents) ([v7.0.1](https://github.com/TooTallNate/proxy-agents/tree/v7.0.1)), distributed under the [MIT License](https://github.com/TooTallNate/proxy-agents/blob/v7.0.1/README.md):

```
MIT License
Expand Down Expand Up @@ -1866,22 +1866,6 @@ This product includes source derived from [@newrelic/newrelic-oss-cli](https://g
limitations under the License.
```

### @newrelic/proxy

This product includes source derived from [@newrelic/proxy](https://github.com/newrelic/proxy) ([v2.0.0](https://github.com/newrelic/proxy/tree/v2.0.0)), distributed under the [MIT License](https://github.com/newrelic/proxy/blob/v2.0.0/README.md):

```
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

### @newrelic/test-utilities

This product includes source derived from [@newrelic/test-utilities](https://github.com/newrelic/node-test-utilities) ([v7.3.2](https://github.com/newrelic/node-test-utilities/tree/v7.3.2)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-test-utilities/blob/v7.3.2/LICENSE):
Expand Down Expand Up @@ -9271,6 +9255,22 @@ By: Ika

```

### proxy

This product includes source derived from [proxy](https://github.com/TooTallNate/proxy-agents) ([v2.1.1](https://github.com/TooTallNate/proxy-agents/tree/v2.1.1)), distributed under the [MIT License](https://github.com/TooTallNate/proxy-agents/blob/v2.1.1/README.md):

```
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

### proxyquire

This product includes source derived from [proxyquire](https://github.com/thlorenz/proxyquire) ([v1.8.0](https://github.com/thlorenz/proxyquire/tree/v1.8.0)), distributed under the [MIT License](https://github.com/thlorenz/proxyquire/blob/v1.8.0/LICENSE):
Expand Down
53 changes: 10 additions & 43 deletions lib/collector/http-agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

'use strict'

const parse = require('url').parse
const ProxyAgent = require('https-proxy-agent')
const { HttpsProxyAgent } = require('https-proxy-agent')
const logger = require('../logger').child({ component: 'http-agent' })
const https = require('https')

Expand Down Expand Up @@ -52,66 +51,34 @@ exports.proxyAgent = function proxyAgent(config) {
if (null !== agentProxyWithKeepAlive) {
return agentProxyWithKeepAlive
}
const opts = proxyOptions(config)
const proxyUrl = opts.proxy_url
const proxyUrl = proxyOptions(config)

const proxyOpts = {
host: proxyUrl.host,
port: proxyUrl.port,
protocol: proxyUrl.protocol,
secureEndpoint: config.ssl,
auth: proxyUrl.auth,
ca: opts.certificates,
ca: config?.certificates?.length ? config.certificates : [],
keepAlive: true
}

logger.info(
{
host: proxyOpts.host,
port: proxyOpts.port,
auth: !!proxyOpts.auth,
protocol: proxyUrl.protocol
},
'using proxy'
)

agentProxyWithKeepAlive = new ProxyAgent(proxyOpts)
logger.info(`using proxy: ${proxyUrl}`)
agentProxyWithKeepAlive = new HttpsProxyAgent(proxyUrl, proxyOpts)
return agentProxyWithKeepAlive
}

function proxyOptions(config) {
let proxyUrl
if (config.proxy) {
const parsedUrl = parse(config.proxy)

proxyUrl = {
protocol: parsedUrl.protocol || 'https:',
host: parsedUrl.hostname,
port: parsedUrl.port || 80,
auth: parsedUrl.auth
}
proxyUrl = config.proxy
} else {
proxyUrl = 'https://'
let proxyAuth = config.proxy_user
if (config.proxy_pass !== '') {
proxyAuth += ':' + config.proxy_pass
proxyUrl += `${proxyAuth}@`
}

// Unless a proxy config is provided, default to HTTP.
proxyUrl = {
protocol: 'https:',
host: config.proxy_host || 'localhost',
port: config.proxy_port || 80,
auth: proxyAuth
}
}

const opts = {
proxy_url: proxyUrl
}

if (config.certificates && config.certificates.length > 0) {
opts.certificates = config.certificates
proxyUrl += `${config.proxy_host || 'localhost'}:${config.proxy_port || 80}`
}

return opts
return proxyUrl
}
Loading

0 comments on commit 8c053e0

Please sign in to comment.