GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: support conditional policies by frankyn · Pull Request #110 · googleapis/java-core

This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Conversation

@frankyn

@frankyn frankyn commented Dec 20, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

fixes: #118
Add support for conditional policies based on design document.

PTAL: @broady @jkwlui @JesseLovelace @chingor13

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad added 3 commits December 17, 2019 12:15
Frank Natividad
Base implementation
67e52ce
Frank Natividad
Update with unit tests
84fcfea
Frank Natividad
lint
145f7a0
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 20, 2019
@chingor13 chingor13 changed the title Support conditional policies feat: support conditional policies Jan 6, 2020
@frankyn frankyn changed the title feat: support conditional policies fix: support conditional policies Jan 7, 2020
@frankyn frankyn changed the title fix: support conditional policies feat: support conditional policies Jan 7, 2020
Frank Natividad
correct copyright date
ac1fd6e
@codecov

codecov Bot commented Jan 7, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@d2fab21). Click here to learn what that means.
The diff coverage is 94.59%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #110   +/-   ##
=========================================
  Coverage          ?   67.98%           
  Complexity        ?      377           
=========================================
  Files             ?       36           
  Lines             ?     1968           
  Branches          ?      258           
=========================================
  Hits              ?     1338           
  Misses            ?      526           
  Partials          ?      104
Impacted Files Coverage Δ Complexity Δ
...core/src/main/java/com/google/cloud/Condition.java 100% <ø> (ø) 2 <0> (?)
...d-core/src/main/java/com/google/cloud/Binding.java 100% <100%> (ø) 2 <0> (?)
...ud-core/src/main/java/com/google/cloud/Policy.java 94.47% <93.1%> (ø) 20 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2fab21...505f9bc. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Frank Natividad added 2 commits January 7, 2020 10:50
Frank Natividad
lint
2c8724b
Frank Natividad
Revert removal of helper functions
c90dbb0
@frankyn

frankyn commented Jan 9, 2020

Copy link
Copy Markdown
Contributor Author

Hi @chingor13 @JesseLovelace @jkwlui @broady,

I resolved presubmit checks, please review when you have a moment. Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkwlui
jkwlui reviewed Jan 9, 2020
View reviewed changes

@jkwlui jkwlui left a comment

Copy link
Copy Markdown

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.

a few question, but looks good in general!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
private Condition condition;

public static class Builder {
private List<String> members = new ArrayList();

@jkwlui jkwlui Jan 8, 2020

Copy link
Copy Markdown

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.

Did we end up deciding to use a List instead of a Set for the list of members?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

I updated it to List<> instead of Set<> to get the conversation moving. I can revert back to Set<>.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
@Override
protected Policy fromPb(com.google.iam.v1.Policy policyPb) {
Map<Role, Set<Identity>> bindings = new HashMap<>();
List<Binding> bindingsList = new ArrayList<Binding>();

@jkwlui jkwlui Jan 9, 2020

Copy link
Copy Markdown

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.

Do we want to allow users to modify the binding in-place?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Jan 13, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

I'd need to allow mutations outside of builders. That's okay but it does allow for mutation directly of the policy when it wasn't allowed beforehand.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

This could use ImmutableList.Builder if we want to keep it immutable

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
setCondition(binding.condition);
}

public final Binding.Builder setRole(String role) {

@jkwlui jkwlui Jan 9, 2020

Copy link
Copy Markdown

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.

is there a reason to use String instead of Role?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

I'm trying to remove helpers from the new usage patterns. I could add them back in though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
chingor13
chingor13 reviewed Jan 10, 2020
View reviewed changes
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
private List<String> members;
private Condition condition;

public static class Builder {

@chingor13 chingor13 Jan 9, 2020

Copy link
Copy Markdown
Contributor

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.

Should we be using auto-value for these classes and builders if they are meant to be value classes?

It might be tricky if we're trying to enforce that the list of members is immutable on the actual value, but it's probably worthwhile to have these classes fully immutable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

good call I didn't think about using auto-value and I think you're right in that it can be helpful to be fully immutable reducing the number of builders.

Please correct me but I don't think I should update the Policy class but only Binding and Condition to use Auto-Value.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad added 6 commits January 21, 2020 18:30
Frank Natividad
use auto-value
b0a617f
Frank Natividad
Merge branch 'master' into conditional-policy
9dbfc2d
Frank Natividad
reformat Binding.java and Condition.java
54ad076
Frank Natividad
remove unnecessary dep
ff49620
Frank Natividad
code format
298b2be
Frank Natividad
add dep on com.google.code.findbugs in google-cloud-core
aaebba4
@frankyn
frankyn requested review from chingor13 and jkwlui January 23, 2020 17:19
@jkwlui

jkwlui commented Jan 24, 2020

Copy link
Copy Markdown

I notice there are no documentation on the fields/getter/setter for auto-value classes. @chingor13 how do we usually document these?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frankyn

frankyn commented Jan 28, 2020

Copy link
Copy Markdown
Contributor Author

I can add documentation to autovalue implementation after I get a review of the surface.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chingor13
chingor13 reviewed Jan 28, 2020
View reviewed changes
Comment thread google-cloud-core/src/main/java/com/google/cloud/Condition.java Outdated
import javax.annotation.Nullable;

@AutoValue
abstract class Condition {

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

This should probably be public?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
import javax.annotation.Nullable;

@AutoValue
abstract class Binding {

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

This should probably be public?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
abstract class Binding {
abstract String getRole();

abstract ImmutableList<String> getMembers();

@chingor13 chingor13 Jan 28, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Assuming this class is public, we want to keep guava types off the surface of the classes. This should be a List<String> and we'd document that the implementation is immutable so they shouldn't try to modify it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 21, 2020

Copy link
Copy Markdown
Contributor Author

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.

I missed this comment a while back. The reason I'm using ImmutableList<> is based on recommendation from AutoValue docs https://github.com/google/auto/blob/master/value/userguide/builders-howto.md#-use-a-collection-valued-property. I want getMembers() to support a builder helper as well in case it's easier for users.

WDYT?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 21, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

Removed ImmutableList and now using List in the surface while still supporting helper methods addMembers and removeMembers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
@Override
protected Policy fromPb(com.google.iam.v1.Policy policyPb) {
Map<Role, Set<Identity>> bindings = new HashMap<>();
List<Binding> bindingsList = new ArrayList<Binding>();

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

This could use ImmutableList.Builder if we want to keep it immutable

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google-cloud-core/src/test/java/com/google/cloud/PolicyV3Test.java Outdated

package com.google.cloud;

import static org.junit.Assert.*;

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

nit: avoid * imports

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
* Return false if Policy is version 3 OR bindings has a conditional binding.
* Return true if Policy is version 1 AND bindings does not have a conditional binding.
*/
private static boolean checkVersion(int version, List<Binding> bindingsList) {

@chingor13 chingor13 Jan 28, 2020

Copy link
Copy Markdown
Contributor

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.

I might call this isVersion. The check* methods in guava throw exceptions when conditions are not met, whereas this method is returning a boolean

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jkwlui
jkwlui approved these changes Jan 30, 2020
View reviewed changes

@jkwlui jkwlui left a comment

Copy link
Copy Markdown

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad
address comments
a5f63ea
@frankyn frankyn mentioned this pull request Feb 6, 2020
feat: add IAM Conditions support googleapis/java-storage#120
Merged
2 tasks done
frankyn and others added 2 commits February 10, 2020 20:49
@frankyn
Merge branch 'master' into conditional-policy
4873b73
Frank Natividad
Clean up
c853a84
Frank Natividad added 2 commits February 24, 2020 20:33
Frank Natividad
address feedback
108faec
Frank Natividad
split up unit test
79126b5
@frankyn
frankyn requested a review from elharo February 25, 2020 05:42
@kolea2
kolea2 dismissed their stale review February 25, 2020 16:22

comments addressed, lgtm

Frank Natividad
use guava beta annotation
505f9bc
@codecov

codecov Bot commented Feb 25, 2020

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@d2fab21). Click here to learn what that means.
The diff coverage is 94.59%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #110   +/-   ##
=========================================
  Coverage          ?   67.98%           
  Complexity        ?      377           
=========================================
  Files             ?       36           
  Lines             ?     1968           
  Branches          ?      258           
=========================================
  Hits              ?     1338           
  Misses            ?      526           
  Partials          ?      104
Impacted Files Coverage Δ Complexity Δ
...core/src/main/java/com/google/cloud/Condition.java 100% <ø> (ø) 2 <0> (?)
...d-core/src/main/java/com/google/cloud/Binding.java 100% <100%> (ø) 2 <0> (?)
...ud-core/src/main/java/com/google/cloud/Policy.java 94.47% <93.1%> (ø) 20 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2fab21...505f9bc. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Feb 25, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #110 into master will not change coverage.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #110   +/-   ##
=========================================
  Coverage     67.94%   67.94%           
  Complexity      377      377           
=========================================
  Files            36       36           
  Lines          1959     1959           
  Branches        254      254           
=========================================
  Hits           1331     1331           
  Misses          524      524           
  Partials        104      104
Impacted Files Coverage Δ Complexity Δ
...ud-core/src/main/java/com/google/cloud/Policy.java 94.84% <0%> (ø) 19 <0> (ø) ⬇️
...core/src/main/java/com/google/cloud/Timestamp.java 90.62% <100%> (ø) 25 <2> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f48a15...2b56641. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Frank Natividad added 2 commits February 25, 2020 15:15
Frank Natividad
surface ImmutableList<> for Binding class.
a89ef0c
Frank Natividad
use BetaApi from api.core
f0b5085
@frankyn

frankyn commented Feb 25, 2020

Copy link
Copy Markdown
Contributor Author

Updated based on discussion with @chingor13, @kolea2, @elharo, @jkwlui, and David (not sure of their Github handle).

Please take a look when you have a moment. Thank you for your help.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frankyn

frankyn commented Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

cc: @netdpb (David)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kolea2
kolea2 reviewed Feb 26, 2020
View reviewed changes
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
return false;
}
for (int i = 0; i < bindingsList.size(); i++) {
bindingsList.get(i).equals(other.getBindingsList().get(i));

@kolea2 kolea2 Feb 26, 2020

Copy link
Copy Markdown
Contributor

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.

sorry, missed this. Should this be returning something?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

oh, I missed this as well. Will fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kolea2 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
netdpb
netdpb reviewed Feb 26, 2020
View reviewed changes

@netdpb netdpb left a comment

Copy link
Copy Markdown

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.

I haven't finished reviewing the test code yet, but I have to run.

Feel free not to address all (or any!) of these issues in this PR if they require further discussion.

Some are pure style nits, which you should feel free to ignore anyway (like deleting the final period at the end of a Javadoc @throws clause).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java

public abstract ImmutableList<String> getMembers();

@Nullable

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Why @Nullable instead of a non-nullable Optional<Condition>?

Either is okay, but it's interesting that you're using both patterns in the same class.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

I picked Nullable because it made more sense to me in this case. I'm not well versed in Optional's. Both patterns? Not sure I understand.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@netdpb netdpb Feb 27, 2020

Copy link
Copy Markdown

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.

Sorry, I thought for some reason that you were also using Optional. Don't know why I thought that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated
public abstract static class Builder {
public abstract Builder setRole(String role);

public abstract Builder setMembers(List<String> members);

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

This could even take Iterable<String> if you want to be most general.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

Thanks, addressing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated

public abstract String getRole();

public abstract ImmutableList<String> getMembers();

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Do you expect this to be called other than from addMembers(String...) and removeMembers(String...)? If not, make this have default access.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

No, good point.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java Outdated

public abstract Builder setCondition(Condition condition);

public abstract String getRole();

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Is this used from anywhere? Do you need it? Generally, builders don't need getters.

Same for getCondition().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

removed to reduce surface size. At the moment they were convenience but I'd like to get more developer input before adding unnecessary methods to the public surface.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Condition.java Outdated
@BetaApi("This is a Beta API is not stable yet and may change in the future.")
@AutoValue
public abstract class Condition {
@Nullable

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Why are these nullable?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

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.

Good point, no reason other than my first attempt with AutoValue. removing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java
checkArgument(
!isConditional(this.version, this.bindingsList),
"getBindings() is only supported with version 1 policies and non-conditional policies");
ImmutableMap.Builder<Role, Set<Identity>> bindingsV1Builder = ImmutableMap.builder();

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

You can use an ImmutableSetMultimap instead, regardless of whether you change the method return type. You can always get the map out with Multimaps.asMap().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
}

/** Returns the list of bindings that comprises the policy for version 3. */
public List<Binding> getBindingsList() {

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Suggested change
public List<Binding> getBindingsList() {
public ImmutableList<Binding> getBindingsList() {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
return Objects.equals(bindings, other.getBindings())
&& Objects.equals(etag, other.getEtag())
&& Objects.equals(version, other.getVersion());
if (bindingsList.size() != other.getBindingsList().size()) {

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

This whole block can be just

if (!bindingsList.equals(other.getBindingsList())) {
  return false;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java Outdated
for (int i = 0; i < bindingsList.size(); i++) {
bindingsList.get(i).equals(other.getBindingsList().get(i));
}
return Objects.equals(etag, other.getEtag()) && Objects.equals(version, other.getVersion());

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

Can etag ever be null? If not, just call etag.equals(other.getEtag()).

version is an int, so you can just do version == other.getVersion(). Otherwise you're boxing the int.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/test/java/com/google/cloud/PolicyV3Test.java
Binding.newBuilder().setRole(EDITOR).setMembers(MEMBERS_LIST_2).build());
private static final List<Binding> BINDINGS_WITH_CONDITIONS =
ImmutableList.copyOf(BINDINGS_NO_CONDITIONS)
.of(

@netdpb netdpb Feb 26, 2020

Copy link
Copy Markdown

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.

You're calling a static method on an instance, and throwing the instance away. That's not what you want to do. (If the project used Error-Prone, this would have generated a warning.)

It looks like you want a variant of BINDINGS_NO_CONDITIONS where the viewer role has a condition. What about this?

ImmutableList.of(
    BINDINGS_NO_CONDITIONS.get(0).toBuilder().setCondition(...).build(),
    BINDINGS_NO_CONDITIONS.get(1))

Although it might be nice to have a constant for each element of BINDINGS_NO_CONDITIONS (VIEWER and EDITOR)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad added 6 commits February 26, 2020 12:12
Frank Natividad
return as expected
9f5e600
Frank Natividad
partial addressing of feedback
8580f5a
Frank Natividad
address feedback pt2
9fe4358
Frank Natividad
address remaining feedback
8f48a15
Frank Natividad
Merge branch 'master' into conditional-policy
615ba06
Frank Natividad
address one last feedback
2b56641
@frankyn
frankyn requested a review from kolea2 February 26, 2020 21:10
kolea2
kolea2 approved these changes Feb 27, 2020
View reviewed changes
chingor13
chingor13 approved these changes Feb 27, 2020
View reviewed changes

@chingor13 chingor13 left a comment

Copy link
Copy Markdown
Contributor

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.

We should still clean up a bunch of the review comments, but they are minor and can be done separately. We can merge, but let's not lose the work items to clean up.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@frankyn

frankyn commented Feb 27, 2020

Copy link
Copy Markdown
Contributor Author

I'll make a separate list and file an issue to track it. Thanks @chingor13!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frankyn
frankyn merged commit 61e2d19 into googleapis:master Feb 27, 2020
@frankyn
frankyn deleted the conditional-policy branch February 27, 2020 18:34
@frankyn frankyn mentioned this pull request Feb 27, 2020
Clean up tests for IAM Condition Support #169
Closed
netdpb
netdpb reviewed Feb 27, 2020
View reviewed changes
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java

public abstract ImmutableList<String> getMembers();

@Nullable

@netdpb netdpb Feb 27, 2020

Copy link
Copy Markdown

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.

Sorry, I thought for some reason that you were also using Optional. Don't know why I thought that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java
/** Create a new Binding.Builder */
public static Builder newBuilder() {
return new AutoValue_Binding.Builder();
List<String> emptyMembers = ImmutableList.of();

@netdpb netdpb Feb 27, 2020

Copy link
Copy Markdown

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.

You could just inline emptyMembers into setMembers(ImmutableList.of()).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Binding.java
/**
* Set IAM Members for Policy Binding
*
* @throws NullPointerException if a member is null.

@netdpb netdpb Feb 27, 2020

Copy link
Copy Markdown

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.

You don't really need to repeat this everywhere. It's better to use @Nullable for the hopefully few cases where null is accepted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-core/src/main/java/com/google/cloud/Policy.java
* because conditional policies are not supported
*/
public final Builder removeRole(Role role) {
checkArgument(

@netdpb netdpb Feb 27, 2020

Copy link
Copy Markdown

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.

I still think all of these should use checkState instead of checkArgument so they throw IllegalStateException.

Throw IllegalArgumentException when the caller should have known that the arguments to this method are invalid.
Throw IllegalStateException when the caller should have known that this method cannot be called given the state of the object.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gcf-merge-on-green Bot pushed a commit that referenced this pull request Feb 27, 2020
@release-please
chore: release 1.93.0 (#167)
74f8632
🤖 I have created a release \*beep\* \*boop\* 
---
## [1.93.0](https://www.github.com/googleapis/java-core/compare/v1.92.6...v1.93.0) (2020-02-27)


### Features

* support conditional policies ([#110](https://www.github.com/googleapis/java-core/issues/110)) ([61e2d19](https://www.github.com/googleapis/java-core/commit/61e2d19bb4400978681aa018a8dc200214203830))


### Bug Fixes

* fix conversion for pre-epoch timestamps ([#160](https://www.github.com/googleapis/java-core/issues/160)) ([1f8b6b4](https://www.github.com/googleapis/java-core/commit/1f8b6b4835aaa702ec94bbbde89ed90f519c935a))


### Dependencies

* update dependency com.google.api:gax-bom to v1.54.0 ([#168](https://www.github.com/googleapis/java-core/issues/168)) ([5b52f9e](https://www.github.com/googleapis/java-core/commit/5b52f9e8d8cdc82b56114d3d1e857d137ae7ca98))
* update dependency io.grpc:grpc-bom to v1.27.2 ([#166](https://www.github.com/googleapis/java-core/issues/166)) ([28c9859](https://www.github.com/googleapis/java-core/commit/28c98595c9ee96760a063085bd85024177bd6dd2))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
@chingor13 chingor13 mentioned this pull request Mar 10, 2020
Policy equality fails for binding list order #173
Closed
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release java-core 2.0.0 #653
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@elharo elharo Awaiting requested review from elharo
4 more reviewers
@netdpb netdpb netdpb left review comments
@chingor13 chingor13 chingor13 approved these changes
@jkwlui jkwlui jkwlui approved these changes
@kolea2 kolea2 kolea2 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support conditional IAM Policies

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@frankyn @jkwlui @chingor13 @elharo @netdpb @kolea2 @googlebot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.