Skip to content

Commit 98aa7dd

Browse files
authored
Merge pull request #68 from packagist/package-security-monitoring
Package: add endpoints to show and edit the security monitoring config
2 parents 4a34304 + e20cb98 commit 98aa7dd

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
* [List all dependents of a package](#list-all-dependents-of-a-package)
9898
* [List all customers with access to a package](#list-all-customers-with-access-to-a-package)
9999
* [List all security issues of a package](#list-all-security-issues-of-a-package)
100+
* [Show the security monitoring config of a package](#show-the-security-monitoring-config-of-a-package)
101+
* [Edit the security monitoring config of a package](#edit-the-security-monitoring-config-of-a-package)
100102
* [Create an artifact package file](#create-an-artifact-package-file)
101103
* [Create an artifact package](#create-an-artifact-package)
102104
* [Add an artifact file to an existing package](#add-an-artifact-file-to-an-existing-package)
@@ -128,7 +130,7 @@
128130
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
129131
* [License](#license)
130132

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

133135
<!--te-->
134136

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

863+
#### Show the security monitoring config of a package
864+
```php
865+
$client->packages()->showSecurityMonitoringConfig('acme-website/package');
866+
```
867+
Returns the security monitoring config of the package.
868+
869+
#### Edit the security monitoring config of a package
870+
```php
871+
$config = [
872+
"monitorAllBranches" => false, // If set to true then monitoredBranches will be ignored and can be omitted
873+
"monitoredBranches" => [
874+
"dev-main"
875+
],
876+
];
877+
$client->packages()->editSecurityMonitoringConfig('acme-website/package', $config);
878+
```
879+
Returns the edited security monitoring config of the package.
880+
861881
#### Create an artifact package file
862882

863883
```php

src/Api/Packages.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function createCustomPackage($customJson, $credentialId = null)
6868

6969
return $this->post('/packages/', ['repoType' => 'package', 'repoConfig' => $customJson, 'credentials' => $credentialId]);
7070
}
71-
71+
7272
public function createArtifactPackage(array $artifactPackageFileIds)
7373
{
7474
return $this->post('/packages/', ['repoType' => 'artifact', 'artifactIds' => $artifactPackageFileIds]);
@@ -125,6 +125,16 @@ public function listSecurityIssues($packageName, array $filters = [])
125125
return $this->get(sprintf('/packages/%s/security-issues/', $packageName), $filters);
126126
}
127127

128+
public function showSecurityMonitoringConfig($packageName)
129+
{
130+
return $this->get(sprintf('/packages/%s/security-monitoring/', $packageName));
131+
}
132+
133+
public function editSecurityMonitoringConfig($packageName, array $config)
134+
{
135+
return $this->put(sprintf('/packages/%s/security-monitoring/', $packageName), $config);
136+
}
137+
128138
public function artifacts()
129139
{
130140
return new Artifacts($this->client, $this->client->getResponseMediator());

tests/Api/PackagesTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,47 @@ public function testListSecurityIssues()
292292
$this->assertSame($expected, $api->listSecurityIssues($packageName));
293293
}
294294

295+
public function testShowSecurityMonitoringConfig()
296+
{
297+
$packageName = 'acme-website/core-package';
298+
$expected = [
299+
"monitorAllBranches" => false,
300+
"monitoredBranches" => [
301+
"dev-main"
302+
],
303+
];
304+
305+
/** @var Packages&MockObject $api */
306+
$api = $this->getApiMock();
307+
$api->expects($this->once())
308+
->method('get')
309+
->with($this->equalTo('/packages/acme-website/core-package/security-monitoring/'))
310+
->willReturn($expected);
311+
312+
$this->assertSame($expected, $api->showSecurityMonitoringConfig($packageName));
313+
}
314+
315+
public function testEditSecurityMonitoringConfig()
316+
{
317+
$packageName = 'acme-website/core-package';
318+
319+
$editedConfig = [
320+
"monitorAllBranches" => false,
321+
"monitoredBranches" => [
322+
"dev-main"
323+
],
324+
];
325+
326+
/** @var Packages&MockObject $api */
327+
$api = $this->getApiMock();
328+
$api->expects($this->once())
329+
->method('put')
330+
->with($this->equalTo('/packages/acme-website/core-package/security-monitoring/'), $this->equalTo($editedConfig))
331+
->willReturn($editedConfig);
332+
333+
$this->assertSame($editedConfig, $api->editSecurityMonitoringConfig($packageName, $editedConfig));
334+
}
335+
295336
protected function getApiClass()
296337
{
297338
return Packages::class;

0 commit comments

Comments
 (0)