-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MTDSA-21658] [MTDSA-27974]: Copy Shared Code (#554)
* MTDSA-21658: Copy Shared Code * MTDSA-21658: resolve failing test issue
- Loading branch information
1 parent
2213994
commit 9913263
Showing
212 changed files
with
16,825 additions
and
111 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 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 shared.config | ||
|
||
import play.api.Configuration | ||
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig | ||
|
||
trait AppConfigBase { | ||
protected val config: ServicesConfig | ||
protected val configuration: Configuration | ||
|
||
private def serviceKeyFor(serviceName: String) = s"microservice.services.$serviceName" | ||
|
||
protected def downstreamConfig(serviceName: String): DownstreamConfig = { | ||
val baseUrl = config.baseUrl(serviceName) | ||
|
||
val serviceKey = serviceKeyFor(serviceName) | ||
|
||
val env = config.getString(s"$serviceKey.env") | ||
val token = config.getString(s"$serviceKey.token") | ||
val environmentHeaders = configuration.getOptional[Seq[String]](s"$serviceKey.environmentHeaders") | ||
|
||
DownstreamConfig(baseUrl, env, token, environmentHeaders) | ||
} | ||
|
||
protected def basicAuthDownstreamConfig(serviceName: String): BasicAuthDownstreamConfig = { | ||
val baseUrl = config.baseUrl(serviceName) | ||
|
||
val serviceKey = serviceKeyFor(serviceName) | ||
|
||
val env = config.getString(s"$serviceKey.env") | ||
val clientId = config.getString(s"$serviceKey.clientId") | ||
val clientSecret = config.getString(s"$serviceKey.clientSecret") | ||
val environmentHeaders = configuration.getOptional[Seq[String]](s"$serviceKey.environmentHeaders") | ||
|
||
BasicAuthDownstreamConfig(baseUrl, env, clientId, clientSecret, environmentHeaders) | ||
} | ||
|
||
} |
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,28 @@ | ||
/* | ||
* Copyright 2024 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 shared.config | ||
|
||
import java.time.LocalDateTime | ||
|
||
sealed trait Deprecation | ||
|
||
object Deprecation { | ||
case object NotDeprecated extends Deprecation | ||
|
||
case class Deprecated(deprecatedOn: LocalDateTime, sunsetDate: Option[LocalDateTime]) extends Deprecation | ||
|
||
} |
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,32 @@ | ||
/* | ||
* 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 shared.config | ||
|
||
case class DownstreamConfig( | ||
baseUrl: String, | ||
env: String, | ||
token: String, | ||
environmentHeaders: Option[Seq[String]] | ||
) | ||
|
||
case class BasicAuthDownstreamConfig( | ||
baseUrl: String, | ||
env: String, | ||
clientId: String, | ||
clientSecret: String, | ||
environmentHeaders: Option[Seq[String]] | ||
) |
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,42 @@ | ||
/* | ||
* 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 shared.config | ||
|
||
import play.api.Configuration | ||
|
||
trait FeatureSwitches { | ||
|
||
protected val featureSwitchConfig: Configuration | ||
|
||
def isEnabled(feature: String): Boolean = isConfigTrue(feature + ".enabled") | ||
|
||
def isReleasedInProduction(feature: String): Boolean = isConfigTrue(feature + ".released-in-production") | ||
|
||
private def isConfigTrue(key: String): Boolean = featureSwitchConfig.getOptional[Boolean](key).getOrElse(true) | ||
|
||
def supportingAgentsAccessControlEnabled: Boolean = isEnabled("supporting-agents-access-control") | ||
|
||
} | ||
|
||
/** This is just here for non-typesafe usage such as Handlebars using OasFeatureRewriter. In most cases, should use the API-specific | ||
* XyzFeatureSwitches class instead. | ||
*/ | ||
case class ConfigFeatureSwitches private (protected val featureSwitchConfig: Configuration) extends FeatureSwitches | ||
|
||
object ConfigFeatureSwitches { | ||
def apply()(implicit appConfig: SharedAppConfig): ConfigFeatureSwitches = ConfigFeatureSwitches(appConfig.featureSwitchConfig) | ||
} |
Oops, something went wrong.