-
Notifications
You must be signed in to change notification settings - Fork 78
refactor(FR-2529): extract backend.ai-client as standalone workspace package #6614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,12 @@ | ||
| { | ||
| "tabWidth": 2, | ||
| "semi": true, | ||
| "singleQuote": true, | ||
| "importOrderSeparation": true, | ||
| "importOrderParserPlugins": ["typescript", "jsx"], | ||
| "printWidth": 80, | ||
| "bracketSpacing": true, | ||
| "trailingComma": "all", | ||
| "plugins": ["@trivago/prettier-plugin-sort-imports"], | ||
| "singleAttributePerLine": false | ||
| } |
This file contains hidden or 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,51 @@ | ||
| { | ||
| "name": "backend.ai-client", | ||
| "version": "26.4.0-alpha.0", | ||
| "description": "Backend.AI API client library for JavaScript/TypeScript", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/lablup/backend.ai-webui/tree/main/packages/backend.ai-client" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/lablup/backend.ai-webui/issues" | ||
| }, | ||
| "author": "Lablup Inc. <contact@lablup.com>", | ||
| "license": "LGPL-3.0-or-later", | ||
| "keywords": [ | ||
| "backend.ai", | ||
| "client", | ||
| "sdk", | ||
| "api" | ||
| ], | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "sideEffects": false, | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "dev": "tsup --watch", | ||
| "build": "tsup", | ||
| "test": "vitest run", | ||
| "vitest": "vitest run", | ||
| "vitest:watch": "vitest", | ||
| "lint": "eslint ./src --max-warnings=0", | ||
| "prepublishOnly": "pnpm lint && pnpm test && pnpm build" | ||
| }, | ||
| "dependencies": { | ||
| "crypto-es": "^2.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "tsup": "^8.5.0", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.1.4" | ||
| }, | ||
| "type": "module" | ||
| } | ||
This file contains hidden or 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,140 @@ | ||
| // @ts-nocheck | ||
| class ClientConfig { | ||
| public _apiVersionMajor: string; | ||
| public _apiVersion: string; | ||
| public _hashType: string; | ||
| public _endpoint: string; | ||
| public _endpointHost: string; | ||
| public _accessKey: string; | ||
| public _secretKey: string; | ||
| public _userId: string; | ||
| public _password: string; | ||
| public _proxyURL: any; | ||
| public _proxyToken: any; | ||
| public _connectionMode: string; | ||
|
|
||
| /** | ||
| * The client Configuration object. | ||
| * | ||
| * @param {string} accessKey - access key to connect Backend.AI manager | ||
| * @param {string} secretKey - secret key to connect Backend.AI manager | ||
| * @param {string} endpoint - endpoint of Backend.AI manager | ||
| * @param {string} connectionMode - connection mode. 'API', 'SESSION' is supported. `SESSION` mode requires webserver. | ||
| */ | ||
| constructor( | ||
| accessKey?: string, | ||
| secretKey?: string, | ||
| endpoint?: string, | ||
| connectionMode: string = 'API', | ||
| ) { | ||
| // default configs. | ||
| this._apiVersionMajor = '8'; | ||
| this._apiVersion = 'v8.20240915'; // For compatibility with 24.09. | ||
| this._hashType = 'sha256'; | ||
| if (endpoint === undefined || endpoint === null) { | ||
| endpoint = 'https://api.backend.ai'; | ||
| } | ||
| endpoint = endpoint.replace(/\/+$/, ''); | ||
|
yomybaby marked this conversation as resolved.
|
||
| this._endpoint = endpoint; | ||
| this._endpointHost = endpoint.replace(/^[^:]+:\/\//, ''); | ||
| if (connectionMode === 'API') { | ||
| // API mode | ||
| // dynamic configs | ||
| if (accessKey === undefined || accessKey === null) { | ||
| throw new Error( | ||
| 'You must set accessKey! (either as argument or environment variable)', | ||
| ); | ||
| } | ||
| if (secretKey === undefined || secretKey === null) { | ||
| throw new Error( | ||
| 'You must set secretKey! (either as argument or environment variable)', | ||
| ); | ||
| } | ||
| this._accessKey = accessKey; | ||
| this._secretKey = secretKey; | ||
| this._userId = ''; | ||
| this._password = ''; | ||
| } else { | ||
| // Session mode | ||
| // dynamic configs | ||
| if (accessKey === undefined || accessKey === null) { | ||
| throw new Error( | ||
| 'You must set user id! (either as argument or environment variable)', | ||
| ); | ||
| } | ||
| if (secretKey === undefined || secretKey === null) { | ||
| throw new Error( | ||
| 'You must set password! (either as argument or environment variable)', | ||
| ); | ||
| } | ||
| this._accessKey = ''; | ||
| this._secretKey = ''; | ||
| this._userId = accessKey; | ||
| this._password = secretKey; | ||
| } | ||
| this._proxyURL = null; | ||
| this._proxyToken = null; | ||
| this._connectionMode = connectionMode; | ||
| } | ||
|
|
||
| get accessKey() { | ||
| return this._accessKey; | ||
| } | ||
|
|
||
| get secretKey() { | ||
| return this._secretKey; | ||
| } | ||
|
|
||
| get userId() { | ||
| return this._userId; | ||
| } | ||
|
|
||
| get password() { | ||
| return this._password; | ||
| } | ||
|
|
||
| get endpoint() { | ||
| return this._endpoint; | ||
| } | ||
|
|
||
| get proxyURL() { | ||
| return this._proxyURL; | ||
| } | ||
|
|
||
| get proxyToken() { | ||
| return this._proxyToken; | ||
| } | ||
|
|
||
| get endpointHost() { | ||
| return this._endpointHost; | ||
| } | ||
|
|
||
| get apiVersion() { | ||
| return this._apiVersion; | ||
| } | ||
|
|
||
| get apiVersionMajor() { | ||
| return this._apiVersionMajor; | ||
| } | ||
|
|
||
| get hashType() { | ||
| return this._hashType; | ||
| } | ||
|
|
||
| get connectionMode() { | ||
| return this._connectionMode; | ||
| } | ||
|
|
||
| /** | ||
| * Create a ClientConfig object from environment variables. | ||
| */ | ||
| static createFromEnv() { | ||
| return new this( | ||
| process.env.BACKEND_ACCESS_KEY, | ||
| process.env.BACKEND_SECRET_KEY, | ||
| process.env.BACKEND_ENDPOINT, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export { ClientConfig }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.