This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
/
registration.go
108 lines (91 loc) · 2.47 KB
/
registration.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Copyright (c) 2017 Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package export
import (
"github.com/edgexfoundry/core-domain-go/models"
"gopkg.in/mgo.v2/bson"
)
// Compression algorithm types
const (
CompNone = "NONE"
CompGzip = "GZIP"
CompZip = "ZIP"
)
// Data format types
const (
FormatJSON = "JSON"
FormatXML = "XML"
FormatSerialized = "SERIALIZED"
FormatIoTCoreJSON = "IOTCORE_JSON"
FormatAzureJSON = "AZURE_JSON"
FormatCSV = "CSV"
)
// Export destination types
const (
DestMQTT = "MQTT_TOPIC"
DestZMQ = "ZMQ_TOPIC"
DestIotCoreMQTT = "IOTCORE_TOPIC"
DestAzureMQTT = "AZURE_TOPIC"
DestRest = "REST_ENDPOINT"
)
// Registration - Defines the registration details
// on the part of north side export clients
type Registration struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"_id,omitempty"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
Origin int64 `json:"origin"`
Name string `json:"name,omitempty"`
Addressable models.Addressable `json:"addressable,omitempty"`
Format string `json:"format,omitempty"`
Filter Filter `json:"filter,omitempty"`
Encryption EncryptionDetails `json:"encryption,omitempty"`
Compression string `json:"compression,omitempty"`
Enable bool `json:"enable"`
Destination string `json:"destination,omitempty"`
}
const (
NotifyUpdateAdd = "add"
NotifyUpdateUpdate = "update"
NotifyUpdateDelete = "delete"
)
type NotifyUpdate struct {
Name string `json:"name"`
Operation string `json:"operation"`
}
func (reg *Registration) Validate() bool {
if reg.Compression == "" {
reg.Compression = CompNone
}
if reg.Compression != CompNone &&
reg.Compression != CompGzip &&
reg.Compression != CompZip {
return false
}
if reg.Format != FormatJSON &&
reg.Format != FormatXML &&
reg.Format != FormatSerialized &&
reg.Format != FormatIoTCoreJSON &&
reg.Format != FormatAzureJSON &&
reg.Format != FormatCSV {
return false
}
if reg.Destination != DestMQTT &&
reg.Destination != DestZMQ &&
reg.Destination != DestIotCoreMQTT &&
reg.Destination != DestAzureMQTT &&
reg.Destination != DestRest {
return false
}
if reg.Encryption.Algo == "" {
reg.Encryption.Algo = EncNone
}
if reg.Encryption.Algo != EncNone &&
reg.Encryption.Algo != EncAes {
return false
}
return true
}