diff --git a/README.md b/README.md index 62eab6e..e13e93e 100644 --- a/README.md +++ b/README.md @@ -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) @@ -128,7 +130,7 @@ * [Validate incoming webhook payloads](#validate-incoming-webhook-payloads) * [License](#license) - + @@ -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 diff --git a/src/Api/Packages.php b/src/Api/Packages.php index d644862..e8978b7 100644 --- a/src/Api/Packages.php +++ b/src/Api/Packages.php @@ -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]); @@ -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()); diff --git a/tests/Api/PackagesTest.php b/tests/Api/PackagesTest.php index 37cd394..0291c6d 100644 --- a/tests/Api/PackagesTest.php +++ b/tests/Api/PackagesTest.php @@ -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;