Skip to content
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

Added some composer authentication types #160

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,8 +10,8 @@

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

Check failure on line 14 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan8

Property Kiboko\Component\Satellite\Action\ConfigurationApplier::$packages type has no value type specified in iterable type array.

Check failure on line 14 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan6

Property Kiboko\Component\Satellite\Action\ConfigurationApplier::$packages type has no value type specified in iterable type array.

Check failure on line 14 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan7

Property Kiboko\Component\Satellite\Action\ConfigurationApplier::$packages type has no value type specified in iterable type array.

public function __construct(
private readonly string $plugin,
Expand All @@ -22,7 +22,7 @@

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 All @@ -34,11 +34,11 @@
return $this;
}

public function appendTo(array $config, Satellite\Builder\Repository\Action $action): void

Check failure on line 37 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Component\Satellite\Action\ConfigurationApplier::appendTo() has parameter $config with no value type specified in iterable type array.

Check failure on line 37 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Component\Satellite\Action\ConfigurationApplier::appendTo() has parameter $config with no value type specified in iterable type array.

Check failure on line 37 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Component\Satellite\Action\ConfigurationApplier::appendTo() has parameter $config with no value type specified in iterable type array.
{
$repository = $this->service->compile($config[$this->plugin]);

($this->action)($config, $action->getBuilder(), $repository);

Check failure on line 41 in src/Action/ConfigurationApplier.php

View workflow job for this annotation

GitHub Actions / phpstan8

Trying to invoke Kiboko\Component\Satellite\Action\Action|null but it might not be a callable.

$action->addPackages(...$this->packages);

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 @@ -24,7 +24,7 @@
private readonly Processor $processor;
private readonly ConfigurationInterface $configuration;

public function __construct(

Check failure on line 27 in src/Action/Custom/Factory/Action.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Component\Satellite\Action\Custom\Factory\Action::__construct() has parameter $providers with no value type specified in iterable type array.

Check failure on line 27 in src/Action/Custom/Factory/Action.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Component\Satellite\Action\Custom\Factory\Action::__construct() has parameter $providers with no value type specified in iterable type array.

Check failure on line 27 in src/Action/Custom/Factory/Action.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Component\Satellite\Action\Custom\Factory\Action::__construct() has parameter $providers with no value type specified in iterable type array.
private readonly ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage(),
private readonly array $providers = [],
) {
Expand Down Expand Up @@ -63,7 +63,7 @@
/**
* @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,14 +74,14 @@

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

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

$dumper = new PhpDumper($container);
$repository->addFiles(
new Packaging\File(
sprintf('%s.php', $containerName),
new Packaging\Asset\InMemory(
$dumper->dump(['class' => $containerName, 'namespace' => 'GyroscopsGenerated'])

Check failure on line 84 in src/Action/Custom/Factory/Action.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter #1 $content of class Kiboko\Component\Packaging\Asset\InMemory constructor expects string, array|string given.
)
),
);
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 @@
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 @@ -74,11 +73,11 @@
&& \count($config['expression_language'])
) {
foreach ($config['expression_language'] as $provider) {
$interpreter->registerProvider(new $provider());

Check failure on line 76 in src/Action/Custom/Service.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter #1 $provider of method Symfony\Component\ExpressionLanguage\ExpressionLanguage::registerProvider() expects Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface, object given.
}
}

$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 @@ -167,7 +167,7 @@
{
$composer = json_decode(file_get_contents($this->workdir.'/composer.json'), true, 512, \JSON_THROW_ON_ERROR);
foreach ($autoloads as $type => $autoload) {
match ($type) {

Check failure on line 170 in src/Adapter/Composer.php

View workflow job for this annotation

GitHub Actions / phpstan5

Match expression does not handle remaining value: string
'psr4' => $composer['autoload']['psr-4'] = $autoload,
'file' => $composer['autoload']['file'] = $autoload,
};
Expand Down Expand Up @@ -219,4 +219,61 @@
$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
Loading