Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: azure-storage-blob driver #154

Merged
merged 20 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,53 @@ The driver supports the following authentication methods:
- `databaseName`: The name of the database to use. Defaults to `unstorage`.
- `collectionName`: The name of the collection to use. Defaults to `unstorage`.

## `azure-storage-blob`

Store data in a Azure blob storage [storage-blob](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob).

This driver stores KV information in a Azure blob storage blob. The same container is used for all entries. Each entry is stored in a separate blob with the key as the blob name and the value as the blob content.

To use it, you will need to install `@azure/storage-blob` and `@azure/identity` in your project:

```json
{
"dependencies": {
"@azure/storage-blob": "^12.12.0",
"@azure/identity": "^3.1.3"
}
}
```

Please make sure that the container you want to use exists in your storage account.

```js
import { createStorage } from "unstorage";
import azureStorageBlobDriver from "unstorage/drivers/azure-storage-blob";
const storage = createStorage({
driver: azureStorageBlobDriver({
accountName: "myazurestorageaccount",
}),
});
```

**Authentication:**

The driver supports the following authentication methods:

- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `Storage Blob Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.

**Options:**

- **`accountName`** (required): The name of your storage account.
- `containerName`: The name of the blob container to use. Defaults to `unstorage`.
- `accountKey`: The account key to use for authentication. This is only required if you are using `AzureNamedKeyCredential`.
- `sasKey`: The SAS token to use for authentication. This is only required if you are using `AzureSASCredential`.
- `connectionString`: The storage accounts' connection string. `accountKey` and `sasKey` take precedence.

## Making custom drivers

It is possible to extend unstorage by creating custom drives.
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,28 @@
"ofetch": "^1.0.1",
"ufo": "^1.1.0"
},
"optionalDependencies": {
"@planetscale/database": "^1.5.0",
"mongodb": "^5.0.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230221.0",
"@azure/identity": "^3.1.3",
"@azure/storage-blob": "^12.12.0",
"@cloudflare/workers-types": "^4.20230214.0",
"@planetscale/database": "^1.5.0",
"@types/jsdom": "^21.1.0",
"@types/mri": "^1.1.1",
"@types/node": "^18.14.1",
"@vitejs/plugin-vue": "^4.0.0",
"@vitest/coverage-c8": "^0.29.1",
"@vue/compiler-sfc": "^3.2.47",
"azurite": "^3.21.0",
"c8": "^7.13.0",
"changelogen": "^0.4.1",
"eslint": "^8.34.0",
"eslint-config-unjs": "^0.1.0",
"ioredis-mock": "^8.2.6",
"jiti": "^1.17.1",
"jsdom": "^21.1.0",
"monaco-editor": "^0.36.0",
"mongodb": "^5.0.1",
"mongodb-memory-server": "^8.11.4",
"monaco-editor": "^0.36.0",
"msw": "^1.1.0",
"prettier": "^2.8.4",
"types-cloudflare-worker": "^1.2.0",
Expand All @@ -84,5 +83,10 @@
"vitest": "^0.29.1",
"vue": "^3.2.47"
},
"optionalDependencies": {
"@azure/identity": "^3.1.3",
"@azure/storage-blob": "^12.12.0",
"@planetscale/database": "^1.5.0"
},
"packageManager": "[email protected]"
}
Loading