Skip to content
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

refactor credentials providers && add provider name #94

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.aliyun</groupId>
<artifactId>credentials-java</artifactId>
<version>0.3.12</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>credentials-java</name>
Expand Down Expand Up @@ -54,11 +54,18 @@
</scm>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<powermock.version>2.0.2</powermock.version>
<mockito.version>3.0.0</mockito.version>
</properties>

<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>credentials-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea</artifactId>
Expand Down Expand Up @@ -138,8 +145,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/aliyun/credentials/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.aliyun.credentials.models.CredentialModel;
import com.aliyun.credentials.provider.*;
import com.aliyun.credentials.utils.AuthConstant;
import com.aliyun.credentials.utils.ProviderName;
import com.aliyun.credentials.utils.StringUtils;
import com.aliyun.tea.utils.Validate;

Expand Down Expand Up @@ -37,6 +38,7 @@ private AlibabaCloudCredentialsProvider getProvider(Config config) {
.accessKeySecret(Validate.notNull(
config.accessKeySecret, "AccessKeySecret must not be null."))
.type(config.type)
.providerName(ProviderName.STATIC_AK)
.build())
.build();
case AuthConstant.STS:
Expand All @@ -49,6 +51,7 @@ private AlibabaCloudCredentialsProvider getProvider(Config config) {
.securityToken(Validate.notNull(
config.securityToken, "SecurityToken must not be null."))
.type(config.type)
.providerName(ProviderName.STATIC_STS)
.build())
.build();
case AuthConstant.BEARER:
Expand Down Expand Up @@ -76,6 +79,7 @@ private AlibabaCloudCredentialsProvider getProvider(Config config) {
.accessKeySecret(Validate.notNull(
config.accessKeySecret, "AccessKeySecret must not be null."))
.type(AuthConstant.ACCESS_KEY)
.providerName(ProviderName.STATIC_AK)
.build())
.build();
} else {
Expand All @@ -88,6 +92,7 @@ private AlibabaCloudCredentialsProvider getProvider(Config config) {
.securityToken(Validate.notNull(
config.securityToken, "SecurityToken must not be null."))
.type(AuthConstant.STS)
.providerName(ProviderName.STATIC_STS)
.build())
.build();
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/aliyun/credentials/models/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Config extends TeaModel {
@NameInMap("roleName")
public String roleName;
@NameInMap("disableIMDSv1")
public Boolean disableIMDSv1 = false;
public Boolean disableIMDSv1;
@NameInMap("enableIMDSv2")
public Boolean enableIMDSv2;
@NameInMap("metadataTokenDuration")
Expand All @@ -34,9 +34,9 @@ public class Config extends TeaModel {
@NameInMap("host")
public String host;
@NameInMap("readTimeout")
public int timeout = 10000;
public Integer timeout;
@NameInMap("connectTimeout")
public int connectTimeout = 5000;
public Integer connectTimeout;
@NameInMap("proxy")
public String proxy;
@NameInMap("policy")
Expand All @@ -50,7 +50,7 @@ public class Config extends TeaModel {
@NameInMap("credentialsURI")
public String credentialsURI;
@NameInMap("STSEndpoint")
public String STSEndpoint = "sts.aliyuncs.com";
public String STSEndpoint;
/**
* <p>external id for ram role arn</p>
*/
Expand Down Expand Up @@ -243,7 +243,7 @@ public Config setTimeout(int timeout) {
return this;
}

public int getTimeout() {
public Integer getTimeout() {
return timeout;
}

Expand All @@ -252,7 +252,7 @@ public Config setConnectTimeout(int connectTimeout) {
return this;
}

public int getConnectTimeout() {
public Integer getConnectTimeout() {
return connectTimeout;
}

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/aliyun/credentials/models/CredentialModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
package com.aliyun.credentials.models;

import com.aliyun.credentials.AlibabaCloudCredentials;
import com.aliyun.credentials.api.ICredentials;
import com.aliyun.tea.*;

public class CredentialModel extends TeaModel implements AlibabaCloudCredentials {
public class CredentialModel extends TeaModel implements AlibabaCloudCredentials, ICredentials {
public String accessKeyId;
public String accessKeySecret;
public String securityToken;
public String bearerToken;
public String type;
public String providerName;
public long expiration;

private CredentialModel(Builder builder) {
Expand All @@ -18,6 +20,7 @@ private CredentialModel(Builder builder) {
this.securityToken = builder.securityToken;
this.bearerToken = builder.bearerToken;
this.type = builder.type;
this.providerName = builder.providerName;
this.expiration = builder.expiration;
}

Expand Down Expand Up @@ -79,12 +82,18 @@ public String getBearerToken() {
return this.bearerToken;
}

@Override
public String getProviderName() {
return providerName;
}

public static final class Builder {
private String accessKeyId;
private String accessKeySecret;
private String securityToken;
private String bearerToken;
private String type;
private String providerName;
private long expiration;

public Builder accessKeyId(String accessKeyId) {
Expand Down Expand Up @@ -112,6 +121,11 @@ public Builder type(String type) {
return this;
}

public Builder providerName(String providerName) {
this.providerName = providerName;
return this;
}

public Builder expiration(long expiration) {
this.expiration = expiration;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.aliyun.credentials.provider;

import com.aliyun.credentials.api.ICredentialsProvider;
import com.aliyun.credentials.models.CredentialModel;

public interface AlibabaCloudCredentialsProvider {
public interface AlibabaCloudCredentialsProvider extends ICredentialsProvider {

CredentialModel getCredentials();
}
Loading
Loading