added handling logic for multiple integrations and added docs on how to configure the plugin; added api report

Signed-off-by: Nikunj Hudka <nikunjhudka123@gmail.com>
This commit is contained in:
Nikunj Hudka
2024-11-13 00:55:46 -04:00
parent 68464c85be
commit c105e55582
16 changed files with 327 additions and 38 deletions
+75
View File
@@ -3,9 +3,12 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AnonymousCredential } from '@azure/storage-blob';
import { Config } from '@backstage/config';
import { ConsumedResponse } from '@backstage/errors';
import { RestEndpointMethodTypes } from '@octokit/rest';
import { StorageSharedKeyCredential } from '@azure/storage-blob';
import { TokenCredential } from '@azure/identity';
// @public
export class AwsCodeCommitIntegration implements ScmIntegration {
@@ -70,6 +73,43 @@ export type AwsS3IntegrationConfig = {
externalId?: string;
};
// @public
export type AzureBlobStorageIntegrationConfig = {
accountName?: string;
accountKey?: string;
sasToken?: string;
connectionString?: string;
endpointSuffix?: string;
host: string;
endpoint?: string;
aadCredential?: {
clientId: string;
tenantId: string;
clientSecret: string;
};
};
// @public
export class AzureBlobStorageIntergation implements ScmIntegration {
constructor(integrationConfig: AzureBlobStorageIntegrationConfig);
// (undocumented)
get config(): AzureBlobStorageIntegrationConfig;
// (undocumented)
static factory: ScmIntegrationsFactory<AzureBlobStorageIntergation>;
// (undocumented)
resolveEditUrl(url: string): string;
// (undocumented)
resolveUrl(options: {
url: string;
base: string;
lineNumber?: number | undefined;
}): string;
// (undocumented)
get title(): string;
// (undocumented)
get type(): string;
}
// @public
export type AzureClientSecretCredential = AzureCredentialBase & {
kind: 'ClientSecret';
@@ -84,6 +124,16 @@ export type AzureCredentialBase = {
organizations?: string[];
};
// @public
export interface AzureCredentialsManager {
// (undocumented)
getCredentials(
accountName: string,
): Promise<
TokenCredential | StorageSharedKeyCredential | AnonymousCredential
>;
}
// @public
export type AzureDevOpsCredential =
| AzureClientSecretCredential
@@ -257,6 +307,15 @@ export function buildGerritGitilesArchiveUrl(
filePath: string,
): string;
// @public
export class DefaultAzureCredentialsManager implements AzureCredentialsManager {
static fromIntegrations(
integrations: ScmIntegrationRegistry,
): DefaultAzureCredentialsManager;
// (undocumented)
getCredentials(accountName: string): Promise<TokenCredential>;
}
// @public
export class DefaultAzureDevOpsCredentialsProvider
implements AzureDevOpsCredentialsProvider
@@ -723,6 +782,8 @@ export interface IntegrationsByType {
awsS3: ScmIntegrationsGroup<AwsS3Integration>;
// (undocumented)
azure: ScmIntegrationsGroup<AzureIntegration>;
// (undocumented)
azureBlobStorage: ScmIntegrationsGroup<AzureBlobStorageIntergation>;
// @deprecated (undocumented)
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
// (undocumented)
@@ -826,6 +887,16 @@ export function readAwsS3IntegrationConfigs(
configs: Config[],
): AwsS3IntegrationConfig[];
// @public
export function readAzureBlobStorageIntegrationConfig(
config: Config,
): AzureBlobStorageIntegrationConfig;
// @public
export function readAzureBlobStorageIntegrationConfigs(
configs: Config[],
): AzureBlobStorageIntegrationConfig[];
// @public
export function readAzureIntegrationConfig(
config: Config,
@@ -940,6 +1011,8 @@ export interface ScmIntegrationRegistry
awsS3: ScmIntegrationsGroup<AwsS3Integration>;
// (undocumented)
azure: ScmIntegrationsGroup<AzureIntegration>;
// (undocumented)
azureBlobStorage: ScmIntegrationsGroup<AzureBlobStorageIntergation>;
// @deprecated (undocumented)
bitbucket: ScmIntegrationsGroup<BitbucketIntegration>;
// (undocumented)
@@ -973,6 +1046,8 @@ export class ScmIntegrations implements ScmIntegrationRegistry {
get awsS3(): ScmIntegrationsGroup<AwsS3Integration>;
// (undocumented)
get azure(): ScmIntegrationsGroup<AzureIntegration>;
// (undocumented)
get azureBlobStorage(): ScmIntegrationsGroup<AzureBlobStorageIntergation>;
// @deprecated (undocumented)
get bitbucket(): ScmIntegrationsGroup<BitbucketIntegration>;
// (undocumented)
@@ -21,6 +21,11 @@ import {
readAzureBlobStorageIntegrationConfigs,
} from './config';
/**
* Microsoft Azure Blob storage based integration.
*
* @public
*/
export class AzureBlobStorageIntergation implements ScmIntegration {
static factory: ScmIntegrationsFactory<AzureBlobStorageIntergation> = ({
config,
@@ -23,26 +23,58 @@ import { AzureBlobStorageIntegrationConfig } from './config';
import { AzureCredentialsManager } from './types';
import { ScmIntegrationRegistry } from '../registry';
/**
* Default implementation of AzureCredentialsManager that supports multiple Azure Blob Storage integrations.
* @public
*/
export class DefaultAzureCredentialsManager implements AzureCredentialsManager {
private config: AzureBlobStorageIntegrationConfig;
private cachedCredentials: Map<string, TokenCredential>;
constructor(config: AzureBlobStorageIntegrationConfig) {
this.config = config;
private constructor(
private readonly configProviders: Map<
string,
AzureBlobStorageIntegrationConfig
>,
) {
this.cachedCredentials = new Map<string, TokenCredential>();
}
/**
* Creates an instance of DefaultAzureCredentialsManager from a Backstage Config.
* Creates an instance of DefaultAzureCredentialsManager from a Backstage integration registry.
*/
static fromIntegrations(
integration: ScmIntegrationRegistry,
integrations: ScmIntegrationRegistry,
): DefaultAzureCredentialsManager {
const azureConfig = integration.azureBlobStorage.list().length
? integration.azureBlobStorage.list()[0].config
: { host: 'blob.core.windows.net' }; // Default to Azure Blob Storage host if no config found
const configProviders = integrations.azureBlobStorage
.list()
.reduce((acc, integration) => {
acc.set(
integration.config.accountName || 'default',
integration.config,
);
return acc;
}, new Map<string, AzureBlobStorageIntegrationConfig>());
return new DefaultAzureCredentialsManager(azureConfig);
return new DefaultAzureCredentialsManager(configProviders);
}
private createCredential(
config: AzureBlobStorageIntegrationConfig,
): TokenCredential {
if (
config.aadCredential &&
config.aadCredential.clientId &&
config.aadCredential.clientSecret &&
config.aadCredential.tenantId
) {
return new ClientSecretCredential(
config.aadCredential.tenantId,
config.aadCredential.clientId,
config.aadCredential.clientSecret,
);
}
return new DefaultAzureCredential();
}
async getCredentials(accountName: string): Promise<TokenCredential> {
@@ -50,23 +82,13 @@ export class DefaultAzureCredentialsManager implements AzureCredentialsManager {
return this.cachedCredentials.get(accountName)!;
}
let credential: TokenCredential;
if (
this.config.aadCredential &&
this.config.aadCredential.clientId &&
this.config.aadCredential.clientSecret &&
this.config.aadCredential.tenantId
) {
credential = new ClientSecretCredential(
this.config.aadCredential.tenantId,
this.config.aadCredential.clientId,
this.config.aadCredential.clientSecret,
);
} else {
credential = new DefaultAzureCredential();
const config = this.configProviders.get(accountName);
if (!config) {
throw new Error(`No configuration found for account: ${accountName}`);
}
const credential = this.createCredential(config);
// Cache the credentials for future use
this.cachedCredentials.set(accountName, credential);
@@ -20,6 +20,12 @@ import {
AnonymousCredential,
} from '@azure/storage-blob';
/**
* This allows implementations to be provided to retrieve Azure Storage accounts credentials.
*
* @public
*
*/
export interface AzureCredentialsManager {
getCredentials(
accountName: string,