From de99cb9a05940c3062488a3f1f1c659a4bb4b741 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 20 Apr 2022 13:20:23 -0700 Subject: [PATCH 1/4] Sorting --- modules/core/src/main/scala/AbstractCodegenPlugin.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/scala/AbstractCodegenPlugin.scala b/modules/core/src/main/scala/AbstractCodegenPlugin.scala index 7697f4b..b213b92 100644 --- a/modules/core/src/main/scala/AbstractCodegenPlugin.scala +++ b/modules/core/src/main/scala/AbstractCodegenPlugin.scala @@ -44,8 +44,8 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => val contextTransforms = Seq[ContextImpl => ContextImpl]( kindaLens(customExtraction)(a => _.copy(customExtraction=a)), - kindaLens(tracing)(a => _.copy(tracing=a)), - kindaLens(tagsBehaviour)(a => _.copy(tagsBehaviour=a)) + kindaLens(tagsBehaviour)(a => _.copy(tagsBehaviour=a)), + kindaLens(tracing)(a => _.copy(tracing=a)) ) ArgsImpl.empty.copy( From 031b2e96112862fba0f14c7887f3c9d4a1d6979b Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 20 Apr 2022 13:23:42 -0700 Subject: [PATCH 2/4] Adding authImplementation parameter --- modules/core/src/main/scala/AbstractCodegenPlugin.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/AbstractCodegenPlugin.scala b/modules/core/src/main/scala/AbstractCodegenPlugin.scala index b213b92..9a3c55e 100644 --- a/modules/core/src/main/scala/AbstractCodegenPlugin.scala +++ b/modules/core/src/main/scala/AbstractCodegenPlugin.scala @@ -7,6 +7,7 @@ import dev.guardrail.runner.GuardrailRunner import dev.guardrail.terms.protocol.PropertyRequirement import dev.guardrail.{ Args => ArgsImpl, + AuthImplementation, CodegenTarget => CodegenTargetImpl, Context => ContextImpl } @@ -28,7 +29,8 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => encodeOptionalAs: Option[CodingConfig], decodeOptionalAs: Option[CodingConfig], customExtraction: Option[Boolean], - tagsBehaviour: Option[ContextImpl.TagsBehaviour] + tagsBehaviour: Option[ContextImpl.TagsBehaviour], + authImplementation: Option[AuthImplementation] ): ArgsImpl = { val propertyRequirement = (encodeOptionalAs, decodeOptionalAs) match { case (None, None) => ContextImpl.empty.propertyRequirement @@ -43,6 +45,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => def kindaLens[A](member: Option[A])(proj: A => ContextImpl => ContextImpl): ContextImpl => ContextImpl = member.fold[ContextImpl => ContextImpl](identity _)(proj) val contextTransforms = Seq[ContextImpl => ContextImpl]( + kindaLens(authImplementation)(a => _.copy(authImplementation=a)), kindaLens(customExtraction)(a => _.copy(customExtraction=a)), kindaLens(tagsBehaviour)(a => _.copy(tagsBehaviour=a)), kindaLens(tracing)(a => _.copy(tracing=a)) @@ -81,6 +84,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default, tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default, + authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default, ): Types.Args = (language, impl( kind = kind, specPath = Some(specPath), @@ -94,6 +98,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => decodeOptionalAs = decodeOptionalAs.toOption, customExtraction = customExtraction.toOption, tagsBehaviour = tagsBehaviour.toOption, + authImplementation = authImplementation.toOption, defaults = false )) @@ -108,6 +113,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default, tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default, + authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default, // Deprecated parameters packageName: Keys.GuardrailConfigValue[String] = Keys.Default, @@ -125,6 +131,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => decodeOptionalAs = decodeOptionalAs.toOption, customExtraction = customExtraction.toOption, tagsBehaviour = tagsBehaviour.toOption, + authImplementation = authImplementation.toOption, defaults = true )) } From 2e7819ae40d639284576115fd35cc4b91e6bb27f Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 20 Apr 2022 13:26:23 -0700 Subject: [PATCH 3/4] Exposing authImplementation{Disable, Native, Simple, Custom} members --- modules/core/src/main/scala/AbstractCodegenPlugin.scala | 5 +++++ modules/core/src/main/scala/Keys.scala | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/AbstractCodegenPlugin.scala b/modules/core/src/main/scala/AbstractCodegenPlugin.scala index 9a3c55e..5145265 100644 --- a/modules/core/src/main/scala/AbstractCodegenPlugin.scala +++ b/modules/core/src/main/scala/AbstractCodegenPlugin.scala @@ -177,6 +177,11 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => def tagsAreIgnored = Keys.tagsAreIgnored def tagsAsPackage = Keys.tagsAsPackage + + def authImplementationDisable = Keys.authImplementationDisable + def authImplementationNative = Keys.authImplementationNative + def authImplementationSimple = Keys.authImplementationSimple + def authImplementationCustom = Keys.authImplementationCustom } private def cachedGuardrailTask(projectName: String, scope: String, scalaBinaryVersion: String)(kind: String, streams: _root_.sbt.Keys.TaskStreams)(tasks: List[(String, Args)], sources: Seq[java.io.File]) = { diff --git a/modules/core/src/main/scala/Keys.scala b/modules/core/src/main/scala/Keys.scala index 2f80919..9a16cbe 100644 --- a/modules/core/src/main/scala/Keys.scala +++ b/modules/core/src/main/scala/Keys.scala @@ -6,7 +6,7 @@ import java.io.File import _root_.sbt.{ SettingKey, TaskKey } import scala.language.implicitConversions -import dev.guardrail.Context +import dev.guardrail.{AuthImplementation, Context} import dev.guardrail.terms.protocol.PropertyRequirement sealed trait CodingConfig { @@ -45,4 +45,9 @@ object Keys { def tagsAreIgnored: Context.TagsBehaviour = Context.TagsAreIgnored def tagsAsPackage: Context.TagsBehaviour = Context.PackageFromTags + + def authImplementationDisable: AuthImplementation = AuthImplementation.Disable + def authImplementationNative: AuthImplementation = AuthImplementation.Native + def authImplementationSimple: AuthImplementation = AuthImplementation.Simple + def authImplementationCustom: AuthImplementation = AuthImplementation.Custom } From 5a14f5cb3a3e4a645e2ebe5b3bfd69c49477ddf1 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 20 Apr 2022 13:44:20 -0700 Subject: [PATCH 4/4] Add a totality check for members in Context so we don't forget to add new fields when the core changes --- build.sbt | 6 ++++++ .../guardrail/sbt/ContextParameterSpec.scala | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala diff --git a/build.sbt b/build.sbt index 05dc930..e65105d 100644 --- a/build.sbt +++ b/build.sbt @@ -25,6 +25,12 @@ ThisBuild / developers := List( ThisBuild / scalaVersion := "2.12.15" ThisBuild / scalacOptions ++= List("-feature", "-Xexperimental") +libraryDependencies ++= Seq( + "org.scalatest" %% "scalatest" % "3.2.11" % Test, + "org.scalacheck" %% "scalacheck" % "1.16.0" % Test, + "org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test + ) + // Versioning enablePlugins(GitBranchPrompt) enablePlugins(GitVersioning) diff --git a/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala b/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala new file mode 100644 index 0000000..bf1260c --- /dev/null +++ b/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala @@ -0,0 +1,21 @@ +package dev.guardrail.sbt + +import dev.guardrail.Context + +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers + +class EscapeTreeSpec extends AnyFunSuite with Matchers { + + test("Ensure that all Context fields are accounted for") { + val Context( + framework, + customExtraction, + tracing, + modules, + propertyRequirement, + tagsBehaviour, + authImplementation + ) = Context.empty + } +}