Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files_external: Fix OpenAPI #39717

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/files_external/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -127,6 +128,7 @@ public function getUserMounts(): DataResponse {
* 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);
Expand All @@ -137,7 +139,7 @@ public function askNativeAuth(): DataResponse {
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

// Reset auth
// Reset auth
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);

Expand Down
10 changes: 7 additions & 3 deletions apps/files_external/lib/Lib/StorageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
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;
Expand Down Expand Up @@ -63,7 +66,7 @@ class StorageConfig implements \JsonSerializable {
/**
* Backend options
*
* @var array
* @var array<string, mixed>
*/
private $backendOptions = [];

Expand Down Expand Up @@ -112,7 +115,7 @@ class StorageConfig implements \JsonSerializable {
/**
* Mount-specific options
*
* @var array
* @var array<string, mixed>
*/
private $mountOptions = [];

Expand Down Expand Up @@ -396,6 +399,7 @@ public function setType($type) {

/**
* Serialize config to JSON
* @return FilesExternalStorageConfig
Fixed Show fixed Hide fixed
*/
public function jsonSerialize(bool $obfuscate = false): array {
$result = [];
Expand All @@ -407,7 +411,7 @@ public function jsonSerialize(bool $obfuscate = false): array {
if ($obfuscate) {
$this->formatStorageForUI();
}

$result['mountPoint'] = $this->mountPoint;
$result['backend'] = $this->backend->getIdentifier();
$result['authMechanism'] = $this->authMechanism->getIdentifier();
Expand Down
18 changes: 17 additions & 1 deletion apps/files_external/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
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,
Expand All @@ -35,7 +51,7 @@
* permissions: int,
* id: int,
* class: string,
* config: array<array-key, mixed>,
* config: FilesExternalStorageConfig,
* }
*/
class ResponseDefinitions {
Expand Down
77 changes: 76 additions & 1 deletion apps/files_external/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"scope",
"permissions",
"id",
"class"
"class",
"config"
],
"properties": {
"name": {
Expand Down Expand Up @@ -65,6 +66,9 @@
},
"class": {
"type": "string"
},
"config": {
"$ref": "#/components/schemas/StorageConfig"
}
}
},
Expand All @@ -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"
}
}
}
}
},
Expand Down