-
Notifications
You must be signed in to change notification settings - Fork 121
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: add Dataset ACL support #1763
Merged
stephaniewang526
merged 12 commits into
googleapis:main
from
stephaniewang526:authorize-datasets
Feb 2, 2022
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
db48dc8
feat: add Dataset ACL support
stephaniewang526 b8ef226
some lint updates
stephaniewang526 c3163f2
add back interface that was causing IDE issues
stephaniewang526 b4b19bd
Merge branch 'main' into authorize-datasets
stephaniewang526 d9c1b6d
fix recursive import issue
stephaniewang526 3adb482
debug
stephaniewang526 1933667
update code based on pending discovery doc changes (cl/421673680)
stephaniewang526 8e2c3a6
update code to reflect more changes (target_types should be List<Stri…
stephaniewang526 f8f89a4
Merge branch 'main' into authorize-datasets
stephaniewang526 6846995
🦉 Updates from OwlBot
gcf-owl-bot[bot] f4f7747
Merge branch 'authorize-datasets' of https://github.com/stephaniewang…
gcf-owl-bot[bot] dab1cc8
rename to address feedback
stephaniewang526 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 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 |
---|---|---|
|
@@ -20,9 +20,11 @@ | |
|
||
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.cloud.StringEnumType; | ||
import com.google.cloud.StringEnumValue; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
|
@@ -105,7 +107,8 @@ public enum Type { | |
USER, | ||
VIEW, | ||
IAM_MEMBER, | ||
ROUTINE | ||
ROUTINE, | ||
DATASET | ||
} | ||
|
||
Entity(Type type) { | ||
|
@@ -119,6 +122,11 @@ public Type getType() { | |
abstract Access toPb(); | ||
|
||
static Entity fromPb(Access access) { | ||
if (access.getDataset() != null) { | ||
return new Dataset( | ||
DatasetId.fromPb(access.getDataset().getDataset()), | ||
access.getDataset().getTargetTypes()); | ||
} | ||
if (access.getDomain() != null) { | ||
return new Domain(access.getDomain()); | ||
} | ||
|
@@ -146,6 +154,64 @@ static Entity fromPb(Access access) { | |
} | ||
} | ||
|
||
/** | ||
* Class for a BigQuery Dataset entity. Objects of this class represent a dataset from a different | ||
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. Maybe clarify this is a Dataset ACL entity, not a Dataset entity? 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. Updated. Thanks! |
||
* dataset to grant access to. Only views are supported for now. The role field is not required | ||
* when this field is set. If that dataset is deleted and re-created, its access needs to be | ||
* granted again via an update operation. | ||
*/ | ||
public static final class Dataset extends Entity { | ||
|
||
private static final long serialVersionUID = -8392885851733136526L; | ||
|
||
private final DatasetId id; | ||
private final List<String> targetTypes; | ||
|
||
/** Creates a Dataset entity given the dataset's id. */ | ||
public Dataset(DatasetId id, List<String> targetTypes) { | ||
super(Type.DATASET); | ||
this.id = id; | ||
this.targetTypes = targetTypes; | ||
} | ||
|
||
/** Returns dataset's identity. */ | ||
public DatasetId getId() { | ||
return id; | ||
} | ||
|
||
public List<String> getTargetTypes() { | ||
return targetTypes; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
Dataset dataset = (Dataset) obj; | ||
return Objects.equals(getType(), dataset.getType()) && Objects.equals(id, dataset.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getType(), id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toPb().toString(); | ||
} | ||
|
||
@Override | ||
Access toPb() { | ||
return new Access() | ||
.setDataset(new DatasetAccessEntry().setDataset(id.toPb()).setTargetTypes(targetTypes)); | ||
} | ||
} | ||
|
||
/** | ||
* Class for a BigQuery Domain entity. Objects of this class represent a domain to grant access | ||
* to. Any users signed in with the domain specified will be granted the specified access. | ||
|
@@ -516,6 +582,11 @@ public static Acl of(Entity entity, Role role) { | |
return new Acl(entity, role); | ||
} | ||
|
||
/** Returns an Acl object for a dataset entity. */ | ||
public static Acl of(Dataset dataset) { | ||
return new Acl(dataset, null); | ||
} | ||
|
||
/** Returns an Acl object for a view entity. */ | ||
public static Acl of(View view) { | ||
return new Acl(view, null); | ||
|
This file contains 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor constructor surprise for me, until I realized we're dealing with an ACL.Dataset and not a Dataset. I suspect this is just local ambiguity; any other places where we need to consider the naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree it's a little confusing so I renamed it to be more explicit:
DatasetAclEntity
.