mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
agent: Starting SCADA integration
This commit is contained in:
parent
ebfd35898b
commit
55597dc38f
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/hashicorp/go-checkpoint"
|
"github.com/hashicorp/go-checkpoint"
|
||||||
"github.com/hashicorp/go-syslog"
|
"github.com/hashicorp/go-syslog"
|
||||||
"github.com/hashicorp/logutils"
|
"github.com/hashicorp/logutils"
|
||||||
|
scada "github.com/hashicorp/scada-client"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ type Command struct {
|
|||||||
rpcServer *AgentRPC
|
rpcServer *AgentRPC
|
||||||
httpServers []*HTTPServer
|
httpServers []*HTTPServer
|
||||||
dnsServer *DNSServer
|
dnsServer *DNSServer
|
||||||
|
scadaProvider *scada.Provider
|
||||||
}
|
}
|
||||||
|
|
||||||
// readConfig is responsible for setup of our configuration using
|
// readConfig is responsible for setup of our configuration using
|
||||||
@ -382,6 +384,17 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, logWriter *log
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable the SCADA integration
|
||||||
|
if config.AtlasCluster != "" {
|
||||||
|
provider, err := NewProvider(config, logOutput)
|
||||||
|
if err != nil {
|
||||||
|
agent.Shutdown()
|
||||||
|
c.Ui.Error(fmt.Sprintf("Error starting SCADA connection: %s", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.scadaProvider = provider
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,10 +602,12 @@ func (c *Command) Run(args []string) int {
|
|||||||
if c.dnsServer != nil {
|
if c.dnsServer != nil {
|
||||||
defer c.dnsServer.Shutdown()
|
defer c.dnsServer.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, server := range c.httpServers {
|
for _, server := range c.httpServers {
|
||||||
defer server.Shutdown()
|
defer server.Shutdown()
|
||||||
}
|
}
|
||||||
|
if c.scadaProvider != nil {
|
||||||
|
defer c.scadaProvider.Shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
// Join startup nodes if specified
|
// Join startup nodes if specified
|
||||||
if err := c.startupJoin(config); err != nil {
|
if err := c.startupJoin(config); err != nil {
|
||||||
@ -631,6 +646,12 @@ func (c *Command) Run(args []string) int {
|
|||||||
gossipEncrypted = c.agent.client.Encrypted()
|
gossipEncrypted = c.agent.client.Encrypted()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the Atlas cluster
|
||||||
|
cluster := config.AtlasCluster
|
||||||
|
if cluster == "" {
|
||||||
|
cluster = "<disabled>"
|
||||||
|
}
|
||||||
|
|
||||||
// Let the agent know we've finished registration
|
// Let the agent know we've finished registration
|
||||||
c.agent.StartSync()
|
c.agent.StartSync()
|
||||||
|
|
||||||
@ -644,6 +665,7 @@ func (c *Command) Run(args []string) int {
|
|||||||
config.Ports.SerfLan, config.Ports.SerfWan))
|
config.Ports.SerfLan, config.Ports.SerfWan))
|
||||||
c.Ui.Info(fmt.Sprintf("Gossip encrypt: %v, RPC-TLS: %v, TLS-Incoming: %v",
|
c.Ui.Info(fmt.Sprintf("Gossip encrypt: %v, RPC-TLS: %v, TLS-Incoming: %v",
|
||||||
gossipEncrypted, config.VerifyOutgoing, config.VerifyIncoming))
|
gossipEncrypted, config.VerifyOutgoing, config.VerifyIncoming))
|
||||||
|
c.Ui.Info(fmt.Sprintf(" Atlas Cluster: %v", cluster))
|
||||||
|
|
||||||
// Enable log streaming
|
// Enable log streaming
|
||||||
c.Ui.Info("")
|
c.Ui.Info("")
|
||||||
|
66
command/agent/scada.go
Normal file
66
command/agent/scada.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/hashicorp/scada-client"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// providerService is the service name we use
|
||||||
|
providerService = "consul"
|
||||||
|
|
||||||
|
// resourceType is the type of resource we represent
|
||||||
|
// when connecting to SCADA
|
||||||
|
resourceType = "infrastructures"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProviderService returns the service information for the provider
|
||||||
|
func ProviderService(c *Config) *client.ProviderService {
|
||||||
|
return &client.ProviderService{
|
||||||
|
Service: providerService,
|
||||||
|
ServiceVersion: fmt.Sprintf("%s%s", c.Version, c.VersionPrerelease),
|
||||||
|
Capabilities: map[string]int{
|
||||||
|
"http": 1,
|
||||||
|
},
|
||||||
|
Meta: map[string]string{
|
||||||
|
"type": "",
|
||||||
|
"datacenter": "",
|
||||||
|
},
|
||||||
|
ResourceType: resourceType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderConfig returns the configuration for the SCADA provider
|
||||||
|
func ProviderConfig(c *Config) *client.ProviderConfig {
|
||||||
|
return &client.ProviderConfig{
|
||||||
|
Service: ProviderService(c),
|
||||||
|
Handlers: map[string]client.CapabilityProvider{
|
||||||
|
"http": nil,
|
||||||
|
},
|
||||||
|
ResourceGroup: c.AtlasCluster,
|
||||||
|
Token: c.AtlasToken,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProvider creates a new SCADA provider using the
|
||||||
|
// given configuration. Requests are routed to the
|
||||||
|
func NewProvider(c *Config, logOutput io.Writer) (*client.Provider, error) {
|
||||||
|
// Get the configuration of the provider
|
||||||
|
config := ProviderConfig(c)
|
||||||
|
config.Logger = log.New(logOutput, "", log.LstdFlags)
|
||||||
|
|
||||||
|
// TODO: REMOVE
|
||||||
|
config.TLSConfig = &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Setup the handlers
|
||||||
|
config.Handlers["http"] = nil
|
||||||
|
|
||||||
|
// Create the provider
|
||||||
|
return client.NewProvider(config)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user