Skip to content

Commit

Permalink
PROD-972 ID-1324 Swallow sync deduplication errors in endpoint. (#1477)
Browse files Browse the repository at this point in the history
* PROD-972 ID-1324 Swallow sync deduplication errors in endpoint.

* added test
  • Loading branch information
Ghost-in-a-Jar authored Jul 3, 2024
1 parent 4c5148c commit e630c18
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import org.broadinstitute.dsde.workbench.sam.api.{
SecurityDirectives,
ioMarshaller
}
import org.broadinstitute.dsde.workbench.sam.model.api.SamJsonSupport._
import org.broadinstitute.dsde.workbench.sam.model._
import org.broadinstitute.dsde.workbench.sam.model.api.SamJsonSupport._
import org.broadinstitute.dsde.workbench.sam.model.api.SamUser
import org.broadinstitute.dsde.workbench.sam.service.CloudExtensions
import org.broadinstitute.dsde.workbench.sam.util.SamRequestContext
Expand Down Expand Up @@ -245,9 +245,15 @@ trait GoogleExtensionRoutes extends ExtensionRoutes with SamUserDirectives with
postWithTelemetry(samRequestContext, params: _*) {
complete {
import SamGoogleModelJsonSupport._
googleGroupSynchronizer.synchronizeGroupMembers(policyId, samRequestContext = samRequestContext).map { syncReport =>
StatusCodes.OK -> syncReport
}
googleGroupSynchronizer
.synchronizeGroupMembers(policyId, samRequestContext = samRequestContext)
.recover {
// If the group sync was already done previously, then no need to return any sync report items, just return 200
case _: GroupAlreadySynchronized => Map.empty[WorkbenchEmail, Seq[SyncReportItem]]
}
.map { syncReport =>
StatusCodes.OK -> syncReport
}
}
} ~
getWithTelemetry(samRequestContext, params: _*) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ class MockDirectoryDAO(val groups: mutable.Map[WorkbenchGroupIdentity, Workbench

override def updateSynchronizedDateAndVersion(group: WorkbenchGroup, samRequestContext: SamRequestContext): IO[Unit] = {
groupSynchronizedDates += group.id -> new Date()
groups.get(group.id).foreach {
case g: BasicWorkbenchGroup => groups.put(g.id, g.copy(lastSynchronizedVersion = Option(g.lastSynchronizedVersion.getOrElse(0) + 1)))
case p: AccessPolicy => groups.put(p.id, p.copy(lastSynchronizedVersion = Option(p.lastSynchronizedVersion.getOrElse(0) + 1)))
case _ => ()
}
IO.unit
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,31 @@ class GoogleExtensionRoutesSpec extends GoogleExtensionRoutesSpecHelper with Sca
}
}

"GET /api/google/policy/{resourceTypeName}/{resourceId}/{accessPolicyName}/sync" should "200 with empty response when deduping sync requests" in {
val resourceTypes = Map(resourceType.name -> resourceType)
val (user, samDep, routes) = createTestUser(resourceTypes)

Post(s"/api/resource/${resourceType.name}/foo") ~> routes.route ~> check {
status shouldEqual StatusCodes.NoContent
assertResult("") {
responseAs[String]
}
}

import spray.json.DefaultJsonProtocol._
import SamGoogleModelJsonSupport._
Post(s"/api/google/resource/${resourceType.name}/foo/${resourceType.ownerRoleName.value}/sync") ~> routes.route ~> check {
status shouldEqual StatusCodes.OK
responseAs[Map[WorkbenchEmail, Seq[SyncReportItem]]] should not be empty
}

// A duplicate call should return OK and an empty response
Post(s"/api/google/resource/${resourceType.name}/foo/${resourceType.ownerRoleName.value}/sync") ~> routes.route ~> check {
status shouldEqual StatusCodes.OK
responseAs[Map[WorkbenchEmail, Seq[SyncReportItem]]] shouldBe empty
}
}

"GET /api/google/user/petServiceAccount/{project}/key" should "200 with a new key" in {
assume(databaseEnabled, databaseEnabledClue)

Expand Down

0 comments on commit e630c18

Please sign in to comment.