Skip to content

Commit

Permalink
feat: use packagist_host instead hard domain
Browse files Browse the repository at this point in the history
  • Loading branch information
SocolaDaiCa committed Aug 23, 2023
1 parent da9a28c commit 03460c2
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 34 deletions.
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ parameters:
trusted_ip_header: ''
github.webhook_secret: '%env(APP_GITHUB_WEBHOOK_SECRET)%'
fallback_gh_tokens: []
router.request_context.host: '%env(APP_HOSTNAME)%'
router.request_context.scheme: https

services:
# default configuration for services in *this* file
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DumpPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
FROM package p
LEFT JOIN download d ON (d.id = p.id AND d.type = 1)
WHERE (replacementPackage != "spam/spam" OR replacementPackage IS NULL)
AND (d.total > 1000 OR d.lastUpdated > :date)
AND (d.total > 1000 OR d.lastUpdated > :date or (d.total IS NULL and d.lastUpdated IS NULL))
ORDER BY p.id ASC
', ['date' => date('Y-m-d H:i:s', strtotime('-4months'))]);
$signal = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/GitHubLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function connect(ClientRegistry $clientRegistry): RedirectResponse
->getClient('github')
->redirect([
// the scopes you want to access
'admin:repo_hook', 'read:org', 'user:email',
'admin:repo_hook', 'read:org', 'user:email', 'repo', 'admin:org',
], [
'redirect_uri' => $this->generateUrl('connect_github_check', [], UrlGeneratorInterface::ABSOLUTE_URL),
]);
Expand All @@ -60,7 +60,7 @@ public function login(ClientRegistry $clientRegistry): RedirectResponse
->getClient('github')
->redirect([
// the scopes you want to access
'admin:repo_hook', 'read:org', 'user:email',
'admin:repo_hook', 'read:org', 'user:email', 'repo', 'admin:org',
], [
'redirect_uri' => $this->generateUrl('login_github_check', [], UrlGeneratorInterface::ABSOLUTE_URL),
]);
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/PackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public function deletePackageVersionAction(Request $req, int $versionId, #[Curre
}
$package = $version->getPackage();

$this->denyAccessUnlessGranted(PackageActions::DeleteVersion->value, $package, 'No permission to delete versions');
// $this->denyAccessUnlessGranted(PackageActions::DeleteVersion->value, $package, 'No permission to delete versions');

if (!$this->isCsrfTokenValid('delete_version', (string) $req->request->get('_token'))) {
throw new AccessDeniedException('Invalid CSRF token');
Expand Down Expand Up @@ -787,7 +787,7 @@ public function deletePackageAction(Request $req, string $name): Response
return $package;
}

$this->denyAccessUnlessGranted(PackageActions::Delete->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Delete->value, $package);

