Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / management / PhabricatorFilesManagementGenerateKeyWorkflow.php
blob710c3586a62e56c3dc01401bb7986a2e076835e2
1 <?php
3 final class PhabricatorFilesManagementGenerateKeyWorkflow
4 extends PhabricatorFilesManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('generate-key')
9 ->setSynopsis(
10 pht('Generate an encryption key.'))
11 ->setArguments(
12 array(
13 array(
14 'name' => 'type',
15 'param' => 'keytype',
16 'help' => pht('Select the type of key to generate.'),
18 ));
21 public function execute(PhutilArgumentParser $args) {
22 $type = $args->getArg('type');
23 if (!strlen($type)) {
24 throw new PhutilArgumentUsageException(
25 pht(
26 'Specify the type of key to generate with --type.'));
29 $format = PhabricatorFileStorageFormat::getFormat($type);
30 if (!$format) {
31 throw new PhutilArgumentUsageException(
32 pht(
33 'No key type "%s" exists.',
34 $type));
37 if (!$format->canGenerateNewKeyMaterial()) {
38 throw new PhutilArgumentUsageException(
39 pht(
40 'Storage format "%s" can not generate keys.',
41 $format->getStorageFormatName()));
44 $material = $format->generateNewKeyMaterial();
46 $structure = array(
47 'name' => 'generated-key-'.Filesystem::readRandomCharacters(12),
48 'type' => $type,
49 'material.base64' => $material,
52 $json = id(new PhutilJSON())->encodeFormatted($structure);
54 echo tsprintf(
55 "%s: %s\n\n%B\n",
56 pht('Key Material'),
57 $format->getStorageFormatName(),
58 $json);
60 return 0;