Browse Source

add hostid and separate server name/broker name

Matthew R. Kasun 2 years ago
parent
commit
b3f90f2929
6 changed files with 91 additions and 73 deletions
  1. 2 1
      compose/docker-compose.yml
  2. 5 4
      config/config.go
  3. 71 68
      controllers/node.go
  4. 1 0
      models/node.go
  5. 1 0
      models/structs.go
  6. 11 0
      servercfg/serverconf.go

+ 2 - 1
compose/docker-compose.yml

@@ -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"

+ 5 - 4
config/config.go

@@ -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
 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"`

+ 71 - 68
controllers/node.go

@@ -41,13 +41,13 @@ func nodeHandlers(r *mux.Router) {
 //
 //
 // Authenticate to make further API calls related to a network.
 // Authenticate to make further API calls related to a network.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: successResponse
+//			Responses:
+//				200: successResponse
 func authenticate(response http.ResponseWriter, request *http.Request) {
 func authenticate(response http.ResponseWriter, request *http.Request) {
 
 
 	var authRequest models.AuthParams
 	var authRequest models.AuthParams
@@ -344,13 +344,13 @@ func authorize(nodesAllowed, networkCheck bool, authNetwork string, next http.Ha
 //
 //
 // Gets all nodes associated with network including pending nodes.
 // Gets all nodes associated with network including pending nodes.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeSliceResponse
+//			Responses:
+//				200: nodeSliceResponse
 func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
 func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
 
 
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
@@ -383,13 +383,14 @@ func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Get all nodes across all networks.
 // Get all nodes across all networks.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
+//
+//			Responses:
+//				200: nodeSliceResponse
 //
 //
-//		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
 // 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")
@@ -440,13 +441,13 @@ func getUsersNodes(user models.User) ([]models.Node, error) {
 //
 //
 // Get an individual node.
 // Get an individual node.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func getNode(w http.ResponseWriter, r *http.Request) {
 func getNode(w http.ResponseWriter, r *http.Request) {
 	// set header.
 	// set header.
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
@@ -497,13 +498,14 @@ func getNode(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Get the time that a network of nodes was last modified.
 // Get the time that a network of nodes was last modified.
 //
 //
-//		Schemes: https
+//			Schemes: https
+//
+//			Security:
+//	  		oauth
 //
 //
-// 		Security:
-//   		oauth
+//			Responses:
+//				200: nodeLastModifiedResponse
 //
 //
-//		Responses:
-//			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
@@ -529,13 +531,13 @@ func getLastModified(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Create a node on a network.
 // Create a node on a network.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeGetResponse
+//			Responses:
+//				200: nodeGetResponse
 func createNode(w http.ResponseWriter, r *http.Request) {
 func createNode(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
 
 
@@ -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{
@@ -725,13 +727,14 @@ func createNode(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Takes a node out of pending state.
 // Takes a node out of pending state.
 //
 //
-//		Schemes: https
+//			Schemes: https
+//
+//			Security:
+//	  		oauth
 //
 //
-// 		Security:
-//   		oauth
+//			Responses:
+//				200: nodeResponse
 //
 //
-//		Responses:
-//			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) {
@@ -758,13 +761,13 @@ func uncordonNode(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Create an egress gateway.
 // Create an egress gateway.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func createEgressGateway(w http.ResponseWriter, r *http.Request) {
 func createEgressGateway(w http.ResponseWriter, r *http.Request) {
 	var gateway models.EgressGatewayRequest
 	var gateway models.EgressGatewayRequest
 	var params = mux.Vars(r)
 	var params = mux.Vars(r)
@@ -797,13 +800,13 @@ func createEgressGateway(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Delete an egress gateway.
 // Delete an egress gateway.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func deleteEgressGateway(w http.ResponseWriter, r *http.Request) {
 func deleteEgressGateway(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
 	var params = mux.Vars(r)
 	var params = mux.Vars(r)
@@ -831,13 +834,13 @@ func deleteEgressGateway(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Create an ingress gateway.
 // Create an ingress gateway.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func createIngressGateway(w http.ResponseWriter, r *http.Request) {
 func createIngressGateway(w http.ResponseWriter, r *http.Request) {
 	var params = mux.Vars(r)
 	var params = mux.Vars(r)
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
@@ -875,13 +878,13 @@ func createIngressGateway(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Delete an ingress gateway.
 // Delete an ingress gateway.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func deleteIngressGateway(w http.ResponseWriter, r *http.Request) {
 func deleteIngressGateway(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
 	var params = mux.Vars(r)
 	var params = mux.Vars(r)
@@ -913,13 +916,13 @@ func deleteIngressGateway(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Update an individual node.
 // Update an individual node.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func updateNode(w http.ResponseWriter, r *http.Request) {
 func updateNode(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
 
 
@@ -1024,13 +1027,13 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
 //
 //
 // Delete an individual node.
 // Delete an individual node.
 //
 //
-//		Schemes: https
+//			Schemes: https
 //
 //
-// 		Security:
-//   		oauth
+//			Security:
+//	  		oauth
 //
 //
-//		Responses:
-//			200: nodeResponse
+//			Responses:
+//				200: nodeResponse
 func deleteNode(w http.ResponseWriter, r *http.Request) {
 func deleteNode(w http.ResponseWriter, r *http.Request) {
 	// Set header
 	// Set header
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")

+ 1 - 0
models/node.go

@@ -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"`

+ 1 - 0
models/structs.go

@@ -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"`
 }
 }
 
 

+ 11 - 0
servercfg/serverconf.go

@@ -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