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 {
ConfigPath string
}
type clientConfig struct{
identifier string
endpoint string
username string
password string
type clientConfigs struct {
Client []interfaces.ClientConfig `toml:"client"`
}
type Core struct {
......@@ -98,12 +95,12 @@ func (c *Core)readClientConfig(configFileClient string) error {
if _,err := os.Stat(configFileClient); err != nil {
return err
}
clients := make([]clientConfig, 0)
clients := clientConfigs{}
if _,err := toml.DecodeFile(configFileClient, &clients); err != nil {
return err
}
for _,client := range clients {
c.clients[client.identifier] = ciena.NewMCPClient(client.endpoint, client.username, client.password, &c.database)
for _,client := range clients.Client {
c.clients[client.Identifier] = ciena.NewMCPClient(client.Endpoint, client.Username, client.Password, &c.database, &client)
}
return nil
}
\ No newline at end of file
package interfaces
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 (
"bytes"
"code.fbi.h-da.de/cocsn/gosdn/database"
"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"
apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client"
"crypto/tls"
......@@ -19,15 +20,15 @@ type MCPClient struct {
client *apiclient.ServiceTopologyTAPI
database *database.Database
buffer *bytes.Buffer
config *interfaces.ClientConfig
}
func (c MCPClient) GetConfig() string {
//TODO: Fill with life
return "..."
func (c MCPClient) GetConfig() interfaces.ClientConfig {
return *c.config
}
//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
transport := httptransport.New(endpoint, "/", nil)
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
......@@ -45,6 +46,7 @@ func NewMCPClient(endpoint, username, password string, database *database.Databa
client: client,
database: database,
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