-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11650 from alibaba/v1.x-develop
Merged from v1.x-develop
- Loading branch information
Showing
19 changed files
with
409 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
client/src/main/java/com/alibaba/nacos/client/utils/PreInitUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.client.utils; | ||
|
||
import com.alibaba.nacos.client.config.impl.SpasAdapter; | ||
import com.alibaba.nacos.common.utils.JacksonUtils; | ||
|
||
/** | ||
* Async do pre init to load some cost component. | ||
* | ||
* <ul> | ||
* <li>JacksonUtil</li> | ||
* <li>SpasAdapter</li> | ||
* </ul> | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
public class PreInitUtils { | ||
|
||
/** | ||
* Async pre load cost component. | ||
*/ | ||
@SuppressWarnings("PMD.AvoidManuallyCreateThreadRule") | ||
public static void asyncPreLoadCostComponent() { | ||
Thread preLoadThread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
// Jackson util will init static {@code ObjectMapper}, which will cost hundreds milliseconds. | ||
JacksonUtils.createEmptyJsonNode(); | ||
// Ram auth plugin will try to get credential from env and system when leak input identity by properties. | ||
SpasAdapter.getAk(); | ||
} | ||
}); | ||
preLoadThread.start(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
client/src/main/java/com/alibaba/nacos/client/utils/RamUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.client.utils; | ||
|
||
import com.alibaba.nacos.api.PropertyKeyConst; | ||
import com.alibaba.nacos.api.SystemPropertyKeyConst; | ||
import com.alibaba.nacos.api.common.Constants; | ||
import com.alibaba.nacos.client.config.impl.SpasAdapter; | ||
import com.alibaba.nacos.common.utils.StringUtils; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Util to get ram info, such as AK, SK and RAM role. | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
public class RamUtil { | ||
|
||
public static String getAccessKey(Properties properties) { | ||
boolean isUseRamInfoParsing = Boolean.parseBoolean(properties | ||
.getProperty(PropertyKeyConst.IS_USE_RAM_INFO_PARSING, | ||
System.getProperty(SystemPropertyKeyConst.IS_USE_RAM_INFO_PARSING, | ||
Constants.DEFAULT_USE_RAM_INFO_PARSING))); | ||
|
||
String result = properties.getProperty(PropertyKeyConst.ACCESS_KEY); | ||
if (isUseRamInfoParsing && StringUtils.isBlank(result)) { | ||
result = SpasAdapter.getAk(); | ||
} | ||
return result; | ||
} | ||
|
||
public static String getSecretKey(Properties properties) { | ||
boolean isUseRamInfoParsing = Boolean.parseBoolean(properties | ||
.getProperty(PropertyKeyConst.IS_USE_RAM_INFO_PARSING, | ||
System.getProperty(SystemPropertyKeyConst.IS_USE_RAM_INFO_PARSING, | ||
Constants.DEFAULT_USE_RAM_INFO_PARSING))); | ||
|
||
String result = properties.getProperty(PropertyKeyConst.SECRET_KEY); | ||
if (isUseRamInfoParsing && StringUtils.isBlank(result)) { | ||
result = SpasAdapter.getSk(); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.