Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
List of adapters:
* [GitHub](https://github.com/) (WIP)
* [Camunda](https://docs.camunda.org/manual/7.9/)
* LDAP (Planned)
* [MatterMost](https://mattermost.com/) (Planned)
* [LDAP](https://ldap.com/)
* [MatterMost](https://mattermost.com/)

## Installation

Expand Down Expand Up @@ -94,4 +94,4 @@ Array
```

### Integrations
* [OrgSync CLI](https://github.com/linkorb/org-sync-cli)
* [OrgSync CLI](https://github.com/linkorb/org-sync-cli)
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"description": "Organization sync library",
"require": {
"php": "^7.2",
"ext-json": "*",
"ext-ldap": "*",
"doctrine/annotations": "^1.6",
"gnello/php-mattermost-driver": "^2.9",
"knplabs/github-api": "^2.11",
"php-http/guzzle6-adapter": "^1.1",
"symfony/cache": "^4.3",
"symfony/property-access": "^4.3",
"symfony/property-info": "^4.3",
"symfony/serializer": "^4.3",
"ext-json": "*"
"symfony/serializer": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^8"
Expand Down
7 changes: 7 additions & 0 deletions src/DTO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public function getProperties(): array
return $this->properties;
}

public function addProperty(string $key, string $value, bool $override = true): Group
{
$this->properties[$key] = ($override || !isset($this->properties[$key])) ? $value : $this->properties[$key];

return $this;
}

/**
* @return Target[]
*/
Expand Down
10 changes: 9 additions & 1 deletion src/DTO/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
/**
* @DiscriminatorMap(typeProperty="type", mapping={
* "camunda"="LinkORB\OrgSync\DTO\Target\Camunda",
* "github"="LinkORB\OrgSync\DTO\Target\Github",
* "ldap"="LinkORB\OrgSync\DTO\Target\Ldap",
* "mattermost"="LinkORB\OrgSync\DTO\Target\Mattermost",
* })
*/
abstract class Target
{
public const USER_PUSH = 'push_user';
public const GROUP_PUSH = 'push_group';
public const SET_PASSWORD = 'set_password';
public const PULL_ORGANIZATION = 'organization_pull';

/** @var string */
private $baseUrl;
protected $baseUrl;

/** @var string */
private $name;
Expand Down
25 changes: 25 additions & 0 deletions src/DTO/Target/Github.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace LinkORB\OrgSync\DTO\Target;

use LinkORB\OrgSync\DTO\Target;

class Github extends Target
{
/**
* @var string
*/
private $token;

public function __construct(string $baseUrl, string $name, string $token)
{
$this->token = $token;

parent::__construct($baseUrl, $name);
}

public function getToken(): string
{
return $this->token;
}
}
55 changes: 55 additions & 0 deletions src/DTO/Target/Ldap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php declare(strict_types=1);

namespace LinkORB\OrgSync\DTO\Target;

use LinkORB\OrgSync\DTO\Target;

final class Ldap extends Target
{
/**
* @var string;
*/
private $bindRdn;

/**
* @var string
*/
private $password;

/**
* @var string[]
*/
private $domain;

public function __construct(
string $baseUrl,
string $name,
string $bindRdn,
string $password,
array $domain
) {
parent::__construct($baseUrl, $name);

$this->bindRdn = $bindRdn;
$this->password = $password;
$this->domain = $domain;
}

public function getBindRdn(): string
{
return $this->bindRdn;
}

public function getPassword(): string
{
return $this->password;
}

/**
* @return string[]
*/
public function getDomain(): array
{
return $this->domain;
}
}
59 changes: 59 additions & 0 deletions src/DTO/Target/Mattermost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);

namespace LinkORB\OrgSync\DTO\Target;

use LinkORB\OrgSync\DTO\Target;

class Mattermost extends Target
{
/** @var string */
private $token;

/** @var string */
private $login;

/** @var string */
private $password;

/** @var string */
private $scheme;

public function __construct(
string $baseUrl,
string $name,
string $token = null,
string $login = null,
string $password = null
) {
parent::__construct($baseUrl, $name);

$urlParts = explode('://', $this->getBaseUrl(), 2);

$this->baseUrl = end($urlParts);
$this->scheme = reset($urlParts);

$this->token = $token;
$this->login = $login;
$this->password = $password;
}

public function getToken(): ?string
{
return $this->token;
}

public function getLogin(): ?string
{
return $this->login;
}

public function getPassword(): ?string
{
return $this->password;
}

public function getScheme(): string
{
return $this->scheme;
}
}
24 changes: 22 additions & 2 deletions src/DTO/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

class User
{
public const PREVIOUS_PASSWORD = 'previousPassword';
public const FIRST_NAME = 'firstName';
public const LAST_NAME = 'lastName';

/**
* @var string
*/
Expand Down Expand Up @@ -76,10 +80,26 @@ public function getPassword(): ?string
return $this->password;
}

public function setPassword(?string $password): self
{
$this->password = $password;

return $this;
}

public function setPreviousPassword(?string $password): self
{
if ($password !== null) {
$this->properties[static::PREVIOUS_PASSWORD] = $password;
}

return $this;
}

/**
* @return string
* @return string|null
*/
public function getEmail(): string
public function getEmail(): ?string
{
return $this->email;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Camunda/CamundaUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function map(array $data): User
null,
null,
[
'firstName' => $data['firstName'] ?? null,
'lastName' => $data['lastName'] ?? null,
User::FIRST_NAME => $data['firstName'] ?? null,
User::LAST_NAME => $data['lastName'] ?? null,
]
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Services/InputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use LinkORB\OrgSync\DTO\Group;
use LinkORB\OrgSync\DTO\Organization;
use LinkORB\OrgSync\DTO\Target;
use LinkORB\OrgSync\DTO\User;
use LinkORB\OrgSync\Services\Target\TargetPool;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

class InputHandler
{
public const GITHUB_ORGANIZATION = 'github_organization';

/** @var TargetPool */
private $targetsPool;

Expand Down Expand Up @@ -59,6 +62,8 @@ public function handle(array $targets, array $organization): Organization
);

foreach ($organizationDto->getGroups() as $group) {
$group->addProperty(static::GITHUB_ORGANIZATION, $organizationDto->getName(), false);

$this->handleGroupParents($groupsParents, $group, $organizationDto);
$this->handleGroupMembers($groupsMembers, $group, $organizationDto);
$this->handleGroupTargets($groupsTargets, $group);
Expand All @@ -67,6 +72,9 @@ public function handle(array $targets, array $organization): Organization
return $organizationDto;
}

/**
* @return Target[]
*/
public function getTargets(): array
{
return $this->targetsPool->all();
Expand Down Expand Up @@ -120,4 +128,4 @@ private function handleGroupTargets(array $groupsTargets, Group $group): void
);
}
}
}
}
Loading