Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
67e52ce
Base implementation
Dec 17, 2019
84fcfea
Update with unit tests
Dec 20, 2019
145f7a0
lint
Dec 20, 2019
ac1fd6e
correct copyright date
Jan 7, 2020
2c8724b
lint
Jan 7, 2020
c90dbb0
Revert removal of helper functions
Jan 8, 2020
b0a617f
use auto-value
Jan 22, 2020
9dbfc2d
Merge branch 'master' into conditional-policy
Jan 22, 2020
54ad076
reformat Binding.java and Condition.java
Jan 22, 2020
ff49620
remove unnecessary dep
Jan 22, 2020
298b2be
code format
Jan 22, 2020
aaebba4
add dep on com.google.code.findbugs in google-cloud-core
Jan 22, 2020
a5f63ea
address comments
Feb 6, 2020
4873b73
Merge branch 'master' into conditional-policy
frankyn Feb 11, 2020
c853a84
Clean up
Feb 11, 2020
c64e55a
Merge branch 'conditional-policy' of github.com:frankyn/java-core int…
Feb 11, 2020
d2fab21
respond to comments
Feb 19, 2020
86cd863
Merge branch 'master' into conditional-policy
Feb 19, 2020
085959d
address comments
Feb 20, 2020
174e8c4
format
Feb 20, 2020
14e1aac
address feedback
Feb 21, 2020
fdb040a
remove unnecessary null check
Feb 21, 2020
42199d1
lint
Feb 21, 2020
bbb708a
address feedback
Feb 21, 2020
7f0e33e
remove ImmutableList from Binding AutoValue surface
Feb 21, 2020
108faec
address feedback
Feb 25, 2020
79126b5
split up unit test
Feb 25, 2020
505f9bc
use guava beta annotation
Feb 25, 2020
a89ef0c
surface ImmutableList<> for Binding class.
Feb 25, 2020
f0b5085
use BetaApi from api.core
Feb 25, 2020
9f5e600
return as expected
Feb 26, 2020
8580f5a
partial addressing of feedback
Feb 26, 2020
9fe4358
address feedback pt2
Feb 26, 2020
8f48a15
address remaining feedback
Feb 26, 2020
615ba06
Merge branch 'master' into conditional-policy
Feb 26, 2020
2b56641
address one last feedback
Feb 26, 2020
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
Prev Previous commit
Next Next commit
address feedback
  • Loading branch information
