Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/connectors/in-memory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ISecret, ISecretsConnector } from '../token';

/**
* An in memory password connector to store passwords during the session.
* Refreshing the page clear the passwords.
*
* This is the default implementation of ISecretsConnector.
*/
export class InMemoryConnector implements ISecretsConnector {
async fetch(id: string): Promise<ISecret | undefined> {
return this._secrets.get(id);
}

async save(id: string, value: ISecret): Promise<any> {
this._secrets.set(id, value);
}

async remove(id: string): Promise<any> {
this._secrets.delete(id);
}

async list(
query?: string | undefined
): Promise<{ ids: string[]; values: ISecret[] }> {
const ids: string[] = [];
this._secrets.forEach((value, key) => {
if (value.namespace === query) {
ids.push(key);
}
});
return { ids, values: [] };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the values contain the actual secrets?

Copy link
Collaborator Author

@brichet brichet Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but currently it would be useless because of the interface of the SecretManager

list(namespace: string): Promise<string[]>;

async list(namespace: string): Promise<string[]> {
return (await this._connector.list(namespace)).ids;
}

I would be useful if there was a UI displaying all the secrets.
Maybe we can change it now (probably in another PR to also update the SecretManager), to avoid future breaking changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, probably fine either way.

For now the most important is being able to set and get individual secrets.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I updated it and opened #3

}

private _secrets = new Map<string, ISecret>();
}
2 changes: 2 additions & 0 deletions src/connectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './in-memory';
export * from './local-storage';
25 changes: 20 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ import {
} from '@jupyterlab/application';
import { SecretsManager } from './manager';
import { ISecretsConnector, ISecretsManager } from './token';
import { InMemoryConnector } from './connectors';

/**
* Initialization data for the jupyter-secrets-manager extension.
* A basic secret connector extension, that should be disabled to provide a new
* connector.
*/
const plugin: JupyterFrontEndPlugin<ISecretsManager> = {
id: 'jupyter-secrets-manager:plugin',
const inMemoryConnector: JupyterFrontEndPlugin<ISecretsConnector> = {
id: 'jupyter-secrets-manager:connector',
description: 'A JupyterLab extension to manage secrets.',
autoStart: true,
provides: ISecretsConnector,
activate: (app: JupyterFrontEnd): ISecretsConnector => {
return new InMemoryConnector();
}
};

/**
* The secret manager extension.
*/
const manager: JupyterFrontEndPlugin<ISecretsManager> = {
id: 'jupyter-secrets-manager:manager',
description: 'A JupyterLab extension to manage secrets.',
autoStart: true,
provides: ISecretsManager,
Expand All @@ -23,6 +38,6 @@ const plugin: JupyterFrontEndPlugin<ISecretsManager> = {
}
};

export * from './connectors/local-storage';
export * from './connectors';
export * from './token';
export default plugin;
export default [inMemoryConnector, manager];
Loading