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: support tags for bucket and object #734

Merged
merged 1 commit into from
Jan 14, 2020
Merged
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
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ All operation use es7 async/await to implement. All api is async function.
- [.putBucketEncryption(name[, options])](#putbucketencryptionbucketname-options)
- [.getBucketEncryption(name)](#getbucketencryptionbucketname-options)
- [.deleteBucketEncryption(name)](#deletebucketencryptionbucketname-options)
- tagging
- [.putBucketTags(name, tag[, options])](#putBucketTagsname-tag-options)
- [.getBucketTags(name, [, options])](#getBucketTagsname-options)
- [.deleteBucketTags(name, [, options])](#deleteBucketTagsname-options)
- [Object Operations](#object-operations)
- [.list(query[, options])](#listquery-options)
- [.put(name, file[, options])](#putname-file-options)
Expand Down Expand Up @@ -126,6 +130,9 @@ All operation use es7 async/await to implement. All api is async function.
- [.listUploads(query[, options])](#listuploadsquery-options)
- [.abortMultipartUpload(name, uploadId[, options])](#abortmultipartuploadname-uploadid-options)
- [.calculatePostSignature(policy)](#calculatePostSignaturepolicy)
- [.getObjectTagging(name, [, options])](#getObjectTaggingname-options)
- [.putObjectTagging(name, tag[, options])](#putObjectTaggingname-tag-options)
- [.deleteObjectTagging(name, [, options])](#deleteObjectTaggingname-options)
- [RTMP Operations](#rtmp-operations)
- [.putChannel(id, conf[, options])](#putchannelid-conf-options)
- [.getChannel(id[, options])](#getchannelid-options)
Expand Down Expand Up @@ -1010,6 +1017,55 @@ Success will return:

---

### .putBucketTags(name, tag[, options])

Adds tags for a bucket or modify the tags for a bucket.

parameters:

- name {String} the object name
- tag {Object} tag, eg. `{var1: value1,var2:value2}`
- [options] {Object} optional args

Success will return:

- status {Number} response status
- res {Object} response info

---

### .getBucketTags(name[, options])

Obtains the tags for a bucket.

parameters:

- name {String} the object name
- [options] {Object} optional args

Success will return:

- tag {Object} the tag of object
- res {Object} response info

---

### .deleteBucketTags(name[, options])

Deletes the tags added for a bucket.

parameters:

- name {String} the object name
- [options] {Object} optional args

Success will return:

- status {Number} response status
- res {Object} response info

---

## Object Operations

All operations function return Promise, except `signatureUrl`.
Expand Down Expand Up @@ -2567,6 +2623,56 @@ Object:
- Signature {String}
- policy {Object} response info

### .getObjectTagging(name[, options])

Obtains the tags of an object.

parameters:

- name {String} the object name
- [options] {Object} optional args

Success will return the channel information.

object:

- tag {Object} the tag of object
- res {Object} response info

### .putObjectTagging(name, tag[, options])

Configures or updates the tags of an object.

parameters:

- name {String} the object name
- tag {Object} tag, eg. `{var1: value1,var2:value2}`
- [options] {Object} optional args

Success will return the channel information.

object:

- status {Number} response status
- res {Object} response info

### .deleteObjectTagging(name[, options])

Deletes the tag of a specified object.

parameters:

- name {String} the object name
- tag {Object} tag, eg. `{var1: value1,var2:value2}`
- [options] {Object} optional args

Success will return the channel information.

object:

- status {Number} response status
- res {Object} response info

## RTMP Operations

All operations function is [async], except `getRtmpUrl`.
Expand Down
3 changes: 3 additions & 0 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ proto.deleteMulti = async function deleteMulti(names, options) {
};

merge(proto, require('../common/object/copyObject'));
merge(proto, require('../common/object/getObjectTagging'));
merge(proto, require('../common/object/putObjectTagging'));
merge(proto, require('../common/object/deleteObjectTagging'));

proto.putMeta = async function putMeta(name, meta, options) {
const copyResult = await this.copy(name, name, {
Expand Down
19 changes: 19 additions & 0 deletions lib/common/bucket/deleteBucketTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const proto = exports;
/**
* deleteBucketTags
* @param {String} name - bucket name
* @param {Object} options
*/

proto.deleteBucketTags = async function deleteBucketTags(name, options = {}) {
this._checkBucketName(name);

const params = this._bucketRequestParams('DELETE', name, 'tagging', options);
params.successStatuses = [204];
const result = await this.request(params);

return {
status: result.status,
res: result.res
};
};
30 changes: 30 additions & 0 deletions lib/common/bucket/getBucketTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const proto = exports;
const isObject = require('../utils/isObject');
/**
* getBucketTags
* @param {String} name - bucket name
* @param {Object} options
* @return {Object}
*/

proto.getBucketTags = async function getBucketTags(name, options = {}) {
this._checkBucketName(name);
const params = this._bucketRequestParams('GET', name, 'tagging', options);
params.successStatuses = [200];
const result = await this.request(params);
const Tagging = await this.parseXML(result.data);
let { Tag } = Tagging.TagSet;
Tag = Tag && isObject(Tag) ? [Tag] : Tag || [];

const tag = {};

Tag.forEach((item) => {
tag[item.Key] = item.Value;
});

return {
status: result.status,
res: result.res,
tag
};
};
13 changes: 8 additions & 5 deletions lib/common/bucket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ const merge = require('merge-descriptors');

const proto = exports;

merge(proto, require('./getBucketRequestPayment.js'));
merge(proto, require('./putBucketRequestPayment.js'));
merge(proto, require('./putBucketEncryption.js'));
merge(proto, require('./getBucketEncryption.js'));
merge(proto, require('./deleteBucketEncryption.js'));
merge(proto, require('./getBucketRequestPayment'));
merge(proto, require('./putBucketRequestPayment'));
merge(proto, require('./putBucketEncryption'));
merge(proto, require('./getBucketEncryption'));
merge(proto, require('./deleteBucketEncryption'));
merge(proto, require('./getBucketTags'));
merge(proto, require('./putBucketTags'));
merge(proto, require('./deleteBucketTags'));
38 changes: 38 additions & 0 deletions lib/common/bucket/putBucketTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const obj2xml = require('../utils/obj2xml');
const checkTag = require('../utils/checkBucketTag');

const proto = exports;
/**
* putBucketTags
* @param {Sting} name - bucket name
* @param {Object} tag - bucket tag, eg: `{a: "1", b: "2"}`
* @param {Object} options
*/

proto.putBucketTags = async function putBucketTags(name, tag, options = {}) {
this._checkBucketName(name);
checkTag(tag);
const params = this._bucketRequestParams('PUT', name, 'tagging', options);
params.successStatuses = [200];
tag = Object.keys(tag).map(key => ({
Key: key,
Value: tag[key]
}));

const paramXMLObj = {
Tagging: {
TagSet: {
Tag: tag
}
}
};

params.mime = 'xml';
params.content = obj2xml(paramXMLObj);

const result = await this.request(params);
return {
res: result.res,
status: result.status
};
};
22 changes: 22 additions & 0 deletions lib/common/object/deleteObjectTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const proto = exports;
/**
* deleteObjectTagging
* @param {String} name - object name
* @param {Object} options
*/

proto.deleteObjectTagging = async function deleteObjectTagging(
name,
options = {}
) {
options.subres = 'tagging';
name = this._objectName(name);
const params = this._objectRequestParams('DELETE', name, options);
params.successStatuses = [204];
const result = await this.request(params);

return {
status: result.status,
res: result.res
};
};
31 changes: 31 additions & 0 deletions lib/common/object/getObjectTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const proto = exports;
const isObject = require('../utils/isObject');
/**
* getObjectTagging
* @param {String} name - object name
* @param {Object} options
* @return {Object}
*/

proto.getObjectTagging = async function getObjectTagging(name, options = {}) {
options.subres = 'tagging';
name = this._objectName(name);
const params = this._objectRequestParams('GET', name, options);
params.successStatuses = [200];
const result = await this.request(params);
const Tagging = await this.parseXML(result.data);
let { Tag } = Tagging.TagSet;
Tag = Tag && isObject(Tag) ? [Tag] : Tag || [];

const tag = {};

Tag.forEach((item) => {
tag[item.Key] = item.Value;
});

return {
status: result.status,
res: result.res,
tag
};
};
3 changes: 3 additions & 0 deletions lib/common/object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ merge(proto, require('./putSymlink'));
merge(proto, require('./getObjectMeta'));
merge(proto, require('./copyObject'));
merge(proto, require('./calculatePostSignature'));
merge(proto, require('./getObjectTagging'));
merge(proto, require('./putObjectTagging'));
merge(proto, require('./deleteObjectTagging'));

40 changes: 40 additions & 0 deletions lib/common/object/putObjectTagging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const obj2xml = require('../utils/obj2xml');
const checkTag = require('../utils/checkObjectTag');

const proto = exports;
/**
* putObjectTagging
* @param {Sting} name - object name
* @param {Object} tag - object tag, eg: `{a: "1", b: "2"}`
* @param {Object} options
*/

proto.putObjectTagging = async function putObjectTagging(name, tag, options = {}) {
checkTag(tag);

options.subres = 'tagging';
name = this._objectName(name);
const params = this._objectRequestParams('PUT', name, options);
params.successStatuses = [200];
tag = Object.keys(tag).map(key => ({
Key: key,
Value: tag[key]
}));

const paramXMLObj = {
Tagging: {
TagSet: {
Tag: tag
}
}
};

params.mime = 'xml';
params.content = obj2xml(paramXMLObj);

const result = await this.request(params);
return {
res: result.res,
status: result.status
};
};
Loading