99
1010namespace OC \OCM \Model ;
1111
12+ use OC \Security \Signature \Model \Signatory ;
1213use OCP \EventDispatcher \IEventDispatcher ;
1314use OCP \OCM \Events \ResourceTypeRegisterEvent ;
1415use OCP \OCM \Exceptions \OCMArgumentException ;
1516use OCP \OCM \Exceptions \OCMProviderException ;
1617use OCP \OCM \IOCMProvider ;
1718use OCP \OCM \IOCMResource ;
19+ use OCP \Security \Signature \Model \ISignatory ;
1820
1921/**
2022 * @since 28.0.0
@@ -25,7 +27,7 @@ class OCMProvider implements IOCMProvider {
2527 private string $ endPoint = '' ;
2628 /** @var IOCMResource[] */
2729 private array $ resourceTypes = [];
28-
30+ private ? ISignatory $ signatory = null ;
2931 private bool $ emittedEvent = false ;
3032
3133 public function __construct (
@@ -152,6 +154,14 @@ public function extractProtocolEntry(string $resourceName, string $protocol): st
152154 throw new OCMArgumentException ('resource not found ' );
153155 }
154156
157+ public function setSignatory (ISignatory $ signatory ){
158+ $ this ->signatory = $ signatory ;
159+ }
160+
161+ public function getSignatory (): ?ISignatory {
162+ return $ this ->signatory ;
163+ }
164+
155165 /**
156166 * import data from an array
157167 *
@@ -163,7 +173,7 @@ public function extractProtocolEntry(string $resourceName, string $protocol): st
163173 */
164174 public function import (array $ data ): static {
165175 $ this ->setEnabled (is_bool ($ data ['enabled ' ] ?? '' ) ? $ data ['enabled ' ] : false )
166- ->setApiVersion ((string )($ data ['apiVersion ' ] ?? '' ))
176+ ->setApiVersion ((string )($ data ['version ' ] ?? '' ))
167177 ->setEndPoint ($ data ['endPoint ' ] ?? '' );
168178
169179 $ resources = [];
@@ -173,6 +183,13 @@ public function import(array $data): static {
173183 }
174184 $ this ->setResourceTypes ($ resources );
175185
186+ $ signatory = new Signatory ($ data ['publicKey ' ]['keyId ' ] ?? '' , $ data ['publicKey ' ]['publicKeyPem ' ] ?? '' );
187+ if ($ signatory ->getKeyId () !== ''
188+ && $ signatory ->getPublicKey () !== '' )
189+ {
190+ $ this ->setSignatory ($ signatory );
191+ }
192+
176193 if (!$ this ->looksValid ()) {
177194 throw new OCMProviderException ('remote provider does not look valid ' );
178195 }
@@ -209,8 +226,10 @@ public function jsonSerialize(): array {
209226
210227 return [
211228 'enabled ' => $ this ->isEnabled (),
212- 'apiVersion ' => $ this ->getApiVersion (),
229+ 'apiVersion ' => '1.0-proposal1 ' , // keep it like this to stay compatible with old version
230+ 'version ' => $ this ->getApiVersion (),
213231 'endPoint ' => $ this ->getEndPoint (),
232+ 'publicKey ' => $ this ->getSignatory (),
214233 'resourceTypes ' => $ resourceTypes
215234 ];
216235 }
0 commit comments