From 0024d6d8c0c44ce074cc047729c77fea3448fa47 Mon Sep 17 00:00:00 2001 From: vitorgrenzel Date: Mon, 25 Jan 2021 10:01:30 -0300 Subject: [PATCH] feat(techdocs-common): update Azure Blob Storage --- docs/features/techdocs/using-cloud-storage.md | 6 ++-- .../src/stages/publish/azureBlobStorage.ts | 9 +++--- .../src/stages/publish/publish.test.ts | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/docs/features/techdocs/using-cloud-storage.md b/docs/features/techdocs/using-cloud-storage.md index f384270379..393e478302 100644 --- a/docs/features/techdocs/using-cloud-storage.md +++ b/docs/features/techdocs/using-cloud-storage.md @@ -215,7 +215,7 @@ techdocs: **2. Create an Azure Blob Storage Container** Create a dedicated container for TechDocs sites. -[Refer to the official documentation](https://docs.microsoft.com/pt-br/azure/storage/blobs/storage-quickstart-blobs-portal). +[Refer to the official documentation](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal). TechDocs will publish documentation to this container and will fetch files from here to serve documentation in Backstage. Note that the container names are @@ -240,7 +240,9 @@ your `app-config.yaml` to the your account name. The storage blob client will automatically use the environment variable `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET` to authenticate with Azure Blob Storage. -https://docs.microsoft.com/pt-br/azure/storage/common/storage-auth-aad for more +[Steps to create the service where the variables can be retrieved from](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal). + +https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad for more details. ```yaml diff --git a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts index abfa9d71bf..1b4e59a714 100644 --- a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts +++ b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts @@ -61,15 +61,14 @@ export class AzureBlobStoragePublish implements PublisherBase { ); } - // Credentials is an optional config. If missing, default Azure Blob Storage environment variables - // https://docs.microsoft.com/pt-br/azure/storage/common/storage-auth-aad-app + // Credentials is an optional config. If missing, default Azure Blob Storage environment variables will be used. + // https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-app const accountKey = config.getOptionalString( 'techdocs.publisher.azureBlobStorage.credentials.accountKey', ); let credential; if (accountKey) { - console.log('accountKey =>', accountKey); credential = new StorageSharedKeyCredential(accountName, accountKey); } else { credential = new DefaultAzureCredential(); @@ -91,8 +90,8 @@ export class AzureBlobStoragePublish implements PublisherBase { .catch(reason => { logger.error( `Could not retrieve metadata about the Azure Blob Storage container ${containerName}. ` + - 'Make sure the Azure project and the container exists and the access key located at the path ' + - "techdocs.publisher.azureBlobStorage.credentials defined in app config has the role 'Storage Object Creator'. " + + 'Make sure that the Azure project and container exist and the access key is setup correctly ' + + 'techdocs.publisher.azureBlobStorage.credentials defined in app config has correct permissions. ' + 'Refer to https://backstage.io/docs/features/techdocs/using-cloud-storage', ); throw new Error( diff --git a/packages/techdocs-common/src/stages/publish/publish.test.ts b/packages/techdocs-common/src/stages/publish/publish.test.ts index 4ae59a597e..d1faf82b78 100644 --- a/packages/techdocs-common/src/stages/publish/publish.test.ts +++ b/packages/techdocs-common/src/stages/publish/publish.test.ts @@ -31,6 +31,10 @@ const discovery: jest.Mocked = { }; describe('Publisher', () => { + beforeEach(() => { + jest.resetModules(); // clear the cache + }); + it('should create local publisher by default', async () => { const mockConfig = new ConfigReader({ techdocs: { @@ -130,4 +134,31 @@ describe('Publisher', () => { }); expect(publisher).toBeInstanceOf(AzureBlobStoragePublish); }); + + it('should create Azure Blob Storage publisher from environment variables', async () => { + process.env.AZURE_TENANT_ID = 'AZURE_TENANT_ID'; + process.env.AZURE_CLIENT_ID = 'AZURE_CLIENT_ID'; + process.env.AZURE_CLIENT_SECRET = 'AZURE_CLIENT_SECRET'; + + const mockConfig = new ConfigReader({ + techdocs: { + requestUrl: 'http://localhost:7000', + publisher: { + type: 'azureBlobStorage', + azureBlobStorage: { + credentials: { + accountName: 'accountName', + }, + containerName: 'containerName', + }, + }, + }, + }); + + const publisher = await Publisher.fromConfig(mockConfig, { + logger, + discovery, + }); + expect(publisher).toBeInstanceOf(AzureBlobStoragePublish); + }); });