Repository: wso2/product-microgateway
Issue: Throttle eventpublisher password is not resolved from ENV vars

### Description:
<!-- Describe the issue -->
Throttle publisher password in the config is not resolve from env vars when configured that way.
### Steps to reproduce:
- enable throttling and configure publisher password similar to below.
- start enforcer and check the errors. it says invalid username password when connecting to TM
```toml
  [enforcer.throttling.publisher]
    # Credentials required to establish connection between Traffic Manager
    username = "admin"
    password = "$env{cp_admin_pwd}"
```
### Affected Product Version:
<!-- Members can use Affected/*** labels -->
4.0.0-m10-snapshot

### Environment details (with versions):
- OS: Mac
- Client:
- Env (Docker/K8s):


Changed files:
enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottleAgentConfigDto.java
enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/PublisherConfiguration.java
enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisher.java
enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisherPool.java
enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/ConfigHolder.java

diff --git a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/ConfigHolder.java b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/ConfigHolder.java
index 2872e7c65..2aba559ef 100644
--- a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/ConfigHolder.java
+++ b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/ConfigHolder.java
@@ -46,13 +46,13 @@ import org.wso2.micro.gateway.enforcer.config.dto.ExtendedTokenIssuerDto;
 import org.wso2.micro.gateway.enforcer.config.dto.JWTIssuerConfigurationDto;
 import org.wso2.micro.gateway.enforcer.config.dto.ThrottleAgentConfigDto;
 import org.wso2.micro.gateway.enforcer.config.dto.ThrottleConfigDto;
+import org.wso2.micro.gateway.enforcer.config.dto.ThrottlePublisherConfigDto;
 import org.wso2.micro.gateway.enforcer.constants.Constants;
 import org.wso2.micro.gateway.enforcer.discovery.ConfigDiscoveryClient;
 import org.wso2.micro.gateway.enforcer.exception.DiscoveryException;
 import org.wso2.micro.gateway.enforcer.exception.MGWException;
 import org.wso2.micro.gateway.enforcer.security.jwt.JWTUtil;
 import org.wso2.micro.gateway.enforcer.throttle.databridge.agent.conf.AgentConfiguration;
-import org.wso2.micro.gateway.enforcer.throttle.databridge.publisher.PublisherConfiguration;
 import org.wso2.micro.gateway.enforcer.util.TLSUtils;
 
 import java.io.IOException;
@@ -257,7 +257,7 @@ public class ConfigHolder {
         agentConf.setTrustStore(trustStore);
 
         PublisherPool pool = binary.getPool();
-        PublisherConfiguration pubConf = PublisherConfiguration.getInstance();
+        ThrottlePublisherConfigDto pubConf = new ThrottlePublisherConfigDto();
         pubConf.setUserName(binary.getUsername());
         pubConf.setPassword(binary.getPassword());
         pubConf.setInitIdleObjectDataPublishingAgents(pool.getInitIdleObjectDataPublishingAgents());
@@ -301,7 +301,7 @@ public class ConfigHolder {
      * such that to make them compatible with the binary agent.
      */
     private void processTMPublisherURLGroup(List<TMURLGroup> urlGroups,
-                                            PublisherConfiguration pubConfiguration) {
+                                            ThrottlePublisherConfigDto pubConfiguration) {
         StringBuilder restructuredReceiverURL = new StringBuilder();
         StringBuilder restructuredAuthURL = new StringBuilder();
 
diff --git a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottleAgentConfigDto.java b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottleAgentConfigDto.java
index 0b54b8244..2eb15770e 100644
--- a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottleAgentConfigDto.java
+++ b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottleAgentConfigDto.java
@@ -19,7 +19,6 @@
 package org.wso2.micro.gateway.enforcer.config.dto;
 
 import org.wso2.micro.gateway.enforcer.throttle.databridge.agent.conf.AgentConfiguration;
-import org.wso2.micro.gateway.enforcer.throttle.databridge.publisher.PublisherConfiguration;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -31,7 +30,7 @@ public class ThrottleAgentConfigDto {
     String username;
     String password;
     List<ThrottleURLGroupDto> urlGroup = new ArrayList<>();
-    PublisherConfiguration publisher;
+    ThrottlePublisherConfigDto publisher;
     AgentConfiguration agent;
 
     public String getUsername() {
@@ -58,11 +57,11 @@ public class ThrottleAgentConfigDto {
         this.urlGroup = urlGroup;
     }
 
-    public PublisherConfiguration getPublisher() {
+    public ThrottlePublisherConfigDto getPublisher() {
         return publisher;
     }
 
-    public void setPublisher(PublisherConfiguration publisher) {
+    public void setPublisher(ThrottlePublisherConfigDto publisher) {
         this.publisher = publisher;
     }
 
diff --git a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/PublisherConfiguration.java b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottlePublisherConfigDto.java
similarity index 89%
rename from enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/PublisherConfiguration.java
rename to enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottlePublisherConfigDto.java
index 6519173a1..793450fcb 100644
--- a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/PublisherConfiguration.java
+++ b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/config/dto/ThrottlePublisherConfigDto.java
@@ -16,18 +16,19 @@
  * under the License.
  */
 
-package org.wso2.micro.gateway.enforcer.throttle.databridge.publisher;
+package org.wso2.micro.gateway.enforcer.config.dto;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.wso2.micro.gateway.enforcer.throttle.databridge.publisher.DataPublisherConstants;
 
 import java.util.Map;
 
 /**
  * This class holds the configurations related to binary data publisher.
  */
-public class PublisherConfiguration {
-    private static final Logger log = LogManager.getLogger(PublisherConfiguration.class);
+public class ThrottlePublisherConfigDto {
+    private static final Logger log = LogManager.getLogger(ThrottlePublisherConfigDto.class);
 
     private int maxIdleDataPublishingAgents;
     private int initIdleObjectDataPublishingAgents;
@@ -40,11 +41,6 @@ public class PublisherConfiguration {
     private String userName;
     private char[] password;
 
-    private static PublisherConfiguration instance = new PublisherConfiguration();
-
-    private PublisherConfiguration() {
-    }
-
     public void setMaxIdleDataPublishingAgents(int maxIdleDataPublishingAgents) {
         this.maxIdleDataPublishingAgents = maxIdleDataPublishingAgents;
     }
@@ -117,14 +113,6 @@ public class PublisherConfiguration {
         return String.valueOf(password);
     }
 
-    public static PublisherConfiguration getInstance() {
-        return instance;
-    }
-
-    public static synchronized void setInstance(PublisherConfiguration publisherConfiguration) {
-        instance = publisherConfiguration;
-    }
-
     public void setConfiguration(Map<String, Object> publisherConfiguration) {
         this.receiverUrlGroup = String.valueOf(publisherConfiguration.get(DataPublisherConstants.RECEIVER_URL_GROUP));
         this.authUrlGroup = String.valueOf(publisherConfiguration.get(DataPublisherConstants.AUTH_URL_GROUP));
diff --git a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisher.java b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisher.java
index 13b7f15ef..c15e7a1a2 100644
--- a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisher.java
+++ b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisher.java
@@ -21,6 +21,8 @@ package org.wso2.micro.gateway.enforcer.throttle.databridge.publisher;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.wso2.carbon.databridge.commons.exception.TransportException;
+import org.wso2.micro.gateway.enforcer.config.ConfigHolder;
+import org.wso2.micro.gateway.enforcer.config.dto.ThrottlePublisherConfigDto;
 import org.wso2.micro.gateway.enforcer.throttle.databridge.agent.DataPublisher;
 import org.wso2.micro.gateway.enforcer.throttle.databridge.agent.exception.DataEndpointAuthenticationException;
 import org.wso2.micro.gateway.enforcer.throttle.databridge.agent.exception.DataEndpointConfigurationException;
@@ -57,19 +59,20 @@ public class ThrottleDataPublisher {
      */
     public ThrottleDataPublisher() {
         dataPublisherPool = ThrottleDataPublisherPool.getInstance();
-        PublisherConfiguration publisherConfiguration = PublisherConfiguration.getInstance();
+        ThrottlePublisherConfigDto throttlePublisherConfigDto = ConfigHolder.getInstance().getConfig().
+                getThrottleConfig().getThrottleAgent().getPublisher();
 
         try {
             executor = new DataPublisherThreadPoolExecutor(
-                    publisherConfiguration.getPublisherThreadPoolCoreSize(),
-                    publisherConfiguration.getPublisherThreadPoolMaximumSize(),
-                    publisherConfiguration.getPublisherThreadPoolKeepAliveTime(),
+                    throttlePublisherConfigDto.getPublisherThreadPoolCoreSize(),
+                    throttlePublisherConfigDto.getPublisherThreadPoolMaximumSize(),
+                    throttlePublisherConfigDto.getPublisherThreadPoolKeepAliveTime(),
                     TimeUnit.SECONDS,
                     new LinkedBlockingDeque<Runnable>() {
                     });
-            dataPublisher = new DataPublisher(publisherConfiguration.getReceiverUrlGroup(),
-                    publisherConfiguration.getAuthUrlGroup(), publisherConfiguration.getUserName(),
-                    publisherConfiguration.getPassword());
+            dataPublisher = new DataPublisher(throttlePublisherConfigDto.getReceiverUrlGroup(),
+                    throttlePublisherConfigDto.getAuthUrlGroup(), throttlePublisherConfigDto.getUserName(),
+                    throttlePublisherConfigDto.getPassword());
 
         } catch (DataEndpointException | DataEndpointConfigurationException | DataEndpointAuthenticationException
                 | TransportException e) {
diff --git a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisherPool.java b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisherPool.java
index a8257ac94..a60e2748e 100644
--- a/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisherPool.java
+++ b/enforcer/src/main/java/org/wso2/micro/gateway/enforcer/throttle/databridge/publisher/ThrottleDataPublisherPool.java
@@ -23,6 +23,8 @@ import org.apache.commons.pool.ObjectPool;
 import org.apache.commons.pool.impl.StackObjectPool;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.wso2.micro.gateway.enforcer.config.ConfigHolder;
+import org.wso2.micro.gateway.enforcer.config.dto.ThrottlePublisherConfigDto;
 
 /**
  * This class implemented to hold throttle data publishing agent pool. Reason for implement this is to
@@ -43,7 +45,8 @@ public class ThrottleDataPublisherPool {
         // active" instance created by the pool, but is quite useful for re-using Objects without introducing
         // artificial limits.
         //Proper tuning is mandatory for good performance according to system load.
-        PublisherConfiguration configuration = PublisherConfiguration.getInstance();
+        ThrottlePublisherConfigDto configuration = ConfigHolder.getInstance().getConfig().getThrottleConfig()
+                .getThrottleAgent().getPublisher();
         clientPool = new StackObjectPool(new BasePoolableObjectFactory() {
             @Override
             public Object makeObject() throws Exception {