Repository navigation
Add Google Cloud Events Pubsub & Storage #658
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fd22f6b
clean history
Yummy-Yums fde92c6
Regenerate Github Actions
Yummy-Yums abbc704
fix fmt errors
Yummy-Yums 9ac2c2f
resolved header errors
Yummy-Yums 345f8c9
fixed sbt fmt check
Yummy-Yums c414ea3
resolved CI error
Yummy-Yums 9c511d0
fix mima issues
Yummy-Yums 8ba0a21
use tlVersionIntroduced Map
Yummy-Yums 27b4552
change publishTime from String to Instant; added codecs
Yummy-Yums d6fce5e
update test pattern for consistency
Yummy-Yums 03002c0
forgot to update messagepublished_data_suite
Yummy-Yums 3d93508
message.data type changed to ByteVector
Yummy-Yums 6820e59
update data to use bytevector
Yummy-Yums f0bb1e5
changed date-time format to Instant in storageobject
Yummy-Yums bab8793
fix CI
Yummy-Yums c4ba683
fix CI
Yummy-Yums File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
87 changes: 87 additions & 0 deletions
87
google-cloud/shared/src/main/scala/feral/google-cloud/events/MessagePublishedData.scala
This file contains hidden or 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,87 @@ | ||
| /* | ||
| * Copyright 2021 Typelevel | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package feral.googlecloud | ||
| package events | ||
|
|
||
| import io.circe._ | ||
|
|
||
| sealed abstract class MessagePublishedData { | ||
| def message: PubsubMessage | ||
| def subscription: String | ||
| def deliveryAttempt: Option[Int] | ||
| } | ||
|
|
||
| object MessagePublishedData { | ||
|
|
||
| def apply( | ||
| message: PubsubMessage, | ||
| subscription: String, | ||
| deliveryAttempt: Option[Int] = None | ||
| ): MessagePublishedData = { | ||
| new Impl(message, subscription, deliveryAttempt) | ||
| } | ||
|
|
||
| implicit val decoder: Decoder[MessagePublishedData] = | ||
| Decoder.forProduct3("message", "subscription", "deliveryAttempt")( | ||
| MessagePublishedData.apply | ||
| ) | ||
|
|
||
| private final case class Impl( | ||
| message: PubsubMessage, | ||
| subscription: String, | ||
| deliveryAttempt: Option[Int] | ||
| ) extends MessagePublishedData { | ||
| override def productPrefix = "MessagePublishedData" | ||
| } | ||
| } | ||
|
|
||
| sealed abstract class PubsubMessage { | ||
| def data: String | ||
| def attributes: Map[String, String] | ||
| def messageId: String | ||
| def publishTime: String | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's also protobuf generated. I'd use Instant just as @armanbilge suggested here |
||
| def orderingKey: Option[String] | ||
| } | ||
|
|
||
| object PubsubMessage { | ||
|
|
||
| def apply( | ||
| data: String, | ||
| attributes: Map[String, String], | ||
| messageId: String, | ||
| publishTime: String, | ||
| orderingKey: Option[String] | ||
| ): PubsubMessage = { | ||
| new Impl(data, attributes, messageId, publishTime, orderingKey) | ||
| } | ||
|
|
||
| implicit val decoder: Decoder[PubsubMessage] = Decoder.forProduct5( | ||
| "data", | ||
| "attributes", | ||
| "messageId", | ||
| "publishTime", | ||
| "orderingKey" | ||
| )(PubsubMessage.apply) | ||
|
|
||
| private final case class Impl( | ||
| data: String, | ||
| attributes: Map[String, String], | ||
| messageId: String, | ||
| publishTime: String, | ||
| orderingKey: Option[String] | ||
| ) extends PubsubMessage { override def productPrefix = "PubsubMessage" } | ||
| } | ||
180 changes: 180 additions & 0 deletions
180
google-cloud/shared/src/main/scala/feral/google-cloud/events/StorageObjectData.scala
This file contains hidden or 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,180 @@ | ||
| /* | ||
| * Copyright 2021 Typelevel | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package feral.googlecloud.events | ||
|
|
||
| import io.circe._ | ||
| import io.circe.generic.semiauto.deriveDecoder | ||
|
|
||
| sealed abstract class StorageObjectData { | ||
| def contentEncoding: String | ||
| def contentDisposition: String | ||
| def cacheControl: String | ||
| def contentLanguage: String | ||
| def metageneration: Int | ||
| def timeDeleted: String | ||
| def contentType: String | ||
| def size: Int | ||
| def timeCreated: String | ||
| def crc32c: String | ||
| def componentCount: Int | ||
| def md5Hash: String | ||
| def etag: String | ||
| def updated: String | ||
| def storageClass: String | ||
| def kmsKeyName: String | ||
| def timeStorageClassUpdated: String | ||
| def temporaryHold: Boolean | ||
| def retentionExpirationTime: String | ||
| def metadata: Map[String, String] | ||
| def eventBasedHold: Boolean | ||
| def name: String | ||
| def id: String | ||
| def bucket: String | ||
| def generation: Int | ||
| def customerEncryption: CustomerEncryption | ||
| def mediaLink: String | ||
| def selfLink: String | ||
| def kind: String | ||
| } | ||
|
|
||
| object StorageObjectData { | ||
|
|
||
| def apply( | ||
| contentEncoding: String, | ||
| contentDisposition: String, | ||
| cacheControl: String, | ||
| contentLanguage: String, | ||
| metageneration: Int, | ||
| timeDeleted: String, | ||
| contentType: String, | ||
| size: Int, | ||
| timeCreated: String, | ||
| crc32c: String, | ||
| componentCount: Int, | ||
| md5Hash: String, | ||
| etag: String, | ||
| updated: String, | ||
| storageClass: String, | ||
| kmsKeyName: String, | ||
| timeStorageClassUpdated: String, | ||
| temporaryHold: Boolean, | ||
| retentionExpirationTime: String, | ||
| metadata: Map[String, String], | ||
| eventBasedHold: Boolean, | ||
| name: String, | ||
| id: String, | ||
| bucket: String, | ||
| generation: Int, | ||
| customerEncryption: CustomerEncryption, | ||
| mediaLink: String, | ||
| selfLink: String, | ||
| kind: String | ||
| ): StorageObjectData = { | ||
| new Impl( | ||
| contentEncoding, | ||
| contentDisposition, | ||
| cacheControl, | ||
| contentLanguage, | ||
| metageneration, | ||
| timeDeleted, | ||
| contentType, | ||
| size, | ||
| timeCreated, | ||
| crc32c, | ||
| componentCount, | ||
| md5Hash, | ||
| etag, | ||
| updated, | ||
| storageClass, | ||
| kmsKeyName, | ||
| timeStorageClassUpdated, | ||
| temporaryHold, | ||
| retentionExpirationTime, | ||
| metadata, | ||
| eventBasedHold, | ||
| name, | ||
| id, | ||
| bucket, | ||
| generation, | ||
| customerEncryption, | ||
| mediaLink, | ||
| selfLink, | ||
| kind | ||
| ) | ||
| } | ||
|
|
||
| implicit val decoder: Decoder[StorageObjectData] = deriveDecoder[Impl].map(identity) | ||
|
|
||
| private final case class Impl( | ||
| contentEncoding: String, | ||
| contentDisposition: String, | ||
| cacheControl: String, | ||
| contentLanguage: String, | ||
| metageneration: Int, | ||
| timeDeleted: String, | ||
| contentType: String, | ||
| size: Int, | ||
| timeCreated: String, | ||
| crc32c: String, | ||
| componentCount: Int, | ||
| md5Hash: String, | ||
| etag: String, | ||
| updated: String, | ||
| storageClass: String, | ||
| kmsKeyName: String, | ||
| timeStorageClassUpdated: String, | ||
| temporaryHold: Boolean, | ||
| retentionExpirationTime: String, | ||
| metadata: Map[String, String], | ||
| eventBasedHold: Boolean, | ||
| name: String, | ||
| id: String, | ||
| bucket: String, | ||
| generation: Int, | ||
| customerEncryption: CustomerEncryption, | ||
| mediaLink: String, | ||
| selfLink: String, | ||
| kind: String | ||
| ) extends StorageObjectData { | ||
| override def productPrefix = "StorageObjectData" | ||
| } | ||
| } | ||
|
|
||
| sealed abstract class CustomerEncryption { | ||
| def encryptionAlgorithm: String | ||
| def keySha256: String | ||
| } | ||
|
|
||
| object CustomerEncryption { | ||
|
|
||
| def apply( | ||
| encryptionAlgorithm: String, | ||
| keySha256: String | ||
| ): CustomerEncryption = { | ||
| new Impl(encryptionAlgorithm, keySha256) | ||
| } | ||
|
|
||
| implicit val decoder: Decoder[CustomerEncryption] = | ||
| Decoder.forProduct2("encryptionAlgorithm", "keySha256")( | ||
| CustomerEncryption.apply | ||
| ) | ||
|
|
||
| private final case class Impl(encryptionAlgorithm: String, keySha256: String) | ||
| extends CustomerEncryption { | ||
| override def productPrefix = "CustomerEncryption" | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
google-cloud/shared/src/test/scala/feral/google-cloud/events/MessagePublishedDataSuite.scala
This file contains hidden or 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,52 @@ | ||
| /* | ||
| * Copyright 2021 Typelevel | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package feral.googlecloud.events | ||
|
|
||
| import io.circe.literal._ | ||
| import munit.FunSuite | ||
|
|
||
| class MessagePublishedDataSuite extends FunSuite { | ||
|
|
||
| import MessagePublishedDataSuite._ | ||
|
|
||
| test("decoder") { | ||
| val data = event.as[MessagePublishedData].toTry.get | ||
| assertEquals(data.subscription, "projects/my-project/subscriptions/my-subscription") | ||
| assertEquals(data.message.data, "dGVzdCBtZXNzYWdlIDM=") | ||
| assertEquals(data.message.attributes, Map("attr1" -> "attr1-value")) | ||
| assertEquals(data.message.messageId, "message-id") | ||
| assertEquals(data.message.publishTime, "2021-02-05T04:06:14.109Z") | ||
| } | ||
|
|
||
| } | ||
|
|
||
| object MessagePublishedDataSuite { | ||
|
|
||
| def event = json""" | ||
| { | ||
| "subscription": "projects/my-project/subscriptions/my-subscription", | ||
| "message": { | ||
| "attributes": { | ||
| "attr1":"attr1-value" | ||
| }, | ||
| "data": "dGVzdCBtZXNzYWdlIDM=", | ||
| "messageId": "message-id", | ||
| "publishTime":"2021-02-05T04:06:14.109Z" | ||
| } | ||
| } | ||
| """ | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.