Frank Natividad committed Feb 21, 2020
commit 14e1aaca23afd9af1f7f8149653ed8a195b489fa
1 change: 0 additions & 1 deletion google-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<dependency>
Comment thread
chingor13 marked this conversation as resolved.
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public abstract static class Builder {

public Builder addMembers(String... members) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't make sense to call this with no arguments, right? If you change it to the following, then that wouldn't even compile.

Suggested change
public Builder addMembers(String... members) {
public Builder addMembers(String member, String... moreMembers) {

You can then use Guava's Lists.asList(member, moreMembers) (a good static import method) to combine those two into one list to add.

for (String member : members) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (String member : members) {
membersBuilder.add(members);

That should work, no?


membersBuilder().add(member);
}
return this;
Expand Down
17 changes: 9 additions & 8 deletions google-cloud-core/src/main/java/com/google/cloud/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

/**
* Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access
* settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns a set of
* settings for Cloud Platform resources. A policy is a list of bindings. A binding assigns a set of
* identities to a role, where the identities can be user accounts, Google groups, Google domains,
* and service accounts. A role is a named list of permissions defined by IAM.
*
Expand Down Expand Up @@ -174,8 +174,8 @@ protected Builder(Policy policy) {
* Replaces the builder's map of bindings with the given map of bindings.
*
* @throws NullPointerException if the given map is null or contains any null keys or values
* @throws IllegalArgumentException if any identities in the given map are null
* @throws IllegalArgumentException if policy version is equal to 3 or has conditional bindings.
* @throws IllegalArgumentException if any identities in the given map are null or if policy
* version is equal to 3 or has conditional bindings.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* version is equal to 3 or has conditional bindings.
* version is equal to 3 or has conditional bindings

*/
public final Builder setBindings(Map<Role, Set<Identity>> bindings) {
checkNotNull(bindings, "The provided map of bindings cannot be null.");
Expand Down Expand Up @@ -204,7 +204,8 @@ public final Builder setBindings(Map<Role, Set<Identity>> bindings) {
/**
* Replaces the builder's List of bindings with the given List of Bindings.
*
* @throws NullPointerException if the given map is null or contains any null keys or values
* @throws NullPointerException if the given list is null or contains any null members in
* bindings.
* @throws IllegalArgumentException if any identities in the given map are null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant/contradicts the above NullPointerException

*/
public final Builder setBindings(List<Binding> bindings) {
Expand Down Expand Up @@ -256,7 +257,7 @@ public final Builder addIdentity(Role role, Identity first, Identity... others)
checkNotNull(first, nullIdentityMessage);
checkNotNull(others, nullIdentityMessage);
checkNotNull(role, "The role cannot be null.");
for (int i = 0; i < bindingsList.size(); ++i) {
for (int i = 0; i < bindingsList.size(); i++) {
Binding binding = bindingsList.get(i);
if (binding.getRole().equals(role.getValue())) {
Binding.Builder bindingBuilder = binding.toBuilder().addMembers(first.strValue());
Expand Down Expand Up @@ -290,7 +291,7 @@ public final Builder removeIdentity(Role role, Identity first, Identity... other
checkNotNull(first, nullIdentityMessage);
checkNotNull(others, nullIdentityMessage);
checkNotNull(role, "The role cannot be null.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Alternatively, you could have a private static method that takes a Role, an Identity, and an Identity[] and checks that none is null.

for (int i = 0; i < bindingsList.size(); ++i) {
for (int i = 0; i < bindingsList.size(); i++) {
Binding binding = bindingsList.get(i);
if (binding.getRole().equals(role.getValue())) {
Binding.Builder bindingBuilder = binding.toBuilder().removeMembers(first.strValue());
Expand Down Expand Up @@ -374,7 +375,7 @@ public Map<Role, Set<Identity>> getBindings() {
return bindingsV1Builder.build();
}

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

Copy link
Copy Markdown

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() {

return bindingsList;
}
Expand Down Expand Up @@ -428,7 +429,7 @@ public boolean equals(Object obj) {
if (bindingsList.size() != other.getBindingsList().size()) {

Copy link
Copy Markdown

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;
}

return false;
}
for (int i = 0; i < bindingsList.size(); ++i) {
for (int i = 0; i < bindingsList.size(); i++) {
bindingsList.get(i).equals(other.getBindingsList().get(i));

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

}
return Objects.equals(etag, other.getEtag()) && Objects.equals(version, other.getVersion());

Copy link
Copy Markdown

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.cloud.Policy.DefaultMarshaller;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;

Expand Down Expand Up @@ -116,7 +117,7 @@ public void removeMemberFromPolicy() {
assertEquals(3, FULL_POLICY_V3.getBindingsList().get(0).getMembers().size());
List<Binding> bindings = new ArrayList<>(FULL_POLICY_V3.getBindingsList());

for (int i = 0; i < bindings.size(); ++i) {
for (int i = 0; i < bindings.size(); i++) {
Binding binding = bindings.get(i);
if (binding.getRole().equals(VIEWER)) {
bindings.set(i, binding.toBuilder().removeMembers(ALL_USERS).build());
Expand All @@ -133,7 +134,7 @@ public void addMemberFromPolicy() {
assertEquals(3, FULL_POLICY_V3.getBindingsList().get(0).getMembers().size());
List<Binding> bindings = new ArrayList<>(FULL_POLICY_V3.getBindingsList());

for (int i = 0; i < bindings.size(); ++i) {
for (int i = 0; i < bindings.size(); i++) {
Binding binding = bindings.get(i);
if (binding.getRole().equals(VIEWER)) {
bindings.set(i, binding.toBuilder().addMembers("user:example@example.com").build());
Expand All @@ -149,10 +150,11 @@ public void removeBindingFromPolicy() {
assertEquals(2, FULL_POLICY_V3.getBindingsList().size());
List<Binding> bindings = new ArrayList<>(FULL_POLICY_V3.getBindingsList());

for (int i = 0; i < bindings.size(); ++i) {
Binding binding = bindings.get(i);
Iterator iterator = bindings.iterator();
while (iterator.hasNext()) {
Binding binding = (Binding) iterator.next();
if (binding.getRole().equals(EDITOR) && binding.getCondition() == null) {
bindings.remove(i);
iterator.remove();
break;
}
}
Expand Down