Skip to content
Snippets Groups Projects
Commit 15ca3156 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

GetConfig filled with life

parent 36a8a272
No related branches found
No related tags found
2 merge requests!51Resolve "Read RESTCONF Client from config.toml",!18Develop
Pipeline #52512 passed with warnings
...@@ -18,11 +18,8 @@ type controllerConfig struct { ...@@ -18,11 +18,8 @@ type controllerConfig struct {
ConfigPath string ConfigPath string
} }
type clientConfig struct{ type clientConfigs struct {
identifier string Client []interfaces.ClientConfig `toml:"client"`
endpoint string
username string
password string
} }
type Core struct { type Core struct {
...@@ -98,12 +95,12 @@ func (c *Core)readClientConfig(configFileClient string) error { ...@@ -98,12 +95,12 @@ func (c *Core)readClientConfig(configFileClient string) error {
if _,err := os.Stat(configFileClient); err != nil { if _,err := os.Stat(configFileClient); err != nil {
return err return err
} }
clients := make([]clientConfig, 0) clients := clientConfigs{}
if _,err := toml.DecodeFile(configFileClient, &clients); err != nil { if _,err := toml.DecodeFile(configFileClient, &clients); err != nil {
return err return err
} }
for _,client := range clients { for _,client := range clients.Client {
c.clients[client.identifier] = ciena.NewMCPClient(client.endpoint, client.username, client.password, &c.database) c.clients[client.Identifier] = ciena.NewMCPClient(client.Endpoint, client.Username, client.Password, &c.database, &client)
} }
return nil return nil
} }
\ No newline at end of file
package interfaces package interfaces
type Client interface { type Client interface {
GetConfig() string GetConfig() ClientConfig
} }
package interfaces
type ClientConfig struct {
Identifier string `toml:"identifier"`
Endpoint string `toml:"endpoint"`
Username string `toml:"username"`
Password string `toml:"password"`
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"code.fbi.h-da.de/cocsn/gosdn/database" "code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/log" "code.fbi.h-da.de/cocsn/gosdn/log"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"code.fbi.h-da.de/cocsn/gosdn/restconf/util" "code.fbi.h-da.de/cocsn/gosdn/restconf/util"
apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client" apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client"
"crypto/tls" "crypto/tls"
...@@ -19,15 +20,15 @@ type MCPClient struct { ...@@ -19,15 +20,15 @@ type MCPClient struct {
client *apiclient.ServiceTopologyTAPI client *apiclient.ServiceTopologyTAPI
database *database.Database database *database.Database
buffer *bytes.Buffer buffer *bytes.Buffer
config *interfaces.ClientConfig
} }
func (c MCPClient) GetConfig() string { func (c MCPClient) GetConfig() interfaces.ClientConfig {
//TODO: Fill with life return *c.config
return "..."
} }
//NewMCPClient creates a client //NewMCPClient creates a client
func NewMCPClient(endpoint, username, password string, database *database.Database) *MCPClient { func NewMCPClient(endpoint, username, password string, database *database.Database, config *interfaces.ClientConfig) *MCPClient {
// create the transport // create the transport
transport := httptransport.New(endpoint, "/", nil) transport := httptransport.New(endpoint, "/", nil)
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
...@@ -45,6 +46,7 @@ func NewMCPClient(endpoint, username, password string, database *database.Databa ...@@ -45,6 +46,7 @@ func NewMCPClient(endpoint, username, password string, database *database.Databa
client: client, client: client,
database: database, database: database,
buffer: buffer, buffer: buffer,
config: config,
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment