Skip to content

Commit cf61bed

Browse files
BryanTabarezbryan-tabarez
andauthored
ENG-57007: Add base of Clyde client via Yard (#847)
* ENG-57007: Add base of Clyde client via Yard * fix lint errors --------- Co-authored-by: bryan-tabarez <[email protected]>
1 parent 9df0f84 commit cf61bed

File tree

10 files changed

+274
-0
lines changed

10 files changed

+274
-0
lines changed

packages/clyde/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2024 Fortra's Alert Logic
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

packages/clyde/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@al/clyde
2+
=========
3+
4+
A client for interacting with Clyde API via YARD
5+
6+
This library uses @al/core as its HTTP provider interface.
7+
8+
## Disclaimer
9+
10+
Until the release of version 1.0.0 all current minor version increments may be backwards incompatible. Please bear this in mind when developing against this library. Should you have any further questions, please do not hesitate to contact us as [[email protected]](mailto:[email protected])
11+
12+
## Installation
13+
14+
npm install @al/clyde --save
15+
16+
## Usage
17+
18+
var AlClydeClient = require('@al/clyde').AlClydeClient; //commonjs - e.g. node
19+
import { AlClydeClient } from '@al/clyde'; //ES2015 - e.g. Angular, TS projects
20+
21+
## Interactive
22+
23+
Loads the library into memory and stays in an interactive node shell.
24+
25+
npm run interactive
26+
27+
NOTE - You must build the sources before running this command, see Building section below
28+
29+
## Tests
30+
31+
npm test
32+
33+
## Contributing
34+
35+
The sources are written in Typescript and follow the tslint airbnb style.
36+
37+
## Building
38+
39+
To generate a production build
40+
41+
npm run build
42+
43+
To generate a development build
44+
45+
npm run build-dev
46+
47+
Builds will be be generated into a `dist` folder and will contain commonjs and umd bundles that will be consumed depending on the module system in whichever environment you are using.

packages/clyde/karma.conf.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function( config ) {
2+
var sharedConfig = require( "../../karma.shared.config.js" );
3+
sharedConfig( config, "yard" );
4+
}

packages/clyde/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@al/clyde",
3+
"version": "1.0.0",
4+
"description": "A client for interacting with CLYDE API via YARD",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/alertlogic/nepal-client-libs.git"
8+
},
9+
"keywords": [
10+
"Alert Logic",
11+
"Clyde API",
12+
"Client",
13+
"Service"
14+
],
15+
"author": {
16+
"name": "Bryan Tabarez",
17+
"email": "[email protected]"
18+
},
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/alertlogic/nepal-client-libs/issues"
22+
},
23+
"homepage": "https://github.com/alertlogic/nepal-client-libs#readme",
24+
"maintainers": [
25+
{
26+
"name": "Alert Logic NPM Team",
27+
"email": "[email protected]"
28+
}
29+
],
30+
"main": "./dist/index.cjs.js",
31+
"types": "./dist/index.d.ts",
32+
"module": "./dist/index.esm5.js",
33+
"es2015": "./dist/index.esm2015.js",
34+
"scripts": {
35+
"test": "echo 'No tests yet'",
36+
"test-watch": "karma start --no-single-run --auto-watch",
37+
"build": "rollup -c ../../rollup.config.ts",
38+
"prebuild": "npm run clean && npm run lint && npm run test",
39+
"lint": "tslint -p tsconfig.json",
40+
"clean": "rm -rf dist node_modules",
41+
"prepublishOnly": "npm run build",
42+
"interactive": "npm run build && node -i -e \"const AlClydeClient = require('./dist/commonjs/index.js').AlClydeClient;\""
43+
},
44+
"dependencies": {
45+
"@al/core": "^1.0.173"
46+
},
47+
"files": [
48+
"dist"
49+
],
50+
"publishConfig": {
51+
"access": "public"
52+
}
53+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Al Clyde API client
3+
*/
4+
import {
5+
AlDefaultClient, AlLocation
6+
} from '@al/core';
7+
import {
8+
MinVersionPayload,
9+
MinVersionQueryParams,
10+
GetMinVersionResponse,
11+
SetMinVersionResponse,
12+
} from './types';
13+
14+
export class AlClydeClientInstance {
15+
16+
private readonly serviceStack = AlLocation.YARDAPI;
17+
private version = 'v1';
18+
19+
/**
20+
* Check the minimum version using an specific accountId
21+
* GET
22+
* @param accountId AIMS Account ID
23+
* @param queryParams: {min_version=2.25.0, collection_method=agent}
24+
* @returns a promise with the response of the minimum version for a specific accountId
25+
*
26+
*/
27+
async checkMinVersion(accountId: string, queryParams?: MinVersionQueryParams): Promise<GetMinVersionResponse> {
28+
return AlDefaultClient.get({
29+
service_stack: this.serviceStack,
30+
version: '',
31+
path: `clyde/${this.version}/${accountId}/check_min_version`,
32+
params: {
33+
queryParams
34+
}
35+
});
36+
}
37+
38+
/**
39+
* Get hosts info
40+
* clyde/v1/2/get_hosts
41+
*/
42+
async getHostInfo(accountId: string, queryParams?: any): Promise<unknown> {
43+
return AlDefaultClient.get({
44+
service_stack: this.serviceStack,
45+
version: '',
46+
path: `clyde/${this.version}/${accountId}/get_hosts`,
47+
params: queryParams
48+
});
49+
}
50+
51+
// clyde/v1/{accountId}/set_min_version
52+
async setMinVersion(accountId: string, payload?: MinVersionPayload): Promise<SetMinVersionResponse> {
53+
return AlDefaultClient.post({
54+
service_stack: this.serviceStack,
55+
version: '',
56+
path: `clyde/${this.version}/${accountId}/set_min_version`,
57+
data: payload
58+
});
59+
}
60+
61+
}

