Skip to content

Commit

Permalink
Merge pull request #882 from Rajith90/3.0.x_new
Browse files Browse the repository at this point in the history
Fix #879 #880 - Disbale cors by default and improve reset command
  • Loading branch information
Rajith90 authored Nov 21, 2019
2 parents daf5275 + a04b3ea commit be9af07
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <config-file>", 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
$ micro-gw reset -c /home/user/micro-gw/external-config.toml
2 changes: 1 addition & 1 deletion distribution/resources/cli-conf/toolkit-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trustStoreLocation = ""
trustStorePassword = ""

[corsConfiguration]
corsConfigurationEnabled = true
corsConfigurationEnabled = false
accessControlAllowCredentials = false
accessControlAllowOrigins = ["*"]
accessControlAllowHeaders = ["authorization", "Access-Control-Allow-Origin", "Content-Type", "SOAPAction"]
Expand Down

0 comments on commit be9af07

Please sign in to comment.