Skip to content

Commit

Permalink
Add support for private packages
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l committed Jun 26, 2020
1 parent 176d634 commit 5e6819b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Controller/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public function provider(string $package): JsonResponse
}

/**
* @Route("/p2/{package}.json", name="package_provider_v2", requirements={"package"="%package_name_pattern%"}, methods={"GET"})
* @Route("/p2/{package}.json",
* name="package_provider_v2",
* host="repo.{domain}",
* defaults={"domain"="%domain%"},
* requirements={"package"="%package_name_pattern%","domain"="%domain%"},
* methods={"GET"})
*/
public function providerV2(string $package): JsonResponse
{
Expand Down
20 changes: 20 additions & 0 deletions src/Controller/RepoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Buddy\Repman\Message\Organization\AddDownload;
use Buddy\Repman\Query\User\Model\Organization;
use Buddy\Repman\Query\User\Model\PackageName;
use Buddy\Repman\Query\User\PackageQuery;
use Buddy\Repman\Service\Organization\PackageManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
Expand Down Expand Up @@ -36,6 +37,7 @@ public function packages(Organization $organization): JsonResponse
{
return new JsonResponse([
'packages' => $this->packageManager->findProviders($organization->alias(), $this->packageQuery->getAllNames($organization->id())),
'metadata-url' => '/p2/%package%.json',
'notify-batch' => $this->generateUrl('repo_package_downloads', [
'organization' => $organization->alias(),
], UrlGeneratorInterface::ABSOLUTE_URL),
Expand Down Expand Up @@ -108,6 +110,24 @@ public function downloads(Request $request, Organization $organization): JsonRes
return new JsonResponse(['status' => 'success'], JsonResponse::HTTP_CREATED);
}

/**
* @Route("/p2/{package}.json",
* host="{organization}.repo.{domain}",
* name="repo_package_provider_v2",
* methods={"GET"},
* defaults={"domain":"%domain%"},
* requirements={"domain"="%domain%","package"="%package_name_pattern%"})
*/
public function providerV2(Organization $organization, string $package): JsonResponse
{
$providerData = $this->packageManager->findProviders(
$organization->alias(),
[new PackageName('', $package)]
);

return new JsonResponse($providerData === [] ? new \stdClass() : $providerData);
}

/**
* @return array<string, string>
*/
Expand Down
33 changes: 32 additions & 1 deletion tests/Functional/Controller/RepoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function testOrganizationPackagesAction(): void

self::assertMatchesPattern('
{
"packages": {},
"packages": [],
"metadata-url": "/p2/%package%.json",
"notify-batch": "http://buddy.repo.repman.wip/downloads",
"search": "https://packagist.org/search.json?q=%query%&type=%type%",
"mirrors": [
Expand Down Expand Up @@ -160,4 +161,34 @@ public function testAnonymousUserAccess(): void

self::assertTrue($this->client->getResponse()->isOk());
}

public function testProviderV2Action(): void
{
$adminId = $this->createAndLoginAdmin('[email protected]', 'secret');
$this->fixtures->createToken($this->fixtures->createOrganization('buddy', $adminId), 'secret-org-token');

$this->client->request('GET', '/p2/buddy-works/repman.json', [], [], [
'HTTP_HOST' => 'buddy.repo.repman.wip',
'PHP_AUTH_USER' => 'token',
'PHP_AUTH_PW' => 'secret-org-token',
]);

self::assertTrue($this->client->getResponse()->isOk());

self::assertMatchesPattern('
{
"buddy-works/repman": {
"1.2.3": {
"version": "1.2.3",
"version_normalized": "1.2.3.0",
"dist": {
"type": "zip",
"url": "/path/to/reference.zip",
"reference": "ac7dcaf888af2324cd14200769362129c8dd8550"
}
}
}
}
', $this->client->getResponse()->getContent());
}
}

0 comments on commit 5e6819b

Please sign in to comment.