Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

implement rate limiting

Acho Arnold628be6c0aa47
diff --git a/android/app/src/main/java/com/httpsms/SmsManagerService.kt b/android/app/src/main/java/com/httpsms/SmsManagerService.kt
index 0cb366a6..3b5d1105 100644
--- a/android/app/src/main/java/com/httpsms/SmsManagerService.kt
+++ b/android/app/src/main/java/com/httpsms/SmsManagerService.kt
@@ -21,7 +21,7 @@ class SmsManagerService {
fun sendMessage(context: Context, message: Message, sentIntent:PendingIntent, deliveryIntent: PendingIntent) {
getSmsManager(context)
- .sendTextMessage(message.contact, message.owner, message.content, sentIntent, deliveryIntent)
+ .sendTextMessage(message.contact, null, message.content, sentIntent, deliveryIntent)
}
@Suppress("DEPRECATION")
diff --git a/api/go.mod b/api/go.mod
index 08faa6a4..4507ff5c 100644
--- a/api/go.mod
+++ b/api/go.mod
@@ -3,6 +3,7 @@ module github.com/NdoleStudio/http-sms-manager
go 1.18
require (
+ cloud.google.com/go/cloudtasks v1.4.0
firebase.google.com/go v3.13.0+incompatible
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.8.3
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
@@ -24,18 +25,20 @@ require (
go.opentelemetry.io/otel/exporters/jaeger v1.7.0
go.opentelemetry.io/otel/sdk v1.7.0
go.opentelemetry.io/otel/trace v1.7.0
- google.golang.org/api v0.74.0
+ google.golang.org/api v0.85.0
+ google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad
+ google.golang.org/protobuf v1.28.0
gorm.io/datatypes v1.0.6
gorm.io/driver/postgres v1.3.7
gorm.io/gorm v1.23.5
)
require (
- cloud.google.com/go v0.100.2 // indirect
- cloud.google.com/go/compute v1.5.0 // indirect
+ cloud.google.com/go v0.102.0 // indirect
+ cloud.google.com/go/compute v1.7.0 // indirect
cloud.google.com/go/firestore v1.6.1 // indirect
- cloud.google.com/go/iam v0.1.1 // indirect
- cloud.google.com/go/storage v1.21.0 // indirect
+ cloud.google.com/go/iam v0.3.0 // indirect
+ cloud.google.com/go/storage v1.22.1 // indirect
cloud.google.com/go/trace v1.2.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.32.3 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
@@ -51,8 +54,10 @@ require (
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
- github.com/google/go-cmp v0.5.7 // indirect
- github.com/googleapis/gax-go/v2 v2.2.0 // indirect
+ github.com/google/go-cmp v0.5.8 // indirect
+ github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
+ github.com/googleapis/gax-go/v2 v2.4.0 // indirect
+ github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
@@ -83,16 +88,14 @@ require (
go.uber.org/zap v1.13.0 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
- golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
- golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
- golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
+ golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
+ golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect
+ golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
- golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
+ golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
- google.golang.org/genproto v0.0.0-20220405205423-9d709892a2bf // indirect
- google.golang.org/grpc v1.45.0 // indirect
- google.golang.org/protobuf v1.28.0 // indirect
+ google.golang.org/grpc v1.47.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.3.2 // indirect
)
diff --git a/api/go.sum b/api/go.sum
index 5a0a45d7..7abf1cc4 100644
--- a/api/go.sum
+++ b/api/go.sum
@@ -27,26 +27,30 @@ cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+Y
cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW4=
cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc=
cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA=
-cloud.google.com/go v0.100.1/go.mod h1:fs4QogzfH5n2pBXBP9vRiU+eCny7lD2vmFZy79Iuw1U=
-cloud.google.com/go v0.100.2 h1:t9Iw5QH5v4XtlEQaCtUY7x6sCABps8sW0acw7e2WQ6Y=
cloud.google.com/go v0.100.2/go.mod h1:4Xra9TjzAeYHrl5+oeLlzbM2k3mjVhZh4UqTZ//w99A=
+cloud.google.com/go v0.102.0 h1:DAq3r8y4mDgyB/ZPJ9v/5VJNqjgJAxTn6ZYLlUywOu8=
+cloud.google.com/go v0.102.0/go.mod h1:oWcCzKlqJ5zgHQt9YsaeTY9KzIvjyy0ArmiBUgpQ+nc=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
+cloud.google.com/go/cloudtasks v1.4.0 h1:RzGENtCfmSLml/BQxsQ+EpVU5zlziYLIDK5TFQrABOY=
+cloud.google.com/go/cloudtasks v1.4.0/go.mod h1:QjLAjXFM/hykPzDLTwfzzkN943HVO/04GUjMTSzW3AA=
cloud.google.com/go/compute v0.1.0/go.mod h1:GAesmwr110a34z04OlxYkATPBEfVhkymfTBXtfbBFow=
-cloud.google.com/go/compute v1.2.0/go.mod h1:xlogom/6gr8RJGBe7nT2eGsQYAFUbbv8dbC29qE3Xmw=
cloud.google.com/go/compute v1.3.0/go.mod h1:cCZiE1NHEtai4wiufUhW8I8S1JKkAnhnQJWM7YD99wM=
-cloud.google.com/go/compute v1.5.0 h1:b1zWmYuuHz7gO9kDcM/EpHGr06UgsYNRpNJzI2kFiLM=
cloud.google.com/go/compute v1.5.0/go.mod h1:9SMHyhJlzhlkJqrPAc839t2BZFTSk6Jdj6mkzQJeu0M=
+cloud.google.com/go/compute v1.6.0/go.mod h1:T29tfhtVbq1wvAPo0E3+7vhgmkOYeXjhFvz/FMzPu0s=
+cloud.google.com/go/compute v1.6.1/go.mod h1:g85FgpzFvNULZ+S8AYq87axRKuf2Kh7deLqV/jJ3thU=
+cloud.google.com/go/compute v1.7.0 h1:v/k9Eueb8aAJ0vZuxKMrgm6kPhCLZU9HxFU+AFDs9Uk=
+cloud.google.com/go/compute v1.7.0/go.mod h1:435lt8av5oL9P3fv1OEzSbSUe+ybHXGMPQHHZWZxy9U=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
cloud.google.com/go/firestore v1.6.1 h1:8rBq3zRjnHx8UtBvaOWqBB1xq9jH6/wltfQLlTMh2Fw=
cloud.google.com/go/firestore v1.6.1/go.mod h1:asNXNOzBdyVQmEU+ggO8UPodTkEVFW5Qx+rwHnAz+EY=
-cloud.google.com/go/iam v0.1.1 h1:4CapQyNFjiksks1/x7jsvsygFPhihslYk5GptIrlX68=
-cloud.google.com/go/iam v0.1.1/go.mod h1:CKqrcnI/suGpybEHxZ7BMehL0oA4LpdyJdUlTl9jVMw=
+cloud.google.com/go/iam v0.3.0 h1:exkAomrVUuzx9kWFI1wm3KI0uoDeUFPB4kKGzx6x+Gc=
+cloud.google.com/go/iam v0.3.0/go.mod h1:XzJPvDayI+9zsASAFO68Hk07u3z+f+JrT2xXNdp4bnY=
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
@@ -56,8 +60,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
-cloud.google.com/go/storage v1.21.0 h1:HwnT2u2D309SFDHQII6m18HlrCi3jAXhUMTLOWXYH14=
-cloud.google.com/go/storage v1.21.0/go.mod h1:XmRlxkgPjlBONznT2dDUU/5XlpU2OjMnKuqnZI01LAA=
+cloud.google.com/go/storage v1.22.1 h1:F6IlQJZrZM++apn9V5/VfS3gbTUYg98PS3EMQAzqtfg=
+cloud.google.com/go/storage v1.22.1/go.mod h1:S8N1cAStu7BOeFfE8KAQzmyyLkK8p/vmRq6kuBTW58Y=
cloud.google.com/go/trace v1.2.0 h1:oIaB4KahkIUOpLSAAjEJ8y2desbjY/x/RfP4O3KAtTI=
cloud.google.com/go/trace v1.2.0/go.mod h1:Wc8y/uYyOhPy12KEnXG9XGrvfMz5F5SrYecQlbW1rwM=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
@@ -105,6 +109,7 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
+github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
@@ -130,6 +135,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
+github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
@@ -224,8 +230,9 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
+github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
+github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
@@ -252,12 +259,19 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
+github.com/googleapis/enterprise-certificate-proxy v0.1.0 h1:zO8WHNx/MYiAKJ3d5spxZXZE6KHmIQGQcAzwUzV7qQw=
+github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0=
github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM=
-github.com/googleapis/gax-go/v2 v2.2.0 h1:s7jOdKSaksJVOxE0Y/S32otcfiP+UQ0cL8/GTKaONwE=
github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/OthfcblKl4IGNaM=
+github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM=
+github.com/googleapis/gax-go/v2 v2.4.0 h1:dS9eYAjhrE2RjmzYw2XAPvcXfmcQLtFEQWn0CR82awk=
+github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
+github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA=
+github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/googleinterns/cloud-operations-api-mock v0.0.0-20200709193332-a1e58c29bdd3 h1:eHv/jVY/JNop1xg2J9cBb4EzyMpWZoNCP1BslSAIkOI=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
@@ -586,8 +600,11 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
-golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
-golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc=
+golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -606,8 +623,10 @@ golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
-golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
+golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
+golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb h1:8tDJ3aechhddbdPAxpycgXHJRMLpk/Ab+aa4OgdN5/g=
+golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -619,6 +638,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -680,14 +700,18 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
+golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -771,8 +795,11 @@ golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
+golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f h1:uF6paiQQebLeSXkrTqHqz0MXhXXS1KgF41eUdBNvxK0=
+golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
@@ -805,14 +832,16 @@ google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdr
google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU=
google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I=
google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo=
-google.golang.org/api v0.64.0/go.mod h1:931CdxA8Rm4t6zqTFGSsgwbAEZ2+GMYurbndwSimebM=
-google.golang.org/api v0.66.0/go.mod h1:I1dmXYpX7HGwz/ejRxwQp2qj5bFAz93HiCU1C1oYd9M=
google.golang.org/api v0.67.0/go.mod h1:ShHKP8E60yPsKNw/w8w+VYaj9H6buA5UqDp8dhbQZ6g=
-google.golang.org/api v0.69.0/go.mod h1:boanBiw+h5c3s+tBPgEzLDRHfFLWV0qXxRHz3ws7C80=
google.golang.org/api v0.70.0/go.mod h1:Bs4ZM2HGifEvXwd50TtW70ovgJffJYw2oRCOFU/SkfA=
google.golang.org/api v0.71.0/go.mod h1:4PyU6e6JogV1f9eA4voyrTY2batOLdgZ5qZ5HOCc4j8=
-google.golang.org/api v0.74.0 h1:ExR2D+5TYIrMphWgs5JCgwRhEDlPDXXrLwHHMgPHTXE=
google.golang.org/api v0.74.0/go.mod h1:ZpfMZOVRMywNyvJFeqL9HRWBgAuRfSjJFpe9QtRRyDs=
+google.golang.org/api v0.75.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69ljA=
+google.golang.org/api v0.78.0/go.mod h1:1Sg78yoMLOhlQTeF+ARBoytAcH1NNyyl390YMy6rKmw=
+google.golang.org/api v0.80.0/go.mod h1:xY3nI94gbvBrE0J6NHXhxOmW97HG7Khjkku6AFB3Hyg=
+google.golang.org/api v0.84.0/go.mod h1:NTsGnUFJMYROtiquksZHBWtHfeMC7iYthki7Eq3pa8o=
+google.golang.org/api v0.85.0 h1:8rJoHuRxx+vCmZtAO/3k1dRLvYNVyTJtZ5oaFZvhgvc=
+google.golang.org/api v0.85.0/go.mod h1:AqZf8Ep9uZ2pyTvgL+x0D3Zt0eoT9b5E8fmzfu6FO2g=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@@ -860,6 +889,7 @@ google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
+google.golang.org/genproto v0.0.0-20210329143202-679c6ae281ee/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
@@ -883,21 +913,25 @@ google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ6
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211221195035-429b39de9b1c/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
-google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
-google.golang.org/genproto v0.0.0-20220111164026-67b88f271998/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
-google.golang.org/genproto v0.0.0-20220114231437-d2e6a121cae0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
-google.golang.org/genproto v0.0.0-20220201184016-50beb8ab5c44/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220207164111-0872dc986b00/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
-google.golang.org/genproto v0.0.0-20220211171837-173942840c17/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
-google.golang.org/genproto v0.0.0-20220216160803-4663080d8bc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E=
-google.golang.org/genproto v0.0.0-20220405205423-9d709892a2bf h1:JTjwKJX9erVpsw17w+OIPP7iAgEkN/r8urhWSunEDTs=
-google.golang.org/genproto v0.0.0-20220405205423-9d709892a2bf/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220413183235-5e96e2839df9/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
+google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
+google.golang.org/genproto v0.0.0-20220518221133-4f43b3371335/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
+google.golang.org/genproto v0.0.0-20220523171625-347a074981d8/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
+google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA=
+google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA=
+google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad h1:kqrS+lhvaMHCxul6sKQvKJ8nAAhlVItmZV822hYFH/U=
+google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -925,8 +959,11 @@ google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnD
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
-google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
+google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
+google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
+google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
+google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
diff --git a/api/main.go b/api/main.go
index ccbca16e..26996d70 100644
--- a/api/main.go
+++ b/api/main.go
@@ -23,7 +23,7 @@ import (
//
// @securitydefinitions.apikey ApiKeyAuth
// @in header
-// @name X-API-Key
+// @name x-api-Key
func main() {
if len(os.Args) == 1 {
di.LoadEnv()
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index e603911a..59bee2af 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -7,6 +7,8 @@ import (
"strconv"
"time"
+ cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
+
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
@@ -75,6 +77,8 @@ func NewContainer(projectID string) (container *Container) {
container.RegisterPhoneRoutes()
+ container.RegisterEventRoutes()
+
container.RegisterNotificationListeners()
// this has to be last since it registers the /* route
@@ -188,6 +192,10 @@ func (container *Container) DB() (db *gorm.DB) {
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Phone{})))
}
+ if err = db.AutoMigrate(&entities.PhoneNotification{}); err != nil {
+ container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.PhoneNotification{})))
+ }
+
return container.db
}
@@ -213,6 +221,42 @@ func (container *Container) FirebaseAuthClient() (client *auth.Client) {
return authClient
}
+// CloudTasksClient creates a new instance of cloudtasks.Client
+func (container *Container) CloudTasksClient() (client *cloudtasks.Client) {
+ container.logger.Debug(fmt.Sprintf("creating %T", client))
+
+ client, err := cloudtasks.NewClient(context.Background(), option.WithCredentialsJSON(container.FirebaseCredentials()))
+ if err != nil {
+ container.logger.Fatal(stacktrace.Propagate(err, "cannot initialize cloud tasks client"))
+ }
+
+ return client
+}
+
+// EventsQueueConfiguration creates a new instance of services.PushQueueConfig
+func (container *Container) EventsQueueConfiguration() (config services.PushQueueConfig) {
+ container.logger.Debug(fmt.Sprintf("creating %T", config))
+
+ return services.PushQueueConfig{
+ UserAPIKey: os.Getenv("EVENTS_QUEUE_USER_API_KEY"),
+ Name: os.Getenv("EVENTS_QUEUE_NAME"),
+ UserID: entities.UserID(os.Getenv("EVENTS_QUEUE_USER_ID")),
+ ConsumerEndpoint: os.Getenv("EVENTS_QUEUE_ENDPOINT"),
+ }
+}
+
+// EventsQueue creates a new instance of services.PushQueue
+func (container *Container) EventsQueue() (queue services.PushQueue) {
+ container.logger.Debug("creating events services.PushQueue")
+
+ return services.NewGooglePushQueue(
+ container.Logger(),
+ container.Tracer(),
+ container.CloudTasksClient(),
+ container.EventsQueueConfiguration(),
+ )
+}
+
// FirebaseMessagingClient creates a new instance of messaging.Client
func (container *Container) FirebaseMessagingClient() (client *messaging.Client) {
container.logger.Debug(fmt.Sprintf("creating %T", client))
@@ -317,6 +361,8 @@ func (container *Container) EventDispatcher() (dispatcher *services.EventDispatc
container.Logger(),
container.Tracer(),
container.EventRepository(),
+ container.EventsQueue(),
+ container.EventsQueueConfiguration(),
)
container.eventDispatcher = dispatcher
@@ -343,6 +389,16 @@ func (container *Container) PhoneRepository() (repository repositories.PhoneRepo
)
}
+// PhoneNotificationRepository creates a new instance of repositories.PhoneNotificationRepository
+func (container *Container) PhoneNotificationRepository() (repository repositories.PhoneNotificationRepository) {
+ container.logger.Debug("creating GORM repositories.PhoneNotificationRepository")
+ return repositories.NewGormPhoneNotificationRepository(
+ container.Logger(),
+ container.Tracer(),
+ container.DB(),
+ )
+}
+
// MessageThreadRepository creates a new instance of repositories.MessageThreadRepository
func (container *Container) MessageThreadRepository() (repository repositories.MessageThreadRepository) {
container.logger.Debug("creating GORM repositories.MessageThreadRepository")
@@ -446,6 +502,18 @@ func (container *Container) PhoneHandler() (handler *handlers.PhoneHandler) {
)
}
+// EventsHandler creates a new instance of handlers.EventsHandler
+func (container *Container) EventsHandler() (handler *handlers.EventsHandler) {
+ container.logger.Debug(fmt.Sprintf("creating %T", handler))
+
+ return handlers.NewEventsHandler(
+ container.Logger(),
+ container.Tracer(),
+ container.EventsQueueConfiguration(),
+ container.EventDispatcher(),
+ )
+}
+
// RegisterMessageListeners registers event listeners for listeners.MessageListener
func (container *Container) RegisterMessageListeners() {
container.logger.Debug(fmt.Sprintf("registering listners for %T", listeners.MessageListener{}))
@@ -523,6 +591,8 @@ func (container *Container) NotificationService() (service *services.Notificatio
container.Tracer(),
container.FirebaseMessagingClient(),
container.PhoneRepository(),
+ container.PhoneNotificationRepository(),
+ container.EventDispatcher(),
)
}
@@ -556,6 +626,12 @@ func (container *Container) RegisterUserRoutes() {
container.UserHandler().RegisterRoutes(container.AuthRouter())
}
+// RegisterEventRoutes registers routes for the /events prefix
+func (container *Container) RegisterEventRoutes() {
+ container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.EventsHandler{}))
+ container.EventsHandler().RegisterRoutes(container.AuthRouter())
+}
+
// RegisterSwaggerRoutes registers routes for swagger
func (container *Container) RegisterSwaggerRoutes() {
container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.MessageHandler{}))
diff --git a/api/pkg/entities/Phone.go b/api/pkg/entities/Phone.go
deleted file mode 100644
index c5bbd68d..00000000
--- a/api/pkg/entities/Phone.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package entities
-
-import (
- "time"
-
- "github.com/google/uuid"
-)
-
-// Phone represents an android phone which has installed the http sms app
-type Phone struct {
- ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
- UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
- FcmToken *string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....."`
- PhoneNumber string `json:"phone_number" example:"+18005550199"`
- CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
- UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
-}
diff --git a/api/pkg/entities/phone.go b/api/pkg/entities/phone.go
new file mode 100644
index 00000000..a7712e88
--- /dev/null
+++ b/api/pkg/entities/phone.go
@@ -0,0 +1,18 @@
+package entities
+
+import (
+ "time"
+
+ "github.com/google/uuid"
+)
+
+// Phone represents an android phone which has installed the http sms app
+type Phone struct {
+ ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
+ UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
+ FcmToken *string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....."`
+ PhoneNumber string `json:"phone_number" example:"+18005550199"`
+ MessagesPerMinute uint `json:"messages_per_second" example:"1"`
+ CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
+ UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
+}
diff --git a/api/pkg/entities/phone_notification.go b/api/pkg/entities/phone_notification.go
new file mode 100644
index 00000000..8720579a
--- /dev/null
+++ b/api/pkg/entities/phone_notification.go
@@ -0,0 +1,31 @@
+package entities
+
+import (
+ "time"
+
+ "github.com/google/uuid"
+)
+
+const (
+ // PhoneNotificationStatusPending is the status when a notification is scheduled to be sent
+ PhoneNotificationStatusPending = "pending"
+ // PhoneNotificationStatusSent is the status when a notification has been sent
+ PhoneNotificationStatusSent = "sent"
+ // PhoneNotificationStatusFailed is the status when a notification could not be sent.
+ PhoneNotificationStatusFailed = "failed"
+)
+
+// PhoneNotificationStatus is the status of a phone notification
+type PhoneNotificationStatus string
+
+// PhoneNotification represents an FCM notification to a mobile phone
+type PhoneNotification struct {
+ ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;"`
+ MessageID uuid.UUID `json:"message_id"`
+ UserID UserID `json:"user_id"`
+ PhoneID uuid.UUID `json:"phone_id"`
+ Status string `json:"status"`
+ ScheduledAt time.Time `json:"scheduled_at"`
+ CreatedAt time.Time `json:"created_at"`
+ UpdatedAt time.Time `json:"updated_at"`
+}
diff --git a/api/pkg/events/message_notification_scheduled_event.go b/api/pkg/events/message_notification_scheduled_event.go
new file mode 100644
index 00000000..745da660
--- /dev/null
+++ b/api/pkg/events/message_notification_scheduled_event.go
@@ -0,0 +1,21 @@
+package events
+
+import (
+ "time"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/entities"
+
+ "github.com/google/uuid"
+)
+
+// EventTypeMessageNotificationScheduled is emitted when a new message notification is scheduled
+const EventTypeMessageNotificationScheduled = "message.notification.scheduled"
+
+// MessageNotificationScheduledPayload is the payload of the MessageNotificationScheduledPayload event
+type MessageNotificationScheduledPayload struct {
+ MessageID uuid.UUID `json:"id"`
+ UserID entities.UserID `json:"user_id"`
+ PhoneID uuid.UUID `json:"phone_id"`
+ ScheduledAt time.Time `json:"scheduled_at"`
+ NotificationID uuid.UUID `json:"notification_id"`
+}
diff --git a/api/pkg/handlers/events_handler.go b/api/pkg/handlers/events_handler.go
new file mode 100644
index 00000000..90a79971
--- /dev/null
+++ b/api/pkg/handlers/events_handler.go
@@ -0,0 +1,79 @@
+package handlers
+
+import (
+ "fmt"
+
+ cloudevents "github.com/cloudevents/sdk-go/v2"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/services"
+ "github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
+ "github.com/davecgh/go-spew/spew"
+ "github.com/gofiber/fiber/v2"
+ "github.com/palantir/stacktrace"
+)
+
+// EventsHandler handles heartbeat http requests.
+type EventsHandler struct {
+ handler
+ logger telemetry.Logger
+ tracer telemetry.Tracer
+ queueConfig services.PushQueueConfig
+ service *services.EventDispatcher
+}
+
+// NewEventsHandler creates a new EventsHandler
+func NewEventsHandler(
+ logger telemetry.Logger,
+ tracer telemetry.Tracer,
+ queueConfig services.PushQueueConfig,
+ service *services.EventDispatcher,
+) (h *EventsHandler) {
+ return &EventsHandler{
+ logger: logger.WithService(fmt.Sprintf("%T", h)),
+ tracer: tracer,
+ queueConfig: queueConfig,
+ service: service,
+ }
+}
+
+// RegisterRoutes registers the routes for the MessageHandler
+func (h *EventsHandler) RegisterRoutes(router fiber.Router) {
+ router.Post("/events", h.Dispatch)
+}
+
+// Dispatch a cloud event
+// This is an internal API so no documentation provided
+func (h *EventsHandler) Dispatch(c *fiber.Ctx) error {
+ ctx, span := h.tracer.StartFromFiberCtx(c)
+ defer span.End()
+
+ ctxLogger := h.tracer.CtxLogger(h.logger, span)
+
+ var request cloudevents.Event
+ if err := c.BodyParser(&request); err != nil {
+ msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
+ ctxLogger.Warn(stacktrace.Propagate(err, msg))
+ return h.responseBadRequest(c, err)
+ }
+
+ if err := request.Validate(); err != nil {
+ msg := fmt.Sprintf("validation errors [%s], while dispatching event [%+#v]", spew.Sdump(err.Error()), request)
+ ctxLogger.Warn(stacktrace.NewError(msg))
+ return h.responseUnprocessableEntity(c, map[string][]string{"event": {err.Error()}}, "validation errors while dispatching event")
+ }
+
+ if h.userIDFomContext(c) != h.queueConfig.UserID {
+ msg := fmt.Sprintf("user with ID [%s], cannot dispatch event [%+#v]", h.userIDFomContext(c), request)
+ ctxLogger.Error(stacktrace.NewError(msg))
+ return h.responseForbidden(c)
+ }
+
+ err := h.service.Dispatch(ctx, request)
+ if err != nil {
+ msg := fmt.Sprintf("cannot dispatch event with ID [%s]", request.ID())
+ ctxLogger.Error(stacktrace.Propagate(err, msg))
+ return h.responseInternalServerError(c)
+ }
+
+ return h.responseNoContent(c, "event dispatched successfully")
+}
diff --git a/api/pkg/handlers/heartbeat_handler.go b/api/pkg/handlers/heartbeat_handler.go
index 8bbc18f6..9dbafec3 100644
--- a/api/pkg/handlers/heartbeat_handler.go
+++ b/api/pkg/handlers/heartbeat_handler.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/NdoleStudio/http-sms-manager/pkg/requests"
-
"github.com/NdoleStudio/http-sms-manager/pkg/services"
"github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
"github.com/NdoleStudio/http-sms-manager/pkg/validators"
diff --git a/api/pkg/listeners/message_listener.go b/api/pkg/listeners/message_listener.go
index ea3a815f..824c831f 100644
--- a/api/pkg/listeners/message_listener.go
+++ b/api/pkg/listeners/message_listener.go
@@ -51,21 +51,8 @@ func (listener *MessageListener) OnMessageAPISent(ctx context.Context, event clo
ctx, span := listener.tracer.Start(ctx)
defer span.End()
- handled, err := listener.repository.Has(ctx, event.ID(), listener.signature(event))
- if err != nil {
- msg := fmt.Sprintf("cannot verify if event [%s] has been handled by [%T]", event.ID(), listener.signature(event))
- return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
- }
-
- ctxLogger := listener.tracer.CtxLogger(listener.logger, span)
-
- if handled {
- ctxLogger.Info(fmt.Sprintf("event [%s] has already been handled by [%s]", event.ID(), listener.signature(event)))
- return nil
- }
-
var payload events.MessageAPISentPayload
- if err = event.DataAs(&payload); err != nil {
+ if err := event.DataAs(&payload); err != nil {
msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload)
return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
@@ -78,12 +65,12 @@ func (listener *MessageListener) OnMessageAPISent(ctx context.Context, event clo
Timestamp: payload.RequestReceivedAt,
}
- if _, err = listener.service.StoreSentMessage(ctx, storeParams); err != nil {
+ if _, err := listener.service.StoreSentMessage(ctx, storeParams); err != nil {
msg := fmt.Sprintf("cannot store message with ID [%s] for event with ID [%s]", storeParams.ID, event.ID())
return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
- return listener.storeEventListenerLog(ctx, listener.signature(event), event)
+ return nil
}
// OnMessagePhoneSending handles the events.EventTypeMessagePhoneSending event
diff --git a/api/pkg/listeners/notification_listener.go b/api/pkg/listeners/notification_listener.go
index 18f5c404..322975a1 100644
--- a/api/pkg/listeners/notification_listener.go
+++ b/api/pkg/listeners/notification_listener.go
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
+ "github.com/davecgh/go-spew/spew"
+
"github.com/NdoleStudio/http-sms-manager/pkg/events"
"github.com/NdoleStudio/http-sms-manager/pkg/services"
"github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
@@ -31,11 +33,12 @@ func NewNotificationListener(
}
return l, map[string]events.EventListener{
- events.EventTypeMessageAPISent: l.onMessageAPISent,
+ events.EventTypeMessageAPISent: l.onMessageAPISent,
+ events.EventTypeMessageNotificationScheduled: l.onMessageNotificationScheduled,
}
}
-// onMessageAPISent handles the events.EventTypeHeartbeatPhoneOutstanding event
+// onMessageAPISent handles the events.EventTypeMessageAPISent event
func (listener *NotificationListener) onMessageAPISent(ctx context.Context, event cloudevents.Event) error {
ctx, span := listener.tracer.Start(ctx)
defer span.End()
@@ -46,14 +49,41 @@ func (listener *NotificationListener) onMessageAPISent(ctx context.Context, even
return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
- sentParams := &services.NotificationMessageSentParams{
+ sendParams := &services.NotificationScheduleParams{
UserID: payload.UserID,
Owner: payload.Owner,
+ Source: event.Source(),
MessageID: payload.ID,
}
- if err := listener.service.MessageSent(ctx, sentParams); err != nil {
- msg := fmt.Sprintf("cannot send notification with params [%+#v] for event with ID [%s]", sentParams, event.ID())
+ if err := listener.service.Schedule(ctx, sendParams); err != nil {
+ msg := fmt.Sprintf("cannot send notification with params [%s] for event with ID [%s]", spew.Sdump(sendParams), event.ID())
+ return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ return nil
+}
+
+// onMessageNotificationScheduled handles the events.EventTypeMessageNotificationScheduled event
+func (listener *NotificationListener) onMessageNotificationScheduled(ctx context.Context, event cloudevents.Event) error {
+ ctx, span := listener.tracer.Start(ctx)
+ defer span.End()
+
+ var payload events.MessageNotificationScheduledPayload
+ if err := event.DataAs(&payload); err != nil {
+ msg := fmt.Sprintf("cannot decode [%s] into [%T]", event.Data(), payload)
+ return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ scheduleParams := &services.NotificationSendParams{
+ UserID: payload.UserID,
+ PhoneID: payload.PhoneID,
+ PhoneNotificationID: payload.NotificationID,
+ MessageID: payload.MessageID,
+ }
+
+ if err := listener.service.Send(ctx, scheduleParams); err != nil {
+ msg := fmt.Sprintf("cannot schedule notification with params [%s] for event with ID [%s]", spew.Sdump(scheduleParams), event.ID())
return listener.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
diff --git a/api/pkg/middlewares/authenticated_middlesare.go b/api/pkg/middlewares/authenticated_middlesare.go
index bd3e1418..d4487270 100644
--- a/api/pkg/middlewares/authenticated_middlesare.go
+++ b/api/pkg/middlewares/authenticated_middlesare.go
@@ -8,7 +8,7 @@ import (
const (
authHeaderBearer = "Authorization"
- authHeaderAPIKey = "X-API-Key"
+ authHeaderAPIKey = "x-api-key"
bearerScheme = "Bearer"
)
@@ -27,7 +27,7 @@ func Authenticated(tracer telemetry.Tracer) fiber.Handler {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "You are not authorized to carry out this request.",
- "data": "Make sure your API key is set in the [X-API-Key] header in the request",
+ "data": "Make sure your API key is set in the [x-api-key] header in the request",
})
}
diff --git a/api/pkg/repositories/gorm_phone_notification_repository.go b/api/pkg/repositories/gorm_phone_notification_repository.go
new file mode 100644
index 00000000..86dad2d2
--- /dev/null
+++ b/api/pkg/repositories/gorm_phone_notification_repository.go
@@ -0,0 +1,104 @@
+package repositories
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "time"
+
+ "github.com/cockroachdb/cockroach-go/v2/crdb/crdbgorm"
+ "github.com/google/uuid"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/entities"
+ "github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
+ "github.com/palantir/stacktrace"
+ "gorm.io/gorm"
+)
+
+// gormPhoneNotificationRepository is responsible for persisting entities.PhoneNotification
+type gormPhoneNotificationRepository struct {
+ logger telemetry.Logger
+ tracer telemetry.Tracer
+ db *gorm.DB
+}
+
+// NewGormPhoneNotificationRepository creates the GORM version of the PhoneNotificationRepository
+func NewGormPhoneNotificationRepository(
+ logger telemetry.Logger,
+ tracer telemetry.Tracer,
+ db *gorm.DB,
+) PhoneNotificationRepository {
+ return &gormPhoneNotificationRepository{
+ logger: logger.WithService(fmt.Sprintf("%T", &gormHeartbeatRepository{})),
+ tracer: tracer,
+ db: db,
+ }
+}
+
+// UpdateStatus of an entities.PhoneNotification
+func (repository gormPhoneNotificationRepository) UpdateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) error {
+ ctx, span := repository.tracer.Start(ctx)
+ defer span.End()
+
+ err := repository.db.
+ WithContext(ctx).
+ Model(&entities.PhoneNotification{ID: notificationID}).
+ Update("status", status).
+ Error
+ if err != nil {
+ msg := fmt.Sprintf("cannot update notification [%s] with status [%s]", notificationID, status)
+ return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ return nil
+}
+
+// Schedule a notification to be sent in the future
+func (repository gormPhoneNotificationRepository) Schedule(ctx context.Context, messagesPerMinute uint, notification *entities.PhoneNotification) error {
+ ctx, span := repository.tracer.Start(ctx)
+ defer span.End()
+
+ if messagesPerMinute == 0 {
+ return repository.insert(ctx, notification)
+ }
+
+ err := crdbgorm.ExecuteTx(ctx, repository.db, nil, func(tx *gorm.DB) error {
+ var messagesCount int64
+ err := tx.WithContext(ctx).
+ Where("phone_id = ?", notification.PhoneID).
+ Where("status = ?", entities.PhoneNotificationStatusPending).
+ Count(&messagesCount).
+ Error
+ if err != nil {
+ msg := fmt.Sprintf("cannot count messages with phoneID [%s] and status [%s]", notification.PhoneID, entities.PhoneNotificationStatusPending)
+ return stacktrace.Propagate(err, msg)
+ }
+
+ timeout := int(math.Ceil(float64(messagesCount) / float64(messagesPerMinute))) // how many minutes to wait
+ notification.ScheduledAt = time.Now().UTC().Add(time.Minute * time.Duration(timeout))
+
+ if err = tx.WithContext(ctx).Create(notification).Error; err != nil {
+ msg := fmt.Sprintf("cannot create new notification with id [%s] and schedule [%s]", notification.ID, notification.ScheduledAt.String())
+ return stacktrace.Propagate(err, msg)
+ }
+ return nil
+ })
+ if err != nil {
+ msg := fmt.Sprintf("cannot schedule phone notification with ID [%s]", notification.ID)
+ return stacktrace.Propagate(err, msg)
+ }
+
+ return nil
+}
+
+func (repository *gormPhoneNotificationRepository) insert(ctx context.Context, notification *entities.PhoneNotification) error {
+ ctx, span := repository.tracer.Start(ctx)
+ defer span.End()
+
+ err := repository.db.WithContext(ctx).Create(notification).Error
+ if err != nil {
+ msg := fmt.Sprintf("cannot store notification with id [%s]", notification.ID)
+ return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+ return nil
+}
diff --git a/api/pkg/repositories/gorm_phone_repository.go b/api/pkg/repositories/gorm_phone_repository.go
index 3ec3e25c..f8870b76 100644
--- a/api/pkg/repositories/gorm_phone_repository.go
+++ b/api/pkg/repositories/gorm_phone_repository.go
@@ -33,6 +33,26 @@ func NewGormPhoneRepository(
}
}
+// LoadByID loads a phone by ID
+func (repository *gormPhoneRepository) LoadByID(ctx context.Context, phoneID uuid.UUID) (*entities.Phone, error) {
+ ctx, span := repository.tracer.Start(ctx)
+ defer span.End()
+
+ phone := new(entities.Phone)
+ err := repository.db.WithContext(ctx).First(phone, phoneID).Error
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ msg := fmt.Sprintf("phone with ID [%s] does not exist", phoneID)
+ return nil, repository.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, ErrCodeNotFound, msg))
+ }
+
+ if err != nil {
+ msg := fmt.Sprintf("cannot load phone with ID [%s]", phoneID)
+ return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ return phone, nil
+}
+
// Delete an entities.Phone
func (repository *gormPhoneRepository) Delete(ctx context.Context, userID entities.UserID, phoneID uuid.UUID) error {
ctx, span := repository.tracer.Start(ctx)
diff --git a/api/pkg/repositories/phone_notification_repository.go b/api/pkg/repositories/phone_notification_repository.go
new file mode 100644
index 00000000..488dba41
--- /dev/null
+++ b/api/pkg/repositories/phone_notification_repository.go
@@ -0,0 +1,18 @@
+package repositories
+
+import (
+ "context"
+
+ "github.com/google/uuid"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/entities"
+)
+
+// PhoneNotificationRepository loads and persists an entities.PhoneNotification
+type PhoneNotificationRepository interface {
+ // Schedule a new entities.PhoneNotification
+ Schedule(ctx context.Context, messagesPerMinute uint, notification *entities.PhoneNotification) error
+
+ // UpdateStatus of a notification
+ UpdateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) error
+}
diff --git a/api/pkg/repositories/phone_repository.go b/api/pkg/repositories/phone_repository.go
index 0cde42f0..cda04575 100644
--- a/api/pkg/repositories/phone_repository.go
+++ b/api/pkg/repositories/phone_repository.go
@@ -19,6 +19,9 @@ type PhoneRepository interface {
// Load a phone by user and phone number
Load(ctx context.Context, userID entities.UserID, phoneNumber string) (*entities.Phone, error)
+ // LoadByID a phone by ID
+ LoadByID(ctx context.Context, phoneID uuid.UUID) (*entities.Phone, error)
+
// Delete an entities.Phone
Delete(ctx context.Context, userID entities.UserID, phoneID uuid.UUID) error
}
diff --git a/api/pkg/services/event_dispatcher_service.go b/api/pkg/services/event_dispatcher_service.go
index dc8f2be6..640b65d7 100644
--- a/api/pkg/services/event_dispatcher_service.go
+++ b/api/pkg/services/event_dispatcher_service.go
@@ -2,8 +2,11 @@ package services
import (
"context"
+ "encoding/json"
"fmt"
+ "net/http"
"sync"
+ "time"
"github.com/NdoleStudio/http-sms-manager/pkg/events"
"github.com/NdoleStudio/http-sms-manager/pkg/repositories"
@@ -14,10 +17,12 @@ import (
// EventDispatcher dispatches a new event
type EventDispatcher struct {
- logger telemetry.Logger
- tracer telemetry.Tracer
- repository repositories.EventRepository
- listeners map[string][]events.EventListener
+ logger telemetry.Logger
+ tracer telemetry.Tracer
+ repository repositories.EventRepository
+ listeners map[string][]events.EventListener
+ queue PushQueue
+ queueConfig PushQueueConfig
}
// NewEventDispatcher creates a new EventDispatcher
@@ -25,12 +30,16 @@ func NewEventDispatcher(
logger telemetry.Logger,
tracer telemetry.Tracer,
repository repositories.EventRepository,
+ queue PushQueue,
+ queueConfig PushQueueConfig,
) (dispatcher *EventDispatcher) {
return &EventDispatcher{
- logger: logger,
- tracer: tracer,
- listeners: make(map[string][]events.EventListener),
- repository: repository,
+ logger: logger,
+ tracer: tracer,
+ listeners: make(map[string][]events.EventListener),
+ repository: repository,
+ queue: queue,
+ queueConfig: queueConfig,
}
}
@@ -48,6 +57,25 @@ func (dispatcher *EventDispatcher) Dispatch(ctx context.Context, event cloudeven
return nil
}
+// DispatchWithTimeout dispatches an event with a timeout
+func (dispatcher *EventDispatcher) DispatchWithTimeout(ctx context.Context, event cloudevents.Event, timeout time.Duration) error {
+ ctx, span := dispatcher.tracer.Start(ctx)
+ defer span.End()
+
+ task, err := dispatcher.createCloudTask(event)
+ if err != nil {
+ msg := fmt.Sprintf("cannot create cloud task for event [%s] with id [%s]", event.Type(), event.ID())
+ return dispatcher.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ if err = dispatcher.queue.Enqueue(ctx, task, timeout); err != nil {
+ msg := fmt.Sprintf("cannot enqueue event with ID [%s] and type [%s]", event.ID(), event.Type())
+ return dispatcher.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ return nil
+}
+
// Subscribe a listener to an event
func (dispatcher *EventDispatcher) Subscribe(eventType string, listener events.EventListener) {
if _, ok := dispatcher.listeners[eventType]; !ok {
@@ -84,3 +112,19 @@ func (dispatcher *EventDispatcher) Publish(ctx context.Context, event cloudevent
wg.Wait()
}
+
+func (dispatcher *EventDispatcher) createCloudTask(event cloudevents.Event) (*PushQueueTask, error) {
+ eventContent, err := json.Marshal(event)
+ if err != nil {
+ return nil, stacktrace.Propagate(err, fmt.Sprintf("cannot marshall [%T] with ID [%s]", event, event.ID()))
+ }
+
+ return &PushQueueTask{
+ Method: http.MethodPost,
+ URL: dispatcher.queueConfig.ConsumerEndpoint,
+ Body: eventContent,
+ Headers: map[string]string{
+ "x-api-key": dispatcher.queueConfig.UserAPIKey,
+ },
+ }, nil
+}
diff --git a/api/pkg/services/google_cloud_push_queue_service.go b/api/pkg/services/google_cloud_push_queue_service.go
new file mode 100644
index 00000000..a655048a
--- /dev/null
+++ b/api/pkg/services/google_cloud_push_queue_service.go
@@ -0,0 +1,98 @@
+package services
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "time"
+
+ cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
+ "github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
+ "github.com/palantir/stacktrace"
+ taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
+ "google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type googlePushQueue struct {
+ queueConfig PushQueueConfig
+ logger telemetry.Logger
+ tracer telemetry.Tracer
+ client *cloudtasks.Client
+}
+
+// NewGooglePushQueue creates a new googlePushQueue
+func NewGooglePushQueue(
+ logger telemetry.Logger,
+ tracer telemetry.Tracer,
+ client *cloudtasks.Client,
+ queueConfig PushQueueConfig,
+) PushQueue {
+ return &googlePushQueue{
+ client: client,
+ tracer: tracer,
+ logger: logger,
+ queueConfig: queueConfig,
+ }
+}
+
+// Enqueue a task to the queue
+func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask, timeout time.Duration) error {
+ ctx, span := queue.tracer.Start(ctx)
+ defer span.End()
+
+ ctxLogger := queue.tracer.CtxLogger(queue.logger, span)
+
+ headers := map[string]string{"Content-Type": "application/json"}
+ for key, value := range task.Headers {
+ headers[key] = value
+ }
+
+ // Build the Task payload.
+ // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#CreateTaskRequest
+ req := &taskspb.CreateTaskRequest{
+ Parent: queue.queueConfig.Name,
+ Task: &taskspb.Task{
+ // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#HttpRequest
+ MessageType: &taskspb.Task_HttpRequest{
+ HttpRequest: &taskspb.HttpRequest{
+ Headers: headers,
+ HttpMethod: queue.httpMethodToProtoHTTPMethod(task.Method),
+ Url: task.URL,
+ },
+ },
+ ScheduleTime: timestamppb.New(time.Now().UTC().Add(timeout)),
+ },
+ }
+
+ // Add a payload message if one is present.
+ req.Task.GetHttpRequest().Body = task.Body
+
+ queueTask, err := queue.client.CreateTask(ctx, req)
+ if err != nil {
+ msg := fmt.Sprintf("cannot schedule task %s to URL: %s", string(task.Body), task.URL)
+ return queue.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ ctxLogger.Info(fmt.Sprintf(
+ "item added to [%s] queue with id [%s] and schedule [%s]",
+ queue.queueConfig.Name,
+ queueTask.Name,
+ queueTask.ScheduleTime,
+ ))
+
+ return nil
+}
+
+func (queue *googlePushQueue) httpMethodToProtoHTTPMethod(httpMethod string) taskspb.HttpMethod {
+ method, ok := map[string]taskspb.HttpMethod{
+ http.MethodGet: taskspb.HttpMethod_GET,
+ http.MethodPost: taskspb.HttpMethod_POST,
+ http.MethodPut: taskspb.HttpMethod_PUT,
+ }[httpMethod]
+
+ if !ok {
+ return taskspb.HttpMethod_POST
+ }
+
+ return method
+}
diff --git a/api/pkg/services/notification_service.go b/api/pkg/services/notification_service.go
index 8813d4d5..74ecdf15 100644
--- a/api/pkg/services/notification_service.go
+++ b/api/pkg/services/notification_service.go
@@ -3,6 +3,10 @@ package services
import (
"context"
"fmt"
+ "time"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/events"
+ cloudevents "github.com/cloudevents/sdk-go/v2"
"firebase.google.com/go/messaging"
"github.com/NdoleStudio/http-sms-manager/pkg/entities"
@@ -14,10 +18,12 @@ import (
// NotificationService sends out notifications to mobile phones
type NotificationService struct {
- logger telemetry.Logger
- tracer telemetry.Tracer
- phoneRepository repositories.PhoneRepository
- messagingClient *messaging.Client
+ logger telemetry.Logger
+ tracer telemetry.Tracer
+ phoneNotificationRepository repositories.PhoneNotificationRepository
+ phoneRepository repositories.PhoneRepository
+ messagingClient *messaging.Client
+ eventDispatcher *EventDispatcher
}
// NewNotificationService creates a new NotificationService
@@ -26,36 +32,43 @@ func NewNotificationService(
tracer telemetry.Tracer,
messagingClient *messaging.Client,
phoneRepository repositories.PhoneRepository,
+ phoneNotificationRepository repositories.PhoneNotificationRepository,
+ dispatcher *EventDispatcher,
) (s *NotificationService) {
return &NotificationService{
- logger: logger.WithService(fmt.Sprintf("%T", s)),
- tracer: tracer,
- messagingClient: messagingClient,
- phoneRepository: phoneRepository,
+ logger: logger.WithService(fmt.Sprintf("%T", s)),
+ tracer: tracer,
+ messagingClient: messagingClient,
+ phoneNotificationRepository: phoneNotificationRepository,
+ phoneRepository: phoneRepository,
+ eventDispatcher: dispatcher,
}
}
-// NotificationMessageSentParams are parameters for sending a notification
-type NotificationMessageSentParams struct {
- UserID entities.UserID
- Owner string
- MessageID uuid.UUID
+// NotificationSendParams are parameters for sending a notification
+type NotificationSendParams struct {
+ UserID entities.UserID
+ PhoneID uuid.UUID
+ PhoneNotificationID uuid.UUID
+ MessageID uuid.UUID
}
-// MessageSent sends a message when a message is sent
-func (service *NotificationService) MessageSent(ctx context.Context, params *NotificationMessageSentParams) error {
+// Send sends a message when a message is sent
+func (service *NotificationService) Send(ctx context.Context, params *NotificationSendParams) error {
ctx, span := service.tracer.Start(ctx)
defer span.End()
ctxLogger := service.tracer.CtxLogger(service.logger, span)
- phone, err := service.phoneRepository.Load(ctx, params.UserID, params.Owner)
+ phone, err := service.phoneRepository.LoadByID(ctx, params.PhoneID)
if err != nil {
- msg := fmt.Sprintf("cannot load phone with userID [%s] and phone [%s]", params.UserID, params.Owner)
+ service.updateStatus(ctx, params.PhoneNotificationID, entities.PhoneNotificationStatusFailed)
+ msg := fmt.Sprintf("cannot load phone with userID [%s] and phoneID [%s]", params.UserID, params.PhoneID)
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
if phone.FcmToken == nil {
+ service.updateStatus(ctx, params.PhoneNotificationID, entities.PhoneNotificationStatusFailed)
msg := fmt.Sprintf("phone with id [%s] has no FCM token", phone.ID)
return service.tracer.WrapErrorSpan(span, stacktrace.NewError(msg))
}
@@ -67,10 +80,102 @@ func (service *NotificationService) MessageSent(ctx context.Context, params *Not
Token: *phone.FcmToken,
})
if err != nil {
+ service.updateStatus(ctx, params.PhoneNotificationID, entities.PhoneNotificationStatusFailed)
msg := fmt.Sprintf("cannot send notification for message [%s] to phone [%s]", params.MessageID, phone.ID)
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
ctxLogger.Info(fmt.Sprintf("sent notification [%s] for message [%s] to phone [%s]", result, params.MessageID, phone.ID))
+ service.updateStatus(ctx, params.PhoneNotificationID, entities.PhoneNotificationStatusSent)
return nil
}
+
+// NotificationScheduleParams are parameters for sending a notification
+type NotificationScheduleParams struct {
+ UserID entities.UserID
+ Owner string
+ Source string
+ MessageID uuid.UUID
+}
+
+// Schedule a notification to be sent to a phone
+func (service *NotificationService) Schedule(ctx context.Context, params *NotificationScheduleParams) error {
+ ctx, span := service.tracer.Start(ctx)
+ defer span.End()
+
+ ctxLogger := service.tracer.CtxLogger(service.logger, span)
+
+ phone, err := service.phoneRepository.Load(ctx, params.UserID, params.Owner)
+ if err != nil {
+ msg := fmt.Sprintf("cannot load phone with userID [%s] and phone [%s]", params.UserID, params.Owner)
+ return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ notification := &entities.PhoneNotification{
+ ID: uuid.New(),
+ MessageID: params.MessageID,
+ UserID: params.UserID,
+ PhoneID: phone.ID,
+ Status: entities.PhoneNotificationStatusPending,
+ ScheduledAt: time.Now().UTC(),
+ CreatedAt: time.Now().UTC(),
+ UpdatedAt: time.Now().UTC(),
+ }
+
+ if err = service.phoneNotificationRepository.Schedule(ctx, phone.MessagesPerMinute, notification); err != nil {
+ msg := fmt.Sprintf("cannot schedule notification for message [%s] to phone [%s]", params.MessageID, phone.ID)
+ return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ event, err := service.createEvent(params.Source, notification)
+ if err != nil {
+ return stacktrace.Propagate(err, fmt.Sprintf("cannot create cloud event for notification [%s]", notification.ID))
+ }
+
+ if err = service.eventDispatcher.DispatchWithTimeout(ctx, event, notification.ScheduledAt.Sub(time.Now())); err != nil {
+ return stacktrace.Propagate(err, fmt.Sprintf("cannot dispatch event [%s] for notification [%s]", event.Type(), notification.ID))
+ }
+
+ ctxLogger.Info(fmt.Sprintf("message with id [%s] notification scheduled for [%s] with id [%s]", params.MessageID, notification.ScheduledAt, notification.ID))
+ return nil
+}
+
+func (service *NotificationService) createEvent(source string, notification *entities.PhoneNotification) (cloudevents.Event, error) {
+ event := cloudevents.NewEvent()
+
+ event.SetSource(source)
+ event.SetType(events.EventTypeMessageNotificationScheduled)
+ event.SetTime(time.Now().UTC())
+ event.SetID(uuid.New().String())
+
+ payload := events.MessageNotificationScheduledPayload{
+ MessageID: notification.MessageID,
+ UserID: notification.UserID,
+ PhoneID: notification.PhoneID,
+ ScheduledAt: notification.ScheduledAt,
+ NotificationID: notification.ID,
+ }
+
+ if err := event.SetData(cloudevents.ApplicationJSON, payload); err != nil {
+ msg := fmt.Sprintf("cannot encode %T [%#+v] as JSON", payload, payload)
+ return event, stacktrace.Propagate(err, msg)
+ }
+
+ return event, nil
+}
+
+func (service *NotificationService) updateStatus(ctx context.Context, notificationID uuid.UUID, status entities.PhoneNotificationStatus) {
+ ctx, span := service.tracer.Start(ctx)
+ defer span.End()
+
+ ctxLogger := service.tracer.CtxLogger(service.logger, span)
+
+ err := service.phoneNotificationRepository.UpdateStatus(ctx, notificationID, status)
+ if err != nil {
+ msg := fmt.Sprintf("cannot update status of notificaiton with id [%s] to [%s]", notificationID, status)
+ ctxLogger.Error(stacktrace.Propagate(err, msg))
+ return
+ }
+
+ ctxLogger.Info(fmt.Sprintf("updated status of notificaiton with id [%s] to [%s]", notificationID, status))
+}
diff --git a/api/pkg/services/push_queue_service.go b/api/pkg/services/push_queue_service.go
new file mode 100644
index 00000000..433d3a49
--- /dev/null
+++ b/api/pkg/services/push_queue_service.go
@@ -0,0 +1,30 @@
+package services
+
+import (
+ "context"
+ "time"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/entities"
+)
+
+// PushQueueTask represents a push queue task
+type PushQueueTask struct {
+ Method string
+ URL string
+ Body []byte
+ Headers map[string]string
+}
+
+// PushQueueConfig configurations for the push queue
+type PushQueueConfig struct {
+ Name string
+ UserAPIKey string
+ UserID entities.UserID
+ ConsumerEndpoint string
+}
+
+// PushQueue is a push queue
+type PushQueue interface {
+ // Enqueue adds a message to the push queue
+ Enqueue(ctx context.Context, task *PushQueueTask, timeout time.Duration) error
+}
diff --git a/web/pages/settings/index.vue b/web/pages/settings/index.vue
index cc718f00..afa9c6c2 100644
--- a/web/pages/settings/index.vue
+++ b/web/pages/settings/index.vue
@@ -12,7 +12,7 @@
<v-col cols="12" md="9" offset-md="1" xl="8" offset-xl="2">
<h5 class="text-h4 mb-3 mt-3">API Key</h5>
<p>
- Use your API Key in the <code>X-API-Key</code> HTTP Header when
+ Use your API Key in the <code>x-api-key</code> HTTP Header when
sending requests to
<code>https://api.httpsms.com</code> endpoints.
</p>
diff --git a/web/pages/threads/_id.vue b/web/pages/threads/_id.vue
index b7ae05ea..d053ce99 100644
--- a/web/pages/threads/_id.vue
+++ b/web/pages/threads/_id.vue
@@ -130,7 +130,7 @@
mdi-check
</v-icon>
<v-icon
- v-if="message.status === 'failed'"
+ v-else-if="message.status === 'failed'"
color="error"
class="mt-n2"
>mdi-alert</v-icon