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

Use b2_authorize_account allowed bucketId as default #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions lib/actions/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.delete = function(b2, argsOrBucketId) {
// we're allowing an args object OR bucketId for backwards compatibility
let bucketId = argsOrBucketId;
if (!_.isString(argsOrBucketId)) {
bucketId = _.get(argsOrBucketId, 'bucketId');
bucketId = _.get(argsOrBucketId, 'bucketId') || b2.defaultBucketId;
}
const options = {
url: endpoints(b2).deleteBucketUrl,
Expand Down Expand Up @@ -86,6 +86,8 @@ exports.get = function(b2, args) {
data.bucketName = args.bucketName;
} else if (args.bucketId) {
data.bucketId = args.bucketId;
} else {
data.bucketId = b2.defaultBucketId;
}

const options = {
Expand All @@ -107,7 +109,7 @@ exports.update = function(b2, argsOrBucketId, undefOrBucketType) {
let bucketId = argsOrBucketId;
let bucketType = undefOrBucketType;
if (!_.isString(argsOrBucketId)) {
bucketId = _.get(argsOrBucketId, 'bucketId');
bucketId = _.get(argsOrBucketId, 'bucketId') || b2.defaultBucketId;
bucketType = _.get(argsOrBucketId, 'bucketType');
}
const options = {
Expand All @@ -132,7 +134,7 @@ exports.getUploadUrl = function(b2, argsOrBucketId) {
// we're allowing an args object OR bucketId for backwards compatibility
let bucketId = argsOrBucketId;
if (!_.isString(argsOrBucketId)) {
bucketId = _.get(argsOrBucketId, 'bucketId');
bucketId = _.get(argsOrBucketId, 'bucketId') || b2.defaultBucketId;
}
const options = {
url: endpoints(b2).getBucketUploadUrl,
Expand Down
10 changes: 5 additions & 5 deletions lib/actions/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.startLargeFile = function(b2, args) {
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
bucketId: args.bucketId,
bucketId: args.bucketId || b2.defaultBucketId,
fileName: args.fileName,
contentType: args.contentType || 'b2/x-auto'
}
Expand Down Expand Up @@ -139,7 +139,7 @@ exports.cancelLargeFile = function(b2, args) {
};

exports.listFileNames = function(b2, args) {
const bucketId = args.bucketId;
const bucketId = args.bucketId || b2.defaultBucketId;
const startFileName = args.startFileName;
const maxFileCount = args.maxFileCount;
const prefix = args.prefix;
Expand Down Expand Up @@ -167,7 +167,7 @@ exports.listFileNames = function(b2, args) {
};

exports.listFileVersions = function(b2, args) {
const bucketId = args.bucketId;
const bucketId = args.bucketId || b2.defaultBucketId;
const startFileName = args.startFileName;
const startFileId = args.startFileId;
const maxFileCount = args.maxFileCount;
Expand All @@ -193,7 +193,7 @@ exports.listFileVersions = function(b2, args) {
};

exports.hideFile = function(b2, args) {
const bucketId = args.bucketId;
const bucketId = args.bucketId || b2.defaultBucketId;
const fileName = args.fileName;

const options = {
Expand Down Expand Up @@ -239,7 +239,7 @@ exports.getFileInfo = function(b2, argsOrFileId) {
};

exports.getDownloadAuthorization = function (b2, args) {
const bucketId = args.bucketId;
const bucketId = args.bucketId || b2.defaultBucketId;
const fileNamePrefix = args.fileNamePrefix;
const validDurationInSeconds = args.validDurationInSeconds;
const b2ContentDisposition = args.b2ContentDisposition;
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports.create = function(b2, args) {
capabilities: args.capabilities,
keyName: args.keyName,
validDurationInSeconds: args.validDurationInSeconds,
bucketId: args.bucketId,
bucketId: args.bucketId || b2.defaultBucketId,
namePrefix: args.namePrefix,
}
};
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ exports.saveAuthContext = function (context, authResponse) {
context.apiUrl = authResponse.apiUrl;
context.downloadUrl = authResponse.downloadUrl;
context.accountId = authResponse.accountId;

if (authResponse.allowed) {
context.defaultBucketId = authResponse.allowed.bucketId || '';
}
};

exports.getProcessFileSuccess = function(deferred) {
Expand Down