Compare commits

...

4 Commits

Author SHA1 Message Date
williamlardier ee92c02baf
squash for testing workflow 2022-11-24 11:27:02 +01:00
williamlardier a05aa86d7d
ARTESCA-6420: add releases workflow 2022-11-24 11:18:07 +01:00
williamlardier 48e41ab5b5
ARTESCA-6419: add tests workflows for build and syntax checks 2022-11-24 11:06:32 +01:00
williamlardier 2eeae6d485
ARTESCA-6419: implement base http(s) agents and export 2022-11-24 11:06:32 +01:00
6 changed files with 186 additions and 0 deletions

56
.github/workflows/release.yaml vendored Normal file
View File

@ -0,0 +1,56 @@
name: release
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to be released'
required: true
push:
branches:
- 'master/**'
- 'feature/**'
- 'documentation/**'
- 'improvement/**'
- 'bugfix/**'
- 'w/**'
- 'q/**'
- 'hotfix/**'
- 'task/**'
- 'release/**'
- 'main'
jobs:
verify-release:
name: Verify if tag is valid
runs-on: ubuntu-latest
steps:
- name: Checkout arsenal-networking repository
uses: 'actions/checkout@v3'
with:
ref: ${{ github.ref }}
- name: Fetch tags
run: git fetch --tags
- name: 'Check if tag was already created'
shell: bash
run: >
git show-ref --tags v${{ github.event.inputs.tag }} --quiet \
&& exit 1 || exit 0
release:
name: Release
runs-on: ubuntu-latest
needs:
- verify-release
steps:
- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Release ${{ github.event.inputs.tag }}
tag_name: v${{ github.event.inputs.tag }}
generate_release_notes: true
target_commitish: ${{ github.sha }}

36
.github/workflows/tests.yaml vendored Normal file
View File

@ -0,0 +1,36 @@
name: Tests
on:
push:
branches:
- 'master/**'
- 'feature/**'
- 'documentation/**'
- 'improvement/**'
- 'bugfix/**'
- 'w/**'
- 'q/**'
- 'hotfix/**'
- 'task/**'
- 'release/**'
- 'main'
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install deps
run: sudo apt-get update -q
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install Yarn
run: npm install -g yarn
- name: install dependencies
run: yarn install --frozen-lockfile
- name: run lint
run: yarn run eslint
- name: run build
run: yarn build

10
index.ts Normal file
View File

@ -0,0 +1,10 @@
import httpAgent from "./lib/http-agent";
import httpsAgent from "./lib/https-agent";
export const http = {
Agent: httpAgent,
};
export const https = {
Agent: httpsAgent,
};

6
lib/config/default.ts Normal file
View File

@ -0,0 +1,6 @@
export default interface clientConfigurationDefault {
/**
* Maximum Socket Number: true if TCP session reuse must be enabled
*/
maxSockets?: boolean;
}

39
lib/http-agent.ts Normal file
View File

@ -0,0 +1,39 @@
import * as http from 'http';
import clientConfigurationDefault from './config/default';
/**
* @class ClientHttp
* Abstracts the native http.Agent class to enforce common
* networking configuration across components.
*/
export default class ClientHttp extends http.Agent {
/**
* The maximum socket configuration defaults to 50.
*/
private static maxSocketsConfiguration = Number(process.env.MAX_SOCKETS) || 50;
/**
* Constructor for the ClientHttp class
*
* @param opts - Custom HTTP Agent options
* @param config - user-defined default configuration du apply
*/
constructor(
opts?: http.AgentOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
const defaultConfigurations: http.AgentOptions = {};
if (config.maxSockets) {
defaultConfigurations.keepAlive = true;
defaultConfigurations.maxSockets = ClientHttp.maxSocketsConfiguration;
defaultConfigurations.maxFreeSockets = ClientHttp.maxSocketsConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}

39
lib/https-agent.ts Normal file
View File

@ -0,0 +1,39 @@
import * as https from 'https';
import clientConfigurationDefault from './config/default';
/**
* @class ClientHttps
* Abstracts the native https.Agent class to enforce common
* networking configuration across components.
*/
export default class ClientHttps extends https.Agent {
/**
* The maximum socket configuration defaults to 50.
*/
private static maxSocketsConfiguration = Number(process.env.MAX_SOCKETS) || 50;
/**
* Constructor for the ClientHttps class
*
* @param opts - Custom HTTPs Agent options
* @param config - user-defined default configuration du apply
*/
constructor(
opts?: https.AgentOptions,
config: clientConfigurationDefault = {
maxSockets: true,
},
) {
// Enforce TCP session reuse configuration, unless explicitely specified.
const defaultConfigurations: https.AgentOptions = {};
if (config.maxSockets) {
defaultConfigurations.keepAlive = true;
defaultConfigurations.maxSockets = ClientHttps.maxSocketsConfiguration;
defaultConfigurations.maxFreeSockets = ClientHttps.maxSocketsConfiguration;
}
super({
...opts,
...defaultConfigurations,
});
}
}