Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package: add endpoints to show and edit the security monitoring config #68

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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