Merge pull request #39717 from nextcloud/fix/openapi/files_external

files_external: Fix OpenAPI
This commit is contained in:
Julien Veyssier 2023-08-07 12:10:19 +02:00 committed by GitHub
commit 787caefc9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 103 additions and 6 deletions

View file

@ -34,6 +34,7 @@ use OCA\Files_External\ResponseDefinitions;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
@ -127,6 +128,7 @@ class ApiController extends OCSController {
* Ask for credentials using a browser's native basic auth prompt
* Then returns it if provided
*/
#[IgnoreOpenAPI]
public function askNativeAuth(): DataResponse {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
$response = new DataResponse([], Http::STATUS_UNAUTHORIZED);
@ -137,7 +139,7 @@ class ApiController extends OCSController {
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
// Reset auth
// Reset auth
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);

View file

@ -31,9 +31,12 @@ namespace OCA\Files_External\Lib;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\IUserProvided;
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\ResponseDefinitions;
/**
* External storage configuration
*
* @psalm-import-type FilesExternalStorageConfig from ResponseDefinitions
*/
class StorageConfig implements \JsonSerializable {
public const MOUNT_TYPE_ADMIN = 1;
@ -63,7 +66,7 @@ class StorageConfig implements \JsonSerializable {
/**
* Backend options
*
* @var array
* @var array<string, mixed>
*/
private $backendOptions = [];
@ -112,7 +115,7 @@ class StorageConfig implements \JsonSerializable {
/**
* Mount-specific options
*
* @var array
* @var array<string, mixed>
*/
private $mountOptions = [];
@ -396,6 +399,7 @@ class StorageConfig implements \JsonSerializable {
/**
* Serialize config to JSON
* @return FilesExternalStorageConfig
*/
public function jsonSerialize(bool $obfuscate = false): array {
$result = [];
@ -407,7 +411,7 @@ class StorageConfig implements \JsonSerializable {
if ($obfuscate) {
$this->formatStorageForUI();
}
$result['mountPoint'] = $this->mountPoint;
$result['backend'] = $this->backend->getIdentifier();
$result['authMechanism'] = $this->authMechanism->getIdentifier();

View file

@ -26,6 +26,22 @@ declare(strict_types=1);
namespace OCA\Files_External;
/**
* @psalm-type FilesExternalStorageConfig = array{
* applicableGroups?: string[],
* applicableUsers?: string[],
* authMechanism: string,
* backend: string,
* backendOptions: array<string, mixed>,
* id?: int,
* mountOptions?: array<string, mixed>,
* mountPoint: string,
* priority?: int,
* status?: int,
* statusMessage?: string,
* type: 'personal'|'system',
* userProvided: bool,
* }
*
* @psalm-type FilesExternalMount = array{
* name: string,
* path: string,
@ -35,7 +51,7 @@ namespace OCA\Files_External;
* permissions: int,
* id: int,
* class: string,
* config: array<array-key, mixed>,
* config: FilesExternalStorageConfig,
* }
*/
class ResponseDefinitions {

View file

@ -30,7 +30,8 @@
"scope",
"permissions",
"id",
"class"
"class",
"config"
],
"properties": {
"name": {
@ -65,6 +66,9 @@
},
"class": {
"type": "string"
},
"config": {
"$ref": "#/components/schemas/StorageConfig"
}
}
},
@ -91,6 +95,77 @@
"type": "string"
}
}
},
"StorageConfig": {
"type": "object",
"required": [
"authMechanism",
"backend",
"backendOptions",
"mountPoint",
"type",
"userProvided"
],
"properties": {
"applicableGroups": {
"type": "array",
"items": {
"type": "string"
}
},
"applicableUsers": {
"type": "array",
"items": {
"type": "string"
}
},
"authMechanism": {
"type": "string"
},
"backend": {
"type": "string"
},
"backendOptions": {
"type": "object",
"additionalProperties": {
"type": "object"
}
},
"id": {
"type": "integer",
"format": "int64"
},
"mountOptions": {
"type": "object",
"additionalProperties": {
"type": "object"
}
},
"mountPoint": {
"type": "string"
},
"priority": {
"type": "integer",
"format": "int64"
},
"status": {
"type": "integer",
"format": "int64"
},
"statusMessage": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"personal",
"system"
]
},
"userProvided": {
"type": "boolean"
}
}
}
}
},