From 8b7feef2bc3d470373d3f327bc764b0305ec57c5 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 26 Jun 2024 16:06:31 +0200 Subject: [PATCH 1/5] Added new composer config commands for composer authentication --- src/PHP/ComposerAuthenticationToken.php | 1 + src/PHP/ComposerGithubOauthAuthentication.php | 23 +++++++++++++++++ src/PHP/ComposerGitlabOauthAuthentication.php | 24 ++++++++++++++++++ src/PHP/ComposerGitlabTokenAuthentication.php | 24 ++++++++++++++++++ src/PHP/ComposerHttpBasicAuthentication.php | 25 +++++++++++++++++++ src/PHP/ComposerHttpBearerAuthentication.php | 24 ++++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 src/PHP/ComposerGithubOauthAuthentication.php create mode 100644 src/PHP/ComposerGitlabOauthAuthentication.php create mode 100644 src/PHP/ComposerGitlabTokenAuthentication.php create mode 100644 src/PHP/ComposerHttpBasicAuthentication.php create mode 100644 src/PHP/ComposerHttpBearerAuthentication.php diff --git a/src/PHP/ComposerAuthenticationToken.php b/src/PHP/ComposerAuthenticationToken.php index 76a3df4..f5045fd 100644 --- a/src/PHP/ComposerAuthenticationToken.php +++ b/src/PHP/ComposerAuthenticationToken.php @@ -6,6 +6,7 @@ use Kiboko\Component\Dockerfile\Dockerfile; +/** @deprecated */ final readonly class ComposerAuthenticationToken implements Dockerfile\LayerInterface, \Stringable { public function __construct( diff --git a/src/PHP/ComposerGithubOauthAuthentication.php b/src/PHP/ComposerGithubOauthAuthentication.php new file mode 100644 index 0000000..c5a260e --- /dev/null +++ b/src/PHP/ComposerGithubOauthAuthentication.php @@ -0,0 +1,23 @@ +token)); + } +} diff --git a/src/PHP/ComposerGitlabOauthAuthentication.php b/src/PHP/ComposerGitlabOauthAuthentication.php new file mode 100644 index 0000000..857f419 --- /dev/null +++ b/src/PHP/ComposerGitlabOauthAuthentication.php @@ -0,0 +1,24 @@ +instance, $this->token)); + } +} diff --git a/src/PHP/ComposerGitlabTokenAuthentication.php b/src/PHP/ComposerGitlabTokenAuthentication.php new file mode 100644 index 0000000..55e3437 --- /dev/null +++ b/src/PHP/ComposerGitlabTokenAuthentication.php @@ -0,0 +1,24 @@ +instance, $this->token)); + } +} diff --git a/src/PHP/ComposerHttpBasicAuthentication.php b/src/PHP/ComposerHttpBasicAuthentication.php new file mode 100644 index 0000000..9e733fc --- /dev/null +++ b/src/PHP/ComposerHttpBasicAuthentication.php @@ -0,0 +1,25 @@ +url, $this->username, $this->password)); + } +} diff --git a/src/PHP/ComposerHttpBearerAuthentication.php b/src/PHP/ComposerHttpBearerAuthentication.php new file mode 100644 index 0000000..acfa265 --- /dev/null +++ b/src/PHP/ComposerHttpBearerAuthentication.php @@ -0,0 +1,24 @@ +url, $this->token)); + } +} From f1dbf982d9fb9907ca177004f5f77be32d82fe63 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 26 Jun 2024 16:09:54 +0200 Subject: [PATCH 2/5] Renamed arguments + ran php-cs-fixer --- src/Dockerfile.php | 2 +- src/PHP/ComposerGithubOauthAuthentication.php | 5 +++-- src/PHP/ComposerGitlabOauthAuthentication.php | 4 ++-- src/PHP/ComposerGitlabTokenAuthentication.php | 4 ++-- src/PHP/ComposerHttpBasicAuthentication.php | 4 ++-- src/PHP/ComposerHttpBearerAuthentication.php | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Dockerfile.php b/src/Dockerfile.php index 6308ad4..59f85f8 100644 --- a/src/Dockerfile.php +++ b/src/Dockerfile.php @@ -12,7 +12,7 @@ final class Dockerfile implements \IteratorAggregate, \Countable, FileInterface, /** @var iterable|Dockerfile\LayerInterface[] */ private iterable $layers; - public function __construct(null|LayerInterface ...$layers) + public function __construct(?LayerInterface ...$layers) { $this->layers = $layers; } diff --git a/src/PHP/ComposerGithubOauthAuthentication.php b/src/PHP/ComposerGithubOauthAuthentication.php index c5a260e..1c34ce2 100644 --- a/src/PHP/ComposerGithubOauthAuthentication.php +++ b/src/PHP/ComposerGithubOauthAuthentication.php @@ -10,6 +10,7 @@ { public function __construct( private string $token, + private string $domain = 'github.com', ) { } @@ -17,7 +18,7 @@ public function __toString(): string { return (string) new Dockerfile\Run(sprintf(<<<'RUN' set -ex \ - && composer config --auth github-oauth.github.com %s - RUN, $this->token)); + && composer config --auth github-oauth.%s %s + RUN, $this->domain, $this->token)); } } diff --git a/src/PHP/ComposerGitlabOauthAuthentication.php b/src/PHP/ComposerGitlabOauthAuthentication.php index 857f419..03cdb61 100644 --- a/src/PHP/ComposerGitlabOauthAuthentication.php +++ b/src/PHP/ComposerGitlabOauthAuthentication.php @@ -10,7 +10,7 @@ { public function __construct( private string $token, - private string $instance = 'gitlab.com', + private string $domain = 'gitlab.com', ) { } @@ -19,6 +19,6 @@ public function __toString(): string return (string) new Dockerfile\Run(sprintf(<<<'RUN' set -ex \ && composer config --auth gitlab-oauth.%s %s - RUN, $this->instance, $this->token)); + RUN, $this->domain, $this->token)); } } diff --git a/src/PHP/ComposerGitlabTokenAuthentication.php b/src/PHP/ComposerGitlabTokenAuthentication.php index 55e3437..bd8414e 100644 --- a/src/PHP/ComposerGitlabTokenAuthentication.php +++ b/src/PHP/ComposerGitlabTokenAuthentication.php @@ -10,7 +10,7 @@ { public function __construct( private string $token, - private string $instance = 'gitlab.com', + private string $domain = 'gitlab.com', ) { } @@ -19,6 +19,6 @@ public function __toString(): string return (string) new Dockerfile\Run(sprintf(<<<'RUN' set -ex \ && composer config --auth gitlab-token.%s %s - RUN, $this->instance, $this->token)); + RUN, $this->domain, $this->token)); } } diff --git a/src/PHP/ComposerHttpBasicAuthentication.php b/src/PHP/ComposerHttpBasicAuthentication.php index 9e733fc..b670442 100644 --- a/src/PHP/ComposerHttpBasicAuthentication.php +++ b/src/PHP/ComposerHttpBasicAuthentication.php @@ -9,7 +9,7 @@ final readonly class ComposerHttpBasicAuthentication implements Dockerfile\LayerInterface, \Stringable { public function __construct( - private string $url, + private string $domain, private string $username, private string $password, ) { @@ -20,6 +20,6 @@ public function __toString(): string return (string) new Dockerfile\Run(sprintf(<<<'RUN' set -ex \ && composer config --auth http-basic.%s %s %s - RUN, $this->url, $this->username, $this->password)); + RUN, $this->domain, $this->username, $this->password)); } } diff --git a/src/PHP/ComposerHttpBearerAuthentication.php b/src/PHP/ComposerHttpBearerAuthentication.php index acfa265..dd4f74d 100644 --- a/src/PHP/ComposerHttpBearerAuthentication.php +++ b/src/PHP/ComposerHttpBearerAuthentication.php @@ -9,7 +9,7 @@ final readonly class ComposerHttpBearerAuthentication implements Dockerfile\LayerInterface, \Stringable { public function __construct( - private string $url, + private string $domain, private string $token, ) { } @@ -19,6 +19,6 @@ public function __toString(): string return (string) new Dockerfile\Run(sprintf(<<<'RUN' set -ex \ && composer config --auth bearer.%s %s - RUN, $this->url, $this->token)); + RUN, $this->domain, $this->token)); } } From 54e5507a6741c00603abf3023534781d0561266c Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 26 Jun 2024 16:24:56 +0200 Subject: [PATCH 3/5] Ran php-cs-fixer --- src/PHP/ComposerAutoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHP/ComposerAutoload.php b/src/PHP/ComposerAutoload.php index 3e96cdf..c2248be 100644 --- a/src/PHP/ComposerAutoload.php +++ b/src/PHP/ComposerAutoload.php @@ -38,7 +38,7 @@ private static function escapeArgument(?string $argument): string if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) { return $argument; } - $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument); + $argument = preg_replace('/(\\\+)$/', '$1$1', $argument); return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"'; } From d770fa9f021557cb17fff16e02ba239535af7e7e Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 26 Jun 2024 17:09:20 +0200 Subject: [PATCH 4/5] Reverted CS-fixer change --- src/PHP/ComposerAutoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHP/ComposerAutoload.php b/src/PHP/ComposerAutoload.php index c2248be..3e96cdf 100644 --- a/src/PHP/ComposerAutoload.php +++ b/src/PHP/ComposerAutoload.php @@ -38,7 +38,7 @@ private static function escapeArgument(?string $argument): string if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) { return $argument; } - $argument = preg_replace('/(\\\+)$/', '$1$1', $argument); + $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument); return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"'; } From f49ec82ae87c903f2e5239b1b9bd6b668e75d5a6 Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 1 Jul 2024 15:41:29 +0200 Subject: [PATCH 5/5] Added rule to ignore string implicit backslashes --- .php-cs-fixer.dist.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2a172a0..8b04e81 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -34,6 +34,9 @@ 'error_suppression' => true, 'ereg_to_preg' => true, 'dir_constant' => true, + 'string_implicit_backslashes' => [ + 'single_quoted' => 'ignore', + ], ]) ->setFinder($finder) ->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line