Skip to content
Snippets Groups Projects
Commit b5b22d1c authored by Jonah Husson's avatar Jonah Husson
Browse files

Add file headers & comments

parent 11d1849e
No related branches found
No related tags found
2 merge requests!30Add huawei provider code,!29Refactor providers to clean up code
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// ephemeral.go contains ephemeral ID handling logic
package notifications
import (
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// apns.go contains a notification provider implementation for APNS
package notificationProvider
import (
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// fcm.go contains a notification provider implementation for FCM
package notificationProvider
import (
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2021 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// huawei.go contains a notification provider implementation for Huawei Push notifications
package notificationProvider
import (
......@@ -125,6 +133,7 @@ type AlertDictionary struct {
LaunchImage string `json:"launch-image,omitempty"`
}
// Notify sends a huawei notification
func (h *Huawei) Notify(payload string, target storage.GTNResult) (bool, error) {
ctx := context.Background()
if h.token == "" || time.Now().After(h.expires) {
......@@ -175,6 +184,7 @@ func (h *Huawei) Notify(payload string, target storage.GTNResult) (bool, error)
return true, nil
}
// NewHuawei creates a Huawei provider from a set of HuaweiParams
func NewHuawei(config HuaweiParams) (*Huawei, error) {
transport := &http.Transport{
MaxIdleConns: 10,
......@@ -194,6 +204,8 @@ func NewHuawei(config HuaweiParams) (*Huawei, error) {
}, nil
}
// getAuthToken is a helper function used to get a huawei auth token
// it sets the parameters on the Huawei object which are used when setting bearer auth headers
func (h *Huawei) getAuthToken(ctx *context.Context) error {
// Create authentication request
body := fmt.Sprintf("grant_type=client_credentials&client_secret=%s&client_id=%s", h.appSecret, h.appID)
......@@ -227,12 +239,14 @@ func (h *Huawei) getAuthToken(ctx *context.Context) error {
return nil
}
// resetRequestAuthHeader is a helper to set huawei oauth tokens on an http request
func (h *Huawei) resetRequestAuthHeader(req *http.Request) {
req.Header = http.Header{}
req.Header.Set("Content-Type", "application/json;charset=utf-8")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", h.token))
}
// doNotifyRequest is a helper for sendign a notification request
func (h *Huawei) doNotifyRequest(req *http.Request) (*MessageResponse, error) {
resp, err := h.client.Do(req)
if err != nil {
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// huawei_test.go contains testing code for huawei notifications
package notificationProvider
//func TestHuawei_Notify(t *testing.T) {
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
// provider.go defines the Provider interface for notifications
package notificationProvider
import "gitlab.com/elixxir/notifications-bot/storage"
......
......@@ -352,6 +352,7 @@ func (nb *Impl) ReceivedNdf() *uint32 {
return nb.receivedNdf
}
// Cleaner is a long-running thread which periodically clears the round store of old data
func (nb *Impl) Cleaner() {
cleanF := func(key, val interface{}) bool {
t := val.(time.Time)
......@@ -371,6 +372,7 @@ func (nb *Impl) Cleaner() {
}
}
// Sender is a long-running thread which periodically batches & sends all notifications received from gateways
func (nb *Impl) Sender(sendFreq int) {
sendTicker := time.NewTicker(time.Duration(sendFreq) * time.Second)
for {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment