Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
* client.attachInlinePolicy(policy, "123456789012", "us-west-2", "my-bucket");
* </pre>
*/
public class IamClient {
protected AbstractIam<?> iam;
public class IamClient implements AutoCloseable {
protected AbstractIam iam;

/**
* Constructor for IamClient with IamClientBuilder.
*
* @param iam The abstract IAM driver used to back this client for implementation.
*/
protected IamClient(AbstractIam<?> iam) {
protected IamClient(AbstractIam iam) {
this.iam = iam;
}

Expand Down Expand Up @@ -194,13 +194,18 @@ public String getIdentity(String identityName, String tenantId, String region) {
}
}

@Override
public void close() throws Exception {
this.iam.close();
}

/**
* Builder class for IamClient.
*/
public static class IamClientBuilder {
protected String region;
protected URI endpoint;
protected AbstractIam<?> iam;
protected AbstractIam iam;
protected AbstractIam.Builder<?, ?> iamBuilder;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ private ProviderSupplier() {
*/
static AbstractIam.Builder<?, ?> findProviderBuilder(String providerId) {
ServiceLoader<AbstractIam> services = ServiceLoader.load(AbstractIam.class);
ImmutableSet.Builder<AbstractIam<?>> builder = ImmutableSet.builder();
for (AbstractIam<?> service : services) {
ImmutableSet.Builder<AbstractIam> builder = ImmutableSet.builder();
for (AbstractIam service : services) {
builder.add(service);
}
Iterable<AbstractIam<?>> all = builder.build();
Iterable<AbstractIam> all = builder.build();

for (AbstractIam<?> provider : all) {
for (AbstractIam provider : all) {
if (provider.getProviderId().equals(providerId)) {
return createBuilderInstance(provider);
}
Expand All @@ -43,7 +43,7 @@ private ProviderSupplier() {
* @return The AbstractIam.Builder for the provider.
* @throws RuntimeException if the builder creation fails.
*/
private static AbstractIam.Builder<?, ?> createBuilderInstance(AbstractIam<?> provider) {
private static AbstractIam.Builder<?, ?> createBuilderInstance(AbstractIam provider) {
try {
return (AbstractIam.Builder<?, ?>) provider.getClass().getMethod("builder").invoke(provider);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* and policies across different cloud providers including AWS IAM, GCP IAM, and
* AliCloud RAM.
*/
public abstract class AbstractIam<T extends AbstractIam<T>> implements Provider, Identity {
public abstract class AbstractIam implements Provider, Identity, AutoCloseable {
private final String providerId;
protected final String region;
protected final CredentialsOverrider credentialsOverrider;
Expand Down Expand Up @@ -62,7 +62,7 @@ public String getProviderId() {
* @param <A> The concrete AbstractIam implementation type.
* @param <T> The concrete Builder implementation type.
*/
public abstract static class Builder<A extends AbstractIam<?>, T extends Builder<A, T>> implements Provider.Builder {
public abstract static class Builder<A extends AbstractIam, T extends Builder<A, T>> implements Provider.Builder {
@Getter
protected String region;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@ String createIdentity(String identityName, String description, String tenantId,
* @return identity information as a JSON string
*/
String getIdentity(String identityName, String tenantId, String region);

/**
* Closes resources and connections associated with this IAM driver.
* This method closes the IAM client if it was created.
*/
void close();
}

Loading
Loading