Skip to content

Commit

Permalink
feat: fix resourceNames (#24)
Browse files Browse the repository at this point in the history
* feat: fix resourceNames

* feat: update changes

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
Praful Makani and chingor13 committed Dec 9, 2020
1 parent 2db8bf0 commit 70242d5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Expand Up @@ -138,7 +138,10 @@ final class EntryListOption extends Option {

enum OptionType implements Option.OptionType {
ORDER_BY,
FILTER;
FILTER,
ORGANIZATION,
BILLINGACCOUNT,
FOLDER;

@SuppressWarnings("unchecked")
<T> T get(Map<Option.OptionType, ?> options) {
Expand Down Expand Up @@ -177,6 +180,21 @@ public static EntryListOption sortOrder(SortingField field, SortingOrder order)
public static EntryListOption filter(String filter) {
return new EntryListOption(OptionType.FILTER, filter);
}

/** Returns an option to specify an organization for the log entries to be listed. */
public static EntryListOption organization(String organization) {
return new EntryListOption(OptionType.ORGANIZATION, organization);
}

/** Returns an option to specify a billingAccount for the log entries to be listed. */
public static EntryListOption billingAccount(String billingAccount) {
return new EntryListOption(OptionType.BILLINGACCOUNT, billingAccount);
}

/** Returns an option to specify a folder for the log entries to be listed. */
public static EntryListOption folder(String folder) {
return new EntryListOption(OptionType.FOLDER, folder);
}
}

/* Sets synchronicity {@link Synchronicity} of logging writes, defaults to asynchronous. */
Expand Down
Expand Up @@ -17,8 +17,11 @@
package com.google.cloud.logging;

import static com.google.api.client.util.Preconditions.checkArgument;
import static com.google.cloud.logging.Logging.EntryListOption.OptionType.BILLINGACCOUNT;
import static com.google.cloud.logging.Logging.EntryListOption.OptionType.FILTER;
import static com.google.cloud.logging.Logging.EntryListOption.OptionType.FOLDER;
import static com.google.cloud.logging.Logging.EntryListOption.OptionType.ORDER_BY;
import static com.google.cloud.logging.Logging.EntryListOption.OptionType.ORGANIZATION;
import static com.google.cloud.logging.Logging.ListOption.OptionType.PAGE_SIZE;
import static com.google.cloud.logging.Logging.ListOption.OptionType.PAGE_TOKEN;
import static com.google.cloud.logging.Logging.WriteOption.OptionType.LABELS;
Expand Down Expand Up @@ -766,6 +769,18 @@ static ListLogEntriesRequest listLogEntriesRequest(
String projectId, Map<Option.OptionType, ?> options) {
ListLogEntriesRequest.Builder builder = ListLogEntriesRequest.newBuilder();
builder.addResourceNames("projects/" + projectId);
String organization = ORGANIZATION.get(options);
if (organization != null) {
builder.addResourceNames("organizations/" + organization);
}
String billingAccount = BILLINGACCOUNT.get(options);
if (billingAccount != null) {
builder.addResourceNames("billingAccounts/" + billingAccount);
}
String folder = FOLDER.get(options);
if (folder != null) {
builder.addResourceNames("folders/" + folder);
}
Integer pageSize = PAGE_SIZE.get(options);
if (pageSize != null) {
builder.setPageSize(pageSize);
Expand Down
Expand Up @@ -77,9 +77,19 @@ public void testEntryListOption() {
LoggingImpl.listLogEntriesRequest(
"some-project-id",
LoggingImpl.optionMap(
EntryListOption.pageToken(PAGE_TOKEN), EntryListOption.pageSize(PAGE_SIZE)));
EntryListOption.pageToken(PAGE_TOKEN),
EntryListOption.pageSize(PAGE_SIZE),
EntryListOption.organization("test-org"),
EntryListOption.billingAccount("test-account"),
EntryListOption.folder("test-folder")));
assertThat(request.getPageToken()).isEqualTo(PAGE_TOKEN);
assertThat(request.getPageSize()).isEqualTo(PAGE_SIZE);
assertThat(request.getResourceNamesList())
.containsExactly(
"projects/some-project-id",
"organizations/test-org",
"billingAccounts/test-account",
"folders/test-folder");
}

@Test
Expand Down

0 comments on commit 70242d5

Please sign in to comment.