-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathupdate.js
93 lines (84 loc) · 2.61 KB
/
update.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
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const BoxCommand = require('../../box-command');
const { Flags, Args } = require('@oclif/core');
class RetentionPoliciesUpdateCommand extends BoxCommand {
async run() {
const { flags, args } = await this.parse(RetentionPoliciesUpdateCommand);
let updates = {};
if (flags['disposition-action']) {
updates.disposition_action = flags['disposition-action'];
}
if (flags['policy-name']) {
updates.policy_name = flags['policy-name'];
}
if (flags['policy-type']) {
updates.policy_type = flags['policy-type'];
}
if (flags['retention-length']) {
updates.retention_length = parseInt(flags['retention-length'], 10);
}
if (flags['non-modifiable']) {
updates.retention_type = this.client.retentionPolicies.retentionTypes.NON_MODIFIABLE;
}
if (flags.retire) {
updates.status = 'retired';
}
if (flags.hasOwnProperty('notify-owners')) {
updates.are_owners_notified = flags['notify-owners'];
}
if (flags.hasOwnProperty('allow-extension')) {
updates.can_owner_extend_retention = flags['allow-extension'];
}
let policy = await this.client.retentionPolicies.update(args.id, updates);
await this.output(policy);
}
}
RetentionPoliciesUpdateCommand.description = 'Update a retention policy';
RetentionPoliciesUpdateCommand.examples = ['box retention-policies:update 12345'];
RetentionPoliciesUpdateCommand._endpoint = 'put_retention_policies_id';
RetentionPoliciesUpdateCommand.flags = {
...BoxCommand.flags,
'disposition-action': Flags.string({
char: 'a',
description: 'For indefinite policies, disposition action must be remove_retention'
}),
'policy-name': Flags.string({
char: 'n',
description: 'New name of retention policy'
}),
'policy-type': Flags.string({
description: 'Type of policy',
options: [
'finite',
'indefinite'
]
}),
'retention-length': Flags.string({
char: 'l',
description: 'The amount of time, in days, to apply the retention policy. Required for finite policies'
}),
'non-modifiable': Flags.boolean({
description: 'Set retention type to non_modifiable. '
}),
retire: Flags.boolean({
char: 'r',
description: 'Retire a retention policy'
}),
'notify-owners': Flags.boolean({
description: 'The owner or co-owner will get notified when a file is nearing expiration',
allowNo: true
}),
'allow-extension': Flags.boolean({
description: 'The owner of a file will be allowed to extend the retention',
allowNo: true
}),
};
RetentionPoliciesUpdateCommand.args = {
id: Args.string({
name: 'id',
required: true,
hidden: false,
description: 'ID of the retention policy to update',
}),
};
module.exports = RetentionPoliciesUpdateCommand;