Search in sources :

Example 6 with Binding

use of org.kie.workbench.common.dmn.api.definition.v1_1.Binding in project java-docs-samples by GoogleCloudPlatform.

the class DeviceRegistryExample method setIamPermissions.

// [END iot_get_iam_policy]
// [START iot_set_iam_policy]
/**
 * Sets IAM permissions for the given registry.
 */
public static void setIamPermissions(String projectId, String cloudRegion, String registryName, String member, String role) throws GeneralSecurityException, IOException {
    GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
    final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
    final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
    com.google.api.services.cloudiot.v1.model.Policy policy = service.projects().locations().registries().getIamPolicy(registryPath, new GetIamPolicyRequest()).execute();
    List<com.google.api.services.cloudiot.v1.model.Binding> bindings = policy.getBindings();
    boolean addNewRole = true;
    if (bindings != null) {
        for (com.google.api.services.cloudiot.v1.model.Binding binding : bindings) {
            if (binding.getRole().equals(role)) {
                List<String> members = binding.getMembers();
                members.add(member);
                binding.setMembers(members);
                addNewRole = false;
            }
        }
    } else {
        bindings = new ArrayList<>();
    }
    if (addNewRole) {
        com.google.api.services.cloudiot.v1.model.Binding bind = new com.google.api.services.cloudiot.v1.model.Binding();
        bind.setRole(role);
        List<String> members = new ArrayList<>();
        members.add(member);
        bind.setMembers(members);
        bindings.add(bind);
    }
    policy.setBindings(bindings);
    SetIamPolicyRequest req = new SetIamPolicyRequest().setPolicy(policy);
    policy = service.projects().locations().registries().setIamPolicy(registryPath, req).execute();
    System.out.println("Policy ETAG: " + policy.getEtag());
    for (com.google.api.services.cloudiot.v1.model.Binding binding : policy.getBindings()) {
        System.out.println(String.format("Role: %s", binding.getRole()));
        System.out.println("Binding members: ");
        for (String mem : binding.getMembers()) {
            System.out.println(String.format("\t%s", mem));
        }
    }
}
Also used : Binding(com.google.iam.v1.Binding) CloudIot(com.google.api.services.cloudiot.v1.CloudIot) SetIamPolicyRequest(com.google.api.services.cloudiot.v1.model.SetIamPolicyRequest) JsonFactory(com.google.api.client.json.JsonFactory) ArrayList(java.util.ArrayList) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) GetIamPolicyRequest(com.google.api.services.cloudiot.v1.model.GetIamPolicyRequest) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Example 7 with Binding

use of org.kie.workbench.common.dmn.api.definition.v1_1.Binding in project java-docs-samples by GoogleCloudPlatform.

the class DeviceRegistryExample method createIotTopic.

/**
 * Creates a topic and grants the IoT service account access.
 */
public static Topic createIotTopic(String projectId, String topicId) throws Exception {
    // Create a new topic
    final TopicName topicName = TopicName.create(projectId, topicId);
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        final Topic topic = topicAdminClient.createTopic(topicName);
        com.google.iam.v1.Policy policy = topicAdminClient.getIamPolicy(topicName.toString());
        // add role -> members binding
        Binding binding = Binding.newBuilder().addMembers("serviceAccount:cloud-iot@system.gserviceaccount.com").setRole(Role.owner().toString()).build();
        // create updated policy
        com.google.iam.v1.Policy updatedPolicy = com.google.iam.v1.Policy.newBuilder(policy).addBindings(binding).build();
        topicAdminClient.setIamPolicy(topicName.toString(), updatedPolicy);
        System.out.println("Setup topic / policy for: " + topic.getName());
        return topic;
    }
}
Also used : Binding(com.google.iam.v1.Binding) TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) Topic(com.google.pubsub.v1.Topic) TopicName(com.google.pubsub.v1.TopicName)

Example 8 with Binding

use of org.kie.workbench.common.dmn.api.definition.v1_1.Binding in project google-cloud-java by GoogleCloudPlatform.

the class SourceSnippets method setIamPolicySource.

// [END securitycenter_get_source]
/**
 * Set IAM policy for a source.
 *
 * @param sourceName The source to set IAM Policy for.
 */
// [START securitycenter_set_source_iam]
static Policy setIamPolicySource(SourceName sourceName, String userEmail) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // userEmail = "someuser@domain.com"
        // Set up IAM Policy for the user userMail to use the role findingsEditor.
        // The user must be a valid google account.
        Policy oldPolicy = client.getIamPolicy(sourceName.toString());
        Binding bindings = Binding.newBuilder().setRole("roles/securitycenter.findingsEditor").addMembers("user:" + userEmail).build();
        Policy policy = oldPolicy.toBuilder().addBindings(bindings).build();
        // Start setting up a request to set IAM policy for a source.
        // SourceName sourceName = SourceName.of("123234324", "423432321");
        SetIamPolicyRequest.Builder request = SetIamPolicyRequest.newBuilder().setPolicy(policy).setResource(sourceName.toString());
        // Call the API.
        Policy response = client.setIamPolicy(request.build());
        System.out.println("Policy: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Policy(com.google.iam.v1.Policy) Binding(com.google.iam.v1.Binding) SetIamPolicyRequest(com.google.iam.v1.SetIamPolicyRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 9 with Binding

use of org.kie.workbench.common.dmn.api.definition.v1_1.Binding in project kie-wb-common by kiegroup.

the class InvocationEditorDefinition method getModelClass.

@Override
public Optional<Invocation> getModelClass() {
    final Invocation invocation = new Invocation();
    invocation.setExpression(new LiteralExpression());
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name("p0"));
    final Binding binding = new Binding();
    binding.setParameter(parameter);
    invocation.getBinding().add(binding);
    return Optional.of(invocation);
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.v1_1.Binding) Invocation(org.kie.workbench.common.dmn.api.definition.v1_1.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasName(org.kie.workbench.common.dmn.api.definition.HasName)

Example 10 with Binding

use of org.kie.workbench.common.dmn.api.definition.v1_1.Binding in project kie-wb-common by kiegroup.

the class AddParameterBindingCommandTest method makeCommand.

private void makeCommand(final int uiRowIndex, final String bindingName, final DMNGridRow uiGridRow) {
    final Binding rowEntry = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name(bindingName));
    rowEntry.setParameter(parameter);
    makeCommand(uiRowIndex, rowEntry, uiGridRow);
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.v1_1.Binding) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Aggregations

Binding (com.google.iam.v1.Binding)6 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)6 Policy (com.google.iam.v1.Policy)4 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)4 Invocation (org.kie.workbench.common.dmn.api.definition.v1_1.Invocation)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)3 TopicName (com.google.pubsub.v1.TopicName)2 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)2 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)2 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 JsonFactory (com.google.api.client.json.JsonFactory)1 CloudIot (com.google.api.services.cloudiot.v1.CloudIot)1 GetIamPolicyRequest (com.google.api.services.cloudiot.v1.model.GetIamPolicyRequest)1 SetIamPolicyRequest (com.google.api.services.cloudiot.v1.model.SetIamPolicyRequest)1 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)1 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)1 TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)1 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)1 SetIamPolicyRequest (com.google.iam.v1.SetIamPolicyRequest)1