Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Added
- N/A

## 1.2.28 - 2018-02-22

### Added
- Added support for the File Storage Service. An example on how to call this service can be found [here](https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/FileStorageServiceExample.java)
- Added support for tagging Bucket resources in the Object Storage Service
- Added support for specifying a restore period for archived objects in the `restoreObjects` operation of the Object Storage service
- Added `paginators` to provide an `Iterable` interface over list operations offered by the SDK

## 1.2.27 - 2018-02-08

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions bmc-audit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk</artifactId>
<version>1.2.27</version>
<version>1.2.28</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -18,7 +18,7 @@
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common</artifactId>
<version>1.2.27</version>
<version>1.2.28</version>
</dependency>
</dependencies>

Expand Down
9 changes: 9 additions & 0 deletions bmc-audit/src/main/java/com/oracle/bmc/audit/Audit.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ public interface Audit extends AutoCloseable {
* @throws BmcException when an error occurs.
*/
UpdateConfigurationResponse updateConfiguration(UpdateConfigurationRequest request);

/**
* Gets the pre-configured paginators available for list operations in this service which may return multiple
* pages of data. These paginators provide an {@link java.lang.Iterable} interface so that service responses, or
* resources/records, can be iterated through without having to manually deal with pagination and page tokens.
*
* @return The service paginators.
*/
AuditPaginators getPaginators();
}
74 changes: 39 additions & 35 deletions bmc-audit/src/main/java/com/oracle/bmc/audit/AuditClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class AuditClient implements Audit {
*/
public static final com.oracle.bmc.Service SERVICE =
com.oracle.bmc.Services.create("AUDIT", "audit");
// attempt twice if it's instance principals, immediately failures will try to refresh the token
private static final int MAX_IMMEDIATE_RETRIES_IF_USING_INSTANCE_PRINCIPALS = 2;

private final AuditPaginators paginators;

@lombok.Getter(value = lombok.AccessLevel.PACKAGE)
private final com.oracle.bmc.http.internal.RestClient client;
Expand Down Expand Up @@ -87,6 +91,8 @@ public AuditClient(
SERVICE, this.authenticationDetailsProvider);
this.client = restClientFactory.create(requestSigner, configuration);

this.paginators = new AuditPaginators(this);

if (this.authenticationDetailsProvider instanceof com.oracle.bmc.auth.RegionProvider) {
com.oracle.bmc.auth.RegionProvider provider =
(com.oracle.bmc.auth.RegionProvider) this.authenticationDetailsProvider;
Expand Down Expand Up @@ -141,25 +147,19 @@ public GetConfigurationResponse getConfiguration(GetConfigurationRequest request
com.google.common.base.Function<javax.ws.rs.core.Response, GetConfigurationResponse>
transformer = GetConfigurationConverter.fromResponse();

if (this.authenticationDetailsProvider
instanceof com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider) {
int attempts = 0;
while (true) {
try {
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
} catch (com.oracle.bmc.model.BmcException e) {
if (e.getStatusCode() == 401) {
((com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider)
this.authenticationDetailsProvider)
.refreshSecurityToken();
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
if (++attempts < MAX_IMMEDIATE_RETRIES_IF_USING_INSTANCE_PRINCIPALS
&& canRetryRequestIfInstancePrincipalsUsed(e)) {
continue;
} else {
throw e;
}
}
} else {
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
}
}

Expand All @@ -172,25 +172,19 @@ public ListEventsResponse listEvents(ListEventsRequest request) {
com.google.common.base.Function<javax.ws.rs.core.Response, ListEventsResponse> transformer =
ListEventsConverter.fromResponse();

if (this.authenticationDetailsProvider
instanceof com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider) {
int attempts = 0;
while (true) {
try {
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
} catch (com.oracle.bmc.model.BmcException e) {
if (e.getStatusCode() == 401) {
((com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider)
this.authenticationDetailsProvider)
.refreshSecurityToken();
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
if (++attempts < MAX_IMMEDIATE_RETRIES_IF_USING_INSTANCE_PRINCIPALS
&& canRetryRequestIfInstancePrincipalsUsed(e)) {
continue;
} else {
throw e;
}
}
} else {
javax.ws.rs.core.Response response = client.get(ib, request);
return transformer.apply(response);
}
}

Expand All @@ -203,28 +197,38 @@ public UpdateConfigurationResponse updateConfiguration(UpdateConfigurationReques
com.google.common.base.Function<javax.ws.rs.core.Response, UpdateConfigurationResponse>
transformer = UpdateConfigurationConverter.fromResponse();

if (this.authenticationDetailsProvider
instanceof com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider) {
int attempts = 0;
while (true) {
try {
javax.ws.rs.core.Response response =
client.put(ib, request.getUpdateConfigurationDetails(), request);
return transformer.apply(response);
} catch (com.oracle.bmc.model.BmcException e) {
if (e.getStatusCode() == 401) {
((com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider)
this.authenticationDetailsProvider)
.refreshSecurityToken();
javax.ws.rs.core.Response response =
client.put(ib, request.getUpdateConfigurationDetails(), request);
return transformer.apply(response);
if (++attempts < MAX_IMMEDIATE_RETRIES_IF_USING_INSTANCE_PRINCIPALS
&& canRetryRequestIfInstancePrincipalsUsed(e)) {
continue;
} else {
throw e;
}
}
} else {
javax.ws.rs.core.Response response =
client.put(ib, request.getUpdateConfigurationDetails(), request);
return transformer.apply(response);
}
}

private boolean canRetryRequestIfInstancePrincipalsUsed(com.oracle.bmc.model.BmcException e) {
if (e.getStatusCode() == 401
&& this.authenticationDetailsProvider
instanceof
com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider) {
((com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider)
this.authenticationDetailsProvider)
.refreshSecurityToken();
return true;
}
return false;
}

@Override
public AuditPaginators getPaginators() {
return paginators;
}
}
141 changes: 141 additions & 0 deletions bmc-audit/src/main/java/com/oracle/bmc/audit/AuditPaginators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
*/
package com.oracle.bmc.audit;

import com.oracle.bmc.audit.requests.*;
import com.oracle.bmc.audit.responses.*;

/**
* Collection of helper methods that can be used to provide an {@link java.lang.Iterable} interface
* to any list operations of Audit where multiple pages of data may be fetched.
* Two styles of iteration are supported:
*
* <ul>
* <li>Iterating over the Response objects returned by the list operation. These are referred to as ResponseIterators, and the methods are suffixed with ResponseIterator. For example: <i>listUsersResponseIterator</i></li>
* <li>Iterating over the resources/records being listed. These are referred to as RecordIterators, and the methods are suffixed with RecordIterator. For example: <i>listUsersRecordIterator</i></li>
* </ul>
*
* These iterables abstract away the need to write code to manually handle pagination via looping and using the page tokens.
* They will automatically fetch more data from the service when required.
*
* As an example, if we were using the ListUsers operation in IdentityService, then the {@link java.lang.Interable} returned by calling a
* ResponseIterator method would iterate over the ListUsersResponse objects returned by each ListUsers call, whereas the {@link java.lang.Iterable}
* returned by calling a RecordIterator method would iterate over the User records and we don't have to deal with ListUsersResponse objects at all.
* In either case, pagination will be automatically handled so we can iterate until there are no more responses or no more resources/records available.
*/
@javax.annotation.Generated(value = "OracleSDKGenerator", comments = "API Version: 20160918")
@lombok.RequiredArgsConstructor
public class AuditPaginators {
private final Audit client;

/**
* Creates a new iterable which will iterate over the responses received from the listEvents operation. This iterable
* will fetch more data from the server as needed.
*
* @param request a request which can be sent to the service operation
* @return an {@link java.lang.Iterable} which can be used to iterate over the responses received from the service.
*/
public Iterable<ListEventsResponse> listEventsResponseIterator(
final ListEventsRequest request) {
return new com.oracle.bmc.paginator.internal.ResponseIterable<
ListEventsRequest.Builder, ListEventsRequest, ListEventsResponse>(
new com.google.common.base.Supplier<ListEventsRequest.Builder>() {
@Override
public ListEventsRequest.Builder get() {
return ListEventsRequest.builder().copy(request);
}
},
new com.google.common.base.Function<ListEventsResponse, String>() {
@Override
public String apply(ListEventsResponse response) {
return response.getOpcNextPage();
}
},
new com.google.common.base.Function<
com.oracle.bmc.paginator.internal.RequestBuilderAndToken<
ListEventsRequest.Builder>,
ListEventsRequest>() {
@Override
public ListEventsRequest apply(
com.oracle.bmc.paginator.internal.RequestBuilderAndToken<
ListEventsRequest.Builder>
input) {
if (input.getToken() == null) {
return input.getRequestBuilder().build();
} else {
return input.getRequestBuilder()
.page(input.getToken().orNull())
.build();
}
}
},
new com.google.common.base.Function<ListEventsRequest, ListEventsResponse>() {
@Override
public ListEventsResponse apply(ListEventsRequest request) {
return client.listEvents(request);
}
});
}

/**
* Creates a new iterable which will iterate over the {@link com.oracle.bmc.audit.model.AuditEvent} objects
* contained in responses from the listEvents operation. This iterable will fetch more data from the
* server as needed.
*
* @param request a request which can be sent to the service operation
* @return an {@link java.lang.Iterable} which can be used to iterate over the {@link com.oracle.bmc.audit.model.AuditEvent} objects
* contained in responses received from the service.
*/
public Iterable<com.oracle.bmc.audit.model.AuditEvent> listEventsRecordIterator(
final ListEventsRequest request) {
return new com.oracle.bmc.paginator.internal.ResponseRecordIterable<
ListEventsRequest.Builder, ListEventsRequest, ListEventsResponse,
com.oracle.bmc.audit.model.AuditEvent>(
new com.google.common.base.Supplier<ListEventsRequest.Builder>() {
@Override
public ListEventsRequest.Builder get() {
return ListEventsRequest.builder().copy(request);
}
},
new com.google.common.base.Function<ListEventsResponse, String>() {
@Override
public String apply(ListEventsResponse response) {
return response.getOpcNextPage();
}
},
new com.google.common.base.Function<
com.oracle.bmc.paginator.internal.RequestBuilderAndToken<
ListEventsRequest.Builder>,
ListEventsRequest>() {
@Override
public ListEventsRequest apply(
com.oracle.bmc.paginator.internal.RequestBuilderAndToken<
ListEventsRequest.Builder>
input) {
if (input.getToken() == null) {
return input.getRequestBuilder().build();
} else {
return input.getRequestBuilder()
.page(input.getToken().orNull())
.build();
}
}
},
new com.google.common.base.Function<ListEventsRequest, ListEventsResponse>() {
@Override
public ListEventsResponse apply(ListEventsRequest request) {
return client.listEvents(request);
}
},
new com.google.common.base.Function<
ListEventsResponse,
java.util.List<com.oracle.bmc.audit.model.AuditEvent>>() {
@Override
public java.util.List<com.oracle.bmc.audit.model.AuditEvent> apply(
ListEventsResponse response) {
return response.getItems();
}
});
}
}
Loading