add hostid and separate server name/broker name

This commit is contained in:
Matthew R. Kasun
2022-11-02 11:22:40 -04:00
parent 482246477c
commit b3f90f2929
6 changed files with 91 additions and 73 deletions

View File

@@ -19,7 +19,8 @@ services:
- sqldata:/root/data - sqldata:/root/data
- mosquitto_data:/etc/netmaker - mosquitto_data:/etc/netmaker
environment: environment:
SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN" BROKER_NAME: "broker.NETMAKER_BASE_DOMAIN"
SERVER_NAME: "NETMAKER_BASE_DOMAIN"
SERVER_HOST: "SERVER_PUBLIC_IP" SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443" SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
COREDNS_ADDR: "SERVER_PUBLIC_IP" COREDNS_ADDR: "SERVER_PUBLIC_IP"

View File

@@ -1,7 +1,7 @@
//Environment file for getting variables // Environment file for getting variables
//Currently the only thing it does is set the master password // Currently the only thing it does is set the master password
//Should probably have it take over functions from OS such as port and mongodb connection details // Should probably have it take over functions from OS such as port and mongodb connection details
//Reads from the config/environments/dev.yaml file by default // Reads from the config/environments/dev.yaml file by default
package config package config
import ( import (
@@ -69,6 +69,7 @@ type ServerConfig struct {
MQPort string `yaml:"mqport"` MQPort string `yaml:"mqport"`
MQServerPort string `yaml:"mqserverport"` MQServerPort string `yaml:"mqserverport"`
Server string `yaml:"server"` Server string `yaml:"server"`
Broker string `yam:"broker"`
PublicIPService string `yaml:"publicipservice"` PublicIPService string `yaml:"publicipservice"`
MQAdminPassword string `yaml:"mqadminpassword"` MQAdminPassword string `yaml:"mqadminpassword"`
MetricsExporter string `yaml:"metrics_exporter"` MetricsExporter string `yaml:"metrics_exporter"`

View File

@@ -390,6 +390,7 @@ func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
// //
// Responses: // Responses:
// 200: nodeSliceResponse // 200: nodeSliceResponse
//
// Not quite sure if this is necessary. Probably necessary based on front end but may want to review after iteration 1 if it's being used or not // Not quite sure if this is necessary. Probably necessary based on front end but may want to review after iteration 1 if it's being used or not
func getAllNodes(w http.ResponseWriter, r *http.Request) { func getAllNodes(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
@@ -504,6 +505,7 @@ func getNode(w http.ResponseWriter, r *http.Request) {
// //
// Responses: // Responses:
// 200: nodeLastModifiedResponse // 200: nodeLastModifiedResponse
//
// TODO: This needs to be refactored // TODO: This needs to be refactored
// Potential way to do this: On UpdateNode, set a new field for "LastModified" // Potential way to do this: On UpdateNode, set a new field for "LastModified"
// If we go with the existing way, we need to at least set network.NodesLastModified on UpdateNode // If we go with the existing way, we need to at least set network.NodesLastModified on UpdateNode
@@ -670,12 +672,12 @@ func createNode(w http.ResponseWriter, r *http.Request) {
return return
} }
// Create client for this node in Mq // Create client for this host in Mq
event := mq.MqDynsecPayload{ event := mq.MqDynsecPayload{
Commands: []mq.MqDynSecCmd{ Commands: []mq.MqDynSecCmd{
{ // delete if any client exists already { // delete if any client exists already
Command: mq.DeleteClientCmd, Command: mq.DeleteClientCmd,
Username: node.ID, Username: node.HostID,
}, },
{ {
Command: mq.CreateRoleCmd, Command: mq.CreateRoleCmd,
@@ -685,7 +687,7 @@ func createNode(w http.ResponseWriter, r *http.Request) {
}, },
{ {
Command: mq.CreateClientCmd, Command: mq.CreateClientCmd,
Username: node.ID, Username: node.HostID,
Password: nodePassword, Password: nodePassword,
Textname: node.Name, Textname: node.Name,
Roles: []mq.MqDynSecRole{ Roles: []mq.MqDynSecRole{
@@ -732,6 +734,7 @@ func createNode(w http.ResponseWriter, r *http.Request) {
// //
// Responses: // Responses:
// 200: nodeResponse // 200: nodeResponse
//
// Takes node out of pending state // Takes node out of pending state
// TODO: May want to use cordon/uncordon terminology instead of "ispending". // TODO: May want to use cordon/uncordon terminology instead of "ispending".
func uncordonNode(w http.ResponseWriter, r *http.Request) { func uncordonNode(w http.ResponseWriter, r *http.Request) {

View File

@@ -48,6 +48,7 @@ type NodeCheckin struct {
// Node - struct for node model // Node - struct for node model
type Node struct { type Node struct {
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" validate:"required,min=5,id_unique"` ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" validate:"required,min=5,id_unique"`
HostID string `json:"hostid,omitempty" bson:"id,omitempty" yaml:"id,omitempty" validate:"required,min=5,id_unique"`
Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"` Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"`
Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"` Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty"` LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty"`

View File

@@ -218,6 +218,7 @@ type ServerConfig struct {
Version string `yaml:"version"` Version string `yaml:"version"`
MQPort string `yaml:"mqport"` MQPort string `yaml:"mqport"`
Server string `yaml:"server"` Server string `yaml:"server"`
Broker string `yaml:"broker"`
Is_EE bool `yaml:"isee"` Is_EE bool `yaml:"isee"`
} }

View File

@@ -379,6 +379,17 @@ func GetServer() string {
return server return server
} }
// GetBroker - gets the broker name
func GetBroker() string {
server := ""
if os.Getenv("BROKER_NAME") != "" {
server = os.Getenv("BROKER_NAME")
} else if config.Config.Server.Broker != "" {
server = config.Config.Server.Broker
}
return server
}
func GetVerbosity() int32 { func GetVerbosity() int32 {
var verbosity = 0 var verbosity = 0
var err error var err error