From b3f90f29291d98ae01d3cb6aae7da66ec10286c9 Mon Sep 17 00:00:00 2001 From: "Matthew R. Kasun" Date: Wed, 2 Nov 2022 11:22:40 -0400 Subject: [PATCH] add hostid and separate server name/broker name --- compose/docker-compose.yml | 3 +- config/config.go | 9 +-- controllers/node.go | 139 +++++++++++++++++++------------------ models/node.go | 1 + models/structs.go | 1 + servercfg/serverconf.go | 11 +++ 6 files changed, 91 insertions(+), 73 deletions(-) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 04c14749..d85dfa70 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -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" diff --git a/config/config.go b/config/config.go index 96ef050b..8ce069d5 100644 --- a/config/config.go +++ b/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 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"` diff --git a/controllers/node.go b/controllers/node.go index 95245f93..51a89bac 100644 --- a/controllers/node.go +++ b/controllers/node.go @@ -41,13 +41,13 @@ func nodeHandlers(r *mux.Router) { // // 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) { 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. // -// Schemes: https +// Schemes: https // -// Security: -// oauth +// Security: +// oauth // -// Responses: -// 200: nodeSliceResponse +// Responses: +// 200: nodeSliceResponse func getNetworkNodes(w http.ResponseWriter, r *http.Request) { 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. // -// 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 func getAllNodes(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") @@ -440,13 +441,13 @@ func getUsersNodes(user models.User) ([]models.Node, error) { // // 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) { // set header. 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. // -// Schemes: https +// Schemes: https // -// Security: -// oauth +// Security: +// oauth +// +// Responses: +// 200: nodeLastModifiedResponse // -// 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 @@ -529,13 +531,13 @@ func getLastModified(w http.ResponseWriter, r *http.Request) { // // 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) { w.Header().Set("Content-Type", "application/json") @@ -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{ @@ -725,13 +727,14 @@ func createNode(w http.ResponseWriter, r *http.Request) { // // 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 // TODO: May want to use cordon/uncordon terminology instead of "ispending". func uncordonNode(w http.ResponseWriter, r *http.Request) { @@ -758,13 +761,13 @@ func uncordonNode(w http.ResponseWriter, r *http.Request) { // // 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) { var gateway models.EgressGatewayRequest var params = mux.Vars(r) @@ -797,13 +800,13 @@ func createEgressGateway(w http.ResponseWriter, r *http.Request) { // // 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) { w.Header().Set("Content-Type", "application/json") var params = mux.Vars(r) @@ -831,13 +834,13 @@ func deleteEgressGateway(w http.ResponseWriter, r *http.Request) { // // 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) { var params = mux.Vars(r) w.Header().Set("Content-Type", "application/json") @@ -875,13 +878,13 @@ func createIngressGateway(w http.ResponseWriter, r *http.Request) { // // 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) { w.Header().Set("Content-Type", "application/json") var params = mux.Vars(r) @@ -913,13 +916,13 @@ func deleteIngressGateway(w http.ResponseWriter, r *http.Request) { // // 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) { w.Header().Set("Content-Type", "application/json") @@ -1024,13 +1027,13 @@ func updateNode(w http.ResponseWriter, r *http.Request) { // // 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) { // Set header w.Header().Set("Content-Type", "application/json") diff --git a/models/node.go b/models/node.go index c4641d35..895b2e47 100644 --- a/models/node.go +++ b/models/node.go @@ -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"` diff --git a/models/structs.go b/models/structs.go index a082d231..13e3efab 100644 --- a/models/structs.go +++ b/models/structs.go @@ -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"` } diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index 0006ce3c..15fcb3af 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -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