-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8aeb1
commit 26bb99d
Showing
18 changed files
with
281 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.aliyun.credentials; | ||
|
||
import com.aliyun.credentials.exception.CredentialException; | ||
import com.aliyun.credentials.models.Config; | ||
import com.aliyun.credentials.provider.*; | ||
import com.aliyun.credentials.utils.AuthConstant; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.text.ParseException; | ||
|
||
public class Client { | ||
|
||
private AlibabaCloudCredentials cloudCredential; | ||
|
||
public Client(Config config) throws ParseException, CredentialException, IOException { | ||
this.cloudCredential = getCredential(config); | ||
} | ||
|
||
public AlibabaCloudCredentials getCredential(Config config) throws IOException, CredentialException, ParseException { | ||
switch (config.type) { | ||
case AuthConstant.ACCESS_KEY: | ||
return new AccessKeyCredential(config.accessKeyId, config.accessKeySecret); | ||
case AuthConstant.STS: | ||
return new StsCredential(config.accessKeyId, config.accessKeySecret, config.securityToken); | ||
case AuthConstant.BEARER: | ||
return new BearerTokenCredential(config.bearerToken); | ||
default: | ||
return this.getProvider(config).getCredentials(); | ||
} | ||
} | ||
|
||
private AlibabaCloudCredentialsProvider getProvider(Config config) throws CredentialException, MalformedURLException { | ||
try { | ||
switch (config.type) { | ||
case AuthConstant.ECS_RAM_ROLE: | ||
return new EcsRamRoleCredentialProvider(config); | ||
case AuthConstant.RAM_ROLE_ARN: | ||
return new RamRoleArnCredentialProvider(config); | ||
case AuthConstant.RSA_KEY_PAIR: | ||
return new RsaKeyPairCredentialProvider(config); | ||
default: | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return new DefaultCredentialsProvider(); | ||
} | ||
|
||
public String getAccessKeyId() { | ||
return this.cloudCredential.getAccessKeyId(); | ||
} | ||
|
||
public String getAccessKeySecret() { | ||
return this.cloudCredential.getAccessKeySecret(); | ||
} | ||
|
||
public String getSecurityToken() { | ||
return this.cloudCredential.getSecurityToken(); | ||
} | ||
|
||
public String getType() { | ||
return this.cloudCredential.getType(); | ||
} | ||
|
||
public String getBearerToken() { | ||
return this.cloudCredential.getBearerToken(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.aliyun.credentials.models; | ||
|
||
import com.aliyun.tea.NameInMap; | ||
import com.aliyun.tea.TeaModel; | ||
|
||
public class Config extends TeaModel { | ||
@NameInMap("type") | ||
public String type = "default"; | ||
@NameInMap("access_key_id") | ||
public String accessKeyId; | ||
@NameInMap("access_key_secret") | ||
public String accessKeySecret; | ||
@NameInMap("role_arn") | ||
public String roleArn; | ||
@NameInMap("role_session_name") | ||
public String roleSessionName; | ||
@NameInMap("private_key_file") | ||
public String privateKeyFile; | ||
@NameInMap("public_key_id") | ||
public String publicKeyId; | ||
@NameInMap("role_name") | ||
public String roleName; | ||
@NameInMap("bearer_token") | ||
public String bearerToken; | ||
@NameInMap("security_token") | ||
public String securityToken; | ||
@NameInMap("host") | ||
public String host; | ||
@NameInMap("rad_time_out") | ||
public int timeout; | ||
@NameInMap("connect_timeout") | ||
public int connectTimeout; | ||
@NameInMap("proxy") | ||
public String proxy; | ||
|
||
public static Config build(java.util.Map<String, ?> map) throws Exception { | ||
Config self = new Config(); | ||
return TeaModel.build(map, self); | ||
} | ||
|
||
} |
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
Oops, something went wrong.