Skip to content

Commit 2d2b9b3

Browse files
committed
Full Magento demo with generated sample data
1 parent ba242c3 commit 2d2b9b3

16 files changed

+686
-83
lines changed

Diff for: README.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Private Packagist API Demos
2+
3+
## Magento Demo
4+
5+
### Setup
6+
7+
Start by creating a mage id on Magento Marketplace and downloading the packages.json to the project root.
8+
Generate all the data we need for later examples with the following code, listing any purchased extensions so they can
9+
be treated as such:
10+
11+
```
12+
/bin/packagist magento-generate-data foo/bar [more extension-names here]
13+
```
14+
15+
Create API credentials for your Private Packagist organization and set the two environment variables
16+
`PACKAGIST_API_KEY` and `PACKAGIST_API_SECRET` accordingly.
17+
18+
Set environment variables `MAGENTO_PUBLIC_KEY` and `MAGENTO_PRIVATE_KEY` to allow for package download from
19+
current repo.magento.com.
20+
21+
### Importing all default Magento packages
22+
This loads all data for all packages into your organization, it skips the Magento project/product packages, so we can
23+
use them later to simulate releases.
24+
25+
```
26+
./bin/packagist magento-import
27+
```
28+
29+
### Creating a customer
30+
This will create a customer entry for my username and mage id with a corresponding access key pair. It will also grant
31+
access to all default Magento packages stored in packages.json.
32+
33+
```
34+
./bin/packagist magento-customer-add nils_adermann MAG005458681 [public-key here] [private-key here]
35+
```
36+
37+
### Releasing an extension
38+
This requires the version JSON data to be present in `examples/magento-extensions/[package-name]-[version].json`. Each
39+
JSON file for a version should contain the JSON for all previous versions as well. You can generate these files from the
40+
downloaded packages.json using `examples/magento-export.php`.
41+
42+
```
43+
./bin/packagist magento-extension-release foo/bar 1.0.0
44+
```
45+
46+
### Granting a customer access to an extension
47+
This requires the version JSON data to be present in `examples/magento-extensions/[package-name]-[version].json`. Each
48+
JSON file for a version should contain the JSON for all previous versions as well. You can generate these files from the
49+
downloaded packages.json using `examples/magento-export.php`.
50+
51+
```
52+
./bin/packagist magento-extension-grant MAG005458681 foo/bar
53+
```
54+
55+
### Revoking customer access to an extension
56+
```
57+
./bin/packagist magento-extension-revoke MAG005458681 foo/bar
58+
```
59+
60+
### Deleting an extension
61+
```
62+
./bin/packagist magento-extension-remove foo/bar
63+
```
64+
65+
### Granting a customer Enterprise access
66+
```
67+
./bin/packagist magento-enterprise-grant MAG005458681
68+
```
69+
70+
### Revoking Enterprise access from a customer
71+
```
72+
./bin/packagist magento-enterprise-revoke MAG005458681
73+
```
74+
75+
### Complete Script
76+
```
77+
./bin/packagist magento-generate-data foo/bar
78+
./bin/packagist magento-import
79+
./bin/packagist magento-customer-add nils_adermann MAG005458681 [public-key here] [private-key here]
80+
81+
./bin/packagist magento-release 2.0.0
82+
./bin/packagist magento-release 2.1.0
83+
84+
./bin/packagist magento-extension-release foo/bar 1.0.0
85+
./bin/packagist magento-extension-grant MAG005458681 foo/bar
86+
./bin/packagist magento-extension-release foo/bar 1.2.0
87+
./bin/packagist magento-extension-revoke MAG005458681 foo/bar
88+
./bin/packagist magento-extension-release foo/bar 1.3.0
89+
./bin/packagist magento-extension-grant MAG005458681 foo/bar
90+
./bin/packagist magento-extension-remove foo/bar
91+
92+
./bin/packagist magento-enterprise-grant MAG005458681
93+
./bin/packagist magento-release 2.3.0
94+
./bin/packagist magento-enterprise-revoke MAG005458681
95+
gtgt```

Diff for: bin/packagist

100644100755
+14-9
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ declare(strict_types=1);
1111
* file that was distributed with this source code.
1212
*/
1313

14-
require_once __DIR__.'/vendor/autoload.php';
14+
require_once __DIR__.'/../vendor/autoload.php';
15+
16+
\Symfony\Component\Debug\Debug::enable();
1517

1618
$app = new \Symfony\Component\Console\Application('Private Packagist');
1719

18-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoReleaseCommand());
19-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoExtensionReleaseCommand());
20-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoExtensionRemoveCommand());
21-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoCustomerAddCommand());
22-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoExtensionGrantCommand());
23-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoExtensionRevokeCommand());
24-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoEnterpriseGrantCommand());
25-
$app->add(new \PrivatePackagist\Demo\Customer\MagentoEnterpriseRevokeCommand());
20+
$app->add(new \PrivatePackagist\Demo\Command\MagentoGenerateDataCommand());
21+
$app->add(new \PrivatePackagist\Demo\Command\MagentoImportCommand());
22+
$app->add(new \PrivatePackagist\Demo\Command\MagentoReleaseCommand());
23+
$app->add(new \PrivatePackagist\Demo\Command\MagentoExtensionReleaseCommand());
24+
$app->add(new \PrivatePackagist\Demo\Command\MagentoExtensionRemoveCommand());
25+
$app->add(new \PrivatePackagist\Demo\Command\MagentoCustomerAddCommand());
26+
$app->add(new \PrivatePackagist\Demo\Command\MagentoExtensionGrantCommand());
27+
$app->add(new \PrivatePackagist\Demo\Command\MagentoExtensionRevokeCommand());
28+
$app->add(new \PrivatePackagist\Demo\Command\MagentoEnterpriseGrantCommand());
29+
$app->add(new \PrivatePackagist\Demo\Command\MagentoEnterpriseRevokeCommand());
30+
$app->add(new \PrivatePackagist\Demo\Command\DeleteAllCommand());
2631

2732
$app->run();

Diff for: composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"require": {
1717
"php": "^7.2",
1818
"symfony/console": "^4.1",
19-
"private-packagist/api-client": "^1.10.0",
20-
"php-http/guzzle6-adapter": "^1.1.0"
19+
"symfony/debug": "^4.1",
20+
"private-packagist/api-client": "^1.12.0",
21+
"php-http/guzzle6-adapter": "^1.1.0",
22+
"ext-json": "*"
2123
}
2224
}

Diff for: composer.lock

+111-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Command/DeleteAllCommand.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/*
5+
* This file is part of Composer.
6+
*
7+
* (c) Packagist Conductors UG (haftungsbeschränkt) <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace PrivatePackagist\Demo\Command;
14+
15+
16+
use PrivatePackagist\ApiClient\Client;
17+
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
class DeleteAllCommand extends MagentoCommand
22+
{
23+
protected function configure(): void
24+
{
25+
$this->setName('delete-all')
26+
->setDescription('Deletes all packages, projects and customers');
27+
}
28+
29+
protected function execute(InputInterface $input, OutputInterface $output): int
30+
{
31+
$client = $this->getPackagistClient();
32+
33+
$output->writeln("Deleting customers");
34+
foreach ($client->customers()->all() as $customer) {
35+
$output->write('.');
36+
$client->customers()->remove($customer['id']);
37+
}
38+
$output->writeln("");
39+
40+
$output->writeln("Deleting projects");
41+
foreach ($client->projects()->all() as $project) {
42+
$output->write('.');
43+
$client->projects()->remove($project['id']);
44+
}
45+
$output->writeln("");
46+
47+
$output->writeln("Deleting packages");
48+
foreach ($client->packages()->all() as $package) {
49+
$output->write('.');
50+
$client->packages()->remove($package['name']);
51+
}
52+
$output->writeln("");
53+
54+
$output->writeln("Deleting credentials");
55+
foreach ($client->credentials()->all() as $credential) {
56+
$output->write('.');
57+
$client->credentials()->remove($credential['id']);
58+
}
59+
$output->writeln("");
60+
61+
return 0;
62+
}
63+
}

0 commit comments

Comments
 (0)