-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcredentials_module.go
61 lines (51 loc) · 1.87 KB
/
credentials_module.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
package iotdevice
import (
"crypto/tls"
)
// ModuleSharedAccessKeyCredentials is a SharedAccessKeyCredentials struct adapted for module connections
type ModuleSharedAccessKeyCredentials struct {
SharedAccessKeyCredentials // embedded SharedAccessKeyCredentials struct
ModuleID string // moduleID
Gateway string // name of host gateway
GenerationID string // module generation ID
WorkloadURI string // IoT Edge workload API URI
EdgeGateway bool // connect via edgeHub
}
// GetModuleID returns ModuleID
func (c *ModuleSharedAccessKeyCredentials) GetModuleID() string {
return c.ModuleID
}
// GetGenerationID returns GenerationID
func (c *ModuleSharedAccessKeyCredentials) GetGenerationID() string {
return c.GenerationID
}
// GetGateway returns Gateway Host Name
func (c *ModuleSharedAccessKeyCredentials) GetGateway() string {
return c.Gateway
}
// UseEdgeGateway returns bool to connect via edgeHub or directly to IoT Hub
func (c *ModuleSharedAccessKeyCredentials) UseEdgeGateway() bool {
return c.EdgeGateway
}
// GetBroker returns gateway host name if UseEdgeGateway is true, else returns IoT Hub host name
func (c *ModuleSharedAccessKeyCredentials) GetBroker() string {
output := c.GetHostName()
gw := c.GetGateway()
usegw := c.UseEdgeGateway()
if usegw && len(gw) > 0 {
output = gw
}
return output
}
// GetCertificate returns nil. Only here to satisfy Credentials interface
func (c *ModuleSharedAccessKeyCredentials) GetCertificate() *tls.Certificate {
return nil
}
// GetSAK returns SharedAccessKey
func (c *ModuleSharedAccessKeyCredentials) GetSAK() string {
return c.SharedAccessKeyCredentials.SharedAccessKey.SharedAccessKey
}
// GetWorkloadURI returns the URI of the IoT Edge workload API
func (c *ModuleSharedAccessKeyCredentials) GetWorkloadURI() string {
return c.WorkloadURI
}