3 final class PhabricatorFilesManagementGenerateKeyWorkflow
4 extends PhabricatorFilesManagementWorkflow
{
6 protected function didConstruct() {
8 ->setName('generate-key')
10 pht('Generate an encryption key.'))
16 'help' => pht('Select the type of key to generate.'),
21 public function execute(PhutilArgumentParser
$args) {
22 $type = $args->getArg('type');
24 throw new PhutilArgumentUsageException(
26 'Specify the type of key to generate with --type.'));
29 $format = PhabricatorFileStorageFormat
::getFormat($type);
31 throw new PhutilArgumentUsageException(
33 'No key type "%s" exists.',
37 if (!$format->canGenerateNewKeyMaterial()) {
38 throw new PhutilArgumentUsageException(
40 'Storage format "%s" can not generate keys.',
41 $format->getStorageFormatName()));
44 $material = $format->generateNewKeyMaterial();
47 'name' => 'generated-key-'.Filesystem
::readRandomCharacters(12),
49 'material.base64' => $material,
52 $json = id(new PhutilJSON())->encodeFormatted($structure);
57 $format->getStorageFormatName(),