Added method \FederationLib > FederationLib > syncPeer()
This commit is contained in:
parent
34e1f27878
commit
2e1a7a612c
2 changed files with 54 additions and 1 deletions
|
@ -13,6 +13,8 @@
|
|||
public const UPDATE_CLIENT_DESCRIPTION = 'update_client_description';
|
||||
public const UPDATE_CLIENT_PERMISSION_ROLE = 'update_client_permission_role';
|
||||
|
||||
public const SYNC_PEER = 'sync_peer';
|
||||
|
||||
|
||||
public const ALL = [
|
||||
self::PING,
|
||||
|
@ -23,5 +25,7 @@
|
|||
self::UPDATE_CLIENT_NAME,
|
||||
self::UPDATE_CLIENT_DESCRIPTION,
|
||||
self::UPDATE_CLIENT_PERMISSION_ROLE,
|
||||
|
||||
self::SYNC_PEER,
|
||||
];
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
use FederationLib\Exceptions\Standard\InvalidClientDescriptionException;
|
||||
use FederationLib\Exceptions\Standard\InvalidClientNameException;
|
||||
use FederationLib\Managers\ClientManager;
|
||||
use FederationLib\Managers\PeerManager;
|
||||
use FederationLib\Objects\ClientRecord;
|
||||
use FederationLib\Objects\ResolvedIdentity;
|
||||
use FederationLib\Objects\Standard\ClientIdentity;
|
||||
|
@ -27,12 +28,18 @@
|
|||
*/
|
||||
private ClientManager $client_manager;
|
||||
|
||||
/**
|
||||
* @var PeerManager
|
||||
*/
|
||||
private PeerManager $peer_manager;
|
||||
|
||||
/**
|
||||
* FederationLib constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->client_manager = new ClientManager($this);
|
||||
$this->peer_manager = new PeerManager($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +153,7 @@
|
|||
|
||||
if($resolved_identity->getPeer() !== null)
|
||||
{
|
||||
return $resolved_identity->getPeer()->getFederatedAddress();
|
||||
return $resolved_identity->getPeer()->getAddress();
|
||||
}
|
||||
|
||||
if($resolved_identity->getClient() !== null)
|
||||
|
@ -337,4 +344,46 @@
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClientIdentity|null $identity
|
||||
* @param string $federated_address
|
||||
* @param array $metadata
|
||||
* @return bool
|
||||
* @throws AccessDeniedException
|
||||
* @throws ClientNotFoundException
|
||||
* @throws DatabaseException
|
||||
* @throws Exceptions\Standard\InvalidFederatedAddressException
|
||||
* @throws Exceptions\Standard\InvalidPeerMetadataException
|
||||
* @throws Exceptions\Standard\UnsupportedPeerType
|
||||
* @throws InternalServerException
|
||||
*/
|
||||
public function syncPeer(?ClientIdentity $identity, string $federated_address, array $metadata): bool
|
||||
{
|
||||
if(!$this->checkPermission(Methods::SYNC_PEER, $this->resolveIdentity($identity)))
|
||||
{
|
||||
throw new Exceptions\Standard\AccessDeniedException('You do not have sufficient permission to sync a peer');
|
||||
}
|
||||
|
||||
if($identity === null)
|
||||
{
|
||||
throw new Exceptions\Standard\AccessDeniedException('You must be authenticated to sync a peer');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->peer_manager->syncPeer($identity->getClientUuid(), $federated_address, $metadata);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
if(in_array($e->getCode(), ErrorCodes::ALL, true))
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw new Exceptions\Standard\InternalServerException('There was an error while syncing the peer', $e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue