Skip to content

Commit

Permalink
fix(s3ArtifactStore): Backport of 1164 direct to branch (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmcintosh authored Mar 7, 2024
1 parent 2ae4f0b commit a982ca0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ public Artifact store(Artifact artifact) {
if (applicationsRegex != null && !Pattern.matches(applicationsRegex, application)) {
return artifact;
}

byte[] referenceBytes;
try {
referenceBytes = getReferenceAsBytes(artifact);
} catch (IllegalArgumentException e) {
// When this occurs, that means we've run into an embedded/base64 artifact
// that does not contain base64 in its reference. This can happen a couple
// of ways with using SpEL within an artifact, manipulating the pipeline
// JSON directly, etc. So instead of trying to evaluate SpEL here or
// failing, we will just return the raw artifact, and not store this
// particular one.
log.warn("Artifact cannot be stored due to reference not being base64 encoded");
return artifact;
}
ArtifactReferenceURI ref = uriBuilder.buildArtifactURI(application, artifact);
Artifact remoteArtifact =
artifact.toBuilder()
Expand All @@ -102,7 +114,7 @@ public Artifact store(Artifact artifact) {
.tagging(Tagging.builder().tagSet(accountTag).build())
.build();

s3Client.putObject(request, RequestBody.fromBytes(getReferenceAsBytes(artifact)));
s3Client.putObject(request, RequestBody.fromBytes(referenceBytes));
return remoteArtifact;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ public void testExceptionPathOfObjectExists() {
});
assertEquals(expectedExceptionMessage, e.getMessage());
}

@Test
public void testInvalidEmbeddedBase64StillSucceeds() {
S3Client client = mock(S3Client.class);
AuthenticatedRequest.setApplication("my-application");
S3ArtifactStoreStorer artifactStore =
new S3ArtifactStoreStorer(client, "my-bucket", new ArtifactStoreURISHA256Builder(), null);
String expectedReference = "${ #nonbase64spel() }";
Artifact artifact =
artifactStore.store(
Artifact.builder()
.type(ArtifactTypes.EMBEDDED_BASE64.getMimeType())
.reference(expectedReference)
.build());
assertEquals(expectedReference, artifact.getReference());
assertEquals(ArtifactTypes.EMBEDDED_BASE64.getMimeType(), artifact.getType());
}
}

0 comments on commit a982ca0

Please sign in to comment.