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

Smithy4s Kinesis Client #36

Merged
merged 32 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3924f80
Update to ProjectMatrix
etspaceman Feb 5, 2023
98db831
Add crossScalaVersions
etspaceman Feb 5, 2023
7644a51
Add scalacOptions manually, generate workflows
etspaceman Feb 5, 2023
3829370
Merge remote-tracking branch 'origin/main' into smithy4sclient
etspaceman Feb 6, 2023
50576b9
Fix scalaVersion derivation
etspaceman Feb 6, 2023
2361949
Cleanup PR
etspaceman Feb 6, 2023
3cb8201
Clean up build
etspaceman Feb 6, 2023
cddb952
Delete ci.yml
etspaceman Feb 6, 2023
a50981b
Delete clean.yml
etspaceman Feb 6, 2023
66d97da
Ignore .sbt files
etspaceman Feb 6, 2023
cc11871
Fix class name
etspaceman Feb 6, 2023
120aeca
Workaround for kinesis-mock bugs, fixed localstack integration
etspaceman Feb 6, 2023
7e8722f
Note, bump memory
etspaceman Feb 6, 2023
c6652a0
Scaladoc
etspaceman Feb 7, 2023
1aaf41a
NoOpLogger default, markdowns
etspaceman Feb 7, 2023
7600912
Merge remote-tracking branch 'origin/main' into smithy4sclient
etspaceman Feb 10, 2023
635a7f9
Updates
etspaceman Feb 10, 2023
5f8385f
Better pretty rules
etspaceman Feb 10, 2023
2122036
Merge remote-tracking branch 'origin/main' into smithy4sclient
etspaceman Feb 10, 2023
4431a22
WIP on using kinesis spec with transformers
etspaceman Feb 10, 2023
fb4cdfe
Cleanup
etspaceman Feb 10, 2023
2d56736
More cleanup
etspaceman Feb 10, 2023
d200414
Merge remote-tracking branch 'origin/main' into smithy4sclient
etspaceman Feb 11, 2023
71d7199
Fixes
etspaceman Feb 11, 2023
9f0721a
Remove scala 2.12, project matrix
etspaceman Feb 11, 2023
315a933
Mergify plugin
etspaceman Feb 11, 2023
3714d04
fix build for some reason
etspaceman Feb 11, 2023
d244cb5
Remove scoverage, bring back scala 2.12/matrix
etspaceman Feb 12, 2023
94cbdd5
Fix for mergify labels
etspaceman Feb 12, 2023
4493101
Fixes
etspaceman Feb 12, 2023
a052373
remove compat dep
etspaceman Feb 12, 2023
4041601
Fix mima
etspaceman Feb 12, 2023
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
20 changes: 18 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,34 @@ lazy val `kinesis-client-tests` = projectMatrix
`kinesis-client-logging-circe` % IT
)

lazy val preprocessors = projectMatrix
.settings(
description := "Preprocessing of modules for the smithy4s project",
libraryDependencies ++= Seq(
Smithy.build(smithy4s.codegen.BuildInfo.smithyVersion)
)
)
.jvmPlatform(List(Scala212))
.enableIntegrationTests
.dependsOn(compat)

lazy val `smithy4s-client` = projectMatrix
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
description := "Cats tooling for the Smithy4s Kinesis Client",
libraryDependencies ++= Seq(
S4S.http4sAws(smithy4sVersion.value),
Log4Cats.noop,
Smithy.rulesEngine % Smithy4s
Smithy.rulesEngine(smithy4s.codegen.BuildInfo.smithyVersion) % Smithy4s,
S4S.kinesis % Smithy4s
),
Compile / smithy4sAllowedNamespaces := List(
"smithy.rules",
"com.amazonaws.kinesis"
)
),
Compile / smithy4sModelTransformers += "KinesisSpecTransformer",
Compile / smithy4sAllDependenciesAsJars +=
(preprocessors.jvm(Scala212) / Compile / packageBin).value
)
.jvmPlatform(last2ScalaVersions)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Brought in sbt-projectmatrix to work through having a subset of scala versions supported here (Smithy4s AWS does not have a 2.12 offering)

.enableIntegrationTests
Expand Down Expand Up @@ -472,6 +487,7 @@ lazy val allProjects = Seq(
`kinesis-client-logging-circe`,
`kinesis-client-localstack`,
`kinesis-client-tests`,
preprocessors,
`smithy4s-client`,
`smithy4s-client-logging-circe`,
`smithy4s-client-localstack`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preprocessors.KinesisSpecTransformer
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package preprocessors

import scala.jdk.CollectionConverters._

import java.util.function
import java.util.function.BiFunction

import software.amazon.smithy.build.ProjectionTransformer
import software.amazon.smithy.build.TransformContext
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.IntegerShape
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.LengthTrait
import software.amazon.smithy.model.traits.RangeTrait
import software.amazon.smithy.model.traits.Trait

final class KinesisSpecTransformer extends ProjectionTransformer {
def getName() = "KinesisSpecTransformer"

private val metricsNameListShapeId =
ShapeId.fromParts("com.amazonaws.kinesis", "MetricsNameList")

private val putRecordsOutputShapeId =
ShapeId.fromParts("com.amazonaws.kinesis", "PutRecordsOutput")

private val nonNegativeIntegerObjectShape =
IntegerShape
.builder()
.id(
ShapeId.fromParts("com.amazonaws.kinesis", "NonNegativeIntegerObject")
Copy link
Owner Author

Choose a reason for hiding this comment

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

Counterpart to PositiveIntegerObject

)
.addTrait(RangeTrait.builder().min(java.math.BigDecimal.ZERO).build())
.build()

val traitTransform: BiFunction[Shape, Trait, Trait] =
(shape: Shape, `trait`: Trait) =>
if (
`trait`.toShapeId() == LengthTrait.ID &&
shape.toShapeId() == metricsNameListShapeId
) {
LengthTrait.builder().min(0).max(7).build()
Copy link
Owner Author

Choose a reason for hiding this comment

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

Usually this is 1-7. Set to 0-7

} else `trait`

val shapeTransform: function.Function[Shape, Shape] = (shape: Shape) =>
if (shape.toShapeId() == putRecordsOutputShapeId) {
val members =
shape.getAllMembers().asScala.toList.map { case (memberName, member) =>
if (memberName == "FailedRecordCount")
MemberShape
.builder()
.target(nonNegativeIntegerObjectShape.getId())
.id(member.getId())
.build()
else member
}

StructureShape
.builder()
.members(members.asJavaCollection)
.id(putRecordsOutputShapeId)
.traits(shape.getAllTraits().values())
.build()
} else shape

def transform(context: TransformContext): Model = {
val withMappedTraits =
context
.getTransformer()
.mapTraits(context.getModel(), traitTransform)

val newShapes = withMappedTraits
.shapes()
.toList()
.asScala
.toList :+ nonNegativeIntegerObjectShape

val withNewShapes =
context.getTransformer().replaceShapes(withMappedTraits, newShapes.asJava)

context.getTransformer().mapShapes(withNewShapes, shapeTransform)
}

}
9 changes: 6 additions & 3 deletions project/LibraryDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ object LibraryDependencies {
}

object Smithy {
val smithyVersion = "1.27.2"
val rulesEngine =
"software.amazon.smithy" % "smithy-rules-engine" % smithyVersion
def rulesEngine(version: String) =
"software.amazon.smithy" % "smithy-rules-engine" % version
def build(version: String) =
"software.amazon.smithy" % "smithy-build" % version
}

object Smithy4s {
Expand All @@ -94,5 +95,7 @@ object LibraryDependencies {
"com.disneystreaming.smithy4s" %% "smithy4s-http4s-swagger" % version
def http4sAws(version: String) =
"com.disneystreaming.smithy4s" %% "smithy4s-aws-http4s" % version
val kinesis =
"com.disneystreaming.smithy" % "aws-kinesis-spec" % "2023.02.10"
}
}
9 changes: 9 additions & 0 deletions smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"imports": ["./kcl-http4s/src/main/smithy"],
"mavenDependencies": [
"software.amazon.smithy:smithy-rules-engine:1.27.2",
"com.disneystreaming.smithy4s:smithy4s-protocol:0.17.3",
"com.disneystreaming.smithy:aws-kinesis-spec:2023.02.10",
"com.disneystreaming.alloy:alloy-core:0.1.11"
]
}
Loading