-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
9df0f84
commit cf61bed
Showing
10 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2024 Fortra's Alert Logic | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@al/clyde | ||
========= | ||
|
||
A client for interacting with Clyde API via YARD | ||
|
||
This library uses @al/core as its HTTP provider interface. | ||
|
||
## Disclaimer | ||
|
||
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]) | ||
|
||
## Installation | ||
|
||
npm install @al/clyde --save | ||
|
||
## Usage | ||
|
||
var AlClydeClient = require('@al/clyde').AlClydeClient; //commonjs - e.g. node | ||
import { AlClydeClient } from '@al/clyde'; //ES2015 - e.g. Angular, TS projects | ||
## Interactive | ||
|
||
Loads the library into memory and stays in an interactive node shell. | ||
|
||
npm run interactive | ||
|
||
NOTE - You must build the sources before running this command, see Building section below | ||
|
||
## Tests | ||
|
||
npm test | ||
|
||
## Contributing | ||
|
||
The sources are written in Typescript and follow the tslint airbnb style. | ||
|
||
## Building | ||
|
||
To generate a production build | ||
|
||
npm run build | ||
|
||
To generate a development build | ||
|
||
npm run build-dev | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function( config ) { | ||
var sharedConfig = require( "../../karma.shared.config.js" ); | ||
sharedConfig( config, "yard" ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@al/clyde", | ||
"version": "1.0.0", | ||
"description": "A client for interacting with CLYDE API via YARD", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/alertlogic/nepal-client-libs.git" | ||
}, | ||
"keywords": [ | ||
"Alert Logic", | ||
"Clyde API", | ||
"Client", | ||
"Service" | ||
], | ||
"author": { | ||
"name": "Bryan Tabarez", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/alertlogic/nepal-client-libs/issues" | ||
}, | ||
"homepage": "https://github.com/alertlogic/nepal-client-libs#readme", | ||
"maintainers": [ | ||
{ | ||
"name": "Alert Logic NPM Team", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"main": "./dist/index.cjs.js", | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.esm5.js", | ||
"es2015": "./dist/index.esm2015.js", | ||
"scripts": { | ||
"test": "echo 'No tests yet'", | ||
"test-watch": "karma start --no-single-run --auto-watch", | ||
"build": "rollup -c ../../rollup.config.ts", | ||
"prebuild": "npm run clean && npm run lint && npm run test", | ||
"lint": "tslint -p tsconfig.json", | ||
"clean": "rm -rf dist node_modules", | ||
"prepublishOnly": "npm run build", | ||
"interactive": "npm run build && node -i -e \"const AlClydeClient = require('./dist/commonjs/index.js').AlClydeClient;\"" | ||
}, | ||
"dependencies": { | ||
"@al/core": "^1.0.173" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Al Clyde API client | ||
*/ | ||
import { | ||
AlDefaultClient, AlLocation | ||
} from '@al/core'; | ||
import { | ||
MinVersionPayload, | ||
MinVersionQueryParams, | ||
GetMinVersionResponse, | ||
SetMinVersionResponse, | ||
} from './types'; | ||
|
||
export class AlClydeClientInstance { | ||
|
||
private readonly serviceStack = AlLocation.YARDAPI; | ||
private version = 'v1'; | ||
|
||
/** | ||
* Check the minimum version using an specific accountId | ||
* GET | ||
* @param accountId AIMS Account ID | ||
* @param queryParams: {min_version=2.25.0, collection_method=agent} | ||
* @returns a promise with the response of the minimum version for a specific accountId | ||
* | ||
*/ | ||
async checkMinVersion(accountId: string, queryParams?: MinVersionQueryParams): Promise<GetMinVersionResponse> { | ||
return AlDefaultClient.get({ | ||
service_stack: this.serviceStack, | ||
version: '', | ||
path: `clyde/${this.version}/${accountId}/check_min_version`, | ||
params: { | ||
queryParams | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get hosts info | ||
* clyde/v1/2/get_hosts | ||
*/ | ||
async getHostInfo(accountId: string, queryParams?: any): Promise<unknown> { | ||
return AlDefaultClient.get({ | ||
service_stack: this.serviceStack, | ||
version: '', | ||
path: `clyde/${this.version}/${accountId}/get_hosts`, | ||
params: queryParams | ||
}); | ||
} | ||
|
||
// clyde/v1/{accountId}/set_min_version | ||
async setMinVersion(accountId: string, payload?: MinVersionPayload): Promise<SetMinVersionResponse> { | ||
return AlDefaultClient.post({ | ||
service_stack: this.serviceStack, | ||
version: '', | ||
path: `clyde/${this.version}/${accountId}/set_min_version`, | ||
data: payload | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AlGlobalizer } from '@al/core'; | ||
import { AlClydeClientInstance } from './al-clyde-client'; | ||
|
||
/* tslint:disable:variable-name */ | ||
export const AlClydeClient = AlGlobalizer.instantiate( "AlClydeClient", () => new AlClydeClientInstance() ); | ||
/* tslint:enable:variable-name */ | ||
|
||
export * from './al-clyde-client'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export type CollectionType = "master" | "updater" | "eventlog" | "syslog" | "flatfile" | "tmhost" | "tmappliance" | "scanappliance"; | ||
export type CollectionMethod = "agent" | "appliance"; | ||
|
||
export interface MinVersionQueryParams { | ||
min_version?: string; | ||
collection_method?: CollectionMethod; | ||
collection_type?: CollectionType; | ||
} | ||
|
||
export interface GetMinVersionResponse { | ||
ok_count: number; | ||
ok_percent?: number; | ||
outdated_clients?: unknown[]; | ||
outdated_count?: number; | ||
outdated_error_count?: number; | ||
outdated_error_percent?: number; | ||
outdated_in_progress_count?: number; | ||
outdated_in_progress_percent?: number; | ||
outdated_not_started_count?: number; | ||
outdated_not_started_percent?: number; | ||
outdated_percent?: number; | ||
result: "ok" | "outdated" | "error"; | ||
total_online_count?: number; | ||
} | ||
|
||
export interface MinVersionPayload { | ||
collection_type?: CollectionType; | ||
collection_method?: CollectionMethod; | ||
min_version: string; | ||
required?: boolean; | ||
} | ||
|
||
export interface SetMinVersionResponse { | ||
details?: string; | ||
result: 'ok' | 'error'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends" : "../../tsconfig.json", | ||
"compileOnSave" : false, | ||
"include" : [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude" : [ | ||
"node_modules", | ||
"**/*.spec.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs" | ||
}, | ||
"compileOnSave" : false, | ||
"include" : [ | ||
"./src/**/*.ts", | ||
"./test/**/*.ts" | ||
], | ||
"exclude" : [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"extends": "tslint-config-airbnb", | ||
"rules": { | ||
"align": [ true, "statements", "members", "elements" ], | ||
"max-line-length": { | ||
"options": [240] | ||
}, | ||
"ter-indent": false, | ||
"ter-arrow-parens": false, | ||
"no-increment-decrement": false, | ||
"arrow-parens": false, | ||
"prefer-const": false, | ||
"prefer-template": false, | ||
"no-consecutive-blank-lines": false, | ||
"no-else-after-return": false, | ||
"no-parameter-reassignment": false, | ||
"space-in-parens": false, | ||
"space-before-function-paren": false, | ||
"quotemark": false, | ||
"object-curly-spacing": false, | ||
"object-literal-shorthand": false, | ||
"array-bracket-spacing": false, | ||
"whitespace": false, | ||
"trailing-comma": [ | ||
true, { | ||
"esSpecCompliant": true | ||
} | ||
], | ||
"object-literal-key-quotes": false, | ||
"member-ordering": [ true, { "order": "fields-first" } ] | ||
} | ||
} |