use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.
the class CredentialsProviderFactory method newSTSKeyPairSessionCredentialsProvider.
/**
* Create an instance of InstanceProfileCredentialsProvider based on RSA key
* pair.
*
* @param regionId
* RAM's available area, for more information about regionId, see
* <a href="https://help.aliyun.com/document_detail/40654.html">
* RegionIdList</a>.
* @param publicKeyId
* Public Key ID.
* @param privateKey
* Private Key.
* @return A {@link StsKeyPairCredentialsProvider} instance.
* @throws ClientException
* OSS Client side exception.
*/
public static STSKeyPairSessionCredentialsProvider newSTSKeyPairSessionCredentialsProvider(String regionId, String publicKeyId, String privateKey) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(regionId);
KeyPairCredentials keyPairCredentials = new KeyPairCredentials(publicKeyId, privateKey);
return new STSKeyPairSessionCredentialsProvider(keyPairCredentials, profile);
}
use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.
the class AuthUtils method deletePublicKey.
/**
* Delete the uploaded public key.
*
* @param regionId
* RAM's available area.
* @param accessKeyId
* Access Key ID of the root user.
* @param accessKeySecret
* Secret Access Key of the root user.
* @param publicKeyId
* Public Key Id.
* @throws ClientException
*/
public static void deletePublicKey(String regionId, String accessKeyId, String accessKeySecret, String publicKeyId) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
DeletePublicKeyRequest deletePublicKeyRequest = new DeletePublicKeyRequest();
deletePublicKeyRequest.setUserPublicKeyId(publicKeyId);
client.getAcsResponse(deletePublicKeyRequest);
}
use of com.aliyuncs.profile.DefaultProfile in project fc-java-sdk by aliyun.
the class PopClient method openFCService.
public OpenFunctionComputeResponse openFCService(Config config, OpenFunctionComputeRequest request) throws ClientException, ServerException {
request.validate();
try {
String accessKeyId = config.getAccessKeyID();
String accessSecret = config.getAccessKeySecret();
DefaultProfile profile = null;
if (StringUtils.isBlank(config.getSecurityToken())) {
profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret);
} else {
String sToken = config.getSecurityToken();
profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret, sToken);
}
OpenFcServiceRequest openFCServiceRequest = new OpenFcServiceRequest();
IAcsClient client = new DefaultAcsClient(profile);
openFCServiceRequest.setSysEndpoint(OPEN_FC_SERVICE_ENDPOINT);
OpenFcServiceResponse openFCServiceResponse = client.getAcsResponse(openFCServiceRequest);
OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
response.setRequestId(openFCServiceResponse.getRequestId());
response.setOrderId(openFCServiceResponse.getOrderId());
return response;
} catch (com.aliyuncs.exceptions.ClientException e) {
if (StringUtils.contains(e.getErrMsg(), "已开通")) {
OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
response.setRequestId(e.getRequestId());
response.setCode(ERROR_CODE_ORDER_OPENED);
response.setMsg("You have subscribed FunctionCompute, please proceed to FC console and start using it.");
return response;
}
throw new ClientException(e.getErrCode(), e.getErrMsg(), e.getRequestId());
}
}
use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.
the class AuthUtils method uploadPublicKey.
/**
* Upload the public key of RSA key pair.
*
* @param regionId
* RAM's available area.
* @param accessKeyId
* Access Key ID of the root user.
* @param accessKeySecret
* Secret Access Key of the root user.
* @param publicKey
* Public key content.
* @return Public key description, include public key id etc.
* @throws ClientException
*/
public static PublicKey uploadPublicKey(String regionId, String accessKeyId, String accessKeySecret, String publicKey) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
UploadPublicKeyRequest uploadPublicKeyRequest = new UploadPublicKeyRequest();
uploadPublicKeyRequest.setPublicKeySpec(publicKey);
UploadPublicKeyResponse uploadPublicKeyResponse = client.getAcsResponse(uploadPublicKeyRequest);
com.aliyuncs.ram.model.v20150501.UploadPublicKeyResponse.PublicKey pubKey = uploadPublicKeyResponse.getPublicKey();
return new PublicKey(pubKey);
}
use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.
the class AuthUtils method listPublicKeys.
/**
* List the public keys that has been uploaded.
*
* @param regionId
* RAM's available area.
* @param accessKeyId
* Access Key ID of the root user.
* @param accessKeySecret
* Secret Access Key of the root user.
* @return Public keys.
* @throws ClientException
*/
public static List<PublicKey> listPublicKeys(String regionId, String accessKeyId, String accessKeySecret) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
ListPublicKeysRequest listPublicKeysRequest = new ListPublicKeysRequest();
ListPublicKeysResponse listPublicKeysResponse = client.getAcsResponse(listPublicKeysRequest);
List<PublicKey> publicKeys = new ArrayList<PublicKey>();
for (com.aliyuncs.ram.model.v20150501.ListPublicKeysResponse.PublicKey publicKey : listPublicKeysResponse.getPublicKeys()) {
publicKeys.add(new PublicKey(publicKey));
}
return publicKeys;
}
Aggregations