|
1 | 1 | import type { CancellationToken, Disposable, Event, Uri } from 'vscode';
|
2 | 2 | import { authentication, EventEmitter, window } from 'vscode';
|
3 | 3 | import type { IntegrationId } from '../../../constants.integrations';
|
4 |
| -import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations'; |
5 |
| -import type { IntegrationAuthenticationKeys, StoredConfiguredIntegrationDescriptor } from '../../../constants.storage'; |
| 4 | +import { HostingIntegrationId } from '../../../constants.integrations'; |
| 5 | +import type { IntegrationAuthenticationKeys } from '../../../constants.storage'; |
6 | 6 | import type { Sources } from '../../../constants.telemetry';
|
7 | 7 | import type { Container } from '../../../container';
|
8 |
| -import { gate } from '../../../system/decorators/-webview/gate'; |
9 |
| -import { debug, log } from '../../../system/decorators/log'; |
| 8 | +import { debug } from '../../../system/decorators/log'; |
10 | 9 | import type { DeferredEventExecutor } from '../../../system/event';
|
11 | 10 | import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils';
|
12 |
| -import { |
13 |
| - isCloudSelfHostedIntegrationId, |
14 |
| - isSelfHostedIntegrationId, |
15 |
| - supportedIntegrationIds, |
16 |
| -} from '../providers/models'; |
17 |
| -import type { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from './models'; |
| 11 | +import { isCloudSelfHostedIntegrationId, isSelfHostedIntegrationId } from '../providers/models'; |
| 12 | +import type { IntegrationAuthenticationService } from './integrationAuthenticationService'; |
| 13 | +import type { ProviderAuthenticationSession } from './models'; |
18 | 14 | import { isSupportedCloudIntegrationId } from './models';
|
19 | 15 |
|
20 | 16 | const maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)
|
@@ -458,7 +454,7 @@ export abstract class CloudIntegrationAuthenticationProvider<
|
458 | 454 | }
|
459 | 455 | }
|
460 | 456 |
|
461 |
| -class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvider { |
| 457 | +export class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvider { |
462 | 458 | constructor(
|
463 | 459 | container: Container,
|
464 | 460 | authenticationService: IntegrationAuthenticationService,
|
@@ -495,171 +491,6 @@ class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvid
|
495 | 491 | }
|
496 | 492 | }
|
497 | 493 |
|
498 |
| -export class IntegrationAuthenticationService implements Disposable { |
499 |
| - private readonly providers = new Map<IntegrationId, IntegrationAuthenticationProvider>(); |
500 |
| - private _configured?: Map<IntegrationId, ConfiguredIntegrationDescriptor[]>; |
501 |
| - |
502 |
| - constructor(private readonly container: Container) {} |
503 |
| - |
504 |
| - dispose() { |
505 |
| - this.providers.forEach(p => void p.dispose()); |
506 |
| - this.providers.clear(); |
507 |
| - } |
508 |
| - |
509 |
| - get configured(): Map<IntegrationId, ConfiguredIntegrationDescriptor[]> { |
510 |
| - if (this._configured == null) { |
511 |
| - this._configured = new Map(); |
512 |
| - const storedConfigured = this.container.storage.get('integrations:configured'); |
513 |
| - for (const [id, configured] of Object.entries(storedConfigured ?? {})) { |
514 |
| - if (configured == null) continue; |
515 |
| - const descriptors = configured.map(d => ({ |
516 |
| - ...d, |
517 |
| - expiresAt: d.expiresAt ? new Date(d.expiresAt) : undefined, |
518 |
| - })); |
519 |
| - this._configured.set(id as IntegrationId, descriptors); |
520 |
| - } |
521 |
| - } |
522 |
| - |
523 |
| - return this._configured; |
524 |
| - } |
525 |
| - |
526 |
| - private async storeConfigured() { |
527 |
| - // We need to convert the map to a record to store |
528 |
| - const configured: Record<string, StoredConfiguredIntegrationDescriptor[]> = {}; |
529 |
| - for (const [id, descriptors] of this.configured) { |
530 |
| - configured[id] = descriptors.map(d => ({ |
531 |
| - ...d, |
532 |
| - expiresAt: d.expiresAt |
533 |
| - ? d.expiresAt instanceof Date |
534 |
| - ? d.expiresAt.toISOString() |
535 |
| - : d.expiresAt |
536 |
| - : undefined, |
537 |
| - })); |
538 |
| - } |
539 |
| - |
540 |
| - await this.container.storage.store('integrations:configured', configured); |
541 |
| - } |
542 |
| - |
543 |
| - async addConfigured(descriptor: ConfiguredIntegrationDescriptor) { |
544 |
| - const descriptors = this.configured.get(descriptor.integrationId) ?? []; |
545 |
| - // Only add if one does not exist |
546 |
| - if (descriptors.some(d => d.domain === descriptor.domain && d.integrationId === descriptor.integrationId)) { |
547 |
| - return; |
548 |
| - } |
549 |
| - descriptors.push(descriptor); |
550 |
| - this.configured.set(descriptor.integrationId, descriptors); |
551 |
| - await this.storeConfigured(); |
552 |
| - } |
553 |
| - |
554 |
| - async removeConfigured(descriptor: Pick<ConfiguredIntegrationDescriptor, 'integrationId' | 'domain'>) { |
555 |
| - const descriptors = this.configured.get(descriptor.integrationId); |
556 |
| - if (descriptors == null) return; |
557 |
| - const index = descriptors.findIndex( |
558 |
| - d => d.domain === descriptor.domain && d.integrationId === descriptor.integrationId, |
559 |
| - ); |
560 |
| - if (index === -1) return; |
561 |
| - |
562 |
| - descriptors.splice(index, 1); |
563 |
| - this.configured.set(descriptor.integrationId, descriptors); |
564 |
| - |
565 |
| - await this.storeConfigured(); |
566 |
| - } |
567 |
| - |
568 |
| - async get(providerId: IntegrationId): Promise<IntegrationAuthenticationProvider> { |
569 |
| - return this.ensureProvider(providerId); |
570 |
| - } |
571 |
| - |
572 |
| - @log() |
573 |
| - async reset() { |
574 |
| - // TODO: This really isn't ideal, since it will only work for "cloud" providers as we won't have any more specific descriptors |
575 |
| - await Promise.allSettled( |
576 |
| - supportedIntegrationIds.map(async providerId => (await this.ensureProvider(providerId)).deleteSession()), |
577 |
| - ); |
578 |
| - } |
579 |
| - |
580 |
| - supports(providerId: string): boolean { |
581 |
| - switch (providerId) { |
582 |
| - case HostingIntegrationId.AzureDevOps: |
583 |
| - case HostingIntegrationId.Bitbucket: |
584 |
| - case SelfHostedIntegrationId.GitHubEnterprise: |
585 |
| - case HostingIntegrationId.GitLab: |
586 |
| - case SelfHostedIntegrationId.GitLabSelfHosted: |
587 |
| - case IssueIntegrationId.Jira: |
588 |
| - return true; |
589 |
| - case HostingIntegrationId.GitHub: |
590 |
| - return isSupportedCloudIntegrationId(HostingIntegrationId.GitHub); |
591 |
| - default: |
592 |
| - return false; |
593 |
| - } |
594 |
| - } |
595 |
| - |
596 |
| - @gate() |
597 |
| - private async ensureProvider(providerId: IntegrationId): Promise<IntegrationAuthenticationProvider> { |
598 |
| - let provider = this.providers.get(providerId); |
599 |
| - if (provider == null) { |
600 |
| - switch (providerId) { |
601 |
| - case HostingIntegrationId.AzureDevOps: |
602 |
| - provider = new ( |
603 |
| - await import(/* webpackChunkName: "integrations" */ './azureDevOps') |
604 |
| - ).AzureDevOpsAuthenticationProvider(this.container, this); |
605 |
| - break; |
606 |
| - case HostingIntegrationId.Bitbucket: |
607 |
| - provider = new ( |
608 |
| - await import(/* webpackChunkName: "integrations" */ './bitbucket') |
609 |
| - ).BitbucketAuthenticationProvider(this.container, this); |
610 |
| - break; |
611 |
| - case HostingIntegrationId.GitHub: |
612 |
| - provider = isSupportedCloudIntegrationId(HostingIntegrationId.GitHub) |
613 |
| - ? new ( |
614 |
| - await import(/* webpackChunkName: "integrations" */ './github') |
615 |
| - ).GitHubAuthenticationProvider(this.container, this) |
616 |
| - : new BuiltInAuthenticationProvider(this.container, this, providerId); |
617 |
| - |
618 |
| - break; |
619 |
| - case SelfHostedIntegrationId.CloudGitHubEnterprise: |
620 |
| - provider = new ( |
621 |
| - await import(/* webpackChunkName: "integrations" */ './github') |
622 |
| - ).GitHubEnterpriseCloudAuthenticationProvider(this.container, this); |
623 |
| - break; |
624 |
| - case SelfHostedIntegrationId.GitHubEnterprise: |
625 |
| - provider = new ( |
626 |
| - await import(/* webpackChunkName: "integrations" */ './github') |
627 |
| - ).GitHubEnterpriseAuthenticationProvider(this.container, this); |
628 |
| - break; |
629 |
| - case HostingIntegrationId.GitLab: |
630 |
| - provider = isSupportedCloudIntegrationId(HostingIntegrationId.GitLab) |
631 |
| - ? new ( |
632 |
| - await import(/* webpackChunkName: "integrations" */ './gitlab') |
633 |
| - ).GitLabCloudAuthenticationProvider(this.container, this) |
634 |
| - : new ( |
635 |
| - await import(/* webpackChunkName: "integrations" */ './gitlab') |
636 |
| - ).GitLabLocalAuthenticationProvider(this.container, this, HostingIntegrationId.GitLab); |
637 |
| - break; |
638 |
| - case SelfHostedIntegrationId.CloudGitLabSelfHosted: |
639 |
| - provider = new ( |
640 |
| - await import(/* webpackChunkName: "integrations" */ './gitlab') |
641 |
| - ).GitLabSelfHostedCloudAuthenticationProvider(this.container, this); |
642 |
| - break; |
643 |
| - case SelfHostedIntegrationId.GitLabSelfHosted: |
644 |
| - provider = new ( |
645 |
| - await import(/* webpackChunkName: "integrations" */ './gitlab') |
646 |
| - ).GitLabLocalAuthenticationProvider(this.container, this, SelfHostedIntegrationId.GitLabSelfHosted); |
647 |
| - break; |
648 |
| - case IssueIntegrationId.Jira: |
649 |
| - provider = new ( |
650 |
| - await import(/* webpackChunkName: "integrations" */ './jira') |
651 |
| - ).JiraAuthenticationProvider(this.container, this); |
652 |
| - break; |
653 |
| - default: |
654 |
| - provider = new BuiltInAuthenticationProvider(this.container, this, providerId); |
655 |
| - } |
656 |
| - this.providers.set(providerId, provider); |
657 |
| - } |
658 |
| - |
659 |
| - return provider; |
660 |
| - } |
661 |
| -} |
662 |
| - |
663 | 494 | function convertStoredSessionToSession(
|
664 | 495 | storedSession: StoredSession,
|
665 | 496 | cloudIfMissing: boolean,
|
|
0 commit comments