Browse Source

Adds stronger typing for secret keys

main
Eric Amodio 1 year ago
parent
commit
3cf152d5da
3 changed files with 7 additions and 4 deletions
  1. +3
    -1
      src/container.ts
  2. +2
    -2
      src/plus/subscription/authenticationProvider.ts
  3. +2
    -1
      src/storage.ts

+ 3
- 1
src/container.ts View File

@ -61,6 +61,8 @@ import { RebaseEditorProvider } from './webviews/rebase/rebaseEditor';
import { SettingsWebview } from './webviews/settings/settingsWebview'; import { SettingsWebview } from './webviews/settings/settingsWebview';
import { WelcomeWebview } from './webviews/welcome/welcomeWebview'; import { WelcomeWebview } from './webviews/welcome/welcomeWebview';
export type Environment = 'dev' | 'staging' | 'production';
export class Container { export class Container {
static #instance: Container | undefined; static #instance: Container | undefined;
static #proxy = new Proxy<Container>({} as Container, { static #proxy = new Proxy<Container>({} as Container, {
@ -360,7 +362,7 @@ export class Container {
} }
@memoize() @memoize()
get env(): 'dev' | 'staging' | 'production' {
get env(): Environment {
if (this.prereleaseOrDebugging) { if (this.prereleaseOrDebugging) {
const env = configuration.getAny('gitkraken.env'); const env = configuration.getAny('gitkraken.env');
if (env === 'dev') return 'dev'; if (env === 'dev') return 'dev';

+ 2
- 2
src/plus/subscription/authenticationProvider.ts View File

@ -5,7 +5,7 @@ import type {
} from 'vscode'; } from 'vscode';
import { authentication, Disposable, EventEmitter, extensions, window } from 'vscode'; import { authentication, Disposable, EventEmitter, extensions, window } from 'vscode';
import { uuid } from '@env/crypto'; import { uuid } from '@env/crypto';
import type { Container } from '../../container';
import type { Container, Environment } from '../../container';
import { debug } from '../../system/decorators/log'; import { debug } from '../../system/decorators/log';
import { Logger } from '../../system/logger'; import { Logger } from '../../system/logger';
import { getLogScope } from '../../system/logger.scope'; import { getLogScope } from '../../system/logger.scope';
@ -50,7 +50,7 @@ export class SubscriptionAuthenticationProvider implements AuthenticationProvide
this._disposable.dispose(); this._disposable.dispose();
} }
private get secretStorageKey(): string {
private get secretStorageKey(): `gitlens.plus.auth:${Environment}` {
return `gitlens.plus.auth:${this.container.env}`; return `gitlens.plus.auth:${this.container.env}`;
} }

+ 2
- 1
src/storage.ts View File

@ -1,6 +1,7 @@
import type { Disposable, Event, ExtensionContext, SecretStorageChangeEvent } from 'vscode'; import type { Disposable, Event, ExtensionContext, SecretStorageChangeEvent } from 'vscode';
import { EventEmitter } from 'vscode'; import { EventEmitter } from 'vscode';
import type { ViewShowBranchComparison } from './config'; import type { ViewShowBranchComparison } from './config';
import type { Environment } from './container';
import type { StoredSearchQuery } from './git/search'; import type { StoredSearchQuery } from './git/search';
import type { Subscription } from './subscription'; import type { Subscription } from './subscription';
import { debug } from './system/decorators/log'; import { debug } from './system/decorators/log';
@ -104,7 +105,7 @@ export class Storage implements Disposable {
} }
} }
export type SecretKeys = string;
export type SecretKeys = `gitlens.integration.auth:${string}` | `gitlens.plus.auth:${Environment}`;
export const enum SyncedStorageKeys { export const enum SyncedStorageKeys {
Version = 'gitlens:synced:version', Version = 'gitlens:synced:version',

Loading…
Cancel
Save