diff --git a/README.md b/README.md index 0567a92..de2b112 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,94 @@ [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![bundle][bundle-src]][bundle-href] -[![JSDocs][jsdocs-src]][jsdocs-href] [![License][license-src]][license-href] -Description +# Description + +Node.js Tacacs+ client. + +## Install + +***npm*** +```bash +npm i @noction/vue-highcharts +``` + +***yarn*** +```bash +yarn add @noction/vue-highcharts +``` + +***pnpm*** +```bash +pnpm add @noction/vue-highcharts +``` + +## Usage +```js +import type { AuthenType } from '@noction/tacacs-plus' +import { AUTHEN_TYPES, Client } from '@noction/tacacs-plus' + +const client = new Client({ + host: '127.0.0.1', + port: 49, + secret: 'tac_test', + // Your application logger (Optional) + logger: { + log: console.log, + // If you provide a debug logger, it will log the sent and received packets + debug: console.debug, + error: console.error, + warn: console.warn, + }, +}) + +// Example Authentication + +try { + const res = await client.authenticate({ + username: 'test_login', + password: 'test_login_password', + authenType: AUTHEN_TYPES.TAC_PLUS_AUTHEN_TYPE_ASCII, + }) + + console.log(res) +} +// Every status, except PASS will be thrown as an Error +catch (err) { + console.log(err) +} + +// Example Authorization + +try { + const res = await client.authorize({ + username: 'test_login', + services: ['idk'], + }) + + console.log(res) +} +// Every status, except PASS_ADD will be thrown as an Error +catch (err) { + console.log(err) +} +``` + +## Supporting + +1. Authentication +2. Authorization + +## Authentication types supported + +- TAC_PLUS_AUTHEN_TYPE_ASCII +- TAC_PLUS_AUTHEN_TYPE_PAP +- TAC_PLUS_AUTHEN_TYPE_CHAP + +## Not supporting + +1. Accounting ## License @@ -20,5 +104,3 @@ Description [bundle-href]: https://bundlephobia.com/result?p=@noction/tacacs-plus [license-src]: https://img.shields.io/github/license/Noction/@noction/tacacs-plus.svg?style=flat&colorA=080f12&colorB=1fa669 [license-href]: https://github.com/Noction/tacacs-plus/blob/main/LICENSE -[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669 -[jsdocs-href]: https://www.jsdocs.io/package/@noction/tacacs-plus diff --git a/package.json b/package.json index 03ea565..944beae 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,8 @@ "version": "0.0.0", "packageManager": "pnpm@8.15.3", "description": "", - "author": "", + "author": "Noction", "license": "MIT", - "keywords": [], - "sideEffects": false, - "main": "index.js", "scripts": { "lint": "pnpm -P -r \"/^lint/\"", "typecheck": "pnpm -P -r \"/^typecheck/\"", diff --git a/packages/playground/package.json b/packages/playground/package.json index ebe82b8..3b1879d 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -1,10 +1,8 @@ { "name": "playground", "version": "0.0.0", - "description": "", - "author": "", + "author": "Noction", "license": "MIT", - "keywords": [], "scripts": { "lint": "eslint .", "start": "esno src/index", @@ -12,7 +10,9 @@ "down:server": "docker compose -f server/docker-compose.yaml down" }, "dependencies": { - "@noction/tacacs-plus": "workspace:", + "@noction/tacacs-plus": "workspace:" + }, + "devDependencies": { "eslint": "^8.56.0", "typescript": "5.3.3" } diff --git a/packages/tacacs-plus/package.json b/packages/tacacs-plus/package.json index 7bd189a..45e560a 100644 --- a/packages/tacacs-plus/package.json +++ b/packages/tacacs-plus/package.json @@ -3,7 +3,7 @@ "type": "module", "version": "0.0.0", "packageManager": "pnpm@8.15.3", - "description": "Description", + "description": "Node.js Tacacs+ client", "author": "Noction", "license": "MIT", "homepage": "https://github.com/Noction/@noction/tacacs-plus#readme", @@ -12,7 +12,7 @@ "url": "git+https://github.com/Noction/@noction/tacacs-plus.git" }, "bugs": "https://github.com/Noction/@noction/tacacs-plus/issues", - "keywords": [], + "keywords": ["node", "tacacs-plus", "tacacs-client", "tacacs-plus-authentication", "tacacs-plus-authorization"], "sideEffects": false, "exports": { ".": { @@ -47,11 +47,9 @@ "start": "esno src/index.ts", "test": "vitest", "typecheck": "tsc --noEmit" - }, "devDependencies": { "@antfu/ni": "^0.21.12", - "@antfu/utils": "^0.7.7", "@types/node": "^20.11.19", "bumpp": "^9.3.0", "eslint": "^8.56.0", @@ -60,7 +58,6 @@ "rimraf": "^5.0.5", "typescript": "5.3.3", "unbuild": "^2.0.0", - "vite": "^5.2.8", "vitest": "^1.3.1" } } diff --git a/packages/tacacs-plus/src/client/index.ts b/packages/tacacs-plus/src/client/index.ts index fc311f2..cc2f0cc 100644 --- a/packages/tacacs-plus/src/client/index.ts +++ b/packages/tacacs-plus/src/client/index.ts @@ -154,7 +154,7 @@ export class Client { return socket } - async authenticate({ username, password, privLvl, authenType }: AuthenticateArgs): Promise { + async authenticate({ username, password, authenType, privLvl = PRIVILEGE_LEVELS.TAC_PLUS_PRIV_LVL_MIN }: AuthenticateArgs): Promise { return new Promise((resolve, reject) => { const socket = this.createSocket() diff --git a/packages/tacacs-plus/src/client/types.ts b/packages/tacacs-plus/src/client/types.ts index ddba06d..e9cdebe 100644 --- a/packages/tacacs-plus/src/client/types.ts +++ b/packages/tacacs-plus/src/client/types.ts @@ -3,6 +3,7 @@ import type { Secret } from '../types' export interface Logger { log: (message: string) => void + // If you provide the debug logger, the packets will be logged debug: (message: string) => void error: (message: string) => void warn: (message: string) => void diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0644c7b..0b66b4e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ importers: '@antfu/ni': specifier: ^0.21.12 version: 0.21.12 - '@antfu/utils': - specifier: ^0.7.7 - version: 0.7.7 '@types/node': specifier: ^20.11.19 version: 20.11.19 @@ -68,9 +65,6 @@ importers: unbuild: specifier: ^2.0.0 version: 2.0.0(typescript@5.3.3) - vite: - specifier: ^5.2.8 - version: 5.2.8(@types/node@20.11.19) vitest: specifier: ^1.3.1 version: 1.3.1(@types/node@20.11.19) @@ -181,10 +175,6 @@ packages: hasBin: true dev: true - /@antfu/utils@0.7.7: - resolution: {integrity: sha512-gFPqTG7otEJ8uP6wrhDv6mqwGWYZKNvAcCq6u9hOj0c+IKCEsY4L1oC9trPq2SaWIzAfHvqfBDxF591JkMf+kg==} - dev: true - /@babel/code-frame@7.22.13: resolution: {integrity: sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==} engines: {node: '>=6.9.0'}