Skip to content

Added some composer authentication types #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
'ereg_to_preg' => true,
'dir_constant' => true,
'method_chaining_indentation' => false,
'string_implicit_backslashes' => [
'single_quoted' => 'escape',
'heredoc' => 'escape',
'double_quoted' => 'escape'
]
])
->setFinder($finder)
->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"php-etl/configurator-contracts": "0.8.*",
"php-etl/satellite-toolbox": "*",
"php-etl/gyroscops-api-client": "^0.3.0",
"php-etl/dockerfile": "*",
"php-etl/dockerfile": "dev-composer-authentication",
"composer/composer": "*",
"symfony/deprecation-contracts": "*",
"react/child-process": "^0.7",
Expand Down
20 changes: 11 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 24 additions & 39 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false">
<testsuites>
<testsuite name="schema">
<directory>tests/schema/</directory>
<exclude>vendor/</exclude>
</testsuite>
<testsuite name="functional">
<directory>tests/functional/</directory>
<exclude>vendor/</exclude>
</testsuite>
<testsuite name="integration">
<directory>tests/integration/</directory>
<exclude>vendor/</exclude>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="allow_url_include" value="1" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="true" colors="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" cacheDirectory=".phpunit.cache" backupStaticProperties="false" requireCoverageMetadata="false">
<testsuites>
<testsuite name="schema">
<directory>tests/schema/</directory>
<exclude>vendor/</exclude>
</testsuite>
<testsuite name="functional">
<directory>tests/functional/</directory>
<exclude>vendor/</exclude>
</testsuite>
<testsuite name="integration">
<directory>tests/integration/</directory>
<exclude>vendor/</exclude>
</testsuite>
</testsuites>
<coverage/>
<php>
<ini name="allow_url_include" value="1"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Action/ConfigurationApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class ConfigurationApplier
{
private ?Satellite\Action\Action $action = null;
private ?Action $action = null;
private array $packages = [];

public function __construct(
Expand All @@ -22,7 +22,7 @@ public function __construct(

public function withAction(): self
{
$this->action = new Satellite\Action\Action($this->plugin, clone $this->interpreter);
$this->action = new Action($this->plugin, clone $this->interpreter);

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Action/Custom/Factory/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function validate(array $config): bool
/**
* @throws Configurator\ConfigurationExceptionInterface
*/
public function compile(array $config): Custom\Factory\Repository\Action
public function compile(array $config): Repository\Action
{
$containerName = sprintf('ProjectServiceContainer%s', ByteString::fromRandom(8)->toString());

Expand All @@ -74,7 +74,7 @@ public function compile(array $config): Custom\Factory\Repository\Action

$container = (new SatelliteDependencyInjection(...$this->providers))($config);

$repository = new Custom\Factory\Repository\Action($builder);
$repository = new Repository\Action($builder);

$dumper = new PhpDumper($container);
$repository->addFiles(
Expand Down
5 changes: 2 additions & 3 deletions src/Action/Custom/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Kiboko\Component\Satellite\Action\Custom;

use Kiboko\Component\Satellite\Action\Custom;
use Kiboko\Component\Satellite\ExpressionLanguage as Satellite;
use Kiboko\Contract\Configurator;
use Symfony\Component\Config\Definition\Exception as Symfony;
Expand All @@ -26,7 +25,7 @@ public function __construct(
private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage()
) {
$this->processor = new Processor();
$this->configuration = new Custom\Configuration();
$this->configuration = new Configuration();
}

public function interpreter(): ExpressionLanguage
Expand Down Expand Up @@ -78,7 +77,7 @@ public function compile(array $config): Configurator\RepositoryInterface
}
}

$actionFactory = new Custom\Factory\Action($this->interpreter);
$actionFactory = new Factory\Action($this->interpreter);

return $actionFactory->compile($config);
}
Expand Down
57 changes: 57 additions & 0 deletions src/Adapter/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,61 @@ public function addAuthenticationToken(string $url, string $token): void
$token
);
}

public function addGitlabOauthAuthentication(string $token, string $url = 'gitlab.com'): void
{
$this->command(
'composer',
'config',
'--auth',
sprintf('gitlab-oauth.%s', $url),
'token',
$token
);
}

public function addGitlabTokenAuthentication(string $token, string $url = 'gitlab.com'): void
{
$this->command(
'composer',
'config',
'--auth',
sprintf('gitlab-token.%s', $url),
$token
);
}

public function addGithubOauthAuthentication(string $token, string $url = 'github.com'): void
{
$this->command(
'composer',
'config',
'--auth',
sprintf('github-oauth.%s', $url),
$token
);
}

public function addHttpBasicAuthentication(string $url, string $username, string $password): void
{
$this->command(
'composer',
'config',
'--auth',
sprintf('http-basic.%s', $url),
$username,
$password,
);
}

public function addHttpBearerAuthentication(string $url, string $token): void
{
$this->command(
'composer',
'config',
'--auth',
sprintf('bearer.%s', $url),
$token
);
}
}
2 changes: 1 addition & 1 deletion src/Adapter/ComposerFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class ComposerFailureException extends \RuntimeException
{
public function __construct(private readonly string $command = '', string $message = '', int $code = 0, \Throwable $previous = null)
public function __construct(private readonly string $command = '', string $message = '', int $code = 0, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Adapter/Docker/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ public function __invoke(array $configuration): Configurator\SatelliteBuilderInt

if (\array_key_exists('auth', $configuration['composer']) && (is_countable($configuration['composer']['auth']) ? \count($configuration['composer']['auth']) : 0) > 0) {
foreach ($configuration['composer']['auth'] as $auth) {
$builder->withComposerAuthenticationToken($auth['url'], $auth['token']);
match ($auth['type']) {
'gitlab-oauth' => $builder->withGitlabOauthAuthentication($auth['token'], $auth['url'] ?? 'gitlab.com'),
'gitlab-token' => $builder->withGitlabTokenAuthentication($auth['token'], $auth['url'] ?? 'gitlab.com'),
'github-oauth' => $builder->withGithubOauthAuthentication($auth['token'], $auth['url'] ?? 'github.com'),
'http-basic' => $builder->withHttpBasicAuthentication($auth['url'], $auth['username'], $auth['password']),
'http-bearer' => $builder->withHttpBearerAuthentication($auth['url'], $auth['token']),
default => throw new \LogicException(),
};
}
}
}
Expand Down
Loading