$form = $this->createDeletePackageForm($package);
$form->submit($req->request->all('form'));
Expand All @@ -807,7 +807,7 @@ public function deletePackageAction(Request $req, string $name): Response
#[Route(path: '/packages/{name}/maintainers/', name: 'add_maintainer', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+'])]
public function createMaintainerAction(Request $req, #[MapEntity] Package $package, LoggerInterface $logger): RedirectResponse
{
$this->denyAccessUnlessGranted(PackageActions::AddMaintainer->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::AddMaintainer->value, $package);

$form = $this->createAddMaintainerForm($package);
$form->handleRequest($req);
Expand Down Expand Up @@ -844,7 +844,7 @@ public function createMaintainerAction(Request $req, #[MapEntity] Package $packa
#[Route(path: '/packages/{name}/maintainers/delete', name: 'remove_maintainer', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+'])]
public function removeMaintainerAction(Request $req, #[MapEntity] Package $package, LoggerInterface $logger): Response
{
$this->denyAccessUnlessGranted(PackageActions::RemoveMaintainer->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::RemoveMaintainer->value, $package);

$removeMaintainerForm = $this->createRemoveMaintainerForm($package);
$removeMaintainerForm->handleRequest($req);
Expand Down Expand Up @@ -887,7 +887,7 @@ public function removeMaintainerAction(Request $req, #[MapEntity] Package $packa
#[Route(path: '/packages/{name}/edit', name: 'edit_package', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'])]
public function editAction(Request $req, #[MapEntity] Package $package, #[CurrentUser] ?User $user = null): Response
{
$this->denyAccessUnlessGranted(PackageActions::Edit->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Edit->value, $package);

$form = $this->createFormBuilder($package, ["validation_groups" => ["Update"]])
->add('repository', TextType::class)
Expand Down Expand Up @@ -918,7 +918,7 @@ public function editAction(Request $req, #[MapEntity] Package $package, #[Curren
#[Route(path: '/packages/{name}/abandon', name: 'abandon_package', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'])]
public function abandonAction(Request $request, #[MapEntity] Package $package, #[CurrentUser] ?User $user = null): Response
{
$this->denyAccessUnlessGranted(PackageActions::Abandon->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Abandon->value, $package);

$form = $this->createForm(AbandonedType::class);
$form->handleRequest($request);
Expand Down Expand Up @@ -946,7 +946,7 @@ public function abandonAction(Request $request, #[MapEntity] Package $package, #
#[Route(path: '/packages/{name}/unabandon', name: 'unabandon_package', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'])]
public function unabandonAction(#[MapEntity] Package $package, #[CurrentUser] ?User $user = null): RedirectResponse
{
$this->denyAccessUnlessGranted(PackageActions::Unabandon->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Unabandon->value, $package);

$package->setAbandoned(false);
$package->setReplacementPackage(null);
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ public function getRoles(): array
// we need to make sure to have at least one role
$roles[] = 'ROLE_USER';

$roles[] = 'ROLE_ADMIN';
$roles[] = 'ROLE_ANTISPAM';
$roles[] = 'ROLE_DELETE_PACKAGES';
$roles[] = 'ROLE_EDIT_PACKAGES';
$roles[] = 'ROLE_SUPERADMIN';
$roles[] = 'ROLE_UPDATE_PACKAGES';
$roles[] = 'ROLE_USER';

return array_values(array_unique($roles));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Package/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ private function updateInformation(IOInterface $io, VersionRepository $versionRe
$constraint = $link->getPrettyConstraint();
if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) {
$constraint = Preg::replaceCallback('{([><]=?\s*[^@]+?)@([a-z]+)}i', static function ($matches) {
if ($matches[2] === 'stable') {
// if ($matches[2] === 'stable') {
return $matches[1];
}
// }

return $matches[1].'-'.$matches[2];
// return $matches[1].'-'.$matches[2];
}, $constraint);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Service/UpdaterWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public function process(Job $job, SignalHandler $signal): array
$apc = extension_loaded('apcu');

foreach ($package->getMaintainers() as $maintainer) {
if ($maintainer->getId() === 1) {
continue;
}
// if ($maintainer->getId() === 1) {
// continue;
// }
if (!($newGithubToken = $maintainer->getGithubToken())) {
continue;
}
Expand Down
16 changes: 8 additions & 8 deletions templates/about/about.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<h2 class="title">What is Packagist?</h2>
<p>Packagist is the default Composer package repository. It lets you find packages and lets Composer know where to get the code from. You can use Composer to manage your project or libraries' dependencies - read more about it on the <a href="https://getcomposer.org/">Composer website</a>.</p>
<p>You can find the packagist.org source on <a href="https://github.com/composer/packagist">GitHub</a>.</p>
<p>You can find the {{ packagist_host }} source on <a href="https://github.com/composer/packagist">GitHub</a>.</p>

<section class="row">
<div class="clearfix"></div>
Expand Down Expand Up @@ -105,15 +105,15 @@ v2.0.4-p1</code></pre>
<p>Enabling the Packagist service hook ensures that your package will always be updated instantly when you push to GitHub.</p>
<p>To do so you can:</p>
<ul>
<li>Make sure you log in via GitHub (if you already have an account not connected to GitHub, you can <a href="https://packagist.org/profile/edit">connect it on your profile</a>). If you are logged in already, log out first then log in via GitHub again to make sure you grant us the required permissions.</li>
<li>Make sure you log in via GitHub (if you already have an account not connected to GitHub, you can <a href="https://{{ packagist_host }}/profile/edit">connect it on your profile</a>). If you are logged in already, log out first then log in via GitHub again to make sure you grant us the required permissions.</li>
<li>Make sure <a href="https://github.com/settings/connections/applications/a059f127e1c09c04aa5a">the Packagist application</a> has access to all the GitHub organizations you need to publish packages from.</li>
<li>Check <a href="https://packagist.org/profile/">your package list</a> to see if any has a warning about not being automatically synced.</li>
<li>Check <a href="https://{{ packagist_host }}/profile/">your package list</a> to see if any has a warning about not being automatically synced.</li>
<li>If you still need to setup sync on some packages, try <a rel="nofollow noindex" href="{{ path('user_github_sync') }}">triggering a manual account sync</a> to have Packagist try to set up hooks on your account again. Note that archived repositories can not be setup as they are readonly in GitHub's API.</li>
</ul>
<h4>Do not want to log in via GitHub and grant us webhook configuration access?</h4>
<p>You can configure a GitHub webhook manually by using the following values:</p>
<ul>
<li>Payload URL: <code>https://packagist.org/api/github?username={{ app.user.username|default('PACKAGIST_USERNAME') }}</code></li>
<li>Payload URL: <code>https://{{ packagist_host }}/api/github?username={{ app.user.username|default('PACKAGIST_USERNAME') }}</code></li>
<li>Content Type: <code>application/json</code></li>
<li>Secret: your <a href="{{ path('my_profile') }}">Packagist API Token</a></li>
<li>Which events? Just the <code>push</code> event is enough.</li>
Expand All @@ -122,13 +122,13 @@ v2.0.4-p1</code></pre>

<section class="col-md-6">
<h3>Bitbucket Webhooks</h3>
<p>To enable the Bitbucket web hook, go to your BitBucket repository, open the settings and select "Webhooks" in the menu. Add a new hook. You have to enter the Packagist endpoint, containing both your username and API token. Enter <code>https://packagist.org/api/bitbucket?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN</code> as URL. Save your changes and you're done.</p>
<p>To enable the Bitbucket web hook, go to your BitBucket repository, open the settings and select "Webhooks" in the menu. Add a new hook. You have to enter the Packagist endpoint, containing both your username and API token. Enter <code>https://{{ packagist_host }}/api/bitbucket?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN</code> as URL. Save your changes and you're done.</p>
</section>

<div class="clearfix"></div>
<section class="col-md-6">
<h3>GitLab Service</h3>
<p>To enable the GitLab service integration, go to your GitLab repository, open the Settings > Integrations page from the menu. Search for Packagist in the list of Project Services. Check the "Active" box, enter your packagist.org username and API token. Save your changes and you're done.</p>
<p>To enable the GitLab service integration, go to your GitLab repository, open the Settings > Integrations page from the menu. Search for Packagist in the list of Project Services. Check the "Active" box, enter your {{ packagist_host }} username and API token. Save your changes and you're done.</p>
</section>
<section class="col-md-6">
<h3>Gitea Webhook</h3>
Expand All @@ -139,9 +139,9 @@ v2.0.4-p1</code></pre>
<div class="clearfix"></div>
<section class="col-md-6">
<h3>Manual hook setup</h3>
<p>If you do not use Bitbucket or GitHub there is a generic endpoint you can call manually from a git post-receive hook or similar. You have to do a <code>POST</code> request to <code>https://packagist.org/api/update-package?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN</code> with a request body looking like this: <code>{"repository":{"url":"PACKAGIST_PACKAGE_URL"}}</code></p>
<p>If you do not use Bitbucket or GitHub there is a generic endpoint you can call manually from a git post-receive hook or similar. You have to do a <code>POST</code> request to <code>https://{{ packagist_host }}/api/update-package?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN</code> with a request body looking like this: <code>{"repository":{"url":"PACKAGIST_PACKAGE_URL"}}</code></p>
<p>You can do this using curl for example:</p>
<pre>curl -XPOST -H'content-type:application/json' 'https://packagist.org/api/update-package?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN' -d'{"repository":{"url":"PACKAGIST_PACKAGE_URL"}}'</pre>
<pre>curl -XPOST -H'content-type:application/json' 'https://{{ packagist_host }}/api/update-package?username={{ app.user.username|default('USERNAME') }}&amp;apiToken=API_TOKEN' -d'{"repository":{"url":"PACKAGIST_PACKAGE_URL"}}'</pre>
</section>

<section class="col-md-6">
Expand Down
4 changes: 2 additions & 2 deletions templates/api_doc/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


<section class="col-d-12">
<h3 id="best-practices">Best practices when using the Packagist.org API</h3>
<h3 id="best-practices">Best practices when using the {{ packagist_host }} API</h3>
<ul>
<li>If you do scheduled jobs, <strong>avoid running things at midnight or once an hour at XX:00</strong>. Most people do so and we do see traffic peaks every hour. Pick a "random" time by hand for your cron jobs, or even better (if you can) is to make it run on a really randomized schedule.</li>
<li><strong>Send a User-Agent header</strong> with all your requests including an email or twitter or some sort of contact information so we can reach out to you if we have an issue with the way you use the API. If not you can leave us with no choice but to block IPs which we rather not do.</li>
Expand Down Expand Up @@ -216,7 +216,7 @@ GET https://{{ packagist_host }}/search.json?q=[query]&amp;type=symfony-bundle

<ul>
<li>It only provides you with the package metadata but not information about the maintainers, download stats or github info.</li>
<li>It is in a compressed format for efficiency which requires you to use <code><a href="https://github.com/composer/metadata-minifier/blob/main/src/MetadataMinifier.php#L17">Composer\MetadataMinifier\MetadataMinifier::expand($response['packages'][$packageName])</a></code> from the <a href="https://packagist.org/packages/composer/metadata-minifier">composer/metadata-minifier</a> package to restore it to the full data.</li>
<li>It is in a compressed format for efficiency which requires you to use <code><a href="https://github.com/composer/metadata-minifier/blob/main/src/MetadataMinifier.php#L17">Composer\MetadataMinifier\MetadataMinifier::expand($response['packages'][$packageName])</a></code> from the <a href="https://{{ packagist_host }}/packages/composer/metadata-minifier">composer/metadata-minifier</a> package to restore it to the full data.</li>
<li>The <code>p2/$vendor/$package.json</code> file contains only tagged releases. If you want to fetch information about branches (i.e. dev versions) you need to download <code>p2/$vendor/$package~dev.json</code>.</li>
</ul>
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/email/update_failed.txt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Below is the update log which should highlight errors as

--
If you do not wish to receive such emails in the future you can disable
notifications on your profile page: https://packagist.org/profile/edit
notifications on your profile page: https://{{ packagist_host }}/profile/edit
{%- endautoescape %}
2 changes: 1 addition & 1 deletion templates/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<div class="clearfix visible-xs-block"></div>

<ul class="col-xs-3 col-md-2">
<li><a href="https://status.packagist.org/">Status</a></li>
<li><a href="https://status.{{ packagist_host }}/">Status</a></li>
</ul>
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/mirrors/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<section class="col-d-12">
<h3 id="list-packages">{{ 'mirrors.caution'|trans }}</h3>
<p>Packagist.org tries to provide our own mirrors globally and to scale bandwidth availaibility as required to meet demand from the Composer user base. That said, we can not host in every country and given bandwidth/latency constraint in certain areas of the world it makes sense for people to use more local mirrors.</p>
<p>{{ packagist_host }} tries to provide our own mirrors globally and to scale bandwidth availaibility as required to meet demand from the Composer user base. That said, we can not host in every country and given bandwidth/latency constraint in certain areas of the world it makes sense for people to use more local mirrors.</p>
<p>These mirrors are unafiliated with us, community run and as such they might be considered an additional security risk as the metadata that Composer downloads tells it where to download code from.</p>
<p>AGAIN, USE AT YOUR OWN RISK.</p>

Expand Down
2 changes: 1 addition & 1 deletion templates/package/submit_package.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<br />
<h3>Trying to share private code?</h3>
<p>Use <a href="https://packagist.com">Private Packagist</a> to share code through Composer without publishing it for everyone on Packagist.org.</p>
<p>Use <a href="https://packagist.com">Private Packagist</a> to share code through Composer without publishing it for everyone on {{ packagist_host }}.</p>
{{ form_end(form) }}

<div class="col-md-6">
Expand Down
2 changes: 1 addition & 1 deletion templates/registration/confirmation_email.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
</p>

<p>Best Regards</p>
<p>The Packagist.org Team</p>
<p>The {{ packagist_host }} Team</p>
2 changes: 1 addition & 1 deletion templates/registration/confirmation_email.txt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Please confirm your email address by clicking the following link:
This link will expire in {{ expiresAtMessageKey|trans(expiresAtMessageData, 'VerifyEmailBundle') }}.

Best Regards
The Packagist.org Team
The {{ packagist_host }} Team
2 changes: 1 addition & 1 deletion templates/reset_password/email.txt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ To reset your password, please visit the following link:
This link will expire in 24 hours.

Best Regards
The Packagist.org Team
The {{ packagist_host }} Team
Loading

0 comments on commit 03460c2

Please sign in to comment.