Skip to content

Commit 7317408

Browse files
committed
Add a default connector plugin (jupyterlab-contrib#1)
* Add a default connector * Connector list() method returns also the values
1 parent f909d00 commit 7317408

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

src/connectors/in-memory.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ISecret, ISecretsConnector } from '../token';
2+
3+
/**
4+
* An in memory password connector to store passwords during the session.
5+
* Refreshing the page clear the passwords.
6+
*
7+
* This is the default implementation of ISecretsConnector.
8+
*/
9+
export class InMemoryConnector implements ISecretsConnector {
10+
async fetch(id: string): Promise<ISecret | undefined> {
11+
return this._secrets.get(id);
12+
}
13+
14+
async save(id: string, value: ISecret): Promise<any> {
15+
this._secrets.set(id, value);
16+
}
17+
18+
async remove(id: string): Promise<any> {
19+
this._secrets.delete(id);
20+
}
21+
22+
async list(
23+
query?: string | undefined
24+
): Promise<{ ids: string[]; values: ISecret[] }> {
25+
const ids: string[] = [];
26+
const values: ISecret[] = [];
27+
this._secrets.forEach((value, key) => {
28+
if (value.namespace === query) {
29+
ids.push(key);
30+
values.push(value);
31+
}
32+
});
33+
return { ids, values };
34+
}
35+
36+
private _secrets = new Map<string, ISecret>();
37+
}

src/connectors/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './in-memory';
2+
export * from './local-storage';

src/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ import {
44
} from '@jupyterlab/application';
55
import { SecretsManager } from './manager';
66
import { ISecretsConnector, ISecretsManager } from './token';
7+
import { InMemoryConnector } from './connectors';
78

89
/**
9-
* Initialization data for the jupyter-secrets-manager extension.
10+
* A basic secret connector extension, that should be disabled to provide a new
11+
* connector.
1012
*/
11-
const plugin: JupyterFrontEndPlugin<ISecretsManager> = {
12-
id: 'jupyter-secrets-manager:plugin',
13+
const inMemoryConnector: JupyterFrontEndPlugin<ISecretsConnector> = {
14+
id: 'jupyter-secrets-manager:connector',
15+
description: 'A JupyterLab extension to manage secrets.',
16+
autoStart: true,
17+
provides: ISecretsConnector,
18+
activate: (app: JupyterFrontEnd): ISecretsConnector => {
19+
return new InMemoryConnector();
20+
}
21+
};
22+
23+
/**
24+
* The secret manager extension.
25+
*/
26+
const manager: JupyterFrontEndPlugin<ISecretsManager> = {
27+
id: 'jupyter-secrets-manager:manager',
1328
description: 'A JupyterLab extension to manage secrets.',
1429
autoStart: true,
1530
provides: ISecretsManager,
@@ -23,6 +38,6 @@ const plugin: JupyterFrontEndPlugin<ISecretsManager> = {
2338
}
2439
};
2540

26-
export * from './connectors/local-storage';
41+
export * from './connectors';
2742
export * from './token';
28-
export default plugin;
43+
export default [inMemoryConnector, manager];

0 commit comments

Comments
 (0)