From 55b4672ee43f3f3d0d7f51e62ee1332a35fbc87a Mon Sep 17 00:00:00 2001 From: Peter Neyens Date: Tue, 14 Jan 2020 18:56:42 +0000 Subject: [PATCH 1/2] Fix transit uris Don't uri encode key paths --- core/src/main/scala/com/banno/vault/transit/Transit.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/com/banno/vault/transit/Transit.scala b/core/src/main/scala/com/banno/vault/transit/Transit.scala index 100ce441..2e8c8913 100644 --- a/core/src/main/scala/com/banno/vault/transit/Transit.scala +++ b/core/src/main/scala/com/banno/vault/transit/Transit.scala @@ -94,9 +94,10 @@ final class TransitClient[F[_]](client: Client[F], vaultUri: Uri, token: String, /* The URIs we use here are those from the transit documentation. * the v1 prefix is specified in https://www.vaultproject.io/api/overview */ - private val encryptUri: Uri = vaultUri / "v1" / "transit" / "encrypt" / key.name - private val decryptUri: Uri = vaultUri / "v1" / "transit" / "decrypt" / key.name - private val readKeyUri: Uri = vaultUri / "v1" / "transit" / "keys" / key.name + + private val encryptUri: Uri = vaultUri.withPath(s"/v1/transit/encrypt/${key.name}") + private val decryptUri: Uri = vaultUri.withPath(s"/v1/transit/decrypt/${key.name}") + private val readKeyUri: Uri = vaultUri.withPath(s"/v1/transit/keys/${key.name}") private val tokenHeaders: Headers = Headers.of(Header("X-Vault-Token", token)) From 51421c4c8d5fb21f66bc3e0c05a105a390b9ed72 Mon Sep 17 00:00:00 2001 From: Peter Neyens Date: Tue, 14 Jan 2020 23:27:27 +0000 Subject: [PATCH 2/2] Drop leading slashes from Key in transit uris --- .../main/scala/com/banno/vault/transit/Transit.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/com/banno/vault/transit/Transit.scala b/core/src/main/scala/com/banno/vault/transit/Transit.scala index 2e8c8913..ec381ec0 100644 --- a/core/src/main/scala/com/banno/vault/transit/Transit.scala +++ b/core/src/main/scala/com/banno/vault/transit/Transit.scala @@ -16,7 +16,7 @@ package com.banno.vault.transit -import cats.syntax.all._ +import cats.implicits._ import cats.effect.Sync import org.http4s._ import org.http4s.Method.{GET, POST} @@ -95,9 +95,11 @@ final class TransitClient[F[_]](client: Client[F], vaultUri: Uri, token: String, * the v1 prefix is specified in https://www.vaultproject.io/api/overview */ - private val encryptUri: Uri = vaultUri.withPath(s"/v1/transit/encrypt/${key.name}") - private val decryptUri: Uri = vaultUri.withPath(s"/v1/transit/decrypt/${key.name}") - private val readKeyUri: Uri = vaultUri.withPath(s"/v1/transit/keys/${key.name}") + private val keyAsPath: String = key.name.dropWhile(_ === '/') + + private val encryptUri: Uri = vaultUri.withPath(s"/v1/transit/encrypt/${keyAsPath}") + private val decryptUri: Uri = vaultUri.withPath(s"/v1/transit/decrypt/${keyAsPath}") + private val readKeyUri: Uri = vaultUri.withPath(s"/v1/transit/keys/${keyAsPath}") private val tokenHeaders: Headers = Headers.of(Header("X-Vault-Token", token))