From 3cf152d5da73e6f9e42022bf57fe60f96f89626a Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 6 Mar 2023 18:21:43 -0500 Subject: [PATCH] Adds stronger typing for secret keys --- src/container.ts | 4 +++- src/plus/subscription/authenticationProvider.ts | 4 ++-- src/storage.ts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/container.ts b/src/container.ts index fcf249c..5ec85ba 100644 --- a/src/container.ts +++ b/src/container.ts @@ -61,6 +61,8 @@ import { RebaseEditorProvider } from './webviews/rebase/rebaseEditor'; import { SettingsWebview } from './webviews/settings/settingsWebview'; import { WelcomeWebview } from './webviews/welcome/welcomeWebview'; +export type Environment = 'dev' | 'staging' | 'production'; + export class Container { static #instance: Container | undefined; static #proxy = new Proxy({} as Container, { @@ -360,7 +362,7 @@ export class Container { } @memoize() - get env(): 'dev' | 'staging' | 'production' { + get env(): Environment { if (this.prereleaseOrDebugging) { const env = configuration.getAny('gitkraken.env'); if (env === 'dev') return 'dev'; diff --git a/src/plus/subscription/authenticationProvider.ts b/src/plus/subscription/authenticationProvider.ts index aa3b488..86fcf7d 100644 --- a/src/plus/subscription/authenticationProvider.ts +++ b/src/plus/subscription/authenticationProvider.ts @@ -5,7 +5,7 @@ import type { } from 'vscode'; import { authentication, Disposable, EventEmitter, extensions, window } from 'vscode'; import { uuid } from '@env/crypto'; -import type { Container } from '../../container'; +import type { Container, Environment } from '../../container'; import { debug } from '../../system/decorators/log'; import { Logger } from '../../system/logger'; import { getLogScope } from '../../system/logger.scope'; @@ -50,7 +50,7 @@ export class SubscriptionAuthenticationProvider implements AuthenticationProvide this._disposable.dispose(); } - private get secretStorageKey(): string { + private get secretStorageKey(): `gitlens.plus.auth:${Environment}` { return `gitlens.plus.auth:${this.container.env}`; } diff --git a/src/storage.ts b/src/storage.ts index 1071b12..f749baa 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,6 +1,7 @@ import type { Disposable, Event, ExtensionContext, SecretStorageChangeEvent } from 'vscode'; import { EventEmitter } from 'vscode'; import type { ViewShowBranchComparison } from './config'; +import type { Environment } from './container'; import type { StoredSearchQuery } from './git/search'; import type { Subscription } from './subscription'; 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 { Version = 'gitlens:synced:version',