Browse Source

add exporter client if not present

Abhishek Kondur 2 years ago
parent
commit
8235ae2e6b
1 changed files with 12 additions and 1 deletions
  1. 12 1
      mq/dynsec.go

+ 12 - 1
mq/dynsec.go

@@ -145,7 +145,7 @@ func Configure() error {
 			json.Unmarshal(data, &dynConfig)
 			json.Unmarshal(data, &dynConfig)
 		}
 		}
 	}
 	}
-
+	exporter := false
 	for i, cI := range dynConfig.Clients {
 	for i, cI := range dynConfig.Clients {
 		if cI.Username == mqAdminUserName || cI.Username == mqNetmakerServerUserName {
 		if cI.Username == mqAdminUserName || cI.Username == mqNetmakerServerUserName {
 			salt := logic.RandomString(12)
 			salt := logic.RandomString(12)
@@ -155,6 +155,7 @@ func Configure() error {
 			cI.Salt = base64.StdEncoding.EncodeToString([]byte(salt))
 			cI.Salt = base64.StdEncoding.EncodeToString([]byte(salt))
 			dynConfig.Clients[i] = cI
 			dynConfig.Clients[i] = cI
 		} else if servercfg.Is_EE && cI.Username == mqExporterUserName {
 		} else if servercfg.Is_EE && cI.Username == mqExporterUserName {
+			exporter = true
 			exporterPassword := servercfg.GetLicenseKey()
 			exporterPassword := servercfg.GetLicenseKey()
 			salt := logic.RandomString(12)
 			salt := logic.RandomString(12)
 			hashed := encodePasswordToPBKDF2(exporterPassword, salt, 101, 64)
 			hashed := encodePasswordToPBKDF2(exporterPassword, salt, 101, 64)
@@ -164,6 +165,16 @@ func Configure() error {
 			dynConfig.Clients[i] = cI
 			dynConfig.Clients[i] = cI
 		}
 		}
 	}
 	}
+	if servercfg.Is_EE && !exporter {
+		exporterPassword := servercfg.GetLicenseKey()
+		salt := logic.RandomString(12)
+		hashed := encodePasswordToPBKDF2(exporterPassword, salt, 101, 64)
+		exporterMQClient.Password = hashed
+		exporterMQClient.Iterations = 101
+		exporterMQClient.Salt = base64.StdEncoding.EncodeToString([]byte(salt))
+		dynConfig.Clients = append(dynConfig.Clients, exporterMQClient)
+		dynConfig.Roles = append(dynConfig.Roles, exporterMQRole)
+	}
 	data, err := json.MarshalIndent(dynConfig, "", " ")
 	data, err := json.MarshalIndent(dynConfig, "", " ")
 	if err != nil {
 	if err != nil {
 		return err
 		return err