Skip to content
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

S3: Make eTag naming consistent #2741

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ import scala.concurrent.{ExecutionContext, Future}
// @formatter:off
val payload = <CompleteMultipartUpload>
{
parts.map { case (partNumber, etag) => <Part><PartNumber>{ partNumber }</PartNumber><ETag>{ etag }</ETag></Part> }
parts.map { case (partNumber, eTag) => <Part><PartNumber>{ partNumber }</PartNumber><ETag>{ eTag }</ETag></Part> }
}
</CompleteMultipartUpload>
// @formatter:on
Expand Down
14 changes: 7 additions & 7 deletions s3/src/main/scala/akka/stream/alpakka/s3/impl/S3Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import scala.util.{Failure, Success, Try}
/** Internal Api */
@InternalApi private[impl] final case class SuccessfulUploadPart(multipartUpload: MultipartUpload,
index: Int,
etag: String)
eTag: String)
extends UploadPartResponse

/** Internal Api */
Expand All @@ -66,7 +66,7 @@ import scala.util.{Failure, Success, Try}
@InternalApi private[impl] final case class CompleteMultipartUploadResult(location: Uri,
bucket: String,
key: String,
etag: String,
eTag: String,
versionId: Option[String] = None)

/** Internal Api */
Expand Down Expand Up @@ -797,7 +797,7 @@ import scala.util.{Failure, Success, Try}

Source
.future(
completeMultipartUploadRequest(parts.head.multipartUpload, parts.map(p => p.index -> p.etag), headers)
completeMultipartUploadRequest(parts.head.multipartUpload, parts.map(p => p.index -> p.eTag), headers)
)
.flatMapConcat(signAndGetAs[CompleteMultipartUploadResult](_, populateResult(_, _)))
.runWith(Sink.head)
Expand Down Expand Up @@ -985,11 +985,11 @@ import scala.util.{Failure, Success, Try}
}
case Success(r) =>
r.entity.discardBytes()
val etag = r.headers.find(_.lowercaseName() == "etag").map(_.value)
etag
val eTag = r.headers.find(_.lowercaseName() == "etag").map(_.value)
eTag
.map(t => Future.successful(SuccessfulUploadPart(upload, index, t)))
.getOrElse(
Future.successful(FailedUploadPart(upload, index, new RuntimeException(s"Cannot find etag in ${r}")))
Future.successful(FailedUploadPart(upload, index, new RuntimeException(s"Cannot find ETag in $r")))
)

case Failure(e) => Future.successful(FailedUploadPart(upload, index, e))
Expand Down Expand Up @@ -1027,7 +1027,7 @@ import scala.util.{Failure, Success, Try}
}
.flatMap(completeMultipartUpload(s3Location, _, sse))
}
.mapMaterializedValue(_.map(r => MultipartUploadResult(r.location, r.bucket, r.key, r.etag, r.versionId)))
.mapMaterializedValue(_.map(r => MultipartUploadResult(r.location, r.bucket, r.key, r.eTag, r.versionId)))
}
.mapMaterializedValue(_.flatMap(identity)(ExecutionContexts.parasitic))

Expand Down
34 changes: 22 additions & 12 deletions s3/src/main/scala/akka/stream/alpakka/s3/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ final class MultipartUploadResult private (
val location: Uri,
val bucket: String,
val key: String,
val etag: String,
val eTag: String,
val versionId: Option[String]
) {

/** Scala API */
@deprecated("Use eTag", "3.0.3")
val etag: String = eTag

/** Java API */
def getLocation: akka.http.javadsl.model.Uri = akka.http.javadsl.model.Uri.create(location)

Expand All @@ -34,28 +38,34 @@ final class MultipartUploadResult private (
def getKey: String = key

/** Java API */
def getEtag: String = etag
def getETag: String = eTag

/** Java API */
@deprecated("Use getETag", "3.0.3")
def getEtag: String = eTag

/** Java API */
def getVersionId: java.util.Optional[String] = versionId.asJava

def withLocation(value: Uri): MultipartUploadResult = copy(location = value)
def withBucket(value: String): MultipartUploadResult = copy(bucket = value)
def withKey(value: String): MultipartUploadResult = copy(key = value)
def withEtag(value: String): MultipartUploadResult = copy(etag = value)
def withETag(value: String): MultipartUploadResult = copy(eTag = value)
@deprecated("Use withETag", "3.0.3")
def withEtag(value: String): MultipartUploadResult = copy(eTag = value)
def withVersionId(value: String): MultipartUploadResult = copy(versionId = Option(value))

private def copy(
location: Uri = location,
bucket: String = bucket,
key: String = key,
etag: String = etag,
eTag: String = eTag,
versionId: Option[String] = versionId
): MultipartUploadResult = new MultipartUploadResult(
location = location,
bucket = bucket,
key = key,
etag = etag,
eTag = eTag,
versionId = versionId
)

Expand All @@ -64,7 +74,7 @@ final class MultipartUploadResult private (
s"location=$location," +
s"bucket=$bucket," +
s"key=$key," +
s"etag=$etag," +
s"eTag=$eTag," +
s"versionId=$versionId" +
")"

Expand All @@ -73,13 +83,13 @@ final class MultipartUploadResult private (
Objects.equals(this.location, that.location) &&
Objects.equals(this.bucket, that.bucket) &&
Objects.equals(this.key, that.key) &&
Objects.equals(this.etag, that.etag) &&
Objects.equals(this.eTag, that.eTag) &&
Objects.equals(this.versionId, that.versionId)
case _ => false
}

override def hashCode(): Int =
Objects.hash(location, bucket, key, etag, versionId)
Objects.hash(location, bucket, key, eTag, versionId)
}

object MultipartUploadResult {
Expand All @@ -89,13 +99,13 @@ object MultipartUploadResult {
location: Uri,
bucket: String,
key: String,
etag: String,
eTag: String,
Copy link
Contributor Author

@mdedetrich mdedetrich Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this can break source compatibility (i.e. if someone calls apply with named parameters specifically within Scala) but it doesn't break binary compatibility.

versionId: Option[String]
): MultipartUploadResult = new MultipartUploadResult(
location,
bucket,
key,
etag,
eTag,
versionId
)

Expand All @@ -104,13 +114,13 @@ object MultipartUploadResult {
location: akka.http.javadsl.model.Uri,
bucket: String,
key: String,
etag: String,
eTag: String,
Copy link
Contributor Author

@mdedetrich mdedetrich Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this can break source compatibility (i.e. if someone calls create with named parameters specifically within Scala) but it doesn't break binary compatibility.

versionId: java.util.Optional[String]
): MultipartUploadResult = apply(
location.asScala(),
bucket,
key,
etag,
eTag,
versionId.asScala
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ trait S3IntegrationSpec
_ <- S3.deleteObject(defaultBucket, objectKey).withAttributes(attributes).runWith(Sink.head)
} yield upload

upload.futureValue.etag should not be empty
upload.futureValue.eTag should not be empty
}

private def uploadAndAndCheckParts(source: Source[ByteString, _], expectedParts: Int): Assertion = {
Expand Down