-
Notifications
You must be signed in to change notification settings - Fork 225
Add other Credentials support for Azure store #811
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
76a44cf
ee5035f
09b2dbb
b7e02ce
b7623cf
9a301b2
345d892
378eb7b
dbc843b
d72e070
6692159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,38 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "private": true, | ||
| "name": "@tus/azure-store", | ||
| "version": "2.0.0", | ||
| "description": "Azure blob storage for @tus/server", | ||
| "main": "./dist/index.js", | ||
| "exports": "./dist/index.js", | ||
| "type": "module", | ||
| "workspaces": [ | ||
| "packages/*", | ||
| "test" | ||
| "homepage": "https://github.com/tus/tus-node-server#readme", | ||
| "bugs": "https://github.com/tus/tus-node-server/issues", | ||
| "repository": "tus/tus-node-server", | ||
| "files": [ | ||
| "dist", | ||
| "src", | ||
| "!test*" | ||
| ], | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "build": "tsc --build", | ||
| "lint": "biome lint --write .", | ||
| "format": "biome format --write .", | ||
| "format:check": "biome format --error-on-warnings .", | ||
| "pretest": "tsc --build", | ||
| "test": "npm test -w ./packages", | ||
| "version": "changeset version && npm install", | ||
| "release": "gh workflow run release", | ||
| "release:local": "npm run build && changeset publish" | ||
| "test": "mocha './dist/test/*.js' --exit" | ||
| }, | ||
| "dependencies": { | ||
| "@tus/utils": "^0.6.0", | ||
| "@azure/storage-blob": "^12.24.0", | ||
| "debug": "^4.3.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "1.9.4", | ||
| "@changesets/changelog-github": "^0.5.0", | ||
| "@changesets/cli": "^2.29.2", | ||
| "typescript": "^5.8.2" | ||
| "@types/debug": "^4.1.12", | ||
| "@types/mocha": "^10.0.6", | ||
| "@types/node": "^22.13.7", | ||
| "mocha": "^11.0.1", | ||
| "should": "^13.2.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20.19.0" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,14 @@ import { | |
| type ContainerClient, | ||
| StorageSharedKeyCredential, | ||
| } from '@azure/storage-blob' | ||
| import type {TokenCredential} from '@azure/core-auth' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need a new dep just for this type? Would be great if this is not needed.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree in general to not need to add a new dependency only to get a type, but I believe it's necessary in this case to show that a user could use other credential authentication to connect to the storage account. |
||
|
|
||
| type Options = { | ||
| cache?: KvStore<Upload> | ||
| account: string | ||
| accountKey: string | ||
| containerName: string | ||
| accountKey?: string | ||
| credential?: TokenCredential | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's one or the other you should make this a discriminated union |
||
| } | ||
|
|
||
| const log = debug('tus-node-server:stores:azurestore') | ||
|
|
@@ -44,22 +46,21 @@ export class AzureStore extends DataStore { | |
| if (!options.account) { | ||
| throw new Error('Azure store must have a account') | ||
| } | ||
| if (!options.accountKey) { | ||
| throw new Error('Azure store must have a account key') | ||
| } | ||
| if (!options.containerName) { | ||
| throw new Error('Azure store must have a container name') | ||
| } | ||
| if (!options.accountKey && !options.credential) { | ||
| throw new Error('Azure store requires either accountKey or credential') | ||
| } | ||
|
|
||
| const storageAccountBaseUrl = `https://${options.account}.blob.core.windows.net` | ||
| const sharedKeyCredential = new StorageSharedKeyCredential( | ||
| options.account, | ||
| options.accountKey | ||
| ) | ||
| const credential = options.credential | ||
| ? options.credential | ||
| : new StorageSharedKeyCredential(options.account, options.accountKey!) | ||
|
|
||
| this.blobServiceClient = new BlobServiceClient( | ||
| storageAccountBaseUrl, | ||
| sharedKeyCredential | ||
| credential | ||
| ) | ||
| this.containerClient = this.blobServiceClient.getContainerClient( | ||
| options.containerName | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.