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
- mosquitto_data:/etc/netmaker
environment:
SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN"
BROKER_NAME: "broker.NETMAKER_BASE_DOMAIN"
SERVER_NAME: "NETMAKER_BASE_DOMAIN"
SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
COREDNS_ADDR: "SERVER_PUBLIC_IP"

View File

@@ -1,7 +1,7 @@
//Environment file for getting variables
//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
//Reads from the config/environments/dev.yaml file by default
// Environment file for getting variables
// 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
// Reads from the config/environments/dev.yaml file by default
package config
import (
@@ -69,6 +69,7 @@ type ServerConfig struct {
MQPort string `yaml:"mqport"`
MQServerPort string `yaml:"mqserverport"`
Server string `yaml:"server"`
Broker string `yam:"broker"`
PublicIPService string `yaml:"publicipservice"`
MQAdminPassword string `yaml:"mqadminpassword"`
MetricsExporter string `yaml:"metrics_exporter"`

View File

@@ -390,6 +390,7 @@ func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
//
// Responses:
// 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
func getAllNodes(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@@ -504,6 +505,7 @@ func getNode(w http.ResponseWriter, r *http.Request) {
//
// Responses:
// 200: nodeLastModifiedResponse
//
// TODO: This needs to be refactored
// 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
@@ -670,12 +672,12 @@ func createNode(w http.ResponseWriter, r *http.Request) {
return
}
// Create client for this node in Mq
// Create client for this host in Mq
event := mq.MqDynsecPayload{
Commands: []mq.MqDynSecCmd{
{ // delete if any client exists already
Command: mq.DeleteClientCmd,
Username: node.ID,
Username: node.HostID,
},
{
Command: mq.CreateRoleCmd,
@@ -685,7 +687,7 @@ func createNode(w http.ResponseWriter, r *http.Request) {
},
{
Command: mq.CreateClientCmd,
Username: node.ID,
Username: node.HostID,
Password: nodePassword,
Textname: node.Name,
Roles: []mq.MqDynSecRole{
@@ -732,6 +734,7 @@ func createNode(w http.ResponseWriter, r *http.Request) {
//
// Responses:
// 200: nodeResponse
//
// Takes node out of pending state
// TODO: May want to use cordon/uncordon terminology instead of "ispending".
func uncordonNode(w http.ResponseWriter, r *http.Request) {

View File

@@ -48,6 +48,7 @@ type NodeCheckin struct {
// Node - struct for node model
type Node struct {
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"`
Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty"`

View File

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

View File

@@ -379,6 +379,17 @@ func GetServer() string {
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 {
var verbosity = 0
var err error