|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Http\Client\Common\Plugin\LoggerPlugin; |
| 4 | +use Monolog\Handler\StreamHandler; |
| 5 | +use Monolog\Logger; |
3 | 6 | use PrivatePackagist\ApiClient\Client; |
4 | 7 | use PrivatePackagist\ApiClient\Exception\HttpTransportException; |
5 | 8 | use PrivatePackagist\ApiClient\Exception\ResourceNotFoundException; |
| 9 | +use PrivatePackagist\ApiClient\HttpClient\HttpPluginClientBuilder; |
6 | 10 | use Symfony\Component\Mime\MimeTypes; |
7 | 11 |
|
8 | 12 | require_once __DIR__ . '/../vendor/autoload.php'; |
|
12 | 16 | } |
13 | 17 |
|
14 | 18 | $packageName = $argv[1]; |
15 | | -$fileName = $argv[2]; |
| 19 | +$fileNameWithPath = $argv[2]; |
16 | 20 | $organizationUrlName = $argv[3]; |
17 | 21 | $privatePackagistUrl = $argv[4]; |
| 22 | +$fileName = basename($fileNameWithPath); |
18 | 23 |
|
19 | | -if (!file_exists($fileName)) { |
20 | | - throw new \RuntimeException('File not found: ' . $fileName); |
| 24 | +if (!file_exists($fileNameWithPath)) { |
| 25 | + throw new \RuntimeException('File not found: ' . $fileNameWithPath); |
21 | 26 | } |
22 | 27 |
|
23 | | -$client = new Client(null, $privatePackagistUrl); |
| 28 | +$logger = new Logger('trusted-publishing'); |
| 29 | +$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); |
| 30 | +$httpClientBuilder = new HttpPluginClientBuilder(); |
| 31 | +$httpClientBuilder->addPlugin(new LoggerPlugin($logger)); |
| 32 | +$client = new Client(null, $privatePackagistUrl, null, $logger); |
24 | 33 |
|
25 | 34 | if (isset($_SERVER['PRIVATE_PACKAGIST_API_KEY']) && isset($_SERVER['PRIVATE_PACKAGIST_API_SECRET'])) { |
26 | 35 | $client->authenticate($_SERVER['PRIVATE_PACKAGIST_API_KEY'], $_SERVER['PRIVATE_PACKAGIST_API_SECRET']); |
| 36 | +} else { |
| 37 | + $client->authenticateWithTrustedPublishing($organizationUrlName, $packageName); |
27 | 38 | } |
28 | 39 |
|
29 | 40 | try { |
30 | | - $file = file_get_contents($fileName); |
31 | | - $contentType = MimeTypes::getDefault()->guessMimeType($fileName); |
| 41 | + $file = file_get_contents($fileNameWithPath); |
| 42 | + $contentType = MimeTypes::getDefault()->guessMimeType($fileNameWithPath); |
32 | 43 |
|
33 | 44 | try { |
34 | 45 | $client->packages()->artifacts()->add($packageName, $file, $contentType, $fileName); |
|
0 commit comments