Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop creating per project pets #1570

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
getWithTelemetry(samRequestContext, "userEmail" -> email, "googleProject" -> googleProject) {
complete {
import spray.json._
googleExtensions.getPetServiceAccountKey(email, googleProject, samRequestContext) map {
googleExtensions.getArbitraryPetServiceAccountKey(email, samRequestContext) map {
// parse json to ensure it is json and tells akka http the right content-type
case Some(key) => StatusCodes.OK -> key.parseJson
case None =>
Expand All @@ -91,7 +91,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
postWithTelemetry(samRequestContext, "userEmail" -> email) {
entity(as[Set[String]]) { scopes =>
complete {
googleExtensions.getPetServiceAccountToken(email, googleProject, scopes, samRequestContext).map {
googleExtensions.getArbitraryPetServiceAccountToken(email, scopes, samRequestContext).map {
case Some(token) => StatusCodes.OK -> JsString(token)
case None =>
throw new WorkbenchExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, "pet service account not found"))
Expand Down Expand Up @@ -144,7 +144,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
import spray.json._
// parse json to ensure it is json and tells akka http the right content-type
googleExtensions
.getPetServiceAccountKey(samUser, GoogleProject(project), samRequestContext)
.getArbitraryPetServiceAccountKey(samUser, samRequestContext)
.map { key =>
StatusCodes.OK -> key.parseJson
}
Expand Down Expand Up @@ -173,7 +173,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
entity(as[Set[String]]) { scopes =>
complete {
googleExtensions
.getPetServiceAccountToken(samUser, GoogleProject(project), scopes, samRequestContext)
.getArbitraryPetServiceAccountToken(samUser, scopes, samRequestContext)
.map { token =>
StatusCodes.OK -> JsString(token)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
) {
getWithTelemetry(samRequestContext, "googleProject" -> projectResourceId) {
complete {
googleExtensions.createUserPetServiceAccount(samUser, GoogleProject(project), samRequestContext).map { petSA =>
googleExtensions.getArbitraryPetServiceAccount(samUser, samRequestContext).map { petSA =>
StatusCodes.OK -> petSA.serviceAccount.email
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,15 @@ class GoogleExtensions(
}
}

def getArbitraryPetServiceAccount(user: SamUser, samRequestContext: SamRequestContext): IO[PetServiceAccount] = {
val googleProject: GoogleProject = GoogleExtensions.getShellGoogleProjectName(user, googleServicesConfig)

for {
_ <- createShellProject(googleProject, samRequestContext)
pet <- createUserPetServiceAccount(user, googleProject, samRequestContext)
} yield pet
}

private[google] def createShellProject(project: GoogleProject, samRequestContext: SamRequestContext): IO[Unit] =
distributedLock.withLock(LockDetails(s"${project.value}-createProject", "createProject", 30 seconds)).use { _ =>
IO.fromFuture(IO(for {
Expand Down
Loading