Skip to content

Commit

Permalink
feat: inventory (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyie committed Sep 22, 2020
1 parent c0dc40c commit 6fa9f3f
Show file tree
Hide file tree
Showing 30 changed files with 1,196 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"printWidth": 120,
"bracketSpacing": true,
"arrowParens": "avoid"
}
162 changes: 162 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ 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)
- inventory
- [.getBucketInventory(name, inventoryId[, options])](#getBucketInventoryname-inventoryid-options)
- [.putBucketInventory(name, inventory[, options])](#putBucketInventoryname-inventory-options)
- [.deleteBucketInventory(name, inventoryId[, options])](#deleteBucketInventoryname-inventoryid-options)
- [.listBucketInventory(name, [, options])](#listBucketInventoryname-options)

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

---


### .getBucketInventory(name, inventoryId[, options])

get bucket inventory by inventory-id

parameters:

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

Success will return:

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

```js
async function getBucketInventoryById() {
try {
const result = await client.getBucketInventory('bucket', 'inventoryid');
console.log(result.inventory)
} catch (err) {
console.log(err)
}
}
getBucketInventoryById();
```

### putBucketInventory(name, inventory[, options])

set bucket inventory

parameters:

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

Success will return:

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

```ts
type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
interface Inventory {
id: string;
isEnabled: true | false;
prefix?: string;
OSSBucketDestination: {
format: 'CSV';
accountId: string;
rolename: string;
bucket: string;
prefix?: string;
encryption?:
| {'SSE-OSS': ''}
| {
'SSE-KMS': {
keyId: string;
};
};
};
frequency: 'Daily' | 'Weekly';
includedObjectVersions: 'Current' | 'All';
optionalFields?: {
field?: Field[];
};
}
```
```js
const inventory = {
id: 'default',
isEnabled: false, // `true` | `false`
prefix: 'ttt', // filter prefix
OSSBucketDestination: {
format: 'CSV',
accountId: '1817184078010220',
rolename: 'AliyunOSSRole',
bucket: 'your bucket',
prefix: 'test',
//encryption: {'SSE-OSS': ''},
/*
encryption: {
'SSE-KMS': {
keyId: 'test-kms-id';
};,
*/
},
frequency: 'Daily', // `WEEKLY` | `Daily`
includedObjectVersions: 'All', // `All` | `Current`
optionalFields: {
field: ["Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus"]
},
}
async function putInventory(){
const bucket = 'Your Bucket Name';
try {
await client.putBucketInventory(bucket, inventory);
} catch(err) {
console.log(err);
}
}
putInventory()
```

### deleteBucketInventory(name, inventoryId[, options])

delete bucket inventory by inventory-id

parameters:

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

Success will return:

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

### listBucketInventory(name[, options])

list bucket inventory

parameters:

- name {String} the bucket name
- [options] {Object} optional args
- continuationToken used by search next page

Success will return:

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

example:

```js
async function listBucketInventory() {
const bucket = 'Your Bucket Name';
let nextContinuationToken;
// list all inventory of the bucket
do {
const result = await client.listBucketInventory(bucket, nextContinuationToken);
console.log(result.inventoryList);
nextContinuationToken = result.nextContinuationToken;
} while (nextContinuationToken)
}
listBucketInventory();
```

## 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 @@ -105,6 +105,12 @@ merge(proto, require('../common/bucket/deleteBucketLifecycle'));
merge(proto, require('../common/bucket/putBucketVersioning'));
merge(proto, require('../common/bucket/getBucketVersioning'));

// inventory
merge(proto, require('../common/bucket/getBucketInventory'));
merge(proto, require('../common/bucket/deleteBucketInventory'));
merge(proto, require('../common/bucket/listBucketInventory'));
merge(proto, require('../common/bucket/putBucketInventory'));

// multipart upload
merge(proto, require('./managed-upload'));
/**
Expand Down
10 changes: 10 additions & 0 deletions lib/common/bucket/deleteBucketInventory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* deleteBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
export declare function deleteBucketInventory(this: any, bucketName: string, inventoryId: string, options?: any): Promise<{
status: any;
res: any;
}>;
22 changes: 22 additions & 0 deletions lib/common/bucket/deleteBucketInventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteBucketInventory = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
/**
* deleteBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
async function deleteBucketInventory(bucketName, inventoryId, options = {}) {
const subres = Object.assign({ inventory: '', inventoryId }, options.subres);
checkBucketName_1.checkBucketName(bucketName);
const params = this._bucketRequestParams('DELETE', bucketName, subres, options);
params.successStatuses = [204];
const result = await this.request(params);
return {
status: result.status,
res: result.res,
};
}
exports.deleteBucketInventory = deleteBucketInventory;
21 changes: 21 additions & 0 deletions lib/common/bucket/deleteBucketInventory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { checkBucketName } from '../utils/checkBucketName';
/**
* deleteBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/

export async function deleteBucketInventory(this: any, bucketName: string, inventoryId: string, options: any = {}) {
const subres: any = Object.assign({ inventory: '', inventoryId }, options.subres);
checkBucketName(bucketName);

const params = this._bucketRequestParams('DELETE', bucketName, subres, options);
params.successStatuses = [204];

const result = await this.request(params);
return {
status: result.status,
res: result.res,
};
}
11 changes: 11 additions & 0 deletions lib/common/bucket/getBucketInventory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* getBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
export declare function getBucketInventory(this: any, bucketName: string, inventoryId: string, options?: any): Promise<{
status: any;
res: any;
inventory: any;
}>;
25 changes: 25 additions & 0 deletions lib/common/bucket/getBucketInventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBucketInventory = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
const formatInventoryConfig_1 = require("../utils/formatInventoryConfig");
/**
* getBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
async function getBucketInventory(bucketName, inventoryId, options = {}) {
const subres = Object.assign({ inventory: '', inventoryId }, options.subres);
checkBucketName_1.checkBucketName(bucketName);
const params = this._bucketRequestParams('GET', bucketName, subres, options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = await this.request(params);
return {
status: result.status,
res: result.res,
inventory: formatInventoryConfig_1.formatInventoryConfig(result.data)
};
}
exports.getBucketInventory = getBucketInventory;
24 changes: 24 additions & 0 deletions lib/common/bucket/getBucketInventory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { checkBucketName } from '../utils/checkBucketName';
import { formatInventoryConfig } from '../utils/formatInventoryConfig';
/**
* getBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/

export async function getBucketInventory(this: any, bucketName: string, inventoryId: string, options: any = {}) {
const subres: any = Object.assign({ inventory: '', inventoryId }, options.subres);
checkBucketName(bucketName);

const params = this._bucketRequestParams('GET', bucketName, subres, options);
params.successStatuses = [200];

params.xmlResponse = true;
const result = await this.request(params);
return {
status: result.status,
res: result.res,
inventory: formatInventoryConfig(result.data)
};
}
4 changes: 4 additions & 0 deletions lib/common/bucket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ merge(proto, require('./putBucketPolicy'));
merge(proto, require('./deleteBucketPolicy'));
merge(proto, require('./getBucketVersioning'));
merge(proto, require('./putBucketVersioning'));
merge(proto, require('./getBucketInventory'));
merge(proto, require('./deleteBucketInventory'));
merge(proto, require('./listBucketInventory'));
merge(proto, require('./putBucketInventory'));
13 changes: 13 additions & 0 deletions lib/common/bucket/listBucketInventory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* listBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
export declare function listBucketInventory(this: any, bucketName: string, options?: any): Promise<{
isTruncated: boolean;
nextContinuationToken: any;
inventoryList: any;
status: any;
res: any;
}>;
29 changes: 29 additions & 0 deletions lib/common/bucket/listBucketInventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listBucketInventory = void 0;
const checkBucketName_1 = require("../utils/checkBucketName");
const formatInventoryConfig_1 = require("../utils/formatInventoryConfig");
/**
* listBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/
async function listBucketInventory(bucketName, options = {}) {
const { continuationToken } = options;
const subres = Object.assign({ inventory: '' }, continuationToken && { 'continuation-token': continuationToken }, options.subres);
checkBucketName_1.checkBucketName(bucketName);
const params = this._bucketRequestParams('GET', bucketName, subres, options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = await this.request(params);
const { data, res, status } = result;
return {
isTruncated: data.IsTruncated === 'true',
nextContinuationToken: data.NextContinuationToken,
inventoryList: formatInventoryConfig_1.formatInventoryConfig(data.InventoryConfiguration, true),
status,
res,
};
}
exports.listBucketInventory = listBucketInventory;
28 changes: 28 additions & 0 deletions lib/common/bucket/listBucketInventory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { checkBucketName } from '../utils/checkBucketName';
import { formatInventoryConfig } from '../utils/formatInventoryConfig';
/**
* listBucketInventory
* @param {String} bucketName - bucket name
* @param {String} inventoryId
* @param {Object} options
*/

export async function listBucketInventory(this: any, bucketName: string, options: any = {}) {
const { continuationToken } = options;
const subres: any = Object.assign({ inventory: '' }, continuationToken && { 'continuation-token': continuationToken }, options.subres);
checkBucketName(bucketName);

const params = this._bucketRequestParams('GET', bucketName, subres, options);
params.successStatuses = [200];

params.xmlResponse = true;
const result = await this.request(params);
const { data, res, status } = result;
return {
isTruncated: data.IsTruncated === 'true',
nextContinuationToken: data.NextContinuationToken,
inventoryList: formatInventoryConfig(data.InventoryConfiguration, true),
status,
res,
};
}
Loading

0 comments on commit 6fa9f3f

Please sign in to comment.