-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MTDSA-16033: Remove references of redundant feature switches for indi…
…viduals-disclosures-api (#113) * MTDSA-16033 progress * MTDSA-16033: Completed * MTDSA-16033: Addressed platops comments * MTDSA-16033: Implemented reviewer comments * Remove .DS_Store from everywhere
- Loading branch information
1 parent
3f0f1a2
commit e979ae1
Showing
23 changed files
with
208 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package routing | ||
|
||
import play.api.http.HeaderNames.ACCEPT | ||
import play.api.libs.json._ | ||
import play.api.mvc.RequestHeader | ||
|
||
object Version { | ||
|
||
object VersionWrites extends Writes[Version] { | ||
|
||
def writes(version: Version): JsValue = version match { | ||
case Version1 => Json.toJson(Version1.name) | ||
} | ||
|
||
} | ||
|
||
object VersionReads extends Reads[Version] { | ||
|
||
override def reads(version: JsValue): JsResult[Version] = | ||
version.validate[String].flatMap { | ||
case Version1.name => JsSuccess(Version1) | ||
case _ => JsError("Unrecognised version") | ||
} | ||
|
||
} | ||
|
||
implicit val versionFormat: Format[Version] = Format(VersionReads, VersionWrites) | ||
} | ||
|
||
sealed trait Version { | ||
val name: String | ||
val configName: String | ||
val maybePrevious: Option[Version] = None | ||
|
||
override def toString: String = name | ||
} | ||
|
||
case object Version1 extends Version { | ||
val name = "1.0" | ||
val configName = "1" | ||
} | ||
|
||
object Versions { | ||
|
||
private val versionsByName: Map[String, Version] = Map( | ||
Version1.name -> Version1 | ||
) | ||
|
||
private val versionRegex = """application/vnd.hmrc.(\d.\d)\+json""".r | ||
|
||
def getFromRequest(request: RequestHeader): Either[GetFromRequestError, Version] = | ||
for { | ||
str <- getFrom(request.headers.headers) | ||
ver <- getFrom(str) | ||
} yield ver | ||
|
||
private def getFrom(headers: Seq[(String, String)]): Either[GetFromRequestError, String] = | ||
headers.collectFirst { case (ACCEPT, versionRegex(ver)) => ver }.toRight(left = InvalidHeader) | ||
|
||
private def getFrom(name: String): Either[GetFromRequestError, Version] = | ||
versionsByName.get(name).toRight(left = VersionNotFound) | ||
|
||
} | ||
|
||
sealed trait GetFromRequestError | ||
case object InvalidHeader extends GetFromRequestError | ||
case object VersionNotFound extends GetFromRequestError |
Oops, something went wrong.