@Override protected Policy fromPb(com.google.iam.v1.Policy policyPb) { Map<Role, Set<Identity>> bindings = new HashMap<>(); for (com.google.iam.v1.Binding bindingPb : policyPb.getBindingsList()) { bindings.put( Role.of(bindingPb.getRole()), ImmutableSet.copyOf( Lists.transform( bindingPb.getMembersList(), new Function<String, Identity>() { @Override public Identity apply(String s) { return IDENTITY_VALUE_OF_FUNCTION.apply(s); } }))); } return newBuilder() .setBindings(bindings) .setEtag( policyPb.getEtag().isEmpty() ? null : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) .setVersion(policyPb.getVersion()) .build(); }
Policy.newBuilder().setBindings(null); fail("Null bindings map should cause exception."); } catch (NullPointerException ex) { Map<Role, Set<Identity>> bindings = new HashMap<>(); bindings.put(VIEWER, null); Policy.newBuilder().setBindings(bindings); fail("Null set of identities should cause exception."); } catch (NullPointerException ex) { identities.add(null); bindings.put(VIEWER, identities); Policy.newBuilder().setBindings(bindings); fail("Null identity should cause exception."); } catch (IllegalArgumentException ex) {
Map<Role, Set<Identity>> editorBinding = ImmutableMap.<Role, Set<Identity>>builder().put(EDITOR, BINDINGS.get(EDITOR)).build(); Policy policy = FULL_POLICY.toBuilder().setBindings(editorBinding).build(); assertEquals(editorBinding, policy.getBindings()); assertEquals("etag", policy.getEtag());
@Override protected Policy fromPb(com.google.iam.v1.Policy policyPb) { Map<Role, Set<Identity>> bindings = new HashMap<>(); for (com.google.iam.v1.Binding bindingPb : policyPb.getBindingsList()) { bindings.put( Role.of(bindingPb.getRole()), ImmutableSet.copyOf( Lists.transform( bindingPb.getMembersList(), new Function<String, Identity>() { @Override public Identity apply(String s) { return IDENTITY_VALUE_OF_FUNCTION.apply(s); } }))); } return newBuilder() .setBindings(bindings) .setEtag( policyPb.getEtag().isEmpty() ? null : BaseEncoding.base64().encode(policyPb.getEtag().toByteArray())) .setVersion(policyPb.getVersion()) .build(); }
@InternalApi("This class should only be extended within google-cloud-java") protected Builder(Policy policy) { setBindings(policy.bindings); setEtag(policy.etag); setVersion(policy.version); }
@InternalApi("This class should only be extended within google-cloud-java") protected Builder(Policy policy) { setBindings(policy.bindings); setEtag(policy.etag); setVersion(policy.version); }