Compare commits
41 Commits
v0.0.1-alp
...
developmen
Author | SHA1 | Date |
---|---|---|
|
045e9c8282 | |
|
32b843aaf3 | |
![]() |
66e97ab935 | |
![]() |
8425d23e04 | |
![]() |
2e3d13c5b9 | |
![]() |
ec4e28f050 | |
![]() |
435c7436d0 | |
![]() |
aae50a9096 | |
![]() |
1881146b28 | |
![]() |
6c600cd02f | |
![]() |
72108aed4f | |
![]() |
e14a16f988 | |
![]() |
bc5fc17097 | |
![]() |
0a56b2a48c | |
![]() |
0330b36bb3 | |
![]() |
179d43d73a | |
![]() |
9304a78cc4 | |
![]() |
eb40166fd8 | |
![]() |
71e1a487a5 | |
![]() |
7c6c9127cb | |
![]() |
93938413e9 | |
![]() |
a3af7cdd1e | |
![]() |
fed919ae16 | |
![]() |
676a70e102 | |
![]() |
481e44308b | |
![]() |
4235b98de8 | |
![]() |
d0b147fe85 | |
![]() |
a4f419ebfa | |
![]() |
fed06b3abf | |
![]() |
264d776838 | |
![]() |
1ef5ac9705 | |
![]() |
34e20e72c8 | |
![]() |
38607a83b3 | |
![]() |
5f688379e7 | |
![]() |
ad70fdf5b0 | |
![]() |
8ea438271b | |
![]() |
d1da0f6575 | |
![]() |
5a3d96b49c | |
![]() |
c09ac9f116 | |
![]() |
51fcaab601 | |
![]() |
a21e1b7b42 |
|
@ -0,0 +1 @@
|
||||||
|
index.d.ts
|
|
@ -0,0 +1,15 @@
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
commonjs: true,
|
||||||
|
es2021: true,
|
||||||
|
},
|
||||||
|
extends: 'airbnb-base',
|
||||||
|
overrides: [
|
||||||
|
],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"env": {
|
|
||||||
"browser": true,
|
|
||||||
"es2021": true
|
|
||||||
},
|
|
||||||
"extends": [
|
|
||||||
"eslint:recommended",
|
|
||||||
"plugin:@typescript-eslint/recommended"
|
|
||||||
],
|
|
||||||
"ignorePatterns": ["build/**/*.js", "build/**/*.d.ts"],
|
|
||||||
"overrides": [
|
|
||||||
],
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": "latest",
|
|
||||||
"sourceType": "module"
|
|
||||||
},
|
|
||||||
"plugins": [
|
|
||||||
"@typescript-eslint"
|
|
||||||
],
|
|
||||||
"rules": {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Tag to be released'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify-release:
|
||||||
|
name: Verify if tag is valid
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout httpagent 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 ${{ 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: ${{ github.event.inputs.tag }}
|
||||||
|
generate_release_notes: true
|
||||||
|
target_commitish: ${{ github.sha }}
|
|
@ -0,0 +1,35 @@
|
||||||
|
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
|
||||||
|
|
17
README.md
17
README.md
|
@ -1,3 +1,16 @@
|
||||||
# Arsenal-Networking
|
# HttpAgent
|
||||||
|
|
||||||
Common utilities for Scality S3 project components networking.
|
HttpAgent is a library on top of the native `http` and `https` NodeJS Agents
|
||||||
|
to enforce consistent, still configurable networking configuration for Scality
|
||||||
|
micro services.
|
||||||
|
|
||||||
|
What HttpAgent is:
|
||||||
|
|
||||||
|
- A wrapper enforcing, by default, both `keepAlive` and `maxSockets` options.
|
||||||
|
- A centralized way of handling Http(s) Agents, while supporting consistent
|
||||||
|
environment variables across components.
|
||||||
|
- A library that can be extended with more standard configurations.
|
||||||
|
|
||||||
|
What HttpAgent is not:
|
||||||
|
|
||||||
|
- An all-in-one library for networking-related code.
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# HttpAgent
|
||||||
|
|
||||||
|
## How to release ARSNN
|
||||||
|
|
||||||
|
To release a ARSNN version:
|
||||||
|
|
||||||
|
- Bump the project version in `package.json` in a PR and merge it.
|
||||||
|
|
||||||
|
- When the PR is merged, trigger the
|
||||||
|
[Release Workflow](https://github.com/scality/httpagent/actions/workflows/release.yaml)
|
||||||
|
via the workflow dispatch function. Use the `development/*` branch.
|
||||||
|
|
||||||
|
- You MUST fill the form with a tag. The new version you enter MUST be a valid
|
||||||
|
[SemVer](https://semver.org) version, matching with your `package.json`
|
||||||
|
version.
|
||||||
|
|
||||||
|
- The workflow will dynamically tag the project and generate a release
|
||||||
|
changelog.
|
|
@ -0,0 +1,29 @@
|
||||||
|
import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
||||||
|
|
||||||
|
import { HttpsOptions, HttpOptions } from 'agentkeepalive';
|
||||||
|
|
||||||
|
declare namespace http {
|
||||||
|
export interface clientConfigurationDefault {
|
||||||
|
/**
|
||||||
|
* Maximum Socket Number: true if TCP session reuse must be enabled
|
||||||
|
*/
|
||||||
|
maxSockets?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Agent extends HttpAgent {
|
||||||
|
constructor(opts?: HttpOptions, config?: clientConfigurationDefault);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace https {
|
||||||
|
export interface clientConfigurationDefault {
|
||||||
|
/**
|
||||||
|
* Maximum Socket Number: true if TCP session reuse must be enabled
|
||||||
|
*/
|
||||||
|
maxSockets?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Agent extends HttpsAgent {
|
||||||
|
constructor(opts?: HttpsOptions, config?: clientConfigurationDefault);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/* eslint-disable global-require */
|
||||||
|
|
||||||
|
exports.http = {
|
||||||
|
Agent: require('./lib/http-agent').default,
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.https = {
|
||||||
|
Agent: require('./lib/https-agent').default,
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.AgentConfiguration = require('./lib/config/agentConfiguration').default;
|
|
@ -0,0 +1,17 @@
|
||||||
|
/**
|
||||||
|
* The maximum socket configuration defaults to 50.
|
||||||
|
*/
|
||||||
|
const maxSocketsNumber = Number(process.env.MAX_SOCKETS) || 50;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default configuration for the maxSocket profile.
|
||||||
|
* The goal is to enforce a `maxSockets` property to properly
|
||||||
|
* handle load.
|
||||||
|
*/
|
||||||
|
const agentConfiguration = {
|
||||||
|
keepAlive: true,
|
||||||
|
maxSockets: maxSocketsNumber,
|
||||||
|
maxFreeSockets: maxSocketsNumber,
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.default = agentConfiguration;
|
|
@ -0,0 +1,28 @@
|
||||||
|
const HttpAgent = require('agentkeepalive');
|
||||||
|
const agentConfiguration = require('./config/agentConfiguration');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class AgentHttp
|
||||||
|
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
|
||||||
|
* networking configuration across components.
|
||||||
|
*/
|
||||||
|
class AgentHttp extends HttpAgent {
|
||||||
|
/**
|
||||||
|
* Constructor for the AgentHttp class
|
||||||
|
*
|
||||||
|
* @param opts - Custom HTTP Agent options
|
||||||
|
* @param config - user-defined default configuration to apply
|
||||||
|
*/
|
||||||
|
constructor(opts, config = {
|
||||||
|
maxSockets: true,
|
||||||
|
}) {
|
||||||
|
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||||
|
let defaultConfigurations = {};
|
||||||
|
if (config.maxSockets) {
|
||||||
|
defaultConfigurations = agentConfiguration;
|
||||||
|
}
|
||||||
|
super({ ...opts, ...defaultConfigurations });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.default = AgentHttp;
|
|
@ -0,0 +1,28 @@
|
||||||
|
const { HttpsAgent } = require('agentkeepalive');
|
||||||
|
const agentConfiguration = require('./config/agentConfiguration');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class AgentHttps
|
||||||
|
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
|
||||||
|
* networking configuration across components.
|
||||||
|
*/
|
||||||
|
class AgentHttps extends HttpsAgent {
|
||||||
|
/**
|
||||||
|
* Constructor for the AgentHttps class
|
||||||
|
*
|
||||||
|
* @param opts - Custom HTTPs Agent options
|
||||||
|
* @param config - user-defined default configuration to apply
|
||||||
|
*/
|
||||||
|
constructor(opts, config = {
|
||||||
|
maxSockets: true,
|
||||||
|
}) {
|
||||||
|
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||||
|
let defaultConfigurations = {};
|
||||||
|
if (config.maxSockets) {
|
||||||
|
defaultConfigurations = agentConfiguration;
|
||||||
|
}
|
||||||
|
super({ ...opts, ...defaultConfigurations });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.default = AgentHttps;
|
29
package.json
29
package.json
|
@ -1,33 +1,30 @@
|
||||||
{
|
{
|
||||||
"name": "arsenal-networking",
|
"name": "httpagent",
|
||||||
"version": "1.0.0",
|
"version": "1.0.6",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
},
|
||||||
"description": "A utility library for networking",
|
"description": "A utility library for networking",
|
||||||
"main": "build/index.js",
|
"main": "index.js",
|
||||||
"repository": "git@github.com:scality/arsenal-networking.git",
|
"repository": "git@github.com:scality/httpagent.git",
|
||||||
"author": "Scality Inc.",
|
"author": "Scality Inc.",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --build tsconfig.json",
|
|
||||||
"format": "prettier --write \"**/*.{ts,tsx,css,html}\" ",
|
"format": "prettier --write \"**/*.{ts,tsx,css,html}\" ",
|
||||||
"prepare": "yarn build || true",
|
|
||||||
"eslint": "eslint ./ --ext .js,.ts,.tsx",
|
"eslint": "eslint ./ --ext .js,.ts,.tsx",
|
||||||
"eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix",
|
"eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix",
|
||||||
"eslint-init": "eslint --init",
|
"eslint-init": "eslint --init"
|
||||||
"lint": "eslint ./ --ext .js,.ts,.tsx --format visualstudio --no-color --max-warnings 10 --report-unused-disable-directives"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^18.11.9"
|
"agentkeepalive": "^4.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
"eslint": "^7.32.0 || ^8.2.0",
|
||||||
"@typescript-eslint/parser": "^5.44.0",
|
|
||||||
"eslint": "^8.28.0",
|
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-config-scality": "git+https://github.com/scality/Guidelines#8.2.0",
|
"eslint-config-scality": "../eslint-config-scality",
|
||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.25.2",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^2.8.0"
|
||||||
"typescript": "^4.9.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es6",
|
|
||||||
"module": "commonjs",
|
|
||||||
"rootDir": "./",
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"checkJs": false,
|
|
||||||
"outDir": "build",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"declaration": true,
|
|
||||||
"noImplicitAny": false,
|
|
||||||
"noEmitOnError": false,
|
|
||||||
"sourceMap": true,
|
|
||||||
"declarationMap": true
|
|
||||||
},
|
|
||||||
"include": ["index.ts", "lib"],
|
|
||||||
"exclude": ["node_modules/*"],
|
|
||||||
"compileOnSave": true
|
|
||||||
}
|
|
Loading…
Reference in New Issue