Skip to content

Commit

Permalink
feat: worm
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyie committed Sep 22, 2020
1 parent c0dc40c commit 99cb638
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 3 deletions.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ All operation use es7 async/await to implement. All api is async function.
- versioning
- [.getBucketVersioning(name, [, options])](#getBucketVersioningname-options)
- [.putBucketVersioning(name, status[, options])](#putBucketVersioningname-status-options)
- worm
- [.abortBucketWorm(name[, options])](#abortBucketWormname-options)
- [.completeBucketWorm(name, wormId[, options])](#completeBucketWormname-wormId-options)
- [.extendBucketWorm(name, wormId, days[, options])](#extendBucketWormname-wormId-days-options)
- [.getBucketWorm(name[, options])](#getBucketWormname-options)
- [.initiateBucketWorm(name, days[, options])](#initiateBucketWormname-days-options)

- [Object Operations](#object-operations)
- [.list(query[, options])](#listquery-options)
Expand Down Expand Up @@ -1259,6 +1265,95 @@ Success will return:

---

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

used to delete an unlocked retention policy.

parameters:

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

Success will return:

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

---

### .completeBucketWorm(name, wormId[, options])

used to lock a retention policy.

parameters:

- name {String} the bucket name
- wormId {String} worm id
- [options] {Object} optional args

Success will return:

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

---

### .extendBucketWorm(name, wormId, days[, options])

used to extend the retention period of objects in a bucket whose retention policy is locked.

parameters:

- name {String} the bucket name
- wormId {String} worm id
- days {String | Number} retention days
- [options] {Object} optional args

Success will return:

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

---

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

used to query the retention policy information of the specified bucket.

parameters:

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

Success will return:

- wormId {String} worm id
- state {String} `Locked` or `InProgress`
- days {String} retention days
- creationDate {String}
- status {Number} response status
- res {Object} response info

---

### .initiateBucketWorm(name, days[, options])

create a retention policy.

parameters:

- name {String} the bucket name
- days {String | Number}} set retention days
- [options] {Object} optional args

Success will return:

- wormId {String} worm id
- status {Number} response status
- res {Object} response info

---

## Object Operations

All operations function return Promise, except `signatureUrl`.
Expand Down
6 changes: 6 additions & 0 deletions lib/browser/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ merge(proto, require('../common/bucket/deleteBucketLifecycle'));
// multiversion
merge(proto, require('../common/bucket/putBucketVersioning'));
merge(proto, require('../common/bucket/getBucketVersioning'));
// worm
merge(proto, require('../common/bucket/abortBucketWorm'));
merge(proto, require('../common/bucket/completeBucketWorm'));
merge(proto, require('../common/bucket/extendBucketWorm'));
merge(proto, require('../common/bucket/getBucketWorm'));
merge(proto, require('../common/bucket/initiateBucketWorm'));

// multipart upload
merge(proto, require('./managed-upload'));
Expand Down
4 changes: 4 additions & 0 deletions lib/common/bucket/abortBucketWorm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function abortBucketWorm(this: any, name: string, options: any): Promise<{
res: any;
status: any;
}>;
14 changes: 14 additions & 0 deletions lib/common/bucket/abortBucketWorm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.abortBucketWorm = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
async function abortBucketWorm(name, options) {
checkBucketName_1.checkBucketName(name);
const params = this._bucketRequestParams('DELETE', name, 'worm', options);
const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
exports.abortBucketWorm = abortBucketWorm;
12 changes: 12 additions & 0 deletions lib/common/bucket/abortBucketWorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { checkBucketName } from '../utils/checkBucketName';

export async function abortBucketWorm(this: any, name: string, options) {
checkBucketName(name);
const params = this._bucketRequestParams('DELETE', name, 'worm', options);

const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
4 changes: 4 additions & 0 deletions lib/common/bucket/completeBucketWorm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function completeBucketWorm(this: any, name: string, wormId: string, options: any): Promise<{
res: any;
status: any;
}>;
14 changes: 14 additions & 0 deletions lib/common/bucket/completeBucketWorm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.completeBucketWorm = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
async function completeBucketWorm(name, wormId, options) {
checkBucketName_1.checkBucketName(name);
const params = this._bucketRequestParams('POST', name, { wormId }, options);
const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
exports.completeBucketWorm = completeBucketWorm;
12 changes: 12 additions & 0 deletions lib/common/bucket/completeBucketWorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { checkBucketName } from '../utils/checkBucketName';

export async function completeBucketWorm(this: any, name: string, wormId: string, options) {
checkBucketName(name);
const params = this._bucketRequestParams('POST', name, { wormId }, options);

const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
4 changes: 4 additions & 0 deletions lib/common/bucket/extendBucketWorm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function extendBucketWorm(this: any, name: string, wormId: string, days: string, options: any): Promise<{
res: any;
status: any;
}>;
23 changes: 23 additions & 0 deletions lib/common/bucket/extendBucketWorm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendBucketWorm = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
const obj2xml_1 = require("../utils/obj2xml");
async function extendBucketWorm(name, wormId, days, options) {
checkBucketName_1.checkBucketName(name);
const params = this._bucketRequestParams('POST', name, { wormExtend: '', wormId }, options);
const paramlXMLObJ = {
ExtendWormConfiguration: {
RetentionPeriodInDays: days
}
};
params.mime = 'xml';
params.content = obj2xml_1.obj2xml(paramlXMLObJ, { headers: true });
params.successStatuses = [200];
const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
exports.extendBucketWorm = extendBucketWorm;
21 changes: 21 additions & 0 deletions lib/common/bucket/extendBucketWorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { checkBucketName } from '../utils/checkBucketName';
import { obj2xml } from '../utils/obj2xml';

export async function extendBucketWorm(this: any, name: string, wormId: string, days: string | number, options) {
checkBucketName(name);
const params = this._bucketRequestParams('POST', name, { wormExtend: '', wormId }, options);
const paramlXMLObJ = {
ExtendWormConfiguration: {
RetentionPeriodInDays: days
}
};

params.mime = 'xml';
params.content = obj2xml(paramlXMLObJ, { headers: true });
params.successStatuses = [200];
const result = await this.request(params);
return {
res: result.res,
status: result.status
};
}
1 change: 1 addition & 0 deletions lib/common/bucket/getBucketWorm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function getBucketWorm(this: any, name: string, options: any): Promise<any>;
20 changes: 20 additions & 0 deletions lib/common/bucket/getBucketWorm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBucketWorm = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
const dataFix_1 = require("../utils/dataFix");
async function getBucketWorm(name, options) {
checkBucketName_1.checkBucketName(name);
const params = this._bucketRequestParams('GET', name, 'worm', options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = await this.request(params);
dataFix_1.dataFix(result.data, {
lowerFirst: true,
rename: {
RetentionPeriodInDays: 'days'
}
});
return Object.assign(Object.assign({}, result.data), { res: result.res, status: result.status });
}
exports.getBucketWorm = getBucketWorm;
22 changes: 22 additions & 0 deletions lib/common/bucket/getBucketWorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { checkBucketName } from '../utils/checkBucketName';
import { dataFix } from '../utils/dataFix';

export async function getBucketWorm(this: any, name: string, options) {
checkBucketName(name);
const params = this._bucketRequestParams('GET', name, 'worm', options);
params.successStatuses = [200];
params.xmlResponse = true;

const result = await this.request(params);
dataFix(result.data, {
lowerFirst: true,
rename: {
RetentionPeriodInDays: 'days'
}
});
return {
...result.data,
res: result.res,
status: result.status
};
}
5 changes: 5 additions & 0 deletions lib/common/bucket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ merge(proto, require('./putBucketPolicy'));
merge(proto, require('./deleteBucketPolicy'));
merge(proto, require('./getBucketVersioning'));
merge(proto, require('./putBucketVersioning'));
merge(proto, require('./abortBucketWorm'));
merge(proto, require('./completeBucketWorm'));
merge(proto, require('./extendBucketWorm'));
merge(proto, require('./getBucketWorm'));
merge(proto, require('./initiateBucketWorm'));
5 changes: 5 additions & 0 deletions lib/common/bucket/initiateBucketWorm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare function initiateBucketWorm(this: any, name: string, days: string, options: any): Promise<{
res: any;
wormId: any;
status: any;
}>;
24 changes: 24 additions & 0 deletions lib/common/bucket/initiateBucketWorm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initiateBucketWorm = void 0;
const obj2xml_1 = require("../utils/obj2xml");
const checkBucketName_1 = require("../utils/checkBucketName");
async function initiateBucketWorm(name, days, options) {
checkBucketName_1.checkBucketName(name);
const params = this._bucketRequestParams('POST', name, 'worm', options);
const paramlXMLObJ = {
InitiateWormConfiguration: {
RetentionPeriodInDays: days
}
};
params.mime = 'xml';
params.content = obj2xml_1.obj2xml(paramlXMLObJ, { headers: true });
params.successStatuses = [200];
const result = await this.request(params);
return {
res: result.res,
wormId: result.res.headers['x-oss-worm-id'],
status: result.status
};
}
exports.initiateBucketWorm = initiateBucketWorm;
28 changes: 28 additions & 0 deletions lib/common/bucket/initiateBucketWorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { obj2xml } from '../utils/obj2xml';
import { checkBucketName } from '../utils/checkBucketName';

export async function initiateBucketWorm(
this: any,
name: string,
days: string,
options
) {
checkBucketName(name);
const params = this._bucketRequestParams('POST', name, 'worm', options);
const paramlXMLObJ = {
InitiateWormConfiguration: {
RetentionPeriodInDays: days
}
};

params.mime = 'xml';
params.content = obj2xml(paramlXMLObJ, { headers: true });
params.successStatuses = [200];

const result = await this.request(params);
return {
res: result.res,
wormId: result.res.headers['x-oss-worm-id'],
status: result.status
};
}
2 changes: 1 addition & 1 deletion lib/common/utils/checkBucketName.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const checkBucketName: (name: string, createBucket: boolean) => void;
export declare const checkBucketName: (name: string, createBucket?: boolean) => void;
2 changes: 1 addition & 1 deletion lib/common/utils/checkBucketName.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkBucketName = void 0;
exports.checkBucketName = (name, createBucket) => {
exports.checkBucketName = (name, createBucket = false) => {
const bucketRegex = createBucket ? /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/ : /^[a-z0-9_][a-z0-9-_]{1,61}[a-z0-9_]$/;
if (!bucketRegex.test(name)) {
throw new Error('The bucket must be conform to the specifications');
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils/checkBucketName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const checkBucketName = (name: string, createBucket: boolean): void => {
export const checkBucketName = (name: string, createBucket = false): void => {
const bucketRegex = createBucket ? /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/ : /^[a-z0-9_][a-z0-9-_]{1,61}[a-z0-9_]$/;
if (!bucketRegex.test(name)) {
throw new Error('The bucket must be conform to the specifications');
Expand Down
12 changes: 12 additions & 0 deletions lib/common/utils/dataFix.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface Rename {
[propName: string]: string;
}
interface Config {
lowerFirst?: boolean;
rename?: Rename;
remove?: string[];
camel?: string[];
bool?: string[];
}
export declare function dataFix(o: object, conf: Config, finalKill?: Function): typeof dataFix | undefined;
export {};
Loading

0 comments on commit 99cb638

Please sign in to comment.