Skip to content

Commit

Permalink
Address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jsaun committed Jan 28, 2025
1 parent 9f228c7 commit a209d3e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import org.broadinstitute.dsde.workbench.leonardo.app.AppInstall.getAzureDatabas
import org.broadinstitute.dsde.workbench.leonardo.{AppContext, WsmControlledDatabaseResource}
import org.broadinstitute.dsde.workbench.leonardo.app.Database.ControlledDatabase
import org.broadinstitute.dsde.workbench.leonardo.auth.SamAuthProvider
import org.broadinstitute.dsde.workbench.leonardo.config.{AzureEnvironmentConverter, CoaAppConfig}
import org.broadinstitute.dsde.workbench.leonardo.config.{
AzureEnvironmentConverter,
AzureHostingModeConfig,
CoaAppConfig
}
import org.broadinstitute.dsde.workbench.leonardo.dao._
import org.broadinstitute.dsde.workbench.leonardo.http._
import org.broadinstitute.dsde.workbench.leonardo.util.AppCreationException
Expand Down Expand Up @@ -71,7 +75,15 @@ class CromwellAppInstall[F[_]](config: CoaAppConfig,

// Get the pet userToken
tokenOpt <- samDao.getCachedArbitraryPetAccessToken(params.app.auditInfo.creator)
userToken <- F.pure(tokenOpt.getOrElse("")) // Empty token when running on Azure.
userToken <- ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${params.app.auditInfo.creator}", Some(ctx.traceId))
)
case true =>
F.pure("") // No pet user token in Azure.
}

values = List(
// azure resources configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ class CromwellRunnerAppInstall[F[_]](config: CromwellRunnerAppConfig,

// Get the pet userToken
tokenOpt <- samDao.getCachedArbitraryPetAccessToken(params.app.auditInfo.creator)
userToken <- F.pure(tokenOpt.getOrElse("")) // Empty token when running on Azure.
userToken <- ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${params.app.auditInfo.creator}", Some(ctx.traceId))
)
case true =>
F.pure("") // No pet user token in Azure.
}

values = List(
// azure resources configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ class WdsAppInstall[F[_]](config: WdsAppConfig,

// Get the pet userToken
tokenOpt <- samDao.getCachedArbitraryPetAccessToken(params.app.auditInfo.creator)
userToken <- F.pure(tokenOpt.getOrElse("")) // Empty token when running on Azure.
userToken <- ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${params.app.auditInfo.creator}", Some(ctx.traceId))
)
case true =>
F.pure("") // No pet user token in Azure.
}

valuesList =
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ class WorkflowsAppInstall[F[_]](config: WorkflowsAppConfig,

// Get the pet userToken
tokenOpt <- samDao.getCachedArbitraryPetAccessToken(params.app.auditInfo.creator)
userToken <- F.pure(tokenOpt.getOrElse("")) // Empty token when running on Azure.
userToken <- ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${params.app.auditInfo.creator}", Some(ctx.traceId))
)
case true =>
F.pure("") // No pet user token in Azure.
}

values =
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ final class LeoAppServiceInterp[F[_]: Parallel](config: AppServiceConfig,
// Retrieve parent workspaceId for the google project
parentWorkspaceId <- samService.lookupWorkspaceParentForGoogleProject(userInfo.accessToken.token, googleProject)

// Leo email used to give permissions when running in Azure.
leoToken <- authProvider.getLeoAuthToken
leoEmail <- samService.getUserEmail(leoToken)
notifySamAndCreate = for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,22 @@ class LeoMetricsMonitor[F[_]](config: LeoMetricsMonitorConfig,
appDAO.isProxyAvailable(project, app.appName, serviceName, ctx.traceId)
case CloudContext.Azure(_) =>
for {
tokenOpt <- samDAO.getCachedArbitraryPetAccessToken(app.auditInfo.creator)
token <- F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${app.auditInfo.creator}", Some(ctx.traceId))
)
token <- ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
for {
tokenOpt <- samDAO.getCachedArbitraryPetAccessToken(app.auditInfo.creator)
token <- F.fromOption(
tokenOpt,
AppCreationException(s"Pet not found for user ${app.auditInfo.creator}", Some(ctx.traceId))
)
} yield token
case true =>
for {
leoAuth <- samDAO.getLeoAuthToken
token = leoAuth.credentials.toString().split(" ")(1)
} yield token
}

authHeader = Authorization(Credentials.Token(AuthScheme.Bearer, token))
relayPath = Uri
.unsafeFromString(baseUri.asString) / s"${app.appName.value}-${app.workspaceId.map(_.value.toString).getOrElse("")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.broadinstitute.dsde.workbench.leonardo.monitor.LeoPubsubMessage.{
DeleteAppMessage,
DeleteAppV2Message
}
import org.broadinstitute.dsde.workbench.leonardo.util.AppCreationException
import org.broadinstitute.dsde.workbench.model.{TraceId, WorkbenchEmail}
import org.broadinstitute.dsde.workbench.openTelemetry.OpenTelemetryMetrics
import org.typelevel.log4cats.Logger
Expand Down Expand Up @@ -222,8 +223,7 @@ class MonitorAtBoot[F[_]](publisherQueue: Queue[F, LeoPubsubMessage],
appContext.traceId
)
)
leoAuth <- samDAO.getLeoAuthToken
token = leoAuth.credentials.toString().split(" ")(1)
token <- getAuthToken(app.auditInfo.creator)
workspaceDescOpt <- wsmClientProvider.getWorkspace(
token,
workspaceId
Expand Down Expand Up @@ -266,8 +266,7 @@ class MonitorAtBoot[F[_]](publisherQueue: Queue[F, LeoPubsubMessage],
appContext.traceId
)
)
leoAuth <- samDAO.getLeoAuthToken
token = leoAuth.credentials.toString().split(" ")(1)
token <- getAuthToken(app.auditInfo.creator)
workspaceDescOpt <- wsmClientProvider.getWorkspace(
token,
workspaceId
Expand Down Expand Up @@ -443,6 +442,26 @@ class MonitorAtBoot[F[_]](publisherQueue: Queue[F, LeoPubsubMessage],
)
case x => F.raiseError(MonitorAtBootException(s"Unexpected status for runtime ${runtime.id}: ${x}", traceId))
}

private def getAuthToken(creator: WorkbenchEmail)(implicit
ev: Ask[F, TraceId]
): F[String] =
ConfigReader.appConfig.azure.hostingModeConfig.enabled match {
case false =>
for {
traceId <- ev.ask
tokenOpt <- samDAO.getCachedArbitraryPetAccessToken(creator)
token <- F.fromOption(
tokenOpt,
MonitorAtBootException(s"Pet not found for user ${creator}", traceId)
)
} yield token
case true =>
for {
leoAuth <- samDAO.getLeoAuthToken
token = leoAuth.credentials.toString().split(" ")(1)
} yield token
}
}

final case class RuntimeToMonitor(
Expand Down

0 comments on commit a209d3e

Please sign in to comment.