-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathassign.js
82 lines (73 loc) · 2.57 KB
/
assign.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const BoxCommand = require('../../box-command');
const BoxCLIError = require('../../cli-error');
const { Flags, Args } = require('@oclif/core');
class RetentionPoliciesAssignCommand extends BoxCommand {
async run() {
const { flags, args } = await this.parse(RetentionPoliciesAssignCommand);
let assignment;
let assignType = flags['assign-to-type'];
let assignID = flags['assign-to-id'];
let options = {};
if (flags.hasOwnProperty('filter-field')) {
options.filter_fields = flags['filter-field'];
}
if (flags.hasOwnProperty('start-date-field')) {
options.start_date_field = flags['start-date-field'];
}
if (assignType === 'enterprise') {
assignment = await this.client.retentionPolicies.assign(args.policyID, assignType, null, options);
} else {
if (!assignID) {
throw new BoxCLIError('An ID of the content to assign the retention policy to is required');
}
assignment = await this.client.retentionPolicies.assign(args.policyID, assignType, assignID, options);
}
await this.output(assignment);
}
}
RetentionPoliciesAssignCommand.description = 'Assign a retention policy assignment';
RetentionPoliciesAssignCommand.examples = ['box retention-policies:assign 12345 --assign-to-type folder --assign-to-id 22222 --filter-field=fieldName=fieldValue --start-date-field=upload_date'];
RetentionPoliciesAssignCommand._endpoint = 'post_retention_policy_assignments';
RetentionPoliciesAssignCommand.flags = {
...BoxCommand.flags,
'assign-to-type': Flags.string({
description: 'The type of the content to assign the retention policy to',
required: true,
options: [
'enterprise',
'folder',
'metadata_template'
],
}),
'assign-to-id': Flags.string({
description: 'The ID of the content to assign the retention policy to',
}),
'filter-field': Flags.string({
description: 'Metadata fields to filter against, if assigning to a metadata template.' +
'Allow properties: field, value. Example: --filter-field=fieldName=fieldValue',
multiple: true,
parse(input) {
const filter = {};
input = input.split('=');
if (input.length !== 2) {
throw new BoxCLIError('Invalid filter field');
}
filter.field = input[0];
filter.value = input[1];
return filter;
}
}),
'start-date-field': Flags.string({
description: 'The date the retention policy assignment begins',
}),
};
RetentionPoliciesAssignCommand.args = {
policyID: Args.string({
name: 'policyID',
required: true,
hidden: false,
description: 'The ID of the retention policy to assign this content to',
}),
};
module.exports = RetentionPoliciesAssignCommand;