Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/management/PhabricatorFilesManagementCycleWorkflow.php
13419 views
1
<?php
2
3
final class PhabricatorFilesManagementCycleWorkflow
4
extends PhabricatorFilesManagementWorkflow {
5
6
protected function didConstruct() {
7
$arguments = $this->newIteratorArguments();
8
$arguments[] = array(
9
'name' => 'key',
10
'param' => 'keyname',
11
'help' => pht('Select a specific storage key to cycle to.'),
12
);
13
14
$this
15
->setName('cycle')
16
->setSynopsis(
17
pht('Cycle master key for encrypted files.'))
18
->setArguments($arguments);
19
}
20
21
public function execute(PhutilArgumentParser $args) {
22
$iterator = $this->buildIterator($args);
23
24
$format_map = PhabricatorFileStorageFormat::getAllFormats();
25
$engines = PhabricatorFileStorageEngine::loadAllEngines();
26
27
$key_name = $args->getArg('key');
28
29
$failed = array();
30
foreach ($iterator as $file) {
31
$monogram = $file->getMonogram();
32
33
$engine_key = $file->getStorageEngine();
34
$engine = idx($engines, $engine_key);
35
36
if (!$engine) {
37
echo tsprintf(
38
"%s\n",
39
pht(
40
'%s: Uses unknown storage engine "%s".',
41
$monogram,
42
$engine_key));
43
$failed[] = $file;
44
continue;
45
}
46
47
if ($engine->isChunkEngine()) {
48
echo tsprintf(
49
"%s\n",
50
pht(
51
'%s: Stored as chunks, declining to cycle directly.',
52
$monogram));
53
continue;
54
}
55
56
$format_key = $file->getStorageFormat();
57
if (empty($format_map[$format_key])) {
58
echo tsprintf(
59
"%s\n",
60
pht(
61
'%s: Uses unknown storage format "%s".',
62
$monogram,
63
$format_key));
64
$failed[] = $file;
65
continue;
66
}
67
68
$format = clone $format_map[$format_key];
69
$format->setFile($file);
70
71
if (!$format->canCycleMasterKey()) {
72
echo tsprintf(
73
"%s\n",
74
pht(
75
'%s: Storage format ("%s") does not support key cycling.',
76
$monogram,
77
$format->getStorageFormatName()));
78
continue;
79
}
80
81
echo tsprintf(
82
"%s\n",
83
pht(
84
'%s: Cycling master key.',
85
$monogram));
86
87
try {
88
if ($key_name) {
89
$format->selectMasterKey($key_name);
90
}
91
92
$file->cycleMasterStorageKey($format);
93
94
echo tsprintf(
95
"%s\n",
96
pht('Done.'));
97
} catch (Exception $ex) {
98
echo tsprintf(
99
"%B\n",
100
pht('Failed! %s', (string)$ex));
101
$failed[] = $file;
102
}
103
}
104
105
if ($failed) {
106
$monograms = mpull($failed, 'getMonogram');
107
108
echo tsprintf(
109
"%s\n",
110
pht('Failures: %s.', implode(', ', $monograms)));
111
112
return 1;
113
}
114
115
return 0;
116
}
117
118
}
119
120