feat(techdocs-common): update Azure Blob Storage
This commit is contained in:
committed by
Tiago A. Simões
parent
0be9694aa6
commit
0024d6d8c0
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -31,6 +31,10 @@ const discovery: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
};
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user