Skip to content

Commit

Permalink
Merge pull request #29 from Ferlab-Ste-Justine/ferload2
Browse files Browse the repository at this point in the history
fix: CQDG-369 Add client id for token method
  • Loading branch information
jecos authored Oct 12, 2023
2 parents 71c7525 + ef6ee20 commit 5dc03c6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Keyckloak Authentication server information :

Ferload Client: This section is used to configure ferload clients taht can be installed to download files by requesting ferload endpoints.
- `FERLOAD_CLIENT_METHOD` : 2 possible values : `token`or `password`. Default `token`.
- `FERLOAD_CLIENT_CLIENT_ID` : client id to use to authenticate user in case of `password` method.
- `FERLOAD_CLIENT_CLIENT_ID` : client id to use to authenticate user (`password` method) or refesh token (`token` method).
- `FERLOAD_CLIENT_TOKEN_LINK` : url to use to fetch new token in case of `token` method.
- `FERLOAD_CLIENT_TOKEN_HELPER` : text to display in ferload client to explain how to get a new token. Used only if `FERLOAD_CLIENT_METHOD` is `token`.

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/bio/ferlab/ferload/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ case class AuthConfig(authUrl: String, realm: String, clientId: String, clientSe
val baseUri = s"$authUrl/realms/$realm"
}

case class FerloadClientConfig(method: String, clientId: Option[String], tokenLink: Option[String], tokenHelper: Option[String])
case class FerloadClientConfig(method: String, clientId: String, tokenLink: Option[String], tokenHelper: Option[String])

object FerloadClientConfig {
val TOKEN: String = "token"
val PASSWORD: String = "password"
def load(): FerloadClientConfig = {
val f = FerloadClientConfig(
sys.env.getOrElse("FERLOAD_CLIENT_METHOD", "token"),
sys.env.get("FERLOAD_CLIENT_CLIENT_ID"),
sys.env("FERLOAD_CLIENT_CLIENT_ID"),
sys.env.get("FERLOAD_CLIENT_TOKEN_LINK"),
sys.env.get("FERLOAD_CLIENT_TOKEN_HELPER")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ object ConfigEndpoint:

def configServerEndpoint(config: Config): ServerEndpoint[Any, IO] = configEndpoint.serverLogicSuccess(_ => {
if (config.ferloadClientConfig.method == FerloadClientConfig.TOKEN) {
val tokenConfig = TokenConfig(config.ferloadClientConfig.tokenLink.get, config.ferloadClientConfig.tokenHelper)
val tokenConfig = TokenConfig(config.ferloadClientConfig.clientId, config.ferloadClientConfig.tokenLink.get, config.ferloadClientConfig.tokenHelper)
IO.pure(FerloadConfig(config.ferloadClientConfig.method, None, Some(tokenConfig)))
} else if (config.ferloadClientConfig.method == FerloadClientConfig.PASSWORD) {
val kc = KeycloakConfig(config.auth.authUrl, config.auth.realm, config.ferloadClientConfig.clientId.get, config.auth.clientId)
val kc = KeycloakConfig(config.auth.authUrl, config.auth.realm, config.ferloadClientConfig.clientId, config.auth.clientId)
IO.pure(FerloadConfig(config.ferloadClientConfig.method, Some(kc), None))
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ case class FerloadConfig(method: String, keycloak: Option[KeycloakConfig], token

case class KeycloakConfig(url: String, realm: String, `client-id`: String, audience: String)

case class TokenConfig(link: String, helper: Option[String])
case class TokenConfig(`client-id`: String, link: String, helper: Option[String])
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigEndpointsSpec extends AnyFlatSpec with Matchers with EitherValues:
HttpConfig("localhost", 9090),
S3Config(Some("accessKey"), Some("secretKey"), Some("endpoint"), Some("bucket"), false, Some("region"), 3600),
DrsConfig("ferlaod", "Ferload", "ferload.ferlab.bio", "1.3.0", "Ferlab", "https://ferlab.bio"),
FerloadClientConfig(FerloadClientConfig.PASSWORD, Some("ferloadClientId"), None, None)
FerloadClientConfig(FerloadClientConfig.PASSWORD, "ferloadClientId", None, None)
)
val backendStub = TapirStubInterpreter(SttpBackendStub(new CatsMonadError[IO]()))
.whenServerEndpointRunLogic(configServerEndpoint(config))
Expand All @@ -45,7 +45,7 @@ class ConfigEndpointsSpec extends AnyFlatSpec with Matchers with EitherValues:
HttpConfig("localhost", 9090),
S3Config(Some("accessKey"), Some("secretKey"), Some("endpoint"), Some("bucket"), false, Some("region"), 3600),
DrsConfig("ferlaod", "Ferload", "ferload.ferlab.bio", "1.3.0", "Ferlab", "https://ferlab.bio"),
FerloadClientConfig(FerloadClientConfig.TOKEN, None, Some("https://ferload.ferlab.bio/token"), Some("Please copy / paste this url in your browser to get a new authentication token."))
FerloadClientConfig(FerloadClientConfig.TOKEN, "ferloadClientId", Some("https://ferload.ferlab.bio/token"), Some("Please copy / paste this url in your browser to get a new authentication token."))
)
val backendStub = TapirStubInterpreter(SttpBackendStub(new CatsMonadError[IO]()))
.whenServerEndpointRunLogic(configServerEndpoint(config))
Expand All @@ -56,6 +56,6 @@ class ConfigEndpointsSpec extends AnyFlatSpec with Matchers with EitherValues:
.response(asJson[FerloadConfig])
.send(backendStub)

val expected = FerloadConfig(FerloadClientConfig.TOKEN, None, Some(TokenConfig("https://ferload.ferlab.bio/token", Some("Please copy / paste this url in your browser to get a new authentication token."))))
val expected = FerloadConfig(FerloadClientConfig.TOKEN, None, Some(TokenConfig("ferloadClientId","https://ferload.ferlab.bio/token", Some("Please copy / paste this url in your browser to get a new authentication token."))))
response.map(_.body.value shouldBe expected).unwrap
}

0 comments on commit 5dc03c6

Please sign in to comment.