Skip to content

sts、oidc申请扮演角色临时访问支持指定endpoint #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2025

Conversation

kuixing233
Copy link
Contributor

No description provided.

@@ -20,6 +20,7 @@ public class STSCredential extends Credential {
private String tmpSecretId;
private String tmpSecretKey;
private String token;
private String endpoint = "sts.tencentcloudapi.com";
private int expiredTime;

public STSCredential(String secretId, String secretKey, String roleArn, String roleSessionName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以改成调用新的参数最全的构造函数,把默认 endpoint 从这里传进去,然后移除掉 23 行的初始化
this(secretId, secretKey, roleArn, roleSessionName, "sts.tencentcloudapi.com")

@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Assert.assertEquals(expectUrl, request.url().host());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样无法写出测试非 sts.tencentcloudapi.com 的测试用例

可以给 MyIntterceptor 加个 field,intercept里修改这个 field,然后在测试用例里读取这个 field,这样可以测试任意你想要的 endpoint


public class OIDCRoleProviderTest {

class MyInterceptor implements Interceptor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class 前面需要加个 static,否则 class 是和 instance 而非 class 关联起来的


class MyInterceptor implements Interceptor {

public static final String expectUrl = "sts.tencentcloudapi.com";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同 OIDCRoleProviderTest.java

@@ -25,6 +27,7 @@ public class OIDCRoleArnProvider implements CredentialsProvider, Credential.Upda
public String WebIdentityToken;
public String RoleArn;
public String RoleSessionName;
public String Endpoint = "sts.tencentcloudapi.com";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同 OIDCRoleProviderTest.java

并且这个 Endpoint 还要加个 getter/setter,因为有一个无参的构造函数

field.set(null, okClient);

cred.getCredentials();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还要测试下 isTke 的场景,这种情况从磁盘里读取配置,因此需要设置环境变量+临时文件,临时文件可以用 File.createTempFile()

@zqfan zqfan merged commit 1ad7ca6 into TencentCloud:master Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants