Skip to content

Commit

Permalink
Merge pull request #1337 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
register all properties in a registry
  • Loading branch information
ashitsalesforce authored Oct 14, 2024
2 parents 3304bc6 + 7f88d9f commit e9369a6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
41 changes: 35 additions & 6 deletions src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ public class AppConfig {
public static final String PROP_OAUTH_CLIENTID = OAUTH_PREFIX + OAUTH_PARTIAL_CLIENTID;
public static final String PROP_OAUTH_REDIRECTURI = OAUTH_PREFIX + OAUTH_PARTIAL_REDIRECTURI;
public static final String PROP_OAUTH_LOGIN_FROM_BROWSER = OAUTH_PREFIX + "loginfrombrowser";
public static final String PROP_OAUTH_CLIENTID_PROD_PARTNER = OAUTH_PREFIX
+ PROD_ENVIRONMENT_VAL
+ "." + OAUTH_PARTIAL_PARTNER_CLIENTID;
public static final String PROP_OAUTH_CLIENTID_PROD_BULK = OAUTH_PREFIX
+ PROD_ENVIRONMENT_VAL
+ "." + OAUTH_PARTIAL_BULK_CLIENTID;
public static final String PROP_OAUTH_CLIENTID_SANDBOX_PARTNER = OAUTH_PREFIX
+ SB_ENVIRONMENT_VAL
+ "." + OAUTH_PARTIAL_PARTNER_CLIENTID;
public static final String PROP_OAUTH_CLIENTID_SANDBOX_BULK = OAUTH_PREFIX
+ SB_ENVIRONMENT_VAL
+ "." + OAUTH_PARTIAL_BULK_CLIENTID;
public static final String OAUTH_REDIRECT_URI_SUFFIX = "services/oauth2/success";
public static final String PROP_REUSE_CLIENT_CONNECTION = "sfdc.reuseClientConnection";
public static final String PROP_RICH_TEXT_FIELD_REGEX = "sfdx.richtext.regex";
Expand Down Expand Up @@ -453,7 +465,7 @@ public class AppConfig {
// Following properties are read-only, i.e. they are not overridden during save() to config.properties
// - These properties are not set in Advanced Settings dialog.
// - Make sure to list all sensitive properties such as password because these properties are not saved.
static final String[] READ_ONLY_PROPERTY_NAMES = {
private static final String[] READ_ONLY_PROPERTY_NAMES = {
PROP_PASSWORD,
PROP_IDLOOKUP_FIELD,
PROP_MAPPING_FILE,
Expand Down Expand Up @@ -497,7 +509,13 @@ public class AppConfig {
PROP_USE_SYSTEM_PROPS_FOR_HTTP_CLIENT,
};

static final String[] ENCRYPTED_PROPERTY_NAMES = {
// internal properties are derived in code.
// They are neither read from, nor written to config.properties file.
private static final String[] INTERNAL_PROPERTY_NAMES = {
PROP_OAUTH_CLIENTID,
};

private static final String[] ENCRYPTED_PROPERTY_NAMES = {
PROP_PASSWORD,
PROP_PROXY_PASSWORD,
PROP_OAUTH_ACCESSTOKEN,
Expand Down Expand Up @@ -634,11 +652,11 @@ private void setDefaults(Map<String, String> cliOptionsMap) {
setDefaultValue(PROP_AUTH_ENVIRONMENTS, PROD_ENVIRONMENT_VAL + AppUtil.COMMA + SB_ENVIRONMENT_VAL);

/* sfdc.oauth.<env>.<bulk | partner>.clientid = DataLoaderBulkUI | DataLoaderPartnerUI */
setDefaultValue(OAUTH_PREFIX + PROD_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_BULK_CLIENTID, OAUTH_BULK_CLIENTID_VAL);
setDefaultValue(OAUTH_PREFIX + PROD_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_PARTNER_CLIENTID, OAUTH_PARTNER_CLIENTID_VAL);
setDefaultValue(PROP_OAUTH_CLIENTID_PROD_BULK, OAUTH_BULK_CLIENTID_VAL);
setDefaultValue(PROP_OAUTH_CLIENTID_PROD_PARTNER, OAUTH_PARTNER_CLIENTID_VAL);

setDefaultValue(OAUTH_PREFIX + SB_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_BULK_CLIENTID, OAUTH_BULK_CLIENTID_VAL);
setDefaultValue(OAUTH_PREFIX + SB_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_PARTNER_CLIENTID, OAUTH_PARTNER_CLIENTID_VAL);
setDefaultValue(PROP_OAUTH_CLIENTID_SANDBOX_BULK, OAUTH_BULK_CLIENTID_VAL);
setDefaultValue(PROP_OAUTH_CLIENTID_SANDBOX_PARTNER, OAUTH_PARTNER_CLIENTID_VAL);

setDefaultValue(PROP_OPERATION, "insert");
setDefaultValue(PROP_REUSE_CLIENT_CONNECTION, true);
Expand Down Expand Up @@ -1021,6 +1039,17 @@ public static boolean isReadOnlyProperty(String propertyName) {
return false;
}

public static boolean isInternalProperty(String propertyName) {
if (propertyName == null) {
return false;
}
for (String roProp : AppConfig.INTERNAL_PROPERTY_NAMES) {
if (roProp.equals(propertyName)) {
return true;
}
}
return false;
}
public static boolean isEncryptedProperty(String propertyName) {
if (propertyName == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;

import com.salesforce.dataloader.ui.Labels;
import com.salesforce.dataloader.util.AppUtil;

/*
* Data class capturing information about configuration property (aka Setting).
Expand All @@ -40,14 +41,16 @@ public class ConfigPropertyMetadata {
private String defaultValue = "";
private boolean readOnly = false;
private boolean encrypted = false;
private boolean internal = false;
private boolean commandLineOption = false;
private final String uiLabelTemplate;
private final String uiTooltipTemplate;

static {
Field[] appConfigFields = AppConfig.class.getDeclaredFields();
for (Field configField : appConfigFields) {
if (configField.getName().startsWith("PROP_")) {
if (configField.getName().startsWith("PROP_")
|| configField.getName().startsWith("CLI_OPTION_")) {
String propName;
try {
propName = configField.get(null).toString();
Expand All @@ -57,6 +60,21 @@ public class ConfigPropertyMetadata {
ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName());
configProp.setEncrypted(AppConfig.isEncryptedProperty(propName));
configProp.setReadOnly(AppConfig.isReadOnlyProperty(propName));
configProp.setInternal(AppConfig.isInternalProperty(propName));
propertiesMap.put(propName, configProp);
}
}
Field[] appUtilFields = AppUtil.class.getDeclaredFields();
for (Field configField : appUtilFields) {
if (configField.getName().startsWith("CLI_OPTION_")) {
String propName;
try {
propName = configField.get(null).toString();
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
continue;
}
ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName());
configProp.setReadOnly(true);
propertiesMap.put(propName, configProp);
}
}
Expand Down Expand Up @@ -124,4 +142,12 @@ public String getUiLabelTemplate() {
public String getUiTooltip() {
return uiTooltipTemplate;
}

public boolean isInternal() {
return internal;
}

public void setInternal(boolean internal) {
this.internal = internal;
}
}

0 comments on commit e9369a6

Please sign in to comment.