Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
9e405098
Commit
9e405098
authored
5 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
MR comment fixes
parent
d7b425c5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/root.go
+8
-2
8 additions, 2 deletions
cmd/root.go
notifications/notifications.go
+7
-2
7 additions, 2 deletions
notifications/notifications.go
with
15 additions
and
4 deletions
cmd/root.go
+
8
−
2
View file @
9e405098
...
...
@@ -96,25 +96,31 @@ var rootCmd = &cobra.Command{
},
}
// setupConnection handles connecting to permissioning and polling for the NDF once connected
func
setupConnection
(
impl
*
notifications
.
Impl
,
permissioningCertPath
,
permissioningAddr
string
)
error
{
// Read in permissioning certificate
cert
,
err
:=
utils
.
ReadFile
(
permissioningCertPath
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Could not read permissioning cert
: %+v"
,
err
)
return
errors
.
Wrap
(
err
,
"Could not read permissioning cert
"
)
}
// Add host for permissioning server
_
,
err
=
impl
.
Comms
.
AddHost
(
id
.
PERMISSIONING
,
permissioningAddr
,
cert
,
true
,
true
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to Create permissioning host
: %+v"
,
err
)
return
errors
.
Wrap
(
err
,
"Failed to Create permissioning host
"
)
}
// Loop until an NDF is received
var
def
*
ndf
.
NetworkDefinition
for
def
==
nil
{
def
,
err
=
notifications
.
PollNdf
(
nil
,
impl
.
Comms
)
// Don't stop if error is expected
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
ndf
.
NO_NDF
)
{
return
errors
.
Wrap
(
err
,
"Failed to get NDF"
)
}
}
// Update NDF & gateway host
err
=
impl
.
UpdateNdf
(
def
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"Failed to update impl's NDF"
)
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications.go
+
7
−
2
View file @
9e405098
...
...
@@ -72,6 +72,7 @@ func (nb *Impl) RunNotificationLoop(loopDuration int, killChan chan struct{}, er
case
<-
time
.
After
(
time
.
Millisecond
*
time
.
Duration
(
loopDuration
))
:
}
// Poll for UIDs to notify
UIDs
,
err
:=
nb
.
pollFunc
(
nb
)
if
err
!=
nil
{
errChan
<-
errors
.
Wrap
(
err
,
"Failed to poll gateway for users to notify"
)
...
...
@@ -79,6 +80,7 @@ func (nb *Impl) RunNotificationLoop(loopDuration int, killChan chan struct{}, er
}
for
_
,
id
:=
range
UIDs
{
// Attempt to notify a given user (will not error if UID not registered)
_
,
err
:=
nb
.
notifyFunc
(
nb
.
fcm
,
id
,
fc
,
nb
.
Storage
)
if
err
!=
nil
{
errChan
<-
errors
.
Wrapf
(
err
,
"Failed to notify user with ID %+v"
,
id
)
...
...
@@ -120,13 +122,15 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
}
}
// set up stored functions
impl
.
pollFunc
=
pollForNotifications
impl
.
notifyFunc
=
notifyUser
// Start notification comms server
handler
:=
NewImplementation
(
impl
)
impl
.
Comms
=
notificationBot
.
StartNotificationBot
(
id
.
NOTIFICATION_BOT
,
params
.
PublicAddress
,
handler
,
cert
,
key
)
// Set up firebase messaging client
if
!
noFirebase
{
app
,
err
:=
firebase
.
SetupMessagingApp
(
params
.
FBCreds
)
if
err
!=
nil
{
...
...
@@ -159,6 +163,7 @@ func notifyUser(fcm *messaging.Client, uid string, fc *firebase.FirebaseComm, db
u
,
err
:=
db
.
GetUser
(
uid
)
if
err
!=
nil
{
jww
.
DEBUG
.
Printf
(
"No registration found for user with ID %+v"
,
uid
)
// This path is not an error. if no results are returned, the user hasn't registered for notifications
return
""
,
nil
}
...
...
@@ -210,7 +215,7 @@ func (nb *Impl) UnregisterForNotifications(auth *connect.Auth) error {
func
(
nb
*
Impl
)
UpdateNdf
(
ndf
*
ndf
.
NetworkDefinition
)
error
{
gw
:=
ndf
.
Gateways
[
len
(
ndf
.
Gateways
)
-
1
]
_
,
err
:=
nb
.
Comms
.
AddHost
(
"gw"
,
gw
.
Address
,
[]
byte
(
gw
.
TlsCertificate
),
fals
e
,
true
)
_
,
err
:=
nb
.
Comms
.
AddHost
(
"gw"
,
gw
.
Address
,
[]
byte
(
gw
.
TlsCertificate
),
tru
e
,
true
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"Failed to add gateway host from NDF"
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment