Skip to content

Commit

Permalink
use az default identity
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardo-devis-agullo committed Jun 17, 2024
1 parent f05163c commit 0566a8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/oc-azure-storage-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"license": "MIT",
"dependencies": {
"@azure/identity": "^4.2.1",
"@azure/storage-blob": "12.11.0",
"azure-storage": "^2.8.1",
"fs-extra": "8.1.0",
Expand Down
28 changes: 13 additions & 15 deletions packages/oc-azure-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@azure/storage-blob';
import Cache from 'nice-cache';
import fs from 'fs-extra';
import { DefaultAzureCredential } from '@azure/identity';
import nodeDir, { PathsResult } from 'node-dir';
import { promisify } from 'util';
import {
Expand Down Expand Up @@ -36,18 +37,13 @@ async function streamToBuffer(readableStream: NodeJS.ReadableStream) {
export interface AzureConfig extends StorageAdapterBaseConfig {
publicContainerName: string;
privateContainerName: string;
accountName: string;
accountKey: string;
accountName?: string;
accountKey?: string;
}

export default function azureAdapter(conf: AzureConfig): StorageAdapter {
const isValid = () => {
if (
!conf.publicContainerName ||
!conf.privateContainerName ||
!conf.accountName ||
!conf.accountKey
) {
if (!conf.publicContainerName || !conf.privateContainerName) {
return false;
}
return true;
Expand All @@ -62,15 +58,12 @@ export default function azureAdapter(conf: AzureConfig): StorageAdapter {

const getClient = () => {
if (!client) {
const sharedKeyCredential = new StorageSharedKeyCredential(
conf.accountName,
conf.accountKey
);
client = new BlobServiceClient(
`https://${conf.accountName}.blob.core.windows.net`,
sharedKeyCredential
conf.accountName && conf.accountKey
? new StorageSharedKeyCredential(conf.accountName, conf.accountKey)
: new DefaultAzureCredential()
);

}
return client;
};
Expand Down Expand Up @@ -233,7 +226,12 @@ export default function azureAdapter(conf: AzureConfig): StorageAdapter {
return result;
};

const putFile = (filePath: string, fileName: string, isPrivate: boolean, client: BlobServiceClient) => {
const putFile = (
filePath: string,
fileName: string,
isPrivate: boolean,
client: BlobServiceClient
) => {
const stream = fs.createReadStream(filePath);
return putFileContent(stream, fileName, isPrivate, client);
};
Expand Down

0 comments on commit 0566a8c

Please sign in to comment.