server icon indicating copy to clipboard operation
server copied to clipboard

feat(ocm): event on ocm discovery and ocm request

Open ArtificialOwl opened this issue 1 month ago • 0 comments

This allow any app to register new ocm capabilities and manage requests done to the ocm endpoint

  • [x] rename local ocm discovery event to a more fitted description (ResourceTypeRegisterEvent => LocalOCMDiscoveryEvent)
  • [x] ability to add capability to local ocm discovery
  • [x] event on /ocm requests to externally manage behavior
  • [x] /ocm requests arguments can be typed
  • [ ] event on /ocm support signed request
  • [ ] /ocm request events contains attached payload
  • [x] remove slashes from capabilities (as expected in ocm 1.2)
  • [x] making legacy route parser to manage a list of methods
  • [x] get rid of ICapabilityAwareOCMProvider and rehabilitate IOCMProvider

Events Listeners

Examples of listeners to inject your app into OCM

Adding a new capability to the local instance

class OCMDiscovery implements IEventListener {
	public function __construct(
	) {
	}

	public function handle(Event $event): void {
		if (!($event instanceof \OCP\OCM\Events\LocalOCMDiscoveryEvent)) {
			return;
		}

		$event->addCapability('my-own-capability');
	}
}

Catching requests made on the ocm endpoint

base url is _https://cloud.example.net/ocm/..._

class OCMRequest implements IEventListener {
	public function __construct(
	) {
	}

	public function handle(Event $event): void {
		if (!($event instanceof \OCP\OCM\Events\OCMEndpointRequestEvent)) {
			return;
		}

		$event->setResponse(new DataResponse(
			[
				'_capability' => $event->getRequestedCapability(),
				'_method' => $event->getUsedMethod(),
				'_path' => $event->getPath(),
				'_args' => $event->getArgs(),
				'_typedArgs' => $event->getArgs(
					\OCP\OCM\Enum\ParamType::STRING,
					\OCP\OCM\Enum\ParamType::STRING,
					\OCP\OCM\Enum\ParamType::INT,
					\OCP\OCM\Enum\ParamType::BOOL,
					\OCP\OCM\Enum\ParamType::INT
				)
			]
		));
	}
}

Expected data

Some example of curl requests ...

Discovery endpoint

$ curl https://cloud.example.net/ocm-provider/ | jq .
{
  "enabled": true,
  "apiVersion": "1.0-proposal1",
  "version": "1.1.0",
  "endPoint": "https://cloud.example.net/index.php/ocm",
[...]  
  "capabilities": [
    "invite-accepted",
    "notifications",
    "shares",
    "my-own-capability"
  ]
}

OCM request

$ curl -X POST -k https://cloud.example.net/ocm/my-own-capability/arg1/arg2/50/yes/not-integer/moar/ignored | jq .
{
  "_capability": "my-own-capability",
  "_method": "POST",
  "_path": "/arg1/arg2/50/yes/not-integer/moar/ignored",
  "_args": [
    "arg1",
    "arg2",
    "50",
    "yes",
    "not-integer",
    "moar",
    "ignored"
  ],
  "_typedArgs": [
    "arg1",
    "arg2",
    50,
    true,
    null
  ]
}

ArtificialOwl avatar Dec 07 '25 11:12 ArtificialOwl