-
Notifications
You must be signed in to change notification settings - Fork 288
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
Conversation
@@ -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) { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还要测试下 isTke 的场景,这种情况从磁盘里读取配置,因此需要设置环境变量+临时文件,临时文件可以用 File.createTempFile()
No description provided.