feat(bigquery): support IAM conditions in datasets in Java client. (#… · googleapis/java-bigquery@6696a9c
@@ -21,6 +21,7 @@
2121import com.google.api.core.ApiFunction;
2222import com.google.api.services.bigquery.model.Dataset.Access;
2323import com.google.api.services.bigquery.model.DatasetAccessEntry;
24+import com.google.api.services.bigquery.model.Expr;
2425import com.google.cloud.StringEnumType;
2526import com.google.cloud.StringEnumValue;
2627import java.io.Serializable;
@@ -41,6 +42,7 @@ public final class Acl implements Serializable {
41424243private final Entity entity;
4344private final Role role;
45+private final Expr condition;
44464547/**
4648 * Dataset roles supported by BigQuery.
@@ -568,9 +570,147 @@ Access toPb() {
568570 }
569571 }
570572573+/** Expr represents the conditional information related to dataset access policies. */
574+public static final class Expr implements Serializable {
575+// Textual representation of an expression in Common Expression Language syntax.
576+private final String expression;
577+/**
578+ * Optional. Title for the expression, i.e. a short string describing its purpose. This can be
579+ * used e.g. in UIs which allow to enter the expression.
580+ */
581+private final String title;
582+/**
583+ * Optional. Description of the expression. This is a longer text which describes the
584+ * expression, e.g. when hovered over it in a UI.
585+ */
586+private final String description;
587+/**
588+ * Optional. String indicating the location of the expression for error reporting, e.g. a file
589+ * name and a position in the file.
590+ */
591+private final String location;
592+593+private static final long serialVersionUID = 7358264726377291156L;
594+595+static final class Builder {
596+private String expression;
597+private String title;
598+private String description;
599+private String location;
600+601+Builder() {}
602+603+Builder(Expr expr) {
604+this.expression = expr.expression;
605+this.title = expr.title;
606+this.description = expr.description;
607+this.location = expr.location;
608+ }
609+610+Builder(com.google.api.services.bigquery.model.Expr bqExpr) {
611+this.expression = bqExpr.getExpression();
612+if (bqExpr.getTitle() != null) {
613+this.title = bqExpr.getTitle();
614+ }
615+if (bqExpr.getDescription() != null) {
616+this.description = bqExpr.getDescription();
617+ }
618+if (bqExpr.getLocation() != null) {
619+this.location = bqExpr.getLocation();
620+ }
621+ }
622+623+public Builder setExpression(String expression) {
624+this.expression = expression;
625+return this;
626+ }
627+628+public Builder setTitle(String title) {
629+this.title = title;
630+return this;
631+ }
632+633+public Builder setDescription(String description) {
634+this.description = description;
635+return this;
636+ }
637+638+public Builder setLocation(String location) {
639+this.location = location;
640+return this;
641+ }
642+643+public Expr build() {
644+return new Expr(this);
645+ }
646+ }
647+648+public Expr(Builder builder) {
649+this.expression = builder.expression;
650+this.title = builder.title;
651+this.description = builder.description;
652+this.location = builder.location;
653+ }
654+655+public Expr(String expression, String title, String description, String location) {
656+this.expression = expression;
657+this.title = title;
658+this.description = description;
659+this.location = location;
660+ }
661+662+com.google.api.services.bigquery.model.Expr toPb() {
663+com.google.api.services.bigquery.model.Expr bqExpr =
664+new com.google.api.services.bigquery.model.Expr();
665+bqExpr.setExpression(this.expression);
666+bqExpr.setTitle(this.title);
667+bqExpr.setDescription(this.description);
668+bqExpr.setLocation(this.location);
669+return bqExpr;
670+ }
671+672+static Expr fromPb(com.google.api.services.bigquery.model.Expr bqExpr) {
673+return new Builder(bqExpr).build();
674+ }
675+676+public Builder toBuilder() {
677+return new Builder(this);
678+ }
679+680+@Override
681+public int hashCode() {
682+return Objects.hash(expression, title, description, location);
683+ }
684+685+@Override
686+public boolean equals(Object obj) {
687+if (this == obj) {
688+return true;
689+ }
690+if (obj == null || getClass() != obj.getClass()) {
691+return false;
692+ }
693+final Expr other = (Expr) obj;
694+return Objects.equals(this.expression, other.expression)
695+&& Objects.equals(this.title, other.title)
696+&& Objects.equals(this.description, other.description)
697+&& Objects.equals(this.location, other.location);
698+ }
699+700+@Override
701+public String toString() {
702+return toPb().toString();
703+ }
704+ }
705+571706private Acl(Entity entity, Role role) {
707+this(entity, role, null);
708+ }
709+710+private Acl(Entity entity, Role role, Expr condition) {
572711this.entity = checkNotNull(entity);
573712this.role = role;
713+this.condition = condition;
574714 }
575715576716/** @return Returns the entity for this ACL. */
@@ -582,6 +722,10 @@ public Entity getEntity() {
582722public Role getRole() {
583723return role;
584724 }
725+/** @return Returns the condition specified by this ACL. */
726+public Expr getCondition() {
727+return condition;
728+ }
585729586730/**
587731 * @return Returns an Acl object.
@@ -592,6 +736,10 @@ public static Acl of(Entity entity, Role role) {
592736return new Acl(entity, role);
593737 }
594738739+public static Acl of(Entity entity, Role role, Expr condition) {
740+return new Acl(entity, role, condition);
741+ }
742+595743/**
596744 * @param datasetAclEntity
597745 * @return Returns an Acl object for a datasetAclEntity.
@@ -618,7 +766,7 @@ public static Acl of(Routine routine) {
618766619767@Override
620768public int hashCode() {
621-return Objects.hash(entity, role);
769+return Objects.hash(entity, role, condition);
622770 }
623771624772@Override
@@ -635,19 +783,26 @@ public boolean equals(Object obj) {
635783return false;
636784 }
637785final Acl other = (Acl) obj;
638-return Objects.equals(this.entity, other.entity) && Objects.equals(this.role, other.role);
786+return Objects.equals(this.entity, other.entity)
787+&& Objects.equals(this.role, other.role)
788+&& Objects.equals(this.condition, other.condition);
639789 }
640790641791Access toPb() {
642792Access accessPb = entity.toPb();
643793if (role != null) {
644794accessPb.setRole(role.name());
645795 }
796+if (condition != null) {
797+accessPb.setCondition(condition.toPb());
798+ }
646799return accessPb;
647800 }
648801649802static Acl fromPb(Access access) {
650803return Acl.of(
651-Entity.fromPb(access), access.getRole() != null ? Role.valueOf(access.getRole()) : null);
804+Entity.fromPb(access),
805+access.getRole() != null ? Role.valueOf(access.getRole()) : null,
806+access.getCondition() != null ? Expr.fromPb(access.getCondition()) : null);
652807 }
653808}