-
Notifications
You must be signed in to change notification settings - Fork 16
add metadata parameter to CodeArtifact api #109
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,12 +43,14 @@ interface CodeArtifactClient { | |
| * | ||
| * @param projectId ID of the project to which the code artifact belongs | ||
| * @param file the file to upload | ||
| * @param metadata the prescan metadata to upload with the file artifact. Null may be given if | ||
| * prescan data is not present. | ||
| * @return new {@link CodeArtifactInner} from Contrast API | ||
| * @throws IOException when an IO error occurs while making the request to the Contrast API | ||
| * @throws UnauthorizedException when Contrast rejects the credentials used to send the request | ||
| * @throws ResourceNotFoundException when the requested resource does not exist | ||
| * @throws HttpResponseException when Contrast rejects this request with an error code | ||
| * @throws ServerResponseException when Contrast API returns a response that cannot be understood | ||
| */ | ||
| CodeArtifactInner upload(String projectId, Path file) throws IOException; | ||
| CodeArtifactInner upload(String projectId, Path file, Path metadata) throws IOException; | ||
seschis marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API asks that the user provide the metadata JSON as a file. Maybe passing the metadata as a file is the only use case we have now (i.e. the Maven plugin), but it doesn't feel like the most flexible assumption for the SDK. I would expect the SDK to accept the metadata as a Java object that describes the data structure, and I would expect the SDK to marshal that object to JSON for me. Are the fields in the metadata JSON object well known, or is this more of an open-ended bag of key-value pairs? If it's the former, then we should define a new class for it. If it's the latter, then maybe all we need is a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the format of the data is defined here: https://github.com/Contrast-Security-OSS/contrast-scan-prescan/blob/master/src/main/resources/schema/scan-input-metadata-schema-1.0.0.json I don't anticipate it changing from json, but I can't say it never will. I also don't know how the content of the data will be required to change over time. The main purpose of the prescan metadata is to allow the engine to generate physical absolute paths to files in its sarif report which GitHub uses as part of preview renderings when displaying the sarif findings.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand. Knowing that has a well-defined schema, I feel more strongly that we should make a corresponding Java class to hold this data, but I don't fully understand what expectation you have for users who wan to use this API. How do they know how to generate this file? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| * #L% | ||
| */ | ||
|
|
||
| import com.contrastsecurity.sdk.internal.Nullable; | ||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
|
|
||
|
|
@@ -52,6 +53,12 @@ public String filename() { | |
| return inner.filename(); | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
gilday marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public String metadata() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the metadata is a String, does that imply that the SDK user is not intended to parse this structured data; rather, they should treat it as an opaque box? Specifically, is this JSON-encoded JSON inside this JSON
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I always considered the generation of prescan data something that was external to the SDK.... but it probably would be more user-friendly to allow the SDK user to call a function that generated prescan data for them.... or perhaps just do it transparently. |
||
| return inner.metadata(); | ||
| } | ||
|
|
||
| @Override | ||
| public Instant createdTime() { | ||
| return inner.createdTime(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| * #L% | ||
| */ | ||
|
|
||
| import com.contrastsecurity.sdk.internal.Nullable; | ||
| import com.google.auto.value.AutoValue; | ||
| import java.time.Instant; | ||
|
|
||
|
|
@@ -44,6 +45,10 @@ static Builder builder() { | |
| /** @return filename */ | ||
| abstract String filename(); | ||
|
|
||
| @Nullable | ||
| /** @return metadata filename */ | ||
seschis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| abstract String metadata(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this imply that the user can retrieve the metadata filename, but not the metadata? What would the user do with the filename? |
||
|
|
||
| /** @return time at which the code artifact was uploaded to Contrast Scan */ | ||
| abstract Instant createdTime(); | ||
|
|
||
|
|
@@ -63,6 +68,9 @@ abstract static class Builder { | |
| /** @see CodeArtifactInner#filename() */ | ||
| abstract Builder filename(String value); | ||
|
|
||
| /** @see CodeArtifactInner#metadata() */ | ||
| abstract Builder metadata(String value); | ||
|
|
||
| /** @see CodeArtifactInner#createdTime() */ | ||
| abstract Builder createdTime(Instant value); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ interface Factory { | |
| */ | ||
| CodeArtifact upload(Path file, String name) throws IOException; | ||
|
|
||
| CodeArtifact upload(Path file, String name, Path metadata, String metaname) throws IOException; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc the filename of the upload is reflected in the UI, and that's why we give the user the capability to set that. I don't see a use case for allowing the user to set the name of the metadata file. I'd argue we take that capability out. Also, I'm still questioning whether the metadata should be sent as a file vs as JSON, but I'll continue that discussion in another thread.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I see now. I can take it out. Before I do any work on it yet though I'll wait until we resolve the fundamental API design questions you have in this area. |
||
| /** | ||
| * Transfers a file from the file system to Contrast Scan to create a new code artifact for static | ||
| * analysis. | ||
|
|
@@ -75,4 +76,6 @@ interface Factory { | |
| * @throws ServerResponseException when Contrast API returns a response that cannot be understood | ||
| */ | ||
| CodeArtifact upload(Path file) throws IOException; | ||
|
|
||
| CodeArtifact upload(Path file, Path metadata) throws IOException; | ||
seschis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.