Skip to content

Commit

Permalink
Merge pull request #68 from packagist/package-security-monitoring
Browse files Browse the repository at this point in the history
Package: add endpoints to show and edit the security monitoring config
  • Loading branch information
pscheit committed Oct 4, 2023
2 parents 4a34304 + e20cb98 commit 98aa7dd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
* [List all dependents of a package](#list-all-dependents-of-a-package)
* [List all customers with access to a package](#list-all-customers-with-access-to-a-package)
* [List all security issues of a package](#list-all-security-issues-of-a-package)
* [Show the security monitoring config of a package](#show-the-security-monitoring-config-of-a-package)
* [Edit the security monitoring config of a package](#edit-the-security-monitoring-config-of-a-package)
* [Create an artifact package file](#create-an-artifact-package-file)
* [Create an artifact package](#create-an-artifact-package)
* [Add an artifact file to an existing package](#add-an-artifact-file-to-an-existing-package)
Expand Down Expand Up @@ -128,7 +130,7 @@
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
* [License](#license)

<!-- Added by: zanbaldwin, at: Wed May 17 20:53:35 CEST 2023 -->
<!-- Added by: glaubinix, at: Wed 27 Sep 2023 14:25:14 BST -->

<!--te-->

Expand Down Expand Up @@ -858,6 +860,24 @@ $client->packages()->listSecurityIssues('acme-website/package', $filters);
```
Returns a list of security issues.

#### Show the security monitoring config of a package
```php
$client->packages()->showSecurityMonitoringConfig('acme-website/package');
```
Returns the security monitoring config of the package.

#### Edit the security monitoring config of a package
```php
$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);
```
Returns the edited security monitoring config of the package.

#### Create an artifact package file

```php
Expand Down
12 changes: 11 additions & 1 deletion src/Api/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function createCustomPackage($customJson, $credentialId = null)

return $this->post('/packages/', ['repoType' => 'package', 'repoConfig' => $customJson, 'credentials' => $credentialId]);
}

public function createArtifactPackage(array $artifactPackageFileIds)
{
return $this->post('/packages/', ['repoType' => 'artifact', 'artifactIds' => $artifactPackageFileIds]);
Expand Down Expand Up @@ -125,6 +125,16 @@ public function listSecurityIssues($packageName, array $filters = [])
return $this->get(sprintf('/packages/%s/security-issues/', $packageName), $filters);
}

public function showSecurityMonitoringConfig($packageName)
{
return $this->get(sprintf('/packages/%s/security-monitoring/', $packageName));
}

public function editSecurityMonitoringConfig($packageName, array $config)
{
return $this->put(sprintf('/packages/%s/security-monitoring/', $packageName), $config);
}

public function artifacts()
{
return new Artifacts($this->client, $this->client->getResponseMediator());
Expand Down
41 changes: 41 additions & 0 deletions tests/Api/PackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,47 @@ public function testListSecurityIssues()
$this->assertSame($expected, $api->listSecurityIssues($packageName));
}

public function testShowSecurityMonitoringConfig()
{
$packageName = 'acme-website/core-package';
$expected = [
"monitorAllBranches" => false,
"monitoredBranches" => [
"dev-main"
],
];

/** @var Packages&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/packages/acme-website/core-package/security-monitoring/'))
->willReturn($expected);

$this->assertSame($expected, $api->showSecurityMonitoringConfig($packageName));
}

public function testEditSecurityMonitoringConfig()
{
$packageName = 'acme-website/core-package';

$editedConfig = [
"monitorAllBranches" => false,
"monitoredBranches" => [
"dev-main"
],
];

/** @var Packages&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with($this->equalTo('/packages/acme-website/core-package/security-monitoring/'), $this->equalTo($editedConfig))
->willReturn($editedConfig);

$this->assertSame($editedConfig, $api->editSecurityMonitoringConfig($packageName, $editedConfig));
}

protected function getApiClass()
{
return Packages::class;
Expand Down

0 comments on commit 98aa7dd

Please sign in to comment.