packages/clyde/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { AlGlobalizer } from '@al/core';
2+
import { AlClydeClientInstance } from './al-clyde-client';
3+
4+
/* tslint:disable:variable-name */
5+
export const AlClydeClient = AlGlobalizer.instantiate( "AlClydeClient", () => new AlClydeClientInstance() );
6+
/* tslint:enable:variable-name */
7+
8+
export * from './al-clyde-client';
9+
export * from './types';

packages/clyde/src/types/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export type CollectionType = "master" | "updater" | "eventlog" | "syslog" | "flatfile" | "tmhost" | "tmappliance" | "scanappliance";
2+
export type CollectionMethod = "agent" | "appliance";
3+
4+
export interface MinVersionQueryParams {
5+
min_version?: string;
6+
collection_method?: CollectionMethod;
7+
collection_type?: CollectionType;
8+
}
9+
10+
export interface GetMinVersionResponse {
11+
ok_count: number;
12+
ok_percent?: number;
13+
outdated_clients?: unknown[];
14+
outdated_count?: number;
15+
outdated_error_count?: number;
16+
outdated_error_percent?: number;
17+
outdated_in_progress_count?: number;
18+
outdated_in_progress_percent?: number;
19+
outdated_not_started_count?: number;
20+
outdated_not_started_percent?: number;
21+
outdated_percent?: number;
22+
result: "ok" | "outdated" | "error";
23+
total_online_count?: number;
24+
}
25+
26+
export interface MinVersionPayload {
27+
collection_type?: CollectionType;
28+
collection_method?: CollectionMethod;
29+
min_version: string;
30+
required?: boolean;
31+
}
32+
33+
export interface SetMinVersionResponse {
34+
details?: string;
35+
result: 'ok' | 'error';
36+
}

packages/clyde/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends" : "../../tsconfig.json",
3+
"compileOnSave" : false,
4+
"include" : [
5+
"./src/**/*.ts"
6+
],
7+
"exclude" : [
8+
"node_modules",
9+
"**/*.spec.ts"
10+
]
11+
}

packages/clyde/tsconfig.spec.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs"
5+
},
6+
"compileOnSave" : false,
7+
"include" : [
8+
"./src/**/*.ts",
9+
"./test/**/*.ts"
10+
],
11+
"exclude" : [
12+
"node_modules"
13+
]
14+
}

packages/clyde/tslint.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"extends": "tslint-config-airbnb",
3+
"rules": {
4+
"align": [ true, "statements", "members", "elements" ],
5+
"max-line-length": {
6+
"options": [240]
7+
},
8+
"ter-indent": false,
9+
"ter-arrow-parens": false,
10+
"no-increment-decrement": false,
11+
"arrow-parens": false,
12+
"prefer-const": false,
13+
"prefer-template": false,
14+
"no-consecutive-blank-lines": false,
15+
"no-else-after-return": false,
16+
"no-parameter-reassignment": false,
17+
"space-in-parens": false,
18+
"space-before-function-paren": false,
19+
"quotemark": false,
20+
"object-curly-spacing": false,
21+
"object-literal-shorthand": false,
22+
"array-bracket-spacing": false,
23+
"whitespace": false,
24+
"trailing-comma": [
25+
true, {
26+
"esSpecCompliant": true
27+
}
28+
],
29+
"object-literal-key-quotes": false,
30+
"member-ordering": [ true, { "order": "fields-first" } ]
31+
}
32+
}

0 commit comments

Comments
 (0)