-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IA-4295] [IA-4327] Add Sam client to Leonardo, populate workspace ID (…
- Loading branch information
Showing
51 changed files
with
1,045 additions
and
491 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,10 @@ import org.scalatest.flatspec.AnyFlatSpecLike | |
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
class DiskRoutesTestJsonCodecSpec extends LeonardoTestSuite with Matchers with AnyFlatSpecLike { | ||
it should "decode DataprocConfig properly" in { | ||
it should "decode GetPersistentDiskResponse properly" in { | ||
val inputString = | ||
""" | ||
|{ | ||
|
@@ -41,7 +42,8 @@ class DiskRoutesTestJsonCodecSpec extends LeonardoTestSuite with Matchers with A | |
| "creator": "[email protected]", | ||
| "googleProject": "gpalloc-dev-master-tzprbkr", | ||
| "serviceAccount": "b305pet-114763077412354570085@gpalloc-dev-master-tzprbkr.iam.gserviceaccount.com" | ||
| } | ||
| }, | ||
| "workspaceId": "5955382f-c8be-464b-b5b9-2c9260cd2661" | ||
|} | ||
|""".stripMargin | ||
|
||
|
@@ -69,7 +71,8 @@ class DiskRoutesTestJsonCodecSpec extends LeonardoTestSuite with Matchers with A | |
"googleProject" -> "gpalloc-dev-master-tzprbkr", | ||
"serviceAccount" -> "b305pet-114763077412354570085@gpalloc-dev-master-tzprbkr.iam.gserviceaccount.com" | ||
), | ||
None | ||
None, | ||
Some(WorkspaceId(UUID.fromString("5955382f-c8be-464b-b5b9-2c9260cd2661"))) | ||
) | ||
res shouldBe (Right(expected)) | ||
} | ||
|
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
41 changes: 0 additions & 41 deletions
41
...la/org/broadinstitute/dsde/workbench/leonardo/auth/PetClusterServiceAccountProvider.scala
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
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
51 changes: 51 additions & 0 deletions
51
.../main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamApiClientProvider.scala
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,51 @@ | ||
package org.broadinstitute.dsde.workbench.leonardo.dao.sam | ||
|
||
import cats.effect.Async | ||
import cats.mtl.Ask | ||
import cats.syntax.all._ | ||
import okhttp3.Protocol | ||
import org.broadinstitute.dsde.workbench.client.sam.ApiClient | ||
import org.broadinstitute.dsde.workbench.client.sam.api.{AzureApi, GoogleApi, ResourcesApi} | ||
import org.broadinstitute.dsde.workbench.leonardo.AppContext | ||
|
||
import scala.concurrent.duration._ | ||
import scala.jdk.CollectionConverters._ | ||
import scala.jdk.DurationConverters._ | ||
|
||
/** | ||
* Provides access to various Sam clients: | ||
* - ResourcesApi is used for interacting with Sam resources and policies to enforce access control. | ||
* - GoogleApi is used for Google-specific extensions for users, such as pet service accounts and proxy groups. | ||
* - AzureApi is used for Azure-specific extensions for users, such as pet managed identities. | ||
*/ | ||
trait SamApiClientProvider[F[_]] { | ||
def resourcesApi(token: String)(implicit ev: Ask[F, AppContext]): F[ResourcesApi] | ||
def googleApi(token: String)(implicit ev: Ask[F, AppContext]): F[GoogleApi] | ||
def azureApi(token: String)(implicit ev: Ask[F, AppContext]): F[AzureApi] | ||
} | ||
|
||
class HttpSamApiClientProvider[F[_]](samUrl: String)(implicit F: Async[F]) extends SamApiClientProvider[F] { | ||
private val okHttpClient = new ApiClient().getHttpClient | ||
private val timeout = 30 seconds | ||
|
||
private def getApiClient(token: String)(implicit ev: Ask[F, AppContext]): F[ApiClient] = | ||
for { | ||
ctx <- ev.ask | ||
okHttpClientBuilder = okHttpClient.newBuilder | ||
.readTimeout(timeout.toJava) | ||
.protocols(Seq(Protocol.HTTP_1_1).asJava) | ||
// TODO add otel interceptors | ||
// See https://broadworkbench.atlassian.net/browse/IA-5052 | ||
apiClient = new ApiClient(okHttpClientBuilder.build()).setBasePath(samUrl) | ||
_ = apiClient.setAccessToken(token) | ||
} yield apiClient | ||
|
||
override def resourcesApi(token: String)(implicit ev: Ask[F, AppContext]): F[ResourcesApi] = | ||
getApiClient(token).map(api => new ResourcesApi(api)) | ||
|
||
override def googleApi(token: String)(implicit ev: Ask[F, AppContext]): F[GoogleApi] = | ||
getApiClient(token).map(api => new GoogleApi(api)) | ||
|
||
override def azureApi(token: String)(implicit ev: Ask[F, AppContext]): F[AzureApi] = | ||
getApiClient(token).map(api => new AzureApi(api)) | ||
} |
Oops, something went wrong.