Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix resourceNames #24

Merged
merged 3 commits into from Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 a organization to the log entries to be listed. */
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
public static EntryListOption organization(String organization) {
return new EntryListOption(OptionType.ORGANIZATION, organization);
}

/** Returns an option to specify a billingAccount to the log entries to be listed. */
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
public static EntryListOption billingAccount(String billingAccount) {
return new EntryListOption(OptionType.BILLINGACCOUNT, billingAccount);
}

/** Returns an option to specify a folder to the log entries to be listed. */
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -633,6 +636,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