-
Notifications
You must be signed in to change notification settings - Fork 68
/
client.go
85 lines (71 loc) · 3.51 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
* Copyright 2019 Dell Inc.
*
* 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.
*******************************************************************************/
// notifications provides a client for integrating with the support-notifications service.
package notifications
import (
"context"
"github.com/edgexfoundry/go-mod-core-contracts/clients"
"github.com/edgexfoundry/go-mod-core-contracts/clients/interfaces"
)
type CategoryEnum string
const (
SECURITY CategoryEnum = "SECURITY"
HW_HEALTH CategoryEnum = "HW_HEALTH"
SW_HEALTH CategoryEnum = "SW_HEALTH"
)
type SeverityEnum string
const (
CRITICAL SeverityEnum = "CRITICAL"
NORMAL SeverityEnum = "NORMAL"
)
type StatusEnum string
const (
NEW StatusEnum = "NEW"
PROCESSED StatusEnum = "PROCESSED"
ESCALATED StatusEnum = "ESCALATED"
)
// NotificationsClient defines the interface for interactions with the EdgeX Foundry support-notifications service.
type NotificationsClient interface {
// SendNotification sends a notification.
SendNotification(ctx context.Context, n Notification) error
}
// Type struct for REST-specific implementation of the NotificationsClient interface
type notificationsRestClient struct {
urlClient interfaces.URLClient
}
// Notification defines the structure of data being sent.
type Notification struct {
Id string `json:"id,omitempty"` // Generated by the system, users can ignore
Slug string `json:"slug"` // A meaningful identifier provided by client
Sender string `json:"sender"` // Indicates the sender of a notification -- possibly a service name or email address
Category CategoryEnum `json:"category"` // Allows for categorization of notifications
Severity SeverityEnum `json:"severity"` // Denotes the severity of a notification
Content string `json:"content"` // Content contains the body of the notification
ContentType string `json:"contenttype,omitempty"` // ContentType contains the content type of the notification
Description string `json:"description,omitempty"` // Description content for the notification
Status StatusEnum `json:"status,omitempty"` // Status reflects a simple workflow assignment for the notification
Labels []string `json:"labels,omitempty"` // Labels allows the notification to be further described/classified
Created int `json:"created,omitempty"` // The creation timestamp
Modified int `json:"modified,omitempty"` // The last modification timestamp
}
// NewNotificationsClient creates an instance of NotificationsClient
func NewNotificationsClient(urlClient interfaces.URLClient) NotificationsClient {
return ¬ificationsRestClient{
urlClient: urlClient,
}
}
func (nc *notificationsRestClient) SendNotification(ctx context.Context, n Notification) error {
_, err := clients.PostJSONRequest(ctx, "", n, nc.urlClient)
return err
}