private-packagist/api-client

私有 Packagist API 客户端

1.37.1 2024-08-21 12:00 UTC

README

目录

需求

安装

通过Composer

$ composer require private-packagist/api-client guzzlehttp/guzzle

为什么需要引入 guzzlehttp/guzzle?我们在HTTPlug 的帮助下与任何HTTP消息客户端解耦,因此您可以选择自己喜欢的HTTP客户端,guzzle只是一个建议。

private-packagist/api-client 客户端的基本用法

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \PrivatePackagist\ApiClient\Client();
$client->authenticate('api-key', 'api-secret');
$packages = $client->packages()->all();

$client 对象,您可以访问完整的Private Packagist API。

文档

完整文档可以在Private Packagist文档中找到。

组织

触发完全同步

$jobs = $client->organization()->sync();

返回创建的作业数组。每个同步都有一个作业。

团队

团队可用的权限

  • canEditTeamPackages:团队成员可以编辑和删除包,分配包权限(仅适用于分配给团队的包)。
  • canAddPackages:团队成员可以向组织添加包;添加、编辑和删除凭据和镜像第三方仓库。
  • canCreateSubrepositories:团队成员可以创建子仓库。
  • canViewVendorCustomers:团队成员可以查看客户、他们的Composer信息、他们的包以及他们的安装统计信息。
  • canManageVendorCustomers:团队成员可以创建和删除客户,添加和删除包,更新他们的设置,查看Composer信息和安装统计信息。
use PrivatePackagist\ApiClient\TeamPermissions;

$permissions = new TeamPermissions;
// Grant all permissions.
$permissions->canEditTeamPackages = true;
$permissions->canAddPackages = true;
$permissions->canCreateSubrepositories = true;
$permissions->canManageVendorCustomers = true;
$permissions->canManageVendorCustomers = true;

权限模型也可以通过标志来构建

use PrivatePackagist\ApiClient\TeamPermissions;

$permissions = TeamPermissions::fromFlags(
    TeamPermissions::PERMISSION_CAN_EDIT_TEAM_PACKAGES | TeamPermissions::PERMISSION_CAN_ADD_PACKAGES,
);

或从现有团队的权限中构建

use PrivatePackagist\ApiClient\TeamPermissions;

$team = $client->teams()->all()[0];
$permissions = TeamPermissions::fromTeamResponse($team);

列出组织的团队

$teams = $client->teams()->all();

返回团队数组。

创建新团队

use PrivatePackagist\ApiClient\TeamPermissions;

$permissions = new TeamPermissions;
$team = $client->teams()->create('New Team Name', $permissions);

创建团队并设置应用于团队成员的权限。返回新创建的团队。

显示团队

$team = $client->teams()->show($teamId);

返回包含所有成员的团队。

编辑团队

use PrivatePackagist\ApiClient\TeamPermissions;

$permissions = new TeamPermissions;
$team = $client->teams()->edit($teamId, 'Altered Team Name', $permissions);

编辑团队名称和应用于团队成员的权限。返回更新的团队。

授权所有包访问

$team = $client->teams()->grantAccessToAllPackages($teamId);

授予团队对所有包的访问权限将使该团队访问所有当前和未来的组织包(这些包的权限尚未同步)。

撤销所有包访问

$team = $client->teams()->revokeAccessToAllPackages($teamId);

撤销团队对所有包的访问权限将不会删除团队当前可以访问的包的访问权限,但将阻止访问新包并允许撤销单个包的访问权限。

删除团队

$client->teams()->remove($teamId);

通过用户 ID 添加成员到团队

$team = $client->teams()->addMember($teamId, $userId);

返回用户被添加到的团队。

从团队中移除成员

$client->teams()->removeMember($teamId, $userId);

列出团队可访问的所有私有包

$teamId = 1;
$packages = $client->teams()->packages($teamId);

返回包数组。

授权团队访问一系列私有包

您传递一个数组,其中包含要提供访问权限的包。数组的值可以是包ID或包名称。

$teamId = 1;
$packages = $client->teams()->addPackages($teamId, ['acme-website/package', 1]);

返回包数组。

从团队中撤销包的访问权限

您可以使用包ID或包名称作为参考。

$teamId = 1;
$packages = $client->teams()->removePackage($teamId, 'acme-website/package');

身份验证令牌

列出组织的团队身份验证令牌

$tokens = $client->tokens()->all();

返回团队令牌数组。

创建新的团队身份验证令牌

// Create a new token with access to all packages
$token = $client->tokens()->create([
    'description' => 'New Team Token',
    'access' => 'read',
    'accessToAllPackages' => true,
]);

// Create a new token with access to packages a team has access to
$token = $client->tokens()->create([
    'description' => 'New Team Token',
    'access' => 'read',
    'teamId' => 1, // Get teamId from the list of teams to determine to which packages the token has access to
]);

返回创建的令牌。

删除团队身份验证令牌

$client->tokens()->remove($tokenId));

重新生成团队身份验证令牌

$customerId = 42;
$confirmation = [
    'IConfirmOldTokenWillStopWorkingImmediately' => true,
];
$token = $client->tokens()->regenerateToken($tokenId, $confirmation);

返回重新生成的令牌。

客户

列出组织的客户

$customers = $client->customers()->all();

返回客户数组。

显示客户

$customerId = 42;
$customer = $client->customers()->show($customerId);
// or
$customerUrlName = 'customer-url-name';
$customer = $client->customers()->show($customerUrlName);

返回单个客户。

创建客户

$customer = $client->customers()->create('New customer name');
// or
$customer = $client->customers()->create('New customer name', false, 'customer-url-name', 'beta', true);

返回客户。

编辑客户

$customerId = 42;
$customerData = [
    'name' => $name,
    'urlName' => 'customer',
    'accessToVersionControlSource' => false,
    'minimumAccessibleStability' => 'beta',
    'assignAllPackages' => true,
];
$customer = $client->customers()->edit($customerId, $customerData);

返回客户。

删除客户

$customerId = 42;
$client->customers()->remove($customerId);

启用客户

$customerId = 42;
$customer = $client->customers()->enable($customerId);

禁用客户

$customerId = 42;
$customer = $client->customers()->disable($customerId);

列出客户的包

$customerId = 42;
$packages = $client->customers()->listPackages($customerId);

返回客户包数组。

显示客户的包

$customerId = 42;
$package = $client->customers()->showPackage($customerId, $packageName);
$accessibleVersions = $package['versions'];

返回客户的包,包括客户已获授权访问的版本。

授权客户访问包或编辑限制

$customerId = 42;
$packages = [
    [
        'name' => 'acme-website/package',
        'versionConstraint' => '^1.0 | ^2.0', // optional version constraint to limit updates the customer receives
        'expirationDate' => (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updates the customer receives
        'minimumAccessibleStability' => 'beta', // optional stability to restrict customers to specific package version stabilities like alpha, beta, or RC
    ],
];
$packages = $client->customers()->addOrEditPackages($customerId, $packages);

返回所有添加或编辑的客户包数组。

从客户撤销包的访问权限

您可以通过包ID或名称引用包。

$customerId = 42;
$packageName = 'acme-website/package';
$client->customers()->removePackage($customerId, $packageName);

重新生成客户的 Composer 仓库令牌

$customerId = 42;
$confirmation = [
    'IConfirmOldTokenWillStopWorkingImmediately' => true,
];
$composerRepository = $client->customers()->regenerateToken($customerId, $confirmation);

返回编辑后的Composer仓库。

列出客户的供应商捆绑包

$customerId = 42;
$packages = $client->customers()->vendorBundles()->listVendorBundles($customerId);

返回客户供应商捆绑包数组。

授权客户访问供应商捆绑包或编辑限制

$customerId = 42;
$vendorBundleId = 12;
$expirationDate = (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updates the customer receives
$packages = $client->customers()->vendorBundles()->addOrEditVendorBundle($customerId, $vendorBundleId, $expirationDate);

返回添加或编辑的客户供应商捆绑包。

从客户撤销供应商捆绑包的访问权限

$customerId = 42;
$vendorBundleId = 12;
$client->customers()->vendorBundles()->removeVendorBundle($customerId, $vendorBundleId);

供应商捆绑包

列出组织的供应商捆绑包

$vendorBundles = $client->vendorBundles()->all();

返回供应商捆绑包数组。

显示供应商捆绑包

$vendorBundleId = 42;
$vendorBundle = $client->vendorBundles()->show($vendorBundleId);

返回单个供应商捆绑包。

创建供应商捆绑包

$vendorBundle = $client->vendorBundles()->create('New bundle name');
// or
$vendorBundle = $client->vendorBundles()->create('New bundle name', 'dev', '^1.0', true, [123]);

返回供应商捆绑包。

编辑客户

$vendorBundleId = 42;
$vendorBundleData = [
    'name' => 'Bundle name',
    'minimumAccessibleStability' => 'dev',
    'versionConstraint' => '^1.0',
    'assignAllPackages' => true,
    'synchronizationIds' => [123], // A list of synchronization ids for which new packages should automatically be added to the bundle.
];
$vendorBundle = $client->vendorBundles()->edit($vendorBundleId, $vendorBundleData);

返回供应商捆绑包。

删除供应商捆绑包

$vendorBundleId = 42;
$client->vendorBundles()->remove($vendorBundleId);

列出供应商捆绑包中的包

$vendorBundleId = 42;
$packages = $client->vendorBundles()->packages()->listPackages($vendorBundleId);

返回供应商捆绑包数组。

将一个或多个包添加到供应商捆绑包或编辑它们的限制

$vendorBundleId = 42;
$packages = [
    [
        'name' => 'acme-website/package',
        'versionConstraint' => '^1.0 | ^2.0', // optional version constraint to limit updates the customer receives
        'minimumAccessibleStability' => 'beta', // optional stability to restrict customers to specific package version stabilities like alpha, beta, or RC
    ],
];
$packages = $client->vendorBundles()->packages()->addOrEditPackages($vendorBundleId, $packages);

返回所有添加或编辑的客户包数组。

从供应商捆绑包中删除包

您可以通过包ID或名称引用包。

$vendorBundleId = 42;
$packageName = 'acme-website/package';
$client->vendorBundles()->packages()->removePackage($vendorBundleId, $packageName);

子仓库

列出组织的子仓库

$subrepositories = $client->subrepositories()->all();

返回子仓库数组。

显示子仓库

$subrepositoryName = 'subrepository';
$subrepository = $client->subrepositories()->show($subrepositoryName);

返回单个子仓库。

创建子仓库

$subrepository = $client->subrepositories()->create('New subrepository name');

返回子仓库。

删除子仓库

$subrepositoryName = 'subrepository';
$client->subrepositories()->remove($subrepositoryName);

列出子仓库的团队

$subrepositoryName = 'subrepository';
$teams = $client->subrepositories()->listTeams($subrepositoryName);

返回子仓库团队数组。

将团队添加到子仓库或编辑权限

$subrepositoryName = 'subrepository';
$teams = [
    [
        'id' => 12,
        'permission' => 'owner',
    ],
];
$teams = $client->subrepositories()->addOrEditTeams($subrepositoryName, $teams);

返回添加的子仓库团队数组。

从子仓库中移除团队

$subrepositoryName = 'subrepository';
$teamId = 12;
$client->subrepositories()->removeTeam($subrepositoryName, $teamId);

列出子仓库中的包

$subrepositoryName = 'subrepository';
$packages = $client->subrepositories()->packages()->all($subrepositoryName);

返回子仓库包数组。

显示子仓库中的包

您可以通过名称或ID引用包。

$subrepositoryName = 'subrepository';
// Either use package name:
$package = $client->subrepositories()->packages()->show($subrepositoryName, 'acme-website/package');
// Or the package ID: 
$package = $client->subrepositories()->packages()->show($subrepositoryName, 123);

返回包。

在子仓库中创建 vcs 包

$subrepositoryName = 'subrepository';
$job = $client->subrepositories()->packages()->createVcsPackage($subrepositoryName, 'https://github.com/acme-website/package');

返回新工作。

在子仓库中创建带凭证的 vcs 包

$subrepositoryName = 'subrepository';
$credentialId = 42;
$job = $client->subrepositories()->packages()->createVcsPackage($subrepositoryName,'https://github.com/acme-website/package', $credentialId);

返回新工作。

在子仓库中创建自定义包

$subrepositoryName = 'subrepository';
$packageDefinition = '{...}';
$job = $client->subrepositories()->packages()->createCustomPackage($subrepositoryName, $packageDefinition);

返回新工作。

在子仓库中创建带凭证的自定义包

$subrepositoryName = 'subrepository';
$packageDefinition = '{...}';
$credentialId = 42;
$job = $client->subrepositories()->packages()->createCustomPackage($subrepositoryName, $packageDefinition, $credentialId);

返回新工作。

在子仓库中编辑子仓库中的 vcs 包

$subrepositoryName = 'subrepository';
$job = $client->subrepositories()->packages()->editVcsPackage($subrepositoryName, 'acme-website/package', 'https://github.com/acme-website/package');

返回新工作。

在子仓库中编辑子仓库中的自定义包

$subrepositoryName = 'subrepository';
$packageDefinition = '{...}';
$job = $client->subrepositories()->packages()->editCustomPackage($subrepositoryName, 'acme-website/package', $packageDefinition);

返回新工作。

从子仓库中删除包

$subrepositoryName = 'subrepository';
$client->subrepositories()->packages()->remove($subrepositoryName, 'acme-website/package');

列出子仓库包的所有依赖者

$subrepositoryName = 'subrepository';
$client->subrepositories()->packages()->listDependents($subrepositoryName, 'acme-website/package');

返回包列表。

列出子仓库的身份验证令牌

$subrepositoryName = 'subrepository';
$tokens = $client->subrepositories()->listTokens($subrepositoryName);

返回身份验证令牌数组。

创建子仓库身份验证令牌

$subrepositoryName = 'subrepository';
$data = [
  'description' => 'Subrepository Token',
  'access' => 'read',
];
$token = $client->subrepositories()->createToken($subrepositoryName, $data);

返回身份验证令牌。

删除子仓库身份验证令牌

$subrepositoryName = 'subrepository';
$tokenId = 33;
$client->subrepositories()->removeToken($subrepositoryName, $tokenId);

重新生成子仓库身份验证令牌

$subrepositoryName = 'subrepository';
$tokenId = 33;
$confirmation = [
    'IConfirmOldTokenWillStopWorkingImmediately' => true,
];
$token = $client->subrepositories()->regenerateToken($subrepositoryName, $confirmation);

返回身份验证令牌。

列出子仓库的镜像仓库

$subrepositoryName = 'subrepository';
$mirroredRepositories = $client->subrepositories()->mirroredRepositories()->all($subrepositoryName);

返回镜像仓库数组。

显示镜像仓库

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$mirroredRepository = $client->subrepositories()->mirroredRepositories()->show($subrepositoryName, $mirroredRepositoryId);

返回镜像仓库。

将镜像仓库添加到子仓库

$subrepositoryName = 'subrepository';
$mirroredRepositoriesToAdd = [
    ['id' => 12, 'mirroringBehavior' => 'add_on_use'],
];
$mirroredRepository = $client->subrepositories()->mirroredRepositories()->add($subrepositoryName, $mirroredRepositoriesToAdd);

返回添加的镜像仓库列表。

编辑子仓库中镜像仓库的镜像行为

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$mirroredRepository = $client->subrepositories()->mirroredRepositories()->create($subrepositoryName, $mirroredRepositoryId, 'add_on_use');

返回编辑后的镜像仓库。

从子仓库中删除镜像仓库

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$client->subrepositories()->mirroredRepositories()->remove($subrepositoryName, $mirroredRepositoryId);

列出子仓库中镜像仓库的所有镜像包

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$packages = $client->subrepositories()->mirroredRepositories()->listPackages($subrepositoryName, $mirroredRepositoryId);

返回包数组。

将一个镜像仓库中的镜像包添加到子仓库

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$packages = [
    'acme/cool-lib
];
$jobs = $client->subrepositories()->mirroredRepositories()->addPackages($subrepositoryName, $mirroredRepositoryId, $packages);

返回工作数组。

从子仓库中删除一个镜像仓库中的所有镜像包

$subrepositoryName = 'subrepository';
$mirroredRepositoryId = 42;
$client->subrepositories()->mirroredRepositories()->removePackages($subrepositoryName, $mirroredRepositoryId);

您可以通过名称或ID引用包。

列出组织的包

$filters = [
    'origin' => \PrivatePackagist\ApiClient\Api\Packages::ORIGIN_PRIVATE, // optional filter to only receive packages that can be added to customers,
    'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN, // optional filter to filter packages with open security issues,
];
$packages = $client->packages()->all($filters);

返回包数组。

显示包

// Either use package name:
$package = $client->packages()->show('acme-website/package');
// Or the package ID: 
$package = $client->packages()->show(123);

返回包。

创建 vcs 包

$job = $client->packages()->createVcsPackage('https://github.com/acme-website/package');

返回新工作。

创建带凭证的 vcs 包

$credentialId = 42;
$job = $client->packages()->createVcsPackage('https://github.com/acme-website/package', $credentialId);

返回新工作。

创建特定类型的 vcs 包

$job = $client->packages()->createVcsPackage('https://github.com/acme-website/package', null, 'git');

返回新工作。

创建自定义包

$packageDefinition = '{...}';
$job = $client->packages()->createCustomPackage($packageDefinition);

返回新工作。

使用凭据创建自定义包

$packageDefinition = '{...}';
$credentialId = 42;
$job = $client->packages()->createCustomPackage($packageDefinition, $credentialId);

返回新工作。

编辑vcs包

$job = $client->packages()->editVcsPackage('acme-website/package', 'https://github.com/acme-website/package');

返回新工作。

编辑自定义包

$packageDefinition = '{...}';
$job = $client->packages()->editCustomPackage('acme-website/package', $packageDefinition);

返回新工作。

删除包

$client->packages()->remove('acme-website/package');

列出包的所有依赖项

$client->packages()->listDependents('acme-website/package');

返回包列表。

列出有权访问包的所有客户

作为参数传递包ID或包名称。

$client->packages()->listCustomers('acme-website/package');

返回具有包访问权限的客户列表。

列出包的所有安全问题

$filters = [
    'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN,
];
$client->packages()->listSecurityIssues('acme-website/package', $filters);

返回安全问题的列表。

显示包的安全监控配置

$client->packages()->showSecurityMonitoringConfig('acme-website/package');

返回包的安全监控配置。

编辑包的安全监控配置

$config = [
    "monitorAllBranches" => false, // If set to true then monitoredBranches will be ignored and can be omitted 
    "monitoredBranches" => [
        "dev-main"
    ],
];
$client->packages()->editSecurityMonitoringConfig('acme-website/package', $config);

返回编辑后的包安全监控配置。

创建工件包文件

$fileName = 'package1.zip'; // your package archive artifact containing a valid composer.json in root directory
$file = file_get_contents($fileName);
$client->packages()->artifacts()->create($file, 'application/zip', $fileName);

创建工件包

$fileName = 'package1.zip';
$file = file_get_contents($fileName);
$response = $client->packages()->artifacts()->create($file, 'application/zip', $fileName);
$artifactId = $response['id'];
$client->packages()->createArtifactPackage([$artifactId]);

将工件文件添加到现有包中

$packageName = 'acme/artifact';
$fileName = 'package1.zip';
$file = file_get_contents($fileName);
$client->packages()->artifacts()->add($packageName, $file, 'application/zip', $fileName);

更新或替换包的工件文件

// in case you want to replace the artifact file with a newly uploaded one
// 1. get current artifact ids
$result = $client->packages()->artifacts()->showPackageArtifacts('acme-website/package');
$artifactIds = array_column($result, 'id'); // [41, 42]

// 2. upload the new artifact file
$fileName = 'package1.zip';
$file = file_get_contents($fileName);
$response = $client->packages()->artifacts()->create($file, 'application/zip', $fileName);
$newArtifactId = $response['id'];

// 3. let's say we don't want to have the artifact file id = 41 and use the newly uploaded file instead
$artifactIds = array_shift($artifactIds);
$artifactIds[] = $newArtifactId;
$client->packages()->editArtifactPackage('acme-website/package', $artifactIds);

凭据

列出组织的凭据

$credentials = $client->credentials()->all();

返回凭证数组。

显示凭据

$credentialId = 42;
$credential = $client->credentials()->show($credentialId);

返回凭证。

创建凭据

$type = \PrivatePackagist\ApiClient\Api\Credentials::TYPE_HTTP_BASIC;
$credential = $client->credentials()->create('ACME http auth', $type, 'acme-website.com', 'username', 'password');

返回新的凭证。

编辑凭据

$credentialId = 42;
$type = \PrivatePackagist\ApiClient\Api\Credentials::TYPE_HTTP_BASIC;
$credential = $client->credentials()->edit($credentialId, $type, 'username', 'password');

返回编辑后的凭证。

删除凭据

$credentialId = 42;
$client->credentials()->remove($credentialId);

镜像仓库

列出组织的镜像仓库

$mirroredRepositories = $client->mirroredRepositories()->all();

返回镜像仓库数组。

显示镜像仓库

$mirroredRepositoryId = 42;
$mirroredRepository = $client->mirroredRepositories()->show($mirroredRepositoryId);

返回镜像仓库。

创建镜像仓库

$mirroredRepository = $client->mirroredRepositories()->create('Mirrored Repository', 'https://composer.example.com', 'add_on_use', 543);

返回新的镜像仓库。

编辑镜像仓库

$mirroredRepositoryId = 42;
$mirroredRepository = $client->mirroredRepositories()->create($mirroredRepositoryId, 'Mirrored Repository', 'https://composer.example.com', 'add_on_use', 543);

返回编辑后的镜像仓库。

删除镜像仓库

$mirroredRepositoryId = 42;
$client->mirroredRepositories()->remove($mirroredRepositoryId);

列出来自一个仓库的所有镜像包

$mirroredRepositoryId = 42;
$packages = $client->mirroredRepositories()->listPackages($mirroredRepositoryId);

返回包数组。

从一个仓库添加镜像包

$mirroredRepositoryId = 42;
$packages = [
    'acme/cool-lib
];
$jobs = $client->mirroredRepositories()->addPackages($mirroredRepositoryId, $packages);

返回工作数组。

从一个仓库移除所有镜像包

$mirroredRepositoryId = 42;
$client->mirroredRepositories()->removePackages($mirroredRepositoryId);

作业

显示作业

$job = $client->jobs()->show($jobId);

返回工作。

等待作业完成

这将定期轮询工作状态,直到工作完成或达到最大等待时间。

$numberOfSecondsToWait = 180;
$jobHelper = new \PrivatePackagist\ApiClient\JobHelper($client);
try {
    $job = $jobHelper->waitForJob($jobId, $numberOfSecondsToWait);
} catch (\PrivatePackagist\ApiClient\Exception\JobTimeoutException $e) {
    // Job didn't finish within the specified time
} catch (\PrivatePackagist\ApiClient\Exception\JobErrorException $e) {
    // Job finished with an error. See the message for more information
    echo $e->getMessage();
}

返回工作。

安全问题

列出组织的安全问题

$filters = [
    'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN, // optional filter to filter packages with open security issues,
];
$packages = $client->securityIssues()->all($filters);

返回安全问题数组。

Magento旧版密钥

列出客户的所有旧版密钥

$customerId = 42;
$legacyKeys = $client->customers()->magentoLegacyKeys()->all($customerId);

返回Magento遗留密钥列表。

为客户创建新的旧版密钥

$legacyKey = $client->customers()->magentoLegacyKeys()->create($customerId, $publicKey, $privateKey);

返回新的Magento遗留密钥。

从客户处删除旧版密钥

$client->customers()->magentoLegacyKeys()->remove($customerId, $publicKey);

验证传入的webhook有效载荷

当在Private Packagist中创建或更新webhook时,可以设置一个可选的秘密。这个秘密用于创建一个签名,该签名作为每个请求的头部中的Packagist-Signature发送。然后可以在您的服务器上使用这个秘密和签名来验证请求是由Private Packagist发起的。如果没有设置秘密,则不会发送签名。

$request = /** any Psr7 request */;
$secret = 'webhook-secret';
$webhookSignature = new \PrivatePackagist\ApiClient\WebhookSignature($secret);
$requestSignature = $request->hasHeader('Packagist-Signature') ? $request->getHeader('Packagist-Signature')[0] : null;
$webhookSignature->validate($requestSignature, (string) $request->getBody());

许可证

private-packagist/api-client是在MIT许可证下授权的。