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 new composer config commands for composer authentication #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/Dockerfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,43 @@
use Kiboko\Component\Dockerfile\Dockerfile\LayerInterface;
use Kiboko\Contract\Packaging\FileInterface;

final class Dockerfile implements \IteratorAggregate, \Countable, FileInterface, \Stringable

Check failure on line 10 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Dockerfile\Dockerfile implements generic interface IteratorAggregate but does not specify its types: TKey, TValue

Check failure on line 10 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Dockerfile\Dockerfile implements generic interface IteratorAggregate but does not specify its types: TKey, TValue

Check failure on line 10 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Dockerfile\Dockerfile implements generic interface IteratorAggregate but does not specify its types: TKey, TValue
{
/** @var iterable|Dockerfile\LayerInterface[] */
private iterable $layers;

public function __construct(null|LayerInterface ...$layers)
public function __construct(?LayerInterface ...$layers)
{
$this->layers = $layers;

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.

Check failure on line 17 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Component\Dockerfile\Dockerfile::$layers (iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface>) does not accept array<int|string, Kiboko\Component\Dockerfile\Dockerfile\LayerInterface|null>.
}

public function push(LayerInterface ...$layers): void
{
array_push($this->layers, ...$layers);

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 22 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_push expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.
}

public function __toString(): string
{
return implode(\PHP_EOL, array_map(fn (LayerInterface $layer) => (string) $layer.\PHP_EOL, $this->layers));

Check failure on line 27 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #2 $array of function array_map expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 27 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #2 $array of function array_map expects array, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.
}

public function getIterator(): \ArrayIterator

Check failure on line 30 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\Dockerfile::getIterator() return type with generic class ArrayIterator does not specify its types: TKey, TValue

Check failure on line 30 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\Dockerfile::getIterator() return type with generic class ArrayIterator does not specify its types: TKey, TValue

Check failure on line 30 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\Dockerfile::getIterator() return type with generic class ArrayIterator does not specify its types: TKey, TValue
{
return new \ArrayIterator($this->layers);

Check failure on line 32 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of class ArrayIterator constructor expects array<TKey of (int|string), TValue>, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 32 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of class ArrayIterator constructor expects array<TKey of (int|string), TValue>, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.
}

public function count(): int
{
return \count($this->layers);

Check failure on line 37 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $value of function count expects array|Countable, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.

Check failure on line 37 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $value of function count expects array|Countable, iterable<Kiboko\Component\Dockerfile\Dockerfile\LayerInterface> given.
}

public function asResource()
{
$resource = fopen('php://temp', 'rb+');
fwrite($resource, (string) $this);

Check failure on line 43 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $stream of function fwrite expects resource, resource|false given.

Check failure on line 43 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $stream of function fwrite expects resource, resource|false given.
fseek($resource, 0, \SEEK_SET);

Check failure on line 44 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $stream of function fseek expects resource, resource|false given.

Check failure on line 44 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $stream of function fseek expects resource, resource|false given.

return $resource;

Check failure on line 46 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\Dockerfile::asResource() should return resource but returns resource|false.

Check failure on line 46 in src/Dockerfile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\Dockerfile::asResource() should return resource but returns resource|false.
}

public function getPath(): string
Expand Down
1 change: 1 addition & 0 deletions src/PHP/ComposerAuthenticationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Kiboko\Component\Dockerfile\Dockerfile;

/** @deprecated */
final readonly class ComposerAuthenticationToken implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/PHP/ComposerAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final readonly class ComposerAutoload implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(

Check failure on line 11 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Dockerfile\PHP\ComposerAutoload::__construct() has parameter $autoloads with no value type specified in iterable type array.
/**
* @param array<string, array<string, string|list<string>>> $autoloads
*/
Expand Down Expand Up @@ -38,7 +38,7 @@
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
return $argument;
}
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
$argument = preg_replace('/(\\\+)$/', '$1$1', $argument);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce changement est volontaire ou c'est CS-fixer qui l'a provoqué ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est CS-Fixer qui l'a changé


return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"';
}
Expand Down Expand Up @@ -66,7 +66,7 @@

$commands = self::and(
...array_map(
fn ($type, $autoload) => match ($type) {

Check failure on line 69 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)

Check failure on line 69 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)
'psr4' => self::and(
self::pipe(
self::command('cat', 'composer.json'),
Expand Down
24 changes: 24 additions & 0 deletions src/PHP/ComposerGithubOauthAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;

final readonly class ComposerGithubOauthAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $token,
private string $domain = 'github.com',
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(sprintf(<<<'RUN'
set -ex \
&& composer config --auth github-oauth.%s %s
RUN, $this->domain, $this->token));
}
}
24 changes: 24 additions & 0 deletions src/PHP/ComposerGitlabOauthAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;

final readonly class ComposerGitlabOauthAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $token,
private string $domain = 'gitlab.com',
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(sprintf(<<<'RUN'
set -ex \
&& composer config --auth gitlab-oauth.%s %s
RUN, $this->domain, $this->token));
}
}
24 changes: 24 additions & 0 deletions src/PHP/ComposerGitlabTokenAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;

final readonly class ComposerGitlabTokenAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $token,
private string $domain = 'gitlab.com',
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(sprintf(<<<'RUN'
set -ex \
&& composer config --auth gitlab-token.%s %s
RUN, $this->domain, $this->token));
}
}
25 changes: 25 additions & 0 deletions src/PHP/ComposerHttpBasicAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;

final readonly class ComposerHttpBasicAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $domain,
private string $username,
private string $password,
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(sprintf(<<<'RUN'
set -ex \
&& composer config --auth http-basic.%s %s %s
RUN, $this->domain, $this->username, $this->password));
}
}
24 changes: 24 additions & 0 deletions src/PHP/ComposerHttpBearerAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Dockerfile\PHP;

use Kiboko\Component\Dockerfile\Dockerfile;

final readonly class ComposerHttpBearerAuthentication implements Dockerfile\LayerInterface, \Stringable
{
public function __construct(
private string $domain,
private string $token,
) {
}

public function __toString(): string
{
return (string) new Dockerfile\Run(sprintf(<<<'RUN'
set -ex \
&& composer config --auth bearer.%s %s
RUN, $this->domain, $this->token));
}
}
Loading