fix(webhooks): Fix a few more psalm notices

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2024-06-11 14:40:29 +02:00
parent bff7d3c769
commit e0b9ff4fa2
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
3 changed files with 54 additions and 20 deletions

View file

@ -28,6 +28,9 @@ class WebhookCall extends QueuedJob {
parent::__construct($timeFactory);
}
/**
* @param array $argument
*/
protected function run($argument): void {
[$data, $webhookId] = $argument;
$webhookListener = $this->mapper->getById($webhookId);

View file

@ -13,6 +13,7 @@ use OCA\WebhookListeners\Db\AuthMethod;
use OCA\WebhookListeners\Db\WebhookListener;
use OCA\WebhookListeners\Db\WebhookListenerMapper;
use OCA\WebhookListeners\ResponseDefinitions;
use OCA\WebhookListeners\Settings\Admin;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
@ -53,7 +54,7 @@ class WebhooksController extends OCSController {
* 200: Webhook registrations returned
*/
#[ApiRoute(verb: 'GET', url: '/api/v1/webhooks')]
#[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')]
#[AuthorizedAdminSetting(settings:Admin::class)]
public function index(): DataResponse {
try {
$webhookListeners = $this->mapper->getAll();
@ -82,7 +83,7 @@ class WebhooksController extends OCSController {
* 200: Webhook registration returned
*/
#[ApiRoute(verb: 'GET', url: '/api/v1/webhooks/{id}')]
#[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')]
#[AuthorizedAdminSetting(settings:Admin::class)]
public function show(int $id): DataResponse {
try {
return new DataResponse($this->mapper->getById($id)->jsonSerialize());
@ -114,7 +115,7 @@ class WebhooksController extends OCSController {
* @throws OCSException Other error
*/
#[ApiRoute(verb: 'POST', url: '/api/v1/webhooks')]
#[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')]
#[AuthorizedAdminSetting(settings:Admin::class)]
public function create(
string $httpMethod,
string $uri,
@ -135,6 +136,8 @@ class WebhooksController extends OCSController {
throw new OCSBadRequestException('This auth method does not exist');
}
try {
/* We can never reach here without a user in session */
assert(is_string($this->userId));
$webhookListener = $this->mapper->addWebhookListener(
$appId,
$this->userId,
@ -178,7 +181,7 @@ class WebhooksController extends OCSController {
* @throws OCSException Other error
*/
#[ApiRoute(verb: 'POST', url: '/api/v1/webhooks/{id}')]
#[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')]
#[AuthorizedAdminSetting(settings:Admin::class)]
public function update(
int $id,
string $httpMethod,
@ -200,6 +203,8 @@ class WebhooksController extends OCSController {
throw new OCSBadRequestException('This auth method does not exist');
}
try {
/* We can never reach here without a user in session */
assert(is_string($this->userId));
$webhookListener = $this->mapper->updateWebhookListener(
$id,
$appId,
@ -237,7 +242,7 @@ class WebhooksController extends OCSController {
* @throws OCSException Other error
*/
#[ApiRoute(verb: 'DELETE', url: '/api/v1/webhooks/{id}')]
#[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')]
#[AuthorizedAdminSetting(settings:Admin::class)]
public function destroy(int $id): DataResponse {
try {
$deleted = $this->mapper->deleteById($id);

View file

@ -20,35 +20,60 @@ use OCP\Security\ICrypto;
* @method ?array getHeaders()
* @method ?string getAuthData()
* @method void setAuthData(?string $data)
* @method ?string getAuthMethod()
* @method string getAuthMethod()
* @psalm-suppress PropertyNotSetInConstructor
*/
class WebhookListener extends Entity implements \JsonSerializable {
/** @var ?string id of the app_api application who added the webhook listener */
protected $appId;
/**
* @var ?string id of the app_api application who added the webhook listener
*/
protected $appId = null;
/** @var string id of the user who added the webhook listener */
/**
* @var string id of the user who added the webhook listener
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $userId;
/** @var string */
/**
* @var string
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $httpMethod;
/** @var string */
/**
* @var string
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $uri;
/** @var string */
/**
* @var string
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $event;
/** @var array */
/**
* @var array
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $eventFilter;
/** @var ?array */
protected $headers;
/**
* @var ?array
*/
protected $headers = null;
/** @var ?string */
/**
* @var string
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $authMethod;
/** @var ?string */
protected $authData;
/**
* @var ?string
*/
protected $authData = null;
private ICrypto $crypto;
@ -75,10 +100,11 @@ class WebhookListener extends Entity implements \JsonSerializable {
}
public function getAuthDataClear(): array {
if ($this->authData === null) {
$authData = $this->getAuthData();
if ($authData === null) {
return [];
}
return json_decode($this->crypto->decrypt($this->getAuthData()), associative:true, flags:JSON_THROW_ON_ERROR);
return json_decode($this->crypto->decrypt($authData), associative:true, flags:JSON_THROW_ON_ERROR);
}
public function setAuthDataClear(