-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ProblemDetails
for invalid policy conditions
The frontend can properly interpret `ProblemDetails` and present a more helpful error message to users than the current generic "request failed" one. Signed-off-by: nscuro <[email protected]>
- Loading branch information
Showing
7 changed files
with
124 additions
and
53 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
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
55 changes: 55 additions & 0 deletions
55
...in/java/org/dependencytrack/resources/v1/problems/InvalidCelExpressionProblemDetails.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,55 @@ | ||
/* | ||
* 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) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1.problems; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
import org.projectnessie.cel.Issues; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @since 5.5.0 | ||
*/ | ||
public class InvalidCelExpressionProblemDetails extends ProblemDetails { | ||
|
||
public record CelExpressionError( | ||
@Parameter(description = "The line in which the error was identified") Integer line, | ||
@Parameter(description = "The column in which the error was identified") Integer column, | ||
@Parameter(description = "The message describing the error") String message | ||
) { | ||
} | ||
|
||
@Parameter(description = "Errors identified during expression compilation") | ||
private final List<CelExpressionError> errors; | ||
|
||
public InvalidCelExpressionProblemDetails(final Issues issues) { | ||
this.errors = issues.getErrors().stream() | ||
.map(error -> new CelExpressionError( | ||
error.getLocation().line(), | ||
error.getLocation().column(), | ||
error.getMessage() | ||
)) | ||
.toList(); | ||
} | ||
|
||
public List<CelExpressionError> getErrors() { | ||
return errors; | ||
} | ||
|
||
} |
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
22 changes: 0 additions & 22 deletions
22
src/main/java/org/dependencytrack/resources/v1/vo/CelExpressionError.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