Skip to content

Commit

Permalink
add preprocessor to rename the KMS service namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bpholt committed Sep 23, 2024
1 parent 30f11ab commit bcf47df
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,5 @@ jobs:
- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: smithy4s-preprocessors_2.12
configs-ignore: test scala-tool scala-doc-tool test-internal
8 changes: 8 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ pull_request_rules:
- status-success=Build and Test (ubuntu-latest, 3, temurin@8)
actions:
merge: {}
- name: Label smithy4s-preprocessors PRs
conditions:
- files~=^smithy4s-preprocessors/
actions:
label:
add:
- smithy4s-preprocessors
remove: []
18 changes: 17 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ ThisBuild / startYear := Option(2018)
ThisBuild / tlBaseVersion := "0.4"
ThisBuild / tlJdkRelease := Some(8)

lazy val `smithy4s-preprocessors` = project
.in(file("smithy4s-preprocessors"))
.settings(
scalaVersion := "2.12.13", // 2.12 to match what SBT uses
scalacOptions -= "-source:future",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-core" % "2.10.0",
"software.amazon.smithy" % "smithy-build" % smithy4s.codegen.BuildInfo.smithyVersion,
)
},
)
.enablePlugins(NoPublishPlugin)

lazy val `secure-config` = (project in file("."))
.settings(
libraryDependencies ++= {
Expand All @@ -30,8 +44,10 @@ lazy val `secure-config` = (project in file("."))
"org.typelevel" %% "mouse" % "1.3.1",
)
},
smithy4sAwsSpecs ++= Seq(AWS.kms), // TODO can we put this into its own package to avoid clashing with generated code downstream?
smithy4sAwsSpecs ++= Seq(AWS.kms),
scalacOptions += "-Wconf:src=src_managed/.*:s",
Compile / smithy4sModelTransformers += "com.dwolla.smithy.ShadeNamespace",
Compile / smithy4sAllDependenciesAsJars += (`smithy4s-preprocessors` / Compile / packageBin).value,
)
.enablePlugins(
Smithy4sCodegenPlugin,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.dwolla.smithy.ShadeNamespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dwolla.smithy

import cats.syntax.all._
import software.amazon.smithy.build.{ProjectionTransformer, TransformContext}
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.Shape

import java.util.stream.Collectors
import scala.collection.JavaConverters._

class ShadeNamespace extends ProjectionTransformer {
override def getName: String = "com.dwolla.smithy.ShadeNamespace"

private val namespacesToRename: Set[String] = Set("com.amazonaws.kms")

override def transform(context: TransformContext): Model = {
val renames =
context.getModel
.shapes().collect(Collectors.toList[Shape]).asScala.toList
.map(_.getId)
.filter(id => namespacesToRename.contains(id.getNamespace))
.fproduct(id => id.withNamespace(s"com.dwolla.smithy_shaded.${id.getNamespace}"))
.toMap.asJava

context.getTransformer.renameShapes(context.getModel, renames)
}
}
2 changes: 1 addition & 1 deletion src/main/scala/com/dwolla/config/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.dwolla

import cats.effect.*
import cats.syntax.all.*
import com.amazonaws.kms.{CiphertextType, KMS}
import com.dwolla.smithy_shaded.com.amazonaws.kms.{CiphertextType, KMS}
import fs2.compression.Compression
import monix.newtypes.NewtypeWrapped
import mouse.all.*
Expand Down

0 comments on commit bcf47df

Please sign in to comment.