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
13 changes: 13 additions & 0 deletions src/SelfManage/Verify/FailedToVerifyRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\Pie\SelfManage\Verify;

use Composer\Downloader\TransportException;
use Php\Pie\SelfManage\Update\ReleaseMetadata;
use RuntimeException;
use Symfony\Component\Process\Exception\ProcessFailedException;
Expand All @@ -14,6 +15,18 @@

class FailedToVerifyRelease extends RuntimeException
{
public static function fromGithubAuthenticationFailure(TransportException $transportException): self
{
return new self(
$transportException->getMessage() . ' while downloading attestation to verify PIE. This likely '
. 'means you have not set up GitHub authentication in Composer yet. PIE relies on this Composer '
. 'authentication configuration to make API requests to GitHub; check out '
. 'https://getcomposer.org/doc/articles/authentication-for-private-packages.md#command-line-github-oauth'
. 'for help configuring Composer, or set GITHUB_TOKEN if the environment makes sense',
previous: $transportException,
);
}

public static function fromAttestationException(FailedToVerifyArtifact $failedToVerifyArtifact): self
{
return new self($failedToVerifyArtifact->getMessage(), 0, $failedToVerifyArtifact);
Expand Down
7 changes: 7 additions & 0 deletions src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\Pie\SelfManage\Verify;

use Composer\Downloader\TransportException;
use Composer\IO\IOInterface;
use Php\Pie\File\BinaryFile;
use Php\Pie\SelfManage\Update\FetchPieRelease;
Expand Down Expand Up @@ -73,6 +74,12 @@ public function verify(ReleaseMetadata $releaseMetadata, BinaryFile $pharFilenam
);
} catch (FailedToVerifyArtifact $failedToVerifyArtifact) {
throw FailedToVerifyRelease::fromAttestationException($failedToVerifyArtifact);
} catch (TransportException $transportException) {
if ($transportException->getStatusCode() === 401) {
throw FailedToVerifyRelease::fromGithubAuthenticationFailure($transportException);
}

throw $transportException;
}

$io->write(sprintf(
Expand Down
Loading