-
Notifications
You must be signed in to change notification settings - Fork 41
feat(openshell): add @nvidia/openshell-sdk and cached mTLS-aware client factory #2712
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
MarsKubeX
merged 5 commits into
openkaiden:main
from
MarsKubeX:add-nvidia-openshell-sdk
Aug 25, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1a8859
feat(openshell): add @nvidia/openshell-sdk and cached mTLS-aware clie…
MarsKubeX 730a7fb
fix(openshell): harden cert error handling and fix CI test failure
MarsKubeX edc1e47
refactor(openshell): extract gateway config into dedicated singleton
MarsKubeX 3b3daf1
refactor(openshell): drop singleton scope from stateless gateway config
MarsKubeX 5ffe5d1
refactor(openshell): rename OpenshellSdkClient to OpenshellSdkClientM…
MarsKubeX 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ env: | |
|
|
||
| permissions: | ||
| contents: read | ||
| packages: read | ||
|
|
||
| jobs: | ||
| tag: | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ env: | |
|
|
||
| permissions: | ||
| contents: read | ||
| packages: read | ||
|
|
||
| jobs: | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ env: | |
|
|
||
| permissions: | ||
| contents: read | ||
| packages: read | ||
|
|
||
| jobs: | ||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| node-linker=hoisted | ||
|
|
||
| @nvidia:registry=https://npm.pkg.github.com | ||
| //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} |
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
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
126 changes: 126 additions & 0 deletions
126
packages/main/src/plugin/openshell-cli/openshell-gateway-config.spec.ts
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,126 @@ | ||
| /********************************************************************** | ||
| * Copyright (C) 2026 Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ***********************************************************************/ | ||
|
|
||
| import { join } from 'node:path'; | ||
|
|
||
| import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
|
||
| import type { GatewayInfo } from '/@api/openshell-gateway-info.js'; | ||
|
|
||
| import { OpenshellGatewayConfig } from './openshell-gateway-config.js'; | ||
|
|
||
| vi.mock(import('node:fs/promises')); | ||
| vi.mock(import('node:os')); | ||
|
|
||
| function gateway(overrides: Partial<GatewayInfo> = {}): GatewayInfo { | ||
| return { | ||
| name: 'kaiden-local', | ||
| endpoint: 'http://127.0.0.1:17670', | ||
| active: true, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| }); | ||
|
|
||
| describe('OpenshellGatewayConfig', () => { | ||
| describe('buildConnectOptions', () => { | ||
| test('returns gateway URL only for http endpoints', async () => { | ||
| const config = new OpenshellGatewayConfig(); | ||
|
|
||
| const options = await config.buildConnectOptions(gateway()); | ||
|
|
||
| expect(options).toStrictEqual({ gateway: 'http://127.0.0.1:17670' }); | ||
| }); | ||
|
|
||
| test('loads mTLS certs for https endpoints', async () => { | ||
| vi.stubEnv('XDG_CONFIG_HOME', '/test/config'); | ||
| const { readFile } = await import('node:fs/promises'); | ||
| vi.mocked(readFile) | ||
| .mockResolvedValueOnce(Buffer.from('ca-data')) | ||
| .mockResolvedValueOnce(Buffer.from('cert-data')) | ||
| .mockResolvedValueOnce(Buffer.from('key-data')); | ||
|
|
||
| const config = new OpenshellGatewayConfig(); | ||
| const gw = gateway({ name: 'remote-gw', endpoint: 'https://gw.example.com', auth: 'mtls' }); | ||
|
|
||
| const options = await config.buildConnectOptions(gw); | ||
|
|
||
| const expectedMtlsDir = join('/test/config', 'openshell', 'gateways', 'remote-gw', 'mtls'); | ||
| expect(vi.mocked(readFile)).toHaveBeenCalledWith(join(expectedMtlsDir, 'ca.crt')); | ||
| expect(vi.mocked(readFile)).toHaveBeenCalledWith(join(expectedMtlsDir, 'tls.crt')); | ||
| expect(vi.mocked(readFile)).toHaveBeenCalledWith(join(expectedMtlsDir, 'tls.key')); | ||
| expect(options).toStrictEqual({ | ||
| gateway: 'https://gw.example.com', | ||
| caCert: Buffer.from('ca-data'), | ||
| clientCert: Buffer.from('cert-data'), | ||
| clientKey: Buffer.from('key-data'), | ||
| }); | ||
| }); | ||
|
|
||
| test('passes undefined certs when mTLS files are missing', async () => { | ||
| vi.stubEnv('XDG_CONFIG_HOME', '/test/config'); | ||
| const { readFile } = await import('node:fs/promises'); | ||
| const enoent = Object.assign(new Error('ENOENT: no such file or directory'), { code: 'ENOENT' }); | ||
| vi.mocked(readFile).mockRejectedValue(enoent); | ||
|
|
||
| const config = new OpenshellGatewayConfig(); | ||
| const gw = gateway({ name: 'no-certs', endpoint: 'https://gw.example.com' }); | ||
|
|
||
| const options = await config.buildConnectOptions(gw); | ||
|
|
||
| expect(options).toStrictEqual({ | ||
| gateway: 'https://gw.example.com', | ||
| caCert: undefined, | ||
| clientCert: undefined, | ||
| clientKey: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| test('propagates non-ENOENT cert read errors', async () => { | ||
| vi.stubEnv('XDG_CONFIG_HOME', '/test/config'); | ||
| const { readFile } = await import('node:fs/promises'); | ||
| const permError = Object.assign(new Error('EACCES: permission denied'), { code: 'EACCES' }); | ||
| vi.mocked(readFile).mockRejectedValue(permError); | ||
|
|
||
| const config = new OpenshellGatewayConfig(); | ||
| const gw = gateway({ name: 'bad-perms', endpoint: 'https://gw.example.com' }); | ||
|
|
||
| await expect(config.buildConnectOptions(gw)).rejects.toThrow(/EACCES/); | ||
| }); | ||
|
|
||
| test('respects XDG_CONFIG_HOME', async () => { | ||
| const { readFile } = await import('node:fs/promises'); | ||
| const enoent = Object.assign(new Error('ENOENT: no such file or directory'), { code: 'ENOENT' }); | ||
| vi.mocked(readFile).mockRejectedValue(enoent); | ||
| vi.stubEnv('XDG_CONFIG_HOME', '/custom/config'); | ||
|
|
||
| const config = new OpenshellGatewayConfig(); | ||
| const gw = gateway({ name: 'xdg-gw', endpoint: 'https://gw.example.com' }); | ||
|
|
||
| await config.buildConnectOptions(gw); | ||
|
|
||
| const expectedMtlsDir = join('/custom/config', 'openshell', 'gateways', 'xdg-gw', 'mtls'); | ||
| expect(vi.mocked(readFile)).toHaveBeenCalledWith(join(expectedMtlsDir, 'ca.crt')); | ||
|
|
||
| vi.unstubAllEnvs(); | ||
| }); | ||
| }); | ||
| }); |
88 changes: 88 additions & 0 deletions
88
packages/main/src/plugin/openshell-cli/openshell-gateway-config.ts
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,88 @@ | ||
| /********************************************************************** | ||
| * Copyright (C) 2026 Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ***********************************************************************/ | ||
|
|
||
| import { readFile } from 'node:fs/promises'; | ||
| import { homedir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| import type { ConnectOptions } from '@nvidia/openshell-sdk'; | ||
| import { injectable } from 'inversify'; | ||
|
|
||
| import type { GatewayInfo } from '/@api/openshell-gateway-info.js'; | ||
|
|
||
| /** | ||
| * Resolves OpenShell gateway configuration (config paths, mTLS certificates) | ||
| * and builds the `ConnectOptions` needed by the SDK to connect to a gateway. | ||
| */ | ||
| @injectable() | ||
| export class OpenshellGatewayConfig { | ||
| async buildConnectOptions(gateway: GatewayInfo): Promise<ConnectOptions> { | ||
| const isHttps = gateway.endpoint.startsWith('https://'); | ||
|
|
||
| if (!isHttps) { | ||
| return { gateway: gateway.endpoint }; | ||
| } | ||
|
|
||
| const mtlsDir = this.#gatewayMtlsDir(gateway.name); | ||
| const [caCert, clientCert, clientKey] = await Promise.all([ | ||
| this.#readCertIfExists(join(mtlsDir, 'ca.crt')), | ||
| this.#readCertIfExists(join(mtlsDir, 'tls.crt')), | ||
| this.#readCertIfExists(join(mtlsDir, 'tls.key')), | ||
| ]); | ||
|
|
||
| return { | ||
| gateway: gateway.endpoint, | ||
| caCert, | ||
| clientCert, | ||
| clientKey, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the OpenShell config root following the same logic as the Rust CLI: | ||
| * 1. $XDG_CONFIG_HOME (all platforms, including Windows) | ||
| * 2. %APPDATA% on win32 | ||
| * 3. $HOME/.config | ||
| */ | ||
| #openshellConfigRoot(): string { | ||
| const xdg = process.env['XDG_CONFIG_HOME']; | ||
| if (xdg) return xdg; | ||
|
|
||
| if (process.platform === 'win32') { | ||
| const appdata = process.env['APPDATA']; | ||
| if (appdata) return appdata; | ||
| } | ||
|
|
||
| return join(homedir(), '.config'); | ||
| } | ||
|
|
||
| #gatewayMtlsDir(gatewayName: string): string { | ||
| return join(this.#openshellConfigRoot(), 'openshell', 'gateways', gatewayName, 'mtls'); | ||
| } | ||
|
|
||
| async #readCertIfExists(filePath: string): Promise<Buffer | undefined> { | ||
| try { | ||
| return await readFile(filePath); | ||
| } catch (error: unknown) { | ||
| if ((error as NodeJS.ErrnoException).code === 'ENOENT') { | ||
| return undefined; | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
| } |
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.