Skip to content

Commit

Permalink
Merge pull request #669 from nextcloud/mgallien/feat/addUploadOfUserC…
Browse files Browse the repository at this point in the history
…ertificate

add a new API to allow user to upload an existing certificate
  • Loading branch information
mgallien authored Aug 13, 2024
2 parents 0516c3b + 27cfa29 commit 2da943c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
['name' => 'Key#setPrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'POST', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#getPrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'GET', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#deletePrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#setPublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'PUT', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#createPublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'POST', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#getPublicKeys', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'GET', 'requirements' => ['apiVersion' => '[1-2]']],
['name' => 'Key#deletePublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '[1-2]']],
Expand Down
20 changes: 20 additions & 0 deletions lib/Controller/KeyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ public function createPublicKey(string $csr): DataResponse {
return new DataResponse(['public-key' => $publicKey]);
}

/**
* Set public key
*
* @NoAdminRequired
* @E2ERestrictUserAgent
* @throws OCSBadRequestException
*/
public function setPublicKey(string $publicKey): DataResponse {
try {
$this->keyStorage->setPublicKey($publicKey, $this->userId);
} catch (KeyExistsException $e) {
return new DataResponse([], Http::STATUS_CONFLICT);
} catch (Exception $e) {
$this->logger->error("Fail to set user public key", ['exception' => $e, 'app' => $this->appName]);
throw new OCSBadRequestException($this->l10n->t('Internal error'));
}

return new DataResponse(['public-key' => $publicKey]);
}

/**
* Delete the users public key
*
Expand Down

0 comments on commit 2da943c

Please sign in to comment.