Skip to content

Commit

Permalink
Rename config integration descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Jan 15, 2025
1 parent 672297d commit 2292551
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
7 changes: 2 additions & 5 deletions src/constants.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ export type GlobalStorage = {
[key in `jira:${string}:projects`]: Stored<StoredJiraProject[] | undefined>;
};

export type StoredIntegrationConfigurations = Record<
string,
StoredConfiguredProviderAuthenticationDescriptor[] | undefined
>;
export type StoredIntegrationConfigurations = Record<string, StoredConfiguredIntegrationDescriptor[] | undefined>;

export interface StoredConfiguredProviderAuthenticationDescriptor {
export interface StoredConfiguredIntegrationDescriptor {
cloud: boolean;
integrationId: IntegrationId;
domain?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/git/remotes/remoteProviders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RemotesConfig } from '../../config';
import { SelfHostedIntegrationId } from '../../constants.integrations';
import type { Container } from '../../container';
import type { ConfiguredProviderAuthenticationDescriptor } from '../../plus/integrations/authentication/models';
import type { ConfiguredIntegrationDescriptor } from '../../plus/integrations/authentication/models';
import { Logger } from '../../system/logger';
import { configuration } from '../../system/vscode/configuration';
import { AzureDevOpsRemote } from './azure-devops';
Expand Down Expand Up @@ -77,7 +77,7 @@ const builtInProviders: RemoteProviders = [

export function loadRemoteProviders(
cfg: RemotesConfig[] | null | undefined,
configuredIntegrations?: ConfiguredProviderAuthenticationDescriptor[],
configuredIntegrations?: ConfiguredIntegrationDescriptor[],
): RemoteProviders {
const providers: RemoteProviders = [];

Expand Down
17 changes: 7 additions & 10 deletions src/plus/integrations/authentication/integrationAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { authentication, EventEmitter, window } from 'vscode';
import { wrapForForcedInsecureSSL } from '@env/fetch';
import type { IntegrationId } from '../../../constants.integrations';
import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
import type {
IntegrationAuthenticationKeys,
StoredConfiguredProviderAuthenticationDescriptor,
} from '../../../constants.storage';
import type { IntegrationAuthenticationKeys, StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
import type { Sources } from '../../../constants.telemetry';
import type { Container } from '../../../container';
import { gate } from '../../../system/decorators/gate';
import { debug, log } from '../../../system/decorators/log';
import type { DeferredEventExecutor } from '../../../system/event';
import { isSelfHostedIntegrationId, supportedIntegrationIds } from '../providers/models';
import type { ConfiguredProviderAuthenticationDescriptor, ProviderAuthenticationSession } from './models';
import type { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from './models';
import { isSupportedCloudIntegrationId } from './models';

const maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)
Expand Down Expand Up @@ -506,7 +503,7 @@ class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvid

export class IntegrationAuthenticationService implements Disposable {
private readonly providers = new Map<IntegrationId, IntegrationAuthenticationProvider>();
private _configured?: Map<IntegrationId, ConfiguredProviderAuthenticationDescriptor[]>;
private _configured?: Map<IntegrationId, ConfiguredIntegrationDescriptor[]>;

constructor(private readonly container: Container) {}

Expand All @@ -515,7 +512,7 @@ export class IntegrationAuthenticationService implements Disposable {
this.providers.clear();
}

get configured(): Map<IntegrationId, ConfiguredProviderAuthenticationDescriptor[]> {
get configured(): Map<IntegrationId, ConfiguredIntegrationDescriptor[]> {
if (this._configured == null) {
this._configured = new Map();
const storedConfigured = this.container.storage.get('integrations:configured');
Expand All @@ -534,7 +531,7 @@ export class IntegrationAuthenticationService implements Disposable {

private async storeConfigured() {
// We need to convert the map to a record to store
const configured: Record<string, StoredConfiguredProviderAuthenticationDescriptor[]> = {};
const configured: Record<string, StoredConfiguredIntegrationDescriptor[]> = {};
for (const [id, descriptors] of this.configured) {
configured[id] = descriptors.map(d => ({
...d,
Expand All @@ -549,7 +546,7 @@ export class IntegrationAuthenticationService implements Disposable {
await this.container.storage.store('integrations:configured', configured);
}

async addConfigured(descriptor: ConfiguredProviderAuthenticationDescriptor) {
async addConfigured(descriptor: ConfiguredIntegrationDescriptor) {
const descriptors = this.configured.get(descriptor.integrationId) ?? [];
// Only add if one does not exist
if (descriptors.some(d => d.domain === descriptor.domain && d.integrationId === descriptor.integrationId)) {
Expand All @@ -560,7 +557,7 @@ export class IntegrationAuthenticationService implements Disposable {
await this.storeConfigured();
}

async removeConfigured(descriptor: Pick<ConfiguredProviderAuthenticationDescriptor, 'integrationId' | 'domain'>) {
async removeConfigured(descriptor: Pick<ConfiguredIntegrationDescriptor, 'integrationId' | 'domain'>) {
const descriptors = this.configured.get(descriptor.integrationId);
if (descriptors == null) return;
const index = descriptors.findIndex(
Expand Down
2 changes: 1 addition & 1 deletion src/plus/integrations/authentication/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ProviderAuthenticationSession extends AuthenticationSession {
readonly expiresAt?: Date;
}

export interface ConfiguredProviderAuthenticationDescriptor {
export interface ConfiguredIntegrationDescriptor {
readonly cloud: boolean;
readonly integrationId: IntegrationId;
readonly domain?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { configuration } from '../../system/vscode/configuration';
import { openUrl } from '../../system/vscode/utils';
import type { SubscriptionChangeEvent } from '../gk/account/subscriptionService';
import type { IntegrationAuthenticationService } from './authentication/integrationAuthentication';
import type { ConfiguredProviderAuthenticationDescriptor } from './authentication/models';
import type { ConfiguredIntegrationDescriptor } from './authentication/models';
import {
CloudIntegrationAuthenticationUriPathPrefix,
getSupportedCloudIntegrationIds,
Expand Down Expand Up @@ -949,7 +949,7 @@ export class IntegrationService implements Disposable {
return isSelfHostedIntegrationId(id) ? (`${id}:${domain}` as const) : id;
}

getConfiguredIntegrationDescriptors(id?: IntegrationId): ConfiguredProviderAuthenticationDescriptor[] {
getConfiguredIntegrationDescriptors(id?: IntegrationId): ConfiguredIntegrationDescriptor[] {
const configured = this.authenticationService.configured;
if (id != null) return configured.get(id) ?? [];
const results = [];
Expand Down

0 comments on commit 2292551

Please sign in to comment.