Skip to content

Commit

Permalink
[MTDSA-21658] [MTDSA-27974]: Copy Shared Code (#554)
Browse files Browse the repository at this point in the history
* MTDSA-21658: Copy Shared Code

* MTDSA-21658: resolve failing test issue
  • Loading branch information
Artemas-Muzanenhamo authored Dec 18, 2024
1 parent 2213994 commit 9913263
Show file tree
Hide file tree
Showing 212 changed files with 16,825 additions and 111 deletions.
111 changes: 0 additions & 111 deletions app/controllers/RewriteableAssets.scala

This file was deleted.

53 changes: 53 additions & 0 deletions app/shared/config/AppConfigBase.scala
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)
}

}
28 changes: 28 additions & 0 deletions app/shared/config/Deprecation.scala
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

}
32 changes: 32 additions & 0 deletions app/shared/config/DownstreamConfig.scala
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]]
)
42 changes: 42 additions & 0 deletions app/shared/config/FeatureSwitches.scala
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)
}
Loading

0 comments on commit 9913263

Please sign in to comment.