| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright 2020 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud; | ||
|
|
||
| import static com.google.common.base.Predicates.in; | ||
| import static com.google.common.base.Predicates.not; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.base.Predicate; | ||
| import com.google.common.collect.Collections2; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.Lists; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access | ||
| * 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. | ||
| * | ||
| * @see <a href="https://cloud.google.com/iam/docs/reference/rest/v1/Policy">Policy</a> | ||
| */ | ||
| @BetaApi("This is a Beta API is not stable yet and may change in the future.") | ||
| @AutoValue | ||
| public abstract class Binding { | ||
|
Comment thread
chingor13 marked this conversation as resolved.
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI'd very much recommend Javadoc for public types and public methods that aren't obvious.
Sorry, something went wrong.
All reactions
|
||
| /** Get IAM Policy Binding Role */ | ||
| public abstract String getRole(); | ||
|
|
||
| /** Get IAM Policy Binding Members */ | ||
| public abstract ImmutableList<String> getMembers(); | ||
|
|
||
| /** Get IAM Policy Binding Condition */ | ||
| @Nullable | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhy @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.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI 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.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, I thought for some reason that you were also using Optional. Don't know why I thought that.
Sorry, something went wrong.
All reactions
|
||
| public abstract Condition getCondition(); | ||
|
|
||
| /** Create a Binding.Builder from an existing Binding */ | ||
| public abstract Builder toBuilder(); | ||
|
|
||
| /** Create a new Binding.Builder */ | ||
| public static Builder newBuilder() { | ||
| List<String> emptyMembers = ImmutableList.of(); | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou could just inline emptyMembers into setMembers(ImmutableList.of()).
Sorry, something went wrong.
All reactions
|
||
| return new AutoValue_Binding.Builder().setMembers(emptyMembers); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| /** | ||
| * Set IAM Role for Policy Binding | ||
| * | ||
| * @throws NullPointerException if the role is null. | ||
| */ | ||
| public abstract Builder setRole(String role); | ||
|
|
||
| /** | ||
| * Set IAM Members for Policy Binding | ||
| * | ||
| * @throws NullPointerException if a member is null. | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou 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.
All reactions
|
||
| */ | ||
| public abstract Builder setMembers(Iterable<String> members); | ||
|
|
||
| /** Set IAM Condition for Policy Binding */ | ||
| public abstract Builder setCondition(Condition condition); | ||
|
|
||
| /** Internal use to getMembers() in addMembers() and removeMembers() */ | ||
| abstract ImmutableList<String> getMembers(); | ||
|
|
||
| /** | ||
| * Add members to Policy Binding. | ||
| * | ||
| * @throws NullPointerException if a member is null. | ||
| */ | ||
| public Builder addMembers(String member, String... moreMembers) { | ||
| ImmutableList.Builder<String> membersBuilder = ImmutableList.builder(); | ||
| membersBuilder.addAll(getMembers()); | ||
| membersBuilder.addAll(Lists.asList(member, moreMembers)); | ||
| setMembers(membersBuilder.build()); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Remove members to Policy Binding. | ||
| * | ||
| * @throws NullPointerException if a member is null. | ||
| */ | ||
| public Builder removeMembers(String... members) { | ||
| Predicate<String> selectMembersNotInList = not(in(Arrays.asList(members))); | ||
| Collection<String> filter = Collections2.filter(getMembers(), selectMembersNotInList); | ||
| setMembers(filter); | ||
| return this; | ||
| } | ||
|
|
||
| public abstract Binding build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright 2020 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.auto.value.AutoValue; | ||
|
|
||
| /** | ||
| * Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access | ||
| * 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. | ||
| * | ||
| * @see <a href="https://cloud.google.com/iam/docs/reference/rest/v1/Policy">Policy</a> | ||
| * @see <a href="https://cloud.google.com/iam/docs/conditions-overview">IAM Conditions</a> | ||
| */ | ||
| @BetaApi("This is a Beta API is not stable yet and may change in the future.") | ||
| @AutoValue | ||
| public abstract class Condition { | ||
| /** Get IAM Policy Binding Condition Title */ | ||
| public abstract String getTitle(); | ||
|
|
||
| /** Get IAM Policy Binding Condition Description */ | ||
| public abstract String getDescription(); | ||
|
|
||
| /** Get IAM Policy Binding Condition Expression */ | ||
| public abstract String getExpression(); | ||
|
|
||
| /** Create a new Condition.Builder from an existing Condition */ | ||
| public abstract Builder toBuilder(); | ||
|
|
||
| /** Create a new Condition.Builder */ | ||
| public static Builder newBuilder() { | ||
| return new AutoValue_Condition.Builder(); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| /** Set IAM Policy Binding Condition Title */ | ||
| public abstract Builder setTitle(String title); | ||
|
|
||
| /** Set IAM Policy Binding Condition Description */ | ||
| public abstract Builder setDescription(String description); | ||
|
|
||
| /** Set IAM Policy Binding Condition Expression */ | ||
| public abstract Builder setExpression(String expression); | ||
|
|
||
| /** Build Builder which creates a Condition instance */ | ||
| public abstract Condition build(); | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.