use of com.qcloud.cos.auth.COSCredentialsProvider in project hadoop-cos by tencentyun.
the class COSCredentialProviderList method close.
@Override
public void close() throws Exception {
if (this.closed()) {
return;
}
int remainder = this.refCount.decrementAndGet();
if (remainder != 0) {
return;
}
this.isClosed.set(true);
for (COSCredentialsProvider provider : this.providers) {
if (provider instanceof Closeable) {
((Closeable) provider).close();
}
}
}
use of com.qcloud.cos.auth.COSCredentialsProvider in project hadoop-cos by tencentyun.
the class CosNUtils method createCOSCredentialProvider.
/**
* create cos cred
* @param uri cos uri
* @param conf config
* @param credClass cred class
* @return provider
* @throws IOException
*/
public static COSCredentialsProvider createCOSCredentialProvider(URI uri, Configuration conf, Class<?> credClass) throws IOException {
COSCredentialsProvider credentialsProvider;
if (!COSCredentialsProvider.class.isAssignableFrom(credClass)) {
throw new IllegalArgumentException("class " + credClass + " " + NOT_COS_CREDENTIAL_PROVIDER);
}
if (Modifier.isAbstract(credClass.getModifiers())) {
throw new IllegalArgumentException("class " + credClass + " " + ABSTRACT_CREDENTIAL_PROVIDER);
}
LOG.debug("Credential Provider class: " + credClass.getName());
try {
// new credClass()
Constructor constructor = getConstructor(credClass);
if (constructor != null) {
credentialsProvider = (COSCredentialsProvider) constructor.newInstance();
return credentialsProvider;
}
// new credClass(conf)
constructor = getConstructor(credClass, Configuration.class);
if (null != constructor) {
credentialsProvider = (COSCredentialsProvider) constructor.newInstance(conf);
return credentialsProvider;
}
// new credClass(uri, conf)
constructor = getConstructor(credClass, URI.class, Configuration.class);
if (null != constructor) {
credentialsProvider = (COSCredentialsProvider) constructor.newInstance(uri, conf);
return credentialsProvider;
}
Method factory = getFactoryMethod(credClass, COSCredentialsProvider.class, "getInstance");
if (null != factory) {
credentialsProvider = (COSCredentialsProvider) factory.invoke(null);
return credentialsProvider;
}
throw new IllegalArgumentException("Not supported constructor or factory method found");
} catch (IllegalAccessException e) {
throw new IOException(credClass.getName() + " " + INSTANTIATION_EXCEPTION + ": " + e, e);
} catch (InstantiationException e) {
throw new IOException(credClass.getName() + " " + INSTANTIATION_EXCEPTION + ": " + e, e);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException == null) {
targetException = e;
}
throw new IOException(credClass.getName() + " " + INSTANTIATION_EXCEPTION + ": " + targetException, targetException);
}
}
use of com.qcloud.cos.auth.COSCredentialsProvider in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method buildCVMInstanceCredentialsCOSClient.
protected static COSClient buildCVMInstanceCredentialsCOSClient() {
InstanceMetadataCredentialsEndpointProvider endpointProvider = new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.CVM);
InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
clientConfig = new ClientConfig(new Region(region));
return new COSClient(cosCredentialsProvider, clientConfig);
}
use of com.qcloud.cos.auth.COSCredentialsProvider in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method buildCPMInstanceCredentialsCOSClient.
protected static COSClient buildCPMInstanceCredentialsCOSClient() {
InstanceMetadataCredentialsEndpointProvider endpointProvider = new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.CPM);
InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
clientConfig = new ClientConfig(new Region(region));
return new COSClient(cosCredentialsProvider, clientConfig);
}
Aggregations