Refactored azureBlobStorage, changelog, techdocs-backend config
Signed-off-by: titanventura <aswath7862001@gmail.com>
This commit is contained in:
@@ -1,69 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs-node': minor
|
||||
'@backstage/plugin-techdocs-backend': minor
|
||||
---
|
||||
|
||||
Add azurite support in techdocs through `techdocs.publisher.azureBlobStorage.azuriteConnectionString`
|
||||
|
||||
These changes are **required** to `plugins/techdocs-node/src/stages/publish/azureBlobStorage.ts` and `docs/features/techdocs/configuration.md`
|
||||
|
||||
```diff
|
||||
diff --git a/docs/features/techdocs/configuration.md b/docs/features/techdocs/configuration.md
|
||||
index 49ee9d7..a8d302c 100644
|
||||
--- a/docs/features/techdocs/configuration.md
|
||||
+++ b/docs/features/techdocs/configuration.md
|
||||
@@ -158,6 +158,11 @@ techdocs:
|
||||
# (Required) Azure Blob Storage Container Name
|
||||
containerName: 'techdocs-storage'
|
||||
|
||||
+ # (Optional) Azurite connection string for local testing.
|
||||
+ # Defaults to undefined
|
||||
+ # if provided, takes higher priority, 'techdocs.publisher.azureBlobStorage.credentials' will become irrelevant
|
||||
+ azuriteConnectionString: ''
|
||||
+
|
||||
# (Required) An account name is required to write to a storage blob container.
|
||||
# https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key
|
||||
credentials:
|
||||
diff --git a/plugins/techdocs-node/src/stages/publish/azureBlobStorage.ts b/plugins/techdocs-node/src/stages/publish/azureBlobStorage.ts
|
||||
index bcbc10a..5f19b80 100644
|
||||
--- a/plugins/techdocs-node/src/stages/publish/azureBlobStorage.ts
|
||||
+++ b/plugins/techdocs-node/src/stages/publish/azureBlobStorage.ts
|
||||
@@ -78,6 +78,26 @@ export class AzureBlobStoragePublish implements PublisherBase {
|
||||
);
|
||||
}
|
||||
|
||||
+ const legacyPathCasing =
|
||||
+ config.getOptionalBoolean(
|
||||
+ 'techdocs.legacyUseCaseSensitiveTripletPaths',
|
||||
+ ) || false;
|
||||
+
|
||||
+ // Give more priority for azurite, if configured, return the AzureBlobStoragePublish object here itself
|
||||
+ const azuriteConnString = config.getOptionalString(
|
||||
+ 'techdocs.publisher.azureBlobStorage.azuriteConnectionString',
|
||||
+ );
|
||||
+ if (azuriteConnString) {
|
||||
+ const storageClient =
|
||||
+ BlobServiceClient.fromConnectionString(azuriteConnString);
|
||||
+ return new AzureBlobStoragePublish({
|
||||
+ storageClient: storageClient,
|
||||
+ containerName: containerName,
|
||||
+ legacyPathCasing: legacyPathCasing,
|
||||
+ logger: logger,
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
let accountName = '';
|
||||
try {
|
||||
accountName = config.getString(
|
||||
@@ -108,11 +128,6 @@ export class AzureBlobStoragePublish implements PublisherBase {
|
||||
credential,
|
||||
);
|
||||
|
||||
- const legacyPathCasing =
|
||||
- config.getOptionalBoolean(
|
||||
- 'techdocs.legacyUseCaseSensitiveTripletPaths',
|
||||
- ) || false;
|
||||
-
|
||||
return new AzureBlobStoragePublish({
|
||||
storageClient: storageClient,
|
||||
containerName: containerName,
|
||||
```
|
||||
Add a `techdocs.publisher.azureBlobStorage.connectionString` app-config setting, which can be leveraged for improved Azurite support.
|
||||
|
||||
Vendored
+6
-1
@@ -198,7 +198,12 @@ export interface Config {
|
||||
*/
|
||||
azureBlobStorage?: {
|
||||
/**
|
||||
* (Required) Credentials used to access a storage container.
|
||||
* (Optional) Connection string of the storage container.
|
||||
* @visibility secret
|
||||
*/
|
||||
connectionString: string;
|
||||
/**
|
||||
* (Optional) Credentials used to access a storage container.
|
||||
* @visibility secret
|
||||
*/
|
||||
credentials: {
|
||||
|
||||
@@ -66,6 +66,7 @@ export class AzureBlobStoragePublish implements PublisherBase {
|
||||
}
|
||||
|
||||
static fromConfig(config: Config, logger: Logger): PublisherBase {
|
||||
let storageClient: BlobServiceClient;
|
||||
let containerName = '';
|
||||
try {
|
||||
containerName = config.getString(
|
||||
@@ -87,49 +88,43 @@ export class AzureBlobStoragePublish implements PublisherBase {
|
||||
const connectionStringKey =
|
||||
'techdocs.publisher.azureBlobStorage.connectionString';
|
||||
const connectionString = config.getOptionalString(connectionStringKey);
|
||||
|
||||
if (connectionString) {
|
||||
logger.info(
|
||||
`using ${connectionStringKey} string to create BlobServiceClient`,
|
||||
`Using '${connectionStringKey}' configuration to create storage client`,
|
||||
);
|
||||
const storageClient =
|
||||
BlobServiceClient.fromConnectionString(connectionString);
|
||||
return new AzureBlobStoragePublish({
|
||||
storageClient: storageClient,
|
||||
containerName: containerName,
|
||||
legacyPathCasing: legacyPathCasing,
|
||||
logger: logger,
|
||||
});
|
||||
}
|
||||
|
||||
let accountName = '';
|
||||
try {
|
||||
accountName = config.getString(
|
||||
'techdocs.publisher.azureBlobStorage.credentials.accountName',
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
"Since techdocs.publisher.type is set to 'azureBlobStorage' in your app config, " +
|
||||
'techdocs.publisher.azureBlobStorage.credentials.accountName is required.',
|
||||
);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
credential = new StorageSharedKeyCredential(accountName, accountKey);
|
||||
storageClient = BlobServiceClient.fromConnectionString(connectionString);
|
||||
} else {
|
||||
credential = new DefaultAzureCredential();
|
||||
}
|
||||
let accountName = '';
|
||||
try {
|
||||
accountName = config.getString(
|
||||
'techdocs.publisher.azureBlobStorage.credentials.accountName',
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
"Since techdocs.publisher.type is set to 'azureBlobStorage' in your app config, " +
|
||||
'techdocs.publisher.azureBlobStorage.credentials.accountName is required.',
|
||||
);
|
||||
}
|
||||
|
||||
const storageClient = new BlobServiceClient(
|
||||
`https://${accountName}.blob.core.windows.net`,
|
||||
credential,
|
||||
);
|
||||
// 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) {
|
||||
credential = new StorageSharedKeyCredential(accountName, accountKey);
|
||||
} else {
|
||||
credential = new DefaultAzureCredential();
|
||||
}
|
||||
|
||||
storageClient = new BlobServiceClient(
|
||||
`https://${accountName}.blob.core.windows.net`,
|
||||
credential,
|
||||
);
|
||||
}
|
||||
|
||||
return new AzureBlobStoragePublish({
|
||||
storageClient: storageClient,
|
||||
|
||||
Reference in New Issue
Block a user