-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1691d1
commit d7f9d9b
Showing
7 changed files
with
51 additions
and
3 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
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,35 @@ | ||
package services | ||
|
||
import com.amazonaws.services.eventbridge.AmazonEventBridgeAsyncClient | ||
import com.amazonaws.services.eventbridge.model.{PutEventsRequest, PutEventsRequestEntry, PutEventsResult} | ||
import com.gu.facia.api.models.faciapress.PressType | ||
import conf.ApplicationConfiguration | ||
import play.api.libs.json.Json | ||
|
||
import java.util.Date | ||
import scala.concurrent.Future | ||
import scala.util.Try | ||
|
||
class EventBridge(config: ApplicationConfiguration) { | ||
val client = AmazonEventBridgeAsyncClient.asyncBuilder().build() | ||
|
||
def putEvent(path: String, pressType: PressType): Future[PutEventsResult] = { | ||
val requestEntry = new PutEventsRequestEntry() | ||
.withTime(new Date()) | ||
.withEventBusName(config.faciatool.eventBridgeBusName) // if we don't define this then we use the default event bus, can be referenced by name or arn | ||
.withSource("facia-tool") // could be used in the EventPattern to trigger only some Rules | ||
.withDetailType("front-path") // maybe superfluous? "used to decide what fields to expect in the event detail" | ||
.withDetail(EventBridgeDetail(path, pressType).toJsonString) | ||
|
||
val request = new PutEventsRequest() | ||
.withEntries(requestEntry) | ||
|
||
Future.fromTry(Try(client.putEvents(request))) | ||
} | ||
} | ||
|
||
case class EventBridgeDetail(`front-path`: String, pressType: PressType) { | ||
def toJsonString: String = { | ||
Json.toJson(this)(Json.writes[EventBridgeDetail]).toString | ||
} | ||
} |
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