-
Notifications
You must be signed in to change notification settings - Fork 128
feat(bigquery): support IAM conditions in datasets in Java client. #3602
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
826654f
feat(bigquery): support IAM conditions in datasets in Java client.
whuffman36 a79baf3
Fix formatting
whuffman36 7610a8f
Account for possible null condition field in Acl.
whuffman36 001ed1c
Add toString() method to Acl.Expr object.
whuffman36 15fc548
Change Acl.User to be default google credentials in IT test
whuffman36 7babc4b
fix formatting
whuffman36 a17b6d9
Add Acl.Expr builder. Fix review nits.
whuffman36 fc6f203
fix formatting
whuffman36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import com.google.api.core.ApiFunction; | ||
| import com.google.api.services.bigquery.model.Dataset.Access; | ||
| import com.google.api.services.bigquery.model.DatasetAccessEntry; | ||
| import com.google.api.services.bigquery.model.Expr; | ||
| import com.google.cloud.StringEnumType; | ||
| import com.google.cloud.StringEnumValue; | ||
| import java.io.Serializable; | ||
|
|
@@ -41,6 +42,7 @@ public final class Acl implements Serializable { | |
|
|
||
| private final Entity entity; | ||
| private final Role role; | ||
| private final Expr condition; | ||
|
|
||
| /** | ||
| * Dataset roles supported by BigQuery. | ||
|
|
@@ -568,9 +570,82 @@ Access toPb() { | |
| } | ||
| } | ||
|
|
||
| /** Expr represents the conditional information related to dataset access policies. */ | ||
| public static final class Expr implements Serializable { | ||
| // Textual representation of an expression in Common Expression Language syntax. | ||
| private final String expression; | ||
| /** | ||
| * Optional. Title for the expression, i.e. a short string describing its purpose. This can be | ||
| * used e.g. in UIs which allow to enter the expression. | ||
| */ | ||
| private final String title; | ||
| /** | ||
| * Optional. Description of the expression. This is a longer text which describes the | ||
| * expression, e.g. when hovered over it in a UI. | ||
| */ | ||
| private final String description; | ||
| /** | ||
| * Optional. String indicating the location of the expression for error reporting, e.g. a file | ||
| * name and a position in the file. | ||
| */ | ||
| private final String location; | ||
|
|
||
| public Expr(String expression, String title, String description, String location) { | ||
PhongChuong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.expression = expression; | ||
| this.title = title; | ||
| this.description = description; | ||
| this.location = location; | ||
| } | ||
|
|
||
| com.google.api.services.bigquery.model.Expr toPb() { | ||
| com.google.api.services.bigquery.model.Expr bqExpr = | ||
| new com.google.api.services.bigquery.model.Expr(); | ||
| bqExpr.setExpression(this.expression); | ||
| bqExpr.setTitle(this.title); | ||
| bqExpr.setDescription(this.description); | ||
| bqExpr.setLocation(this.location); | ||
| return bqExpr; | ||
| } | ||
|
|
||
| static Expr fromPb(com.google.api.services.bigquery.model.Expr bqExpr) { | ||
| return new Expr( | ||
| bqExpr.getExpression(), bqExpr.getTitle(), bqExpr.getDescription(), bqExpr.getLocation()); | ||
| } | ||
|
|
||
| @Override | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include toString() as well as the normal methods like equals and hashcode?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, updated to have toString() method. |
||
| public int hashCode() { | ||
| return Objects.hash(expression, title, description, location); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| final Expr other = (Expr) obj; | ||
| return Objects.equals(this.expression, other.expression) | ||
| && Objects.equals(this.title, other.title) | ||
| && Objects.equals(this.description, other.description) | ||
| && Objects.equals(this.location, other.location); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return toPb().toString(); | ||
| } | ||
| } | ||
|
|
||
| private Acl(Entity entity, Role role) { | ||
| this(entity, role, null); | ||
| } | ||
|
|
||
| private Acl(Entity entity, Role role, Expr condition) { | ||
| this.entity = checkNotNull(entity); | ||
| this.role = role; | ||
| this.condition = condition; | ||
| } | ||
|
|
||
| /** @return Returns the entity for this ACL. */ | ||
|
|
@@ -582,6 +657,10 @@ public Entity getEntity() { | |
| public Role getRole() { | ||
| return role; | ||
| } | ||
| /** @return Returns the condition specified by this ACL. */ | ||
| public Expr getCondition() { | ||
| return condition; | ||
| } | ||
|
|
||
| /** | ||
| * @return Returns an Acl object. | ||
|
|
@@ -592,6 +671,10 @@ public static Acl of(Entity entity, Role role) { | |
| return new Acl(entity, role); | ||
| } | ||
|
|
||
| public static Acl of(Entity entity, Role role, Expr condition) { | ||
| return new Acl(entity, role, condition); | ||
| } | ||
|
|
||
| /** | ||
| * @param datasetAclEntity | ||
| * @return Returns an Acl object for a datasetAclEntity. | ||
|
|
@@ -618,7 +701,7 @@ public static Acl of(Routine routine) { | |
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(entity, role); | ||
| return Objects.hash(entity, role, condition); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -635,19 +718,26 @@ public boolean equals(Object obj) { | |
| return false; | ||
| } | ||
| final Acl other = (Acl) obj; | ||
| return Objects.equals(this.entity, other.entity) && Objects.equals(this.role, other.role); | ||
| return Objects.equals(this.entity, other.entity) | ||
| && Objects.equals(this.role, other.role) | ||
| && Objects.equals(this.condition, other.condition); | ||
| } | ||
|
|
||
| Access toPb() { | ||
| Access accessPb = entity.toPb(); | ||
| if (role != null) { | ||
| accessPb.setRole(role.name()); | ||
| } | ||
| if (condition != null) { | ||
| accessPb.setCondition(condition.toPb()); | ||
| } | ||
| return accessPb; | ||
| } | ||
|
|
||
| static Acl fromPb(Access access) { | ||
| return Acl.of( | ||
| Entity.fromPb(access), access.getRole() != null ? Role.valueOf(access.getRole()) : null); | ||
| Entity.fromPb(access), | ||
| access.getRole() != null ? Role.valueOf(access.getRole()) : null, | ||
| access.getCondition() != null ? Expr.fromPb(access.getCondition()) : null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.