-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1927 from sahibamittal/Issue-1903-osv-ecosystem
Issue 1903 : removed ecosystem hardcoding
- Loading branch information
Showing
8 changed files
with
211 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/main/java/org/dependencytrack/parser/osv/model/Ecosystem.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/org/dependencytrack/resources/v1/OsvEcosytemResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Steve Springett. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1; | ||
|
||
import alpine.server.auth.PermissionRequired; | ||
import alpine.server.resources.AlpineResource; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import io.swagger.annotations.Authorization; | ||
import org.dependencytrack.auth.Permissions; | ||
import org.dependencytrack.tasks.OsvDownloadTask; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.List; | ||
|
||
@Path("/v1/integration/osv/ecosystem") | ||
@Api(value = "ecosystem", authorizations = @Authorization(value = "X-Api-Key")) | ||
public class OsvEcosytemResource extends AlpineResource { | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@ApiOperation( | ||
value = "Returns a list of all ecosystems in OSV", | ||
response = String.class, | ||
responseContainer = "List" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 401, message = "Unauthorized") | ||
}) | ||
@PermissionRequired(Permissions.Constants.SYSTEM_CONFIGURATION) | ||
public Response getAllEcosystems() { | ||
final List<String> ecosystems = OsvDownloadTask.getEcosystems(); | ||
return Response.ok(ecosystems).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/org/dependencytrack/resources/v1/OsvEcosystemResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Steve Springett. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1; | ||
|
||
import alpine.server.filters.ApiFilter; | ||
import alpine.server.filters.AuthenticationFilter; | ||
import org.dependencytrack.ResourceTest; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.servlet.ServletContainer; | ||
import org.glassfish.jersey.test.DeploymentContext; | ||
import org.glassfish.jersey.test.ServletDeploymentContext; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import javax.json.JsonArray; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class OsvEcosystemResourceTest extends ResourceTest { | ||
|
||
@Override | ||
protected DeploymentContext configureDeployment() { | ||
return ServletDeploymentContext.forServlet(new ServletContainer( | ||
new ResourceConfig(OsvEcosytemResource.class) | ||
.register(ApiFilter.class) | ||
.register(AuthenticationFilter.class))) | ||
.build(); | ||
} | ||
|
||
@Before | ||
public void before() throws Exception { | ||
super.before(); | ||
} | ||
|
||
@Test | ||
public void getAllEcosystemsTest() { | ||
Response response = target(V1_OSV_ECOSYSTEM).request() | ||
.header(X_API_KEY, apiKey) | ||
.get(Response.class); | ||
Assert.assertEquals(200, response.getStatus(), 0); | ||
Assert.assertNull(response.getHeaderString(TOTAL_COUNT_HEADER)); | ||
JsonArray json = parseJsonArray(response); | ||
Assert.assertNotNull(json); | ||
Assert.assertFalse(json.isEmpty()); | ||
} | ||
} |
Oops, something went wrong.