Skip to content

Conversation

@ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Dec 7, 2025

Allow any app to register new OCM capabilities and manage requests to remote OCM endpoints.
This is done by:

  • broadcasting a OCMEndpointRequestEvent event on incoming request on /ocm/,
  • and completing current OCM API, aside with some global polishing, with tools to request a remote OCM endpoint.

Complete list of changes:

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

  • tests

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 ArtificialOwl force-pushed the feat/noid/ocm-capabilities branch 8 times, most recently from ae8f5a7 to 94491e8 Compare December 13, 2025 10:40
@ArtificialOwl ArtificialOwl force-pushed the feat/noid/ocm-capabilities branch from 94491e8 to fa9222a Compare December 16, 2025 14:18
@ArtificialOwl ArtificialOwl force-pushed the feat/noid/ocm-capabilities branch from fa9222a to e6ad3a5 Compare December 16, 2025 16:34
@ArtificialOwl ArtificialOwl added the 3. to review Waiting for reviews label Dec 16, 2025
@ArtificialOwl ArtificialOwl added this to the Nextcloud 33 milestone Dec 16, 2025
@ArtificialOwl ArtificialOwl marked this pull request as ready for review December 17, 2025 22:03
@ArtificialOwl ArtificialOwl requested review from a team and nickvergessen as code owners December 17, 2025 22:03
@ArtificialOwl ArtificialOwl requested review from Altahrim, come-nc, icewind1991 and salmart-dev and removed request for a team December 17, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants