Skip to content

Commit 7d2d968

Browse files
committed
push notifications
1 parent 9043c6e commit 7d2d968

File tree

11 files changed

+396
-6
lines changed

11 files changed

+396
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# go environment
22
.env
3+
*.json
34

45
# pem files
56
*.pem

api/v1/device/device.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/gin-gonic/gin"
1313
core "github.com/nettica-com/nettica-admin/core"
1414
model "github.com/nettica-com/nettica-admin/model"
15+
"github.com/nettica-com/nettica-admin/push"
1516
log "github.com/sirupsen/logrus"
1617
)
1718

@@ -234,6 +235,9 @@ func updateDevice(c *gin.Context) {
234235
}
235236

236237
core.FlushCache(id)
238+
if data.Push != "" {
239+
push.SendPushNotification(device.Push, "Device Updated", "Device "+device.Name+" has been updated")
240+
}
237241
c.JSON(http.StatusOK, client)
238242
}
239243

api/v1/net/net.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/gin-gonic/gin"
88
core "github.com/nettica-com/nettica-admin/core"
99
model "github.com/nettica-com/nettica-admin/model"
10+
"github.com/nettica-com/nettica-admin/push"
1011
"github.com/nettica-com/nettica-admin/util"
1112
log "github.com/sirupsen/logrus"
1213
)
@@ -341,6 +342,16 @@ func updateNet(c *gin.Context) {
341342

342343
// flush the cache for this vpn
343344
core.FlushCache(v.DeviceID)
345+
346+
// send push notification if appropriate
347+
if push.PushDevices[v.DeviceID] != "" {
348+
err := push.SendPushNotification(push.PushDevices[v.DeviceID], v.NetName+" updated", "The VPN configuration for "+v.NetName+" has been updated")
349+
if err != nil {
350+
log.WithFields(log.Fields{
351+
"err": err,
352+
}).Error("failed to send push notification")
353+
}
354+
}
344355
}
345356

346357
c.JSON(http.StatusOK, result)

api/v1/vpn/vpn.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/gin-gonic/gin"
99
core "github.com/nettica-com/nettica-admin/core"
1010
model "github.com/nettica-com/nettica-admin/model"
11+
"github.com/nettica-com/nettica-admin/push"
1112
log "github.com/sirupsen/logrus"
1213
"github.com/skip2/go-qrcode"
1314
)
@@ -102,6 +103,17 @@ func createVPN(c *gin.Context) {
102103
for _, v := range vpns {
103104
// flush the cache for this vpn
104105
core.FlushCache(v.DeviceID)
106+
107+
// send push notification if appropriate
108+
if push.PushDevices[v.DeviceID] != "" {
109+
err := push.SendPushNotification(push.PushDevices[v.DeviceID], v.NetName+" updated", "The VPN configuration for "+v.NetName+" has been updated")
110+
if err != nil {
111+
log.WithFields(log.Fields{
112+
"err": err,
113+
}).Error("failed to send push notification")
114+
}
115+
}
116+
105117
}
106118

107119
c.JSON(http.StatusOK, vpn)
@@ -299,6 +311,17 @@ func updateVPN(c *gin.Context) {
299311
for _, v := range vpns {
300312
// flush the cache for this vpn
301313
core.FlushCache(v.DeviceID)
314+
315+
// send push notification if appropriate
316+
if push.PushDevices[v.DeviceID] != "" {
317+
err := push.SendPushNotification(push.PushDevices[v.DeviceID], v.NetName+" updated", "The VPN configuration for "+v.NetName+" has been updated")
318+
if err != nil {
319+
log.WithFields(log.Fields{
320+
"err": err,
321+
}).Error("failed to send push notification")
322+
}
323+
}
324+
302325
}
303326

304327
c.JSON(http.StatusOK, result)
@@ -401,6 +424,17 @@ func deleteVPN(c *gin.Context) {
401424
// flush the cache for this vpn
402425

403426
core.FlushCache(v.DeviceID)
427+
428+
// send push notification if appropriate
429+
if push.PushDevices[v.DeviceID] != "" {
430+
err := push.SendPushNotification(push.PushDevices[v.DeviceID], v.NetName+" updated", "The VPN configuration for "+v.NetName+" has been updated")
431+
if err != nil {
432+
log.WithFields(log.Fields{
433+
"err": err,
434+
}).Error("failed to send push notification")
435+
}
436+
}
437+
404438
}
405439

406440
c.JSON(http.StatusOK, gin.H{})

cmd/nettica-api/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
auth "github.com/nettica-com/nettica-admin/auth"
1717
docs "github.com/nettica-com/nettica-admin/cmd/nettica-api/docs"
1818
"github.com/nettica-com/nettica-admin/mongo"
19+
"github.com/nettica-com/nettica-admin/push"
1920
util "github.com/nettica-com/nettica-admin/util"
2021
version "github.com/nettica-com/nettica-admin/version"
2122
"github.com/patrickmn/go-cache"
@@ -190,6 +191,12 @@ func main() {
190191
log.Error(err)
191192
}
192193

194+
// Initialize push notifications
195+
err = push.Initialize()
196+
if err != nil {
197+
log.Error(err)
198+
}
199+
193200
err = app.Run(fmt.Sprintf("%s:%s", os.Getenv("LISTEN_ADDR"), os.Getenv("PORT")))
194201
if err != nil {
195202
log.WithFields(log.Fields{

go.mod

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,53 @@ require (
2525
)
2626

2727
require (
28+
cel.dev/expr v0.16.1 // indirect
29+
cloud.google.com/go v0.115.1 // indirect
30+
cloud.google.com/go/auth v0.9.8 // indirect
31+
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
32+
cloud.google.com/go/compute/metadata v0.5.2 // indirect
33+
cloud.google.com/go/firestore v1.17.0 // indirect
34+
cloud.google.com/go/iam v1.2.1 // indirect
35+
cloud.google.com/go/longrunning v0.6.1 // indirect
36+
cloud.google.com/go/monitoring v1.21.1 // indirect
37+
cloud.google.com/go/storage v1.44.0 // indirect
38+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 // indirect
39+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
40+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
41+
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
42+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
43+
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
44+
github.com/envoyproxy/go-control-plane v0.13.0 // indirect
45+
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
46+
github.com/felixge/httpsnoop v1.0.4 // indirect
47+
github.com/go-logr/logr v1.4.2 // indirect
48+
github.com/go-logr/stdr v1.2.2 // indirect
49+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
50+
github.com/golang/protobuf v1.5.4 // indirect
51+
github.com/google/s2a-go v0.1.8 // indirect
52+
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
53+
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
54+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
55+
go.opencensus.io v0.24.0 // indirect
56+
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
57+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
58+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
59+
go.opentelemetry.io/otel v1.29.0 // indirect
60+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
61+
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
62+
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
63+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
64+
golang.org/x/time v0.7.0 // indirect
65+
google.golang.org/appengine v1.6.8 // indirect
66+
google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect
67+
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
68+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
69+
google.golang.org/grpc v1.67.1 // indirect
70+
google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
71+
)
72+
73+
require (
74+
firebase.google.com/go v3.13.0+incompatible
2875
github.com/KyleBanks/depth v1.2.1 // indirect
2976
github.com/bytedance/sonic v1.12.2 // indirect
3077
github.com/bytedance/sonic/loader v0.2.0 // indirect
@@ -64,13 +111,14 @@ require (
64111
github.com/xdg-go/stringprep v1.0.4 // indirect
65112
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
66113
golang.org/x/arch v0.10.0 // indirect
67-
golang.org/x/crypto v0.27.0 // indirect
68-
golang.org/x/net v0.29.0 // indirect
114+
golang.org/x/crypto v0.28.0 // indirect
115+
golang.org/x/net v0.30.0 // indirect
69116
golang.org/x/sync v0.8.0 // indirect
70-
golang.org/x/sys v0.25.0 // indirect
71-
golang.org/x/text v0.18.0 // indirect
117+
golang.org/x/sys v0.26.0 // indirect
118+
golang.org/x/text v0.19.0 // indirect
72119
golang.org/x/tools v0.25.0 // indirect
73-
google.golang.org/protobuf v1.34.2 // indirect
120+
google.golang.org/api v0.200.0
121+
google.golang.org/protobuf v1.35.1 // indirect
74122
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
75123
gopkg.in/yaml.v3 v3.0.1 // indirect
76124
)

0 commit comments

Comments
 (0)