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

Bdog 1512 truncate update #142

Merged
merged 19 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 14.0.0

Improves hook-data model for auditing.

This should not affect most clients, as long as a compatible library versions are used. It is generally expected that clients only depend on `bootstrap-play` which will transitively provide compatible versions.


## Version 13.13.0

### Auditing max body length
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import sbt._
Global / concurrentRestrictions += Tags.limitSum(1, Tags.Test, Tags.Untagged)

val scala2_12 = "2.12.15"
val scala2_13 = "2.13.7"
val scala2_13 = "2.13.8"

val silencerVersion = "1.7.7"
val silencerVersion = "1.7.8"

lazy val commonSettings = Seq(
organization := "uk.gov.hmrc",
majorVersion := 13,
majorVersion := 14,
scalaVersion := scala2_12,
isPublicArtefact := true,
scalacOptions ++= Seq("-feature"),
Expand Down
32 changes: 22 additions & 10 deletions http-verbs-common/src/main/scala/uk/gov/hmrc/http/HttpDelete.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@
package uk.gov.hmrc.http

import uk.gov.hmrc.http.HttpVerbs.{DELETE => DELETE_VERB}
import uk.gov.hmrc.http.hooks.HttpHooks
import uk.gov.hmrc.http.hooks.{Body, HttpHooks, RequestData, ResponseData}
import uk.gov.hmrc.http.logging.ConnectionTracing

import scala.concurrent.{ExecutionContext, Future}

trait HttpDelete
extends CoreDelete
with DeleteHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {
extends CoreDelete
with DeleteHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {

private lazy val hcConfig = HeaderCarrier.Config.fromConfig(configuration)

override def DELETE[O](url: String, headers: Seq[(String, String)] = Seq.empty)(implicit rds: HttpReads[O], hc: HeaderCarrier, ec: ExecutionContext): Future[O] =
override def DELETE[O](
url : String,
headers: Seq[(String, String)] = Seq.empty
)(implicit
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(DELETE_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(DELETE_VERB, url)(doDelete(url, allHeaders))
executeHooks(DELETE_VERB, url"$url", allHeaders, None, httpResponse)
executeHooks(
DELETE_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(None)),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(DELETE_VERB, url, httpResponse).map(rds.read(DELETE_VERB, url, _))
}
}
31 changes: 22 additions & 9 deletions http-verbs-common/src/main/scala/uk/gov/hmrc/http/HttpGet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,30 @@ package uk.gov.hmrc.http
import java.net.URLEncoder

import uk.gov.hmrc.http.HttpVerbs.{GET => GET_VERB}
import uk.gov.hmrc.http.hooks.HttpHooks
import uk.gov.hmrc.http.hooks.{Body, HttpHooks, RequestData, ResponseData}
import uk.gov.hmrc.http.logging.ConnectionTracing

import scala.concurrent.{ExecutionContext, Future}

trait HttpGet extends CoreGet with GetHttpTransport with HttpVerb with ConnectionTracing with HttpHooks with Retries {
trait HttpGet
extends CoreGet
with GetHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {

private lazy val hcConfig = HeaderCarrier.Config.fromConfig(configuration)

override def GET[A](
url: String,
url : String,
queryParams: Seq[(String, String)],
headers: Seq[(String, String)])(
implicit rds: HttpReads[A],
hc: HeaderCarrier,
ec: ExecutionContext): Future[A] = {
headers : Seq[(String, String)]
)(implicit
rds: HttpReads[A],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[A] = {
if (queryParams.nonEmpty && url.contains("?")) {
throw new UrlValidationException(
url,
Expand All @@ -45,9 +53,14 @@ trait HttpGet extends CoreGet with GetHttpTransport with HttpVerb with Connectio
val urlWithQuery = url + makeQueryString(queryParams)

withTracing(GET_VERB, urlWithQuery) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(GET_VERB, urlWithQuery)(doGet(urlWithQuery, headers = allHeaders))
executeHooks(GET_VERB, url"$url", allHeaders, None, httpResponse)
executeHooks(
GET_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(None)),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(GET_VERB, urlWithQuery, httpResponse).map(response => rds.read(GET_VERB, urlWithQuery, response))
}
}
Expand Down
39 changes: 23 additions & 16 deletions http-verbs-common/src/main/scala/uk/gov/hmrc/http/HttpPatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,40 @@ package uk.gov.hmrc.http

import play.api.libs.json.{Json, Writes}
import uk.gov.hmrc.http.HttpVerbs.{PATCH => PATCH_VERB}
import uk.gov.hmrc.http.hooks.{HookData, HttpHooks}
import uk.gov.hmrc.http.hooks.{Body, HookData, HttpHooks, RequestData, ResponseData}
import uk.gov.hmrc.http.logging.ConnectionTracing

import scala.concurrent.{ExecutionContext, Future}

trait HttpPatch
extends CorePatch
with PatchHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {
extends CorePatch
with PatchHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {

private lazy val hcConfig = HeaderCarrier.Config.fromConfig(configuration)

override def PATCH[I, O](
url: String,
body: I,
headers: Seq[(String, String)])(
implicit wts: Writes[I],
rds: HttpReads[O],
hc: HeaderCarrier,
ec: ExecutionContext): Future[O] =
url : String,
body : I,
headers: Seq[(String, String)]
)(implicit
wts: Writes[I],
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(PATCH_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(PATCH_VERB, url)(doPatch(url, body, allHeaders))
executeHooks(PATCH_VERB, url"$url", allHeaders, Option(HookData.FromString(Json.stringify(wts.writes(body)))), httpResponse)
executeHooks(
PATCH_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(Option(HookData.FromString(Json.stringify(wts.writes(body)))))),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(PATCH_VERB, url, httpResponse).map(response => rds.read(PATCH_VERB, url, response))
}
}
98 changes: 63 additions & 35 deletions http-verbs-common/src/main/scala/uk/gov/hmrc/http/HttpPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,74 +18,102 @@ package uk.gov.hmrc.http

import play.api.libs.json.{Json, Writes}
import uk.gov.hmrc.http.HttpVerbs.{POST => POST_VERB}
import uk.gov.hmrc.http.hooks.{HookData, HttpHooks}
import uk.gov.hmrc.http.hooks.{Body, HookData, HttpHooks, RequestData, ResponseData}
import uk.gov.hmrc.http.logging.ConnectionTracing

import scala.concurrent.{ExecutionContext, Future}

trait HttpPost
extends CorePost
with PostHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {
extends CorePost
with PostHttpTransport
with HttpVerb
with ConnectionTracing
with HttpHooks
with Retries {

private lazy val hcConfig = HeaderCarrier.Config.fromConfig(configuration)

override def POST[I, O](
url: String,
body: I,
headers: Seq[(String, String)])(
implicit wts: Writes[I],
rds: HttpReads[O],
hc: HeaderCarrier,
ec: ExecutionContext): Future[O] =
url : String,
body : I,
headers: Seq[(String, String)]
)(implicit
wts: Writes[I],
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(POST_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(POST_VERB, url)(doPost(url, body, allHeaders))
executeHooks(POST_VERB, url"$url", allHeaders, Option(HookData.FromString(Json.stringify(wts.writes(body)))), httpResponse)
executeHooks(
POST_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(Option(HookData.FromString(Json.stringify(wts.writes(body)))))),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(POST_VERB, url, httpResponse).map(rds.read(POST_VERB, url, _))
}

override def POSTString[O](
url: String,
body: String,
headers: Seq[(String, String)])(
implicit rds: HttpReads[O],
hc: HeaderCarrier,
ec: ExecutionContext): Future[O] =
url : String,
body : String,
headers: Seq[(String, String)]
)(implicit
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(POST_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(POST_VERB, url)(doPostString(url, body, allHeaders))
executeHooks(POST_VERB, url"$url", allHeaders, Option(HookData.FromString(body)), httpResponse)
executeHooks(
POST_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(Option(HookData.FromString(body)))),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(POST_VERB, url, httpResponse).map(rds.read(POST_VERB, url, _))
}

override def POSTForm[O](
url: String,
body: Map[String, Seq[String]],
headers: Seq[(String, String)])(
implicit rds: HttpReads[O],
hc: HeaderCarrier,
ec: ExecutionContext): Future[O] =
url : String,
body : Map[String, Seq[String]],
headers: Seq[(String, String)]
)(implicit
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(POST_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(POST_VERB, url)(doFormPost(url, body, allHeaders))
executeHooks(POST_VERB, url"$url", allHeaders, Option(HookData.FromMap(body)), httpResponse)
executeHooks(
POST_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(Option(HookData.FromMap(body)))),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(POST_VERB, url, httpResponse).map(rds.read(POST_VERB, url, _))
}

override def POSTEmpty[O](
url: String,
headers: Seq[(String, String)])(
implicit rds: HttpReads[O],
hc: HeaderCarrier,
ec: ExecutionContext): Future[O] =
url : String,
headers: Seq[(String, String)]
)(implicit
rds: HttpReads[O],
hc : HeaderCarrier,
ec : ExecutionContext
): Future[O] =
withTracing(POST_VERB, url) {
val allHeaders = HeaderCarrier.headersForUrl(hcConfig, url, headers) :+ "Http-Client-Version" -> BuildInfo.version
val httpResponse = retryOnSslEngineClosed(POST_VERB, url)(doEmptyPost(url, allHeaders))
executeHooks(POST_VERB, url"$url", allHeaders, None, httpResponse)
executeHooks(
POST_VERB,
url"$url",
RequestData(allHeaders, Body.Complete(None)),
httpResponse.map(ResponseData.fromHttpResponse)
)
mapErrors(POST_VERB, url, httpResponse).map(rds.read(POST_VERB, url, _))
}
}
Loading