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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setDefaultEncryptionConfiguration(
EncryptionConfiguration defaultEncryptionConfiguration) {
infoBuilder.setDefaultEncryptionConfiguration(defaultEncryptionConfiguration);
return this;
}

@Override
public Dataset build() {
return new Dataset(bigquery, infoBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Dataset apply(DatasetInfo datasetInfo) {
private final String location;
private final String selfLink;
private final Labels labels;
private final EncryptionConfiguration defaultEncryptionConfiguration;

/** A builder for {@code DatasetInfo} objects. */
public abstract static class Builder {
Expand Down Expand Up @@ -123,6 +124,14 @@ public abstract static class Builder {

public abstract Builder setLabels(Map<String, String> labels);

/**
* The default encryption key for all tables in the dataset. Once this property is set, all
* newly-created partitioned tables in the dataset will have encryption key set to this value,
* unless table creation request (or query) overrides the key.
*/
public abstract Builder setDefaultEncryptionConfiguration(
EncryptionConfiguration defaultEncryptionConfiguration);

/** Creates a {@code DatasetInfo} object. */
public abstract DatasetInfo build();
}
Expand All @@ -141,6 +150,7 @@ static final class BuilderImpl extends Builder {
private String location;
private String selfLink;
private Labels labels = Labels.ZERO;
private EncryptionConfiguration defaultEncryptionConfiguration;

BuilderImpl() {}

Expand All @@ -157,6 +167,7 @@ static final class BuilderImpl extends Builder {
this.location = datasetInfo.location;
this.selfLink = datasetInfo.selfLink;
this.labels = datasetInfo.labels;
this.defaultEncryptionConfiguration = datasetInfo.defaultEncryptionConfiguration;
}

BuilderImpl(com.google.api.services.bigquery.model.Dataset datasetPb) {
Expand Down Expand Up @@ -184,6 +195,11 @@ public Acl apply(Dataset.Access accessPb) {
this.location = datasetPb.getLocation();
this.selfLink = datasetPb.getSelfLink();
this.labels = Labels.fromPb(datasetPb.getLabels());
if (datasetPb.getDefaultEncryptionConfiguration() != null) {
this.defaultEncryptionConfiguration =
new EncryptionConfiguration.Builder(datasetPb.getDefaultEncryptionConfiguration())
.build();
}
}

@Override
Expand Down Expand Up @@ -265,6 +281,13 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setDefaultEncryptionConfiguration(
EncryptionConfiguration defaultEncryptionConfiguration) {
this.defaultEncryptionConfiguration = defaultEncryptionConfiguration;
return this;
}

@Override
public DatasetInfo build() {
return new DatasetInfo(this);
Expand All @@ -284,6 +307,7 @@ public DatasetInfo build() {
location = builder.location;
selfLink = builder.selfLink;
labels = builder.labels;
defaultEncryptionConfiguration = builder.defaultEncryptionConfiguration;
}

/** Returns the dataset identity. */
Expand Down Expand Up @@ -401,6 +425,10 @@ public Map<String, String> getLabels() {
return labels.userMap();
}

public EncryptionConfiguration getDefaultEncryptionConfiguration() {
return defaultEncryptionConfiguration;
}

/** Returns a builder for the dataset object. */
public Builder toBuilder() {
return new BuilderImpl(this);
Expand All @@ -421,6 +449,7 @@ public String toString() {
.add("selfLink", selfLink)
.add("acl", acl)
.add("labels", labels)
.add("defaultEncryptionConfiguration", defaultEncryptionConfiguration)
.toString();
}

Expand Down Expand Up @@ -483,6 +512,9 @@ public Dataset.Access apply(Acl acl) {
}));
}
datasetPb.setLabels(labels.toPb());
if (defaultEncryptionConfiguration != null) {
datasetPb.setDefaultEncryptionConfiguration(defaultEncryptionConfiguration.toPb());
}
return datasetPb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class DatasetInfoTest {
private static final String SELF_LINK = "http://bigquery/p/d";
private static final DatasetId DATASET_ID = DatasetId.of("dataset");
private static final DatasetId DATASET_ID_COMPLETE = DatasetId.of("project", "dataset");
private static final EncryptionConfiguration DATASET_ENCRYPTION_CONFIGURATION =
EncryptionConfiguration.newBuilder().setKmsKeyName("KMS_KEY_1").build();
private static final DatasetInfo DATASET_INFO =
DatasetInfo.newBuilder(DATASET_ID)
.setAcl(ACCESS_RULES)
Expand All @@ -64,6 +66,7 @@ public class DatasetInfoTest {
.setLocation(LOCATION)
.setSelfLink(SELF_LINK)
.setLabels(LABELS)
.setDefaultEncryptionConfiguration(DATASET_ENCRYPTION_CONFIGURATION)
.build();
private static final DatasetInfo DATASET_INFO_COMPLETE =
DATASET_INFO
Expand Down Expand Up @@ -108,6 +111,8 @@ public void testBuilder() {
assertEquals(LAST_MODIFIED, DATASET_INFO.getLastModified());
assertEquals(LOCATION, DATASET_INFO.getLocation());
assertEquals(SELF_LINK, DATASET_INFO.getSelfLink());
assertEquals(
DATASET_ENCRYPTION_CONFIGURATION, DATASET_INFO.getDefaultEncryptionConfiguration());
assertEquals(DATASET_ID_COMPLETE, DATASET_INFO_COMPLETE.getDatasetId());
assertEquals(ACCESS_RULES_COMPLETE, DATASET_INFO_COMPLETE.getAcl());
assertEquals(CREATION_TIME, DATASET_INFO_COMPLETE.getCreationTime());
Expand Down Expand Up @@ -136,6 +141,7 @@ public void testOf() {
assertNull(datasetInfo.getLastModified());
assertNull(datasetInfo.getLocation());
assertNull(datasetInfo.getSelfLink());
assertNull(datasetInfo.getDefaultEncryptionConfiguration());
assertTrue(datasetInfo.getLabels().isEmpty());

datasetInfo = DatasetInfo.of(DATASET_ID);
Expand All @@ -150,6 +156,7 @@ public void testOf() {
assertNull(datasetInfo.getLastModified());
assertNull(datasetInfo.getLocation());
assertNull(datasetInfo.getSelfLink());
assertNull(datasetInfo.getDefaultEncryptionConfiguration());
assertTrue(datasetInfo.getLabels().isEmpty());
}

Expand Down Expand Up @@ -179,5 +186,7 @@ private void compareDatasets(DatasetInfo expected, DatasetInfo value) {
assertEquals(expected.getDefaultTableLifetime(), value.getDefaultTableLifetime());
assertEquals(expected.getLastModified(), value.getLastModified());
assertEquals(expected.getLabels(), value.getLabels());
assertEquals(
expected.getDefaultEncryptionConfiguration(), value.getDefaultEncryptionConfiguration());
}
}