diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java index 25c31e02f3..9fe74aaa98 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java @@ -284,9 +284,7 @@ public void execute() { //if all the operations are success, write new config to file if (isOverwriteRequired) { Config newConfig = new Config(); - Client client = new Client(); - client.setHttpRequestTimeout(1000000); - newConfig.setClient(client); + newConfig.setClient(config.getClient()); String encryptedCS = GatewayCmdUtils.encrypt(clientSecret, password); String encryptedTrustStorePass = GatewayCmdUtils.encrypt(trustStorePassword, password); @@ -298,7 +296,7 @@ public void execute() { .setTrustStorePassword(encryptedTrustStorePass) .build(); newConfig.setToken(token); - newConfig.setCorsConfiguration(GatewayCmdUtils.getDefaultCorsConfig()); + newConfig.setCorsConfiguration(config.getCorsConfiguration()); GatewayCmdUtils.saveConfig(newConfig, toolkitConfigPath); } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ResetCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ResetCmd.java index 5a95871e91..a129be9761 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ResetCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ResetCmd.java @@ -21,6 +21,9 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import org.apache.commons.lang3.StringUtils; +import org.wso2.apimgt.gateway.cli.config.TOMLConfigParser; +import org.wso2.apimgt.gateway.cli.exception.CLIInternalException; +import org.wso2.apimgt.gateway.cli.exception.ConfigParserException; import org.wso2.apimgt.gateway.cli.model.config.Client; import org.wso2.apimgt.gateway.cli.model.config.Config; import org.wso2.apimgt.gateway.cli.model.config.Token; @@ -58,19 +61,17 @@ public void execute() { Runtime.getRuntime().exit(1); } - //Write empty config to config - Config newConfig = new Config(); - Client client = new Client(); - client.setHttpRequestTimeout(1000000); - newConfig.setClient(client); - Token token = new TokenBuilder().setBaseURL(StringUtils.EMPTY).setRestVersion(StringUtils.EMPTY) - .setPublisherEndpoint(StringUtils.EMPTY).setAdminEndpoint(StringUtils.EMPTY) - .setRegistrationEndpoint(StringUtils.EMPTY).setTokenEndpoint(StringUtils.EMPTY) - .setUsername(StringUtils.EMPTY).setClientId(StringUtils.EMPTY).setClientSecret(StringUtils.EMPTY) - .setTrustStoreLocation(StringUtils.EMPTY).setTrustStorePassword(StringUtils.EMPTY).build(); - newConfig.setToken(token); - newConfig.setCorsConfiguration(GatewayCmdUtils.getDefaultCorsConfig()); - GatewayCmdUtils.saveConfig(newConfig, configPath); + //Reset only the token related configurations and keep the rest of the configuration. + try { + Config newConfig = TOMLConfigParser.parse(configPath, Config.class); + Token token = newConfig.getToken(); + token.setClientId(StringUtils.EMPTY); + token.setClientSecret(StringUtils.EMPTY); + token.setUsername(StringUtils.EMPTY); + GatewayCmdUtils.saveConfig(newConfig, configPath); + } catch (ConfigParserException e) { + throw new CLIInternalException("Error occurred while parsing the configuration : " + configPath, e); + } } @Override diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java index 574e1f299e..e13c69a159 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java @@ -823,7 +823,7 @@ public static void saveConfig(Config config, String configPath) { public static APICorsConfigurationDTO getDefaultCorsConfig() { APICorsConfigurationDTO corsConfigurationDTO = new APICorsConfigurationDTO(); - corsConfigurationDTO.setCorsConfigurationEnabled(true); + corsConfigurationDTO.setCorsConfigurationEnabled(false); corsConfigurationDTO.setAccessControlAllowOrigins(GatewayCliConstants.accessControlAllowOrigins); corsConfigurationDTO.setAccessControlAllowMethods(GatewayCliConstants.accessControlAllowMethods); corsConfigurationDTO.setAccessControlAllowHeaders(GatewayCliConstants.accessControlAllowHeaders); diff --git a/components/micro-gateway-cli/src/main/resources/cli-help/cli-help.help b/components/micro-gateway-cli/src/main/resources/cli-help/cli-help.help index 0b4dfac5de..0179be2978 100644 --- a/components/micro-gateway-cli/src/main/resources/cli-help/cli-help.help +++ b/components/micro-gateway-cli/src/main/resources/cli-help/cli-help.help @@ -20,7 +20,7 @@ COMMAND is one of the available commands listed below: 1. micro-gw init : Initialize a project. 2. micro-gw build : Build the project. 3. micro-gw import : Import a single API or multiple APIs to the project - 4. micro-gw reset : Reset microgateway configurations to default. + 4. micro-gw reset : Reset microgateway configurations to prompt different user credentials. OPTIONS "micro-gw help" has no command line options diff --git a/components/micro-gateway-cli/src/main/resources/cli-help/cli-reset.help b/components/micro-gateway-cli/src/main/resources/cli-help/cli-reset.help index 210b3780cb..dd5a17e3c9 100644 --- a/components/micro-gateway-cli/src/main/resources/cli-help/cli-reset.help +++ b/components/micro-gateway-cli/src/main/resources/cli-help/cli-reset.help @@ -1,23 +1,24 @@ NAME - micro-gw help reset - resets all the previously specified configurations. + micro-gw help reset - resets the user related configurations. SYNOPSIS micro-gw reset [-c|--config] DESCRIPTION - The reset command is used to clear all the previously specified configurations, such as "--server-url", "--username", - etc. + The reset command is used to clear all the previous user configurations, such as "--username", + "--clientId", etc. This will enable different user credentials to be provided when importing APIs from + WSO2 API Manager - When running the setup command for the first time, those configurations are stored internally within the microgateway - CLI tool and will be reused for subsequent setup commands. To rerun the setup command with a new set of configurations, - the reset command needs to be run beforehand. + When running the setup command for the first time, those configurations are stored internally within the + microgateway CLI tool and will be reused for subsequent import commands. To rerun the import command with a + different user credentials, the reset command needs to be run beforehand. Using "micro-gw reset -c ", we can reset an externally provided config file. EXAMPLES - Reset all the configuration to default. + Reset user related configuration to default. $ micro-gw reset Reset an external config file - $ micro-gw reset -c /home/user/micro-gw/external-config.toml \ No newline at end of file + $ micro-gw reset -c /home/user/micro-gw/external-config.toml diff --git a/distribution/resources/cli-conf/toolkit-config.toml b/distribution/resources/cli-conf/toolkit-config.toml index 6d75534c44..771ee70e51 100644 --- a/distribution/resources/cli-conf/toolkit-config.toml +++ b/distribution/resources/cli-conf/toolkit-config.toml @@ -15,7 +15,7 @@ trustStoreLocation = "" trustStorePassword = "" [corsConfiguration] -corsConfigurationEnabled = true +corsConfigurationEnabled = false accessControlAllowCredentials = false accessControlAllowOrigins = ["*"] accessControlAllowHeaders = ["authorization", "Access-Control-Allow-Origin", "Content-Type", "SOAPAction"]