Skip to content

Commit

Permalink
[ISSUE alibaba#11456]Optimize code.
Browse files Browse the repository at this point in the history
  • Loading branch information
stone-98 committed Mar 12, 2024
1 parent 6f71327 commit ae72fbc
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,75 @@ public class RpcConstants {
public static final String NACOS_CLIENT_RPC = "nacos.remote.client.rpc";

public static final String NACOS_CLUSTER_CLIENT_RPC = "nacos.remote.cluster.client.rpc";

public static final String NACOS_SERVER_RPC = "nacos.remote.server.rpc.tls";

public static final String NACOS_CLUSTER_SERVER_RPC = "nacos.remote.cluster.server.rpc.tls";

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_ENABLE = getConfigKey(RpcClientConfigSuffix.TLS_ENABLE);
public static final String RPC_CLIENT_TLS_ENABLE = getConfigKey(ClientSuffix.TLS_ENABLE);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_PROVIDER = getConfigKey(RpcClientConfigSuffix.TLS_PROVIDER);
public static final String RPC_CLIENT_TLS_PROVIDER = getConfigKey(ClientSuffix.TLS_PROVIDER);

@RpcConfigLabel
public static final String RPC_CLIENT_MUTUAL_AUTH = getConfigKey(RpcClientConfigSuffix.MUTUAL_AUTH);
public static final String RPC_CLIENT_MUTUAL_AUTH = getConfigKey(ClientSuffix.MUTUAL_AUTH);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_PROTOCOLS = getConfigKey(RpcClientConfigSuffix.TLS_PROTOCOLS);
public static final String RPC_CLIENT_TLS_PROTOCOLS = getConfigKey(ClientSuffix.TLS_PROTOCOLS);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_CIPHERS = getConfigKey(RpcClientConfigSuffix.TLS_CIPHERS);
public static final String RPC_CLIENT_TLS_CIPHERS = getConfigKey(ClientSuffix.TLS_CIPHERS);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_CERT_CHAIN_PATH = getConfigKey(RpcClientConfigSuffix.TLS_CERT_CHAIN_PATH);
public static final String RPC_CLIENT_TLS_CERT_CHAIN_PATH = getConfigKey(ClientSuffix.TLS_CERT_CHAIN_PATH);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_CERT_KEY = getConfigKey(RpcClientConfigSuffix.TLS_CERT_KEY);
public static final String RPC_CLIENT_TLS_CERT_KEY = getConfigKey(ClientSuffix.TLS_CERT_KEY);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_TRUST_PWD = getConfigKey(RpcClientConfigSuffix.TLS_TRUST_PWD);
public static final String RPC_CLIENT_TLS_TRUST_PWD = getConfigKey(ClientSuffix.TLS_TRUST_PWD);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_TRUST_COLLECTION_CHAIN_PATH = getConfigKey(
RpcClientConfigSuffix.TLS_TRUST_COLLECTION_CHAIN_PATH);
ClientSuffix.TLS_TRUST_COLLECTION_CHAIN_PATH);

@RpcConfigLabel
public static final String RPC_CLIENT_TLS_TRUST_ALL = getConfigKey(RpcClientConfigSuffix.TLS_TRUST_ALL);
public static final String RPC_CLIENT_TLS_TRUST_ALL = getConfigKey(ClientSuffix.TLS_TRUST_ALL);

private static final Set<String> CONFIG_NAMES = new HashSet<>();

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_ENABLE = getClusterConfigKey(RpcClientConfigSuffix.TLS_ENABLE);
public static final String RPC_CLUSTER_CLIENT_TLS_ENABLE = getClusterConfigKey(ClientSuffix.TLS_ENABLE);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_PROVIDER = getClusterConfigKey(RpcClientConfigSuffix.TLS_PROVIDER);
public static final String RPC_CLUSTER_CLIENT_TLS_PROVIDER = getClusterConfigKey(ClientSuffix.TLS_PROVIDER);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_MUTUAL_AUTH = getClusterConfigKey(RpcClientConfigSuffix.MUTUAL_AUTH);
public static final String RPC_CLUSTER_CLIENT_MUTUAL_AUTH = getClusterConfigKey(ClientSuffix.MUTUAL_AUTH);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_PROTOCOLS = getClusterConfigKey(RpcClientConfigSuffix.TLS_PROTOCOLS);
public static final String RPC_CLUSTER_CLIENT_TLS_PROTOCOLS = getClusterConfigKey(ClientSuffix.TLS_PROTOCOLS);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_CIPHERS = getClusterConfigKey(RpcClientConfigSuffix.TLS_CIPHERS);
public static final String RPC_CLUSTER_CLIENT_TLS_CIPHERS = getClusterConfigKey(ClientSuffix.TLS_CIPHERS);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_CERT_CHAIN_PATH = getClusterConfigKey(
RpcClientConfigSuffix.TLS_CERT_CHAIN_PATH);
ClientSuffix.TLS_CERT_CHAIN_PATH);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_CERT_KEY = getClusterConfigKey(RpcClientConfigSuffix.TLS_CERT_KEY);
public static final String RPC_CLUSTER_CLIENT_TLS_CERT_KEY = getClusterConfigKey(ClientSuffix.TLS_CERT_KEY);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_TRUST_PWD = getClusterConfigKey(RpcClientConfigSuffix.TLS_TRUST_PWD);
public static final String RPC_CLUSTER_CLIENT_TLS_TRUST_PWD = getClusterConfigKey(ClientSuffix.TLS_TRUST_PWD);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_TRUST_COLLECTION_CHAIN_PATH = getClusterConfigKey(
RpcClientConfigSuffix.TLS_TRUST_COLLECTION_CHAIN_PATH);
ClientSuffix.TLS_TRUST_COLLECTION_CHAIN_PATH);

@RpcClusterConfigLabel
public static final String RPC_CLUSTER_CLIENT_TLS_TRUST_ALL = getClusterConfigKey(RpcClientConfigSuffix.TLS_TRUST_ALL);
public static final String RPC_CLUSTER_CLIENT_TLS_TRUST_ALL = getClusterConfigKey(ClientSuffix.TLS_TRUST_ALL);

private static final Set<String> CLUSTER_CONFIG_NAMES = new HashSet<>();

Expand All @@ -130,170 +130,136 @@ public class RpcConstants {
}
}

public static String getConfigKey(RpcClientConfigSuffix configSuffix) {
return NACOS_CLIENT_RPC + configSuffix.getSuffix();
public static String getConfigKey(String configSuffix) {
return NACOS_CLIENT_RPC + configSuffix;
}

public static String getClusterConfigKey(RpcClientConfigSuffix configSuffix) {
return NACOS_CLUSTER_CLIENT_RPC + configSuffix.getSuffix();
public static String getClusterConfigKey(String configSuffix) {
return NACOS_CLUSTER_CLIENT_RPC + configSuffix;
}

/**
* Enumeration of common suffixes for RPC configuration properties. Each enum constant represents a specific
* configuration attribute suffix. This allows for the construction of complete configuration property keys.
*/
public enum RpcClientConfigSuffix {
public class ClientSuffix {

/**
* Suffix for 'tls.enable' configuration property.
*/
TLS_ENABLE(".tls.enable"),
public static final String TLS_ENABLE = ".tls.enable";

/**
* Suffix for 'tls.provider' configuration property.
*/
TLS_PROVIDER(".tls.provider"),
public static final String TLS_PROVIDER = ".tls.provider";

/**
* Suffix for 'tls.mutualAuth' configuration property.
*/
MUTUAL_AUTH(".tls.mutualAuth"),
public static final String MUTUAL_AUTH = ".tls.mutualAuth";

/**
* Suffix for 'tls.protocols' configuration property.
*/
TLS_PROTOCOLS(".tls.protocols"),
public static final String TLS_PROTOCOLS = ".tls.protocols";

/**
* Suffix for 'tls.ciphers' configuration property.
*/
TLS_CIPHERS(".tls.ciphers"),
public static final String TLS_CIPHERS = ".tls.ciphers";

/**
* Suffix for 'tls.certChainFile' configuration property.
*/
TLS_CERT_CHAIN_PATH(".tls.certChainFile"),
public static final String TLS_CERT_CHAIN_PATH = ".tls.certChainFile";

/**
* Suffix for 'tls.certPrivateKey' configuration property.
*/
TLS_CERT_KEY(".tls.certPrivateKey"),
public static final String TLS_CERT_KEY = ".tls.certPrivateKey";

/**
* Suffix for 'tls.certPrivateKeyPassword' configuration property.
*/
TLS_TRUST_PWD(".tls.certPrivateKeyPassword"),
public static final String TLS_TRUST_PWD = ".tls.certPrivateKeyPassword";

/**
* Suffix for 'tls.trustCollectionChainPath' configuration property.
*/
TLS_TRUST_COLLECTION_CHAIN_PATH(".tls.trustCollectionChainPath"),
public static final String TLS_TRUST_COLLECTION_CHAIN_PATH = ".tls.trustCollectionChainPath";

/**
* Suffix for 'tls.trustAll' configuration property.
*/
TLS_TRUST_ALL(".tls.trustAll");

private final String suffix;

/**
* Constructor for RpcClientConfigSuffix enumeration.
*
* @param suffix The configuration attribute suffix.
*/
RpcClientConfigSuffix(String suffix) {
this.suffix = suffix;
}

/**
* Retrieve the configuration attribute suffix.
*
* @return The configuration attribute suffix.
*/
public String getSuffix() {
return suffix;
}
public static final String TLS_TRUST_ALL = ".tls.trustAll";
}

/**
* Enumeration of common suffixes for RPC configuration properties. Each enum constant represents a specific
* configuration attribute suffix. This allows for the construction of complete configuration property keys.
*/
public enum RpcServerConfigSuffix {

public class ServerSuffix {
/**
* Suffix for 'tls.enable' configuration property.
*/
TLS_ENABLE(".enableTls"),

public static final String TLS_ENABLE = ".enableTls";
/**
* Suffix for 'tls.provider' configuration property.
*/
TLS_PROVIDER(".sslProvider"),

public static final String TLS_PROVIDER = ".sslProvider";
/**
* Suffix for 'tls.mutualAuth' configuration property.
*/
MUTUAL_AUTH(".mutualAuthEnable"),

public static final String MUTUAL_AUTH = ".mutualAuthEnable";
/**
* Suffix for 'tls.protocols' configuration property.
*/
TLS_PROTOCOLS(".protocols"),

public static final String TLS_PROTOCOLS = ".protocols";
/**
* Suffix for 'tls.ciphers' configuration property.
*/
TLS_CIPHERS(".ciphers"),

public static final String TLS_CIPHERS = ".ciphers";
/**
* Suffix for 'tls.certChainFile' configuration property.
*/
TLS_CERT_CHAIN_PATH(".certChainFile"),

public static final String TLS_CERT_CHAIN_PATH = ".certChainFile";
/**
* Suffix for 'tls.certPrivateKey' configuration property.
*/
TLS_CERT_KEY(".certPrivateKey"),

public static final String TLS_CERT_KEY = ".certPrivateKey";
/**
* Suffix for 'tls.certPrivateKeyPassword' configuration property.
*/
TLS_TRUST_PWD(".certPrivateKeyPassword"),

public static final String TLS_TRUST_PWD = ".certPrivateKeyPassword";
/**
* Suffix for 'tls.trustCollectionChainPath' configuration property.
*/
TLS_TRUST_COLLECTION_CHAIN_PATH(".trustCollectionCertFile"),

public static final String TLS_TRUST_COLLECTION_CHAIN_PATH = ".trustCollectionCertFile";
/**
* Suffix for 'tls.trustAll' configuration property.
*/
TLS_TRUST_ALL(".trustAll"),

SSL_CONTEXT_REFRESHER(".sslContextRefresher"),

COMPATIBILITY(".compatibility");

private final String suffix;

public static final String TLS_TRUST_ALL = ".trustAll";

/**
* Constructor for RpcServerConfigSuffix enumeration.
*
* @param suffix The configuration attribute suffix.
* Suffix for '.sslContextRefresher' configuration property.
*/
RpcServerConfigSuffix(String suffix) {
this.suffix = suffix;
}

public static final String SSL_CONTEXT_REFRESHER = ".sslContextRefresher";

/**
* Retrieve the configuration attribute suffix.
*
* @return The configuration attribute suffix.
* Suffix for '.compatibility' configuration property.
*/
public String getSuffix() {
return suffix;
}
public static final String COMPATIBILITY = ".compatibility";
}


Expand Down
Loading

0 comments on commit ae72fbc

Please sign in to comment.