Mayil-AI-Sandbox / klaw-june23

Apache License 2.0
0 stars 0 forks source link

Missing Principal information when grouping acls #22

Open vikramsubramanian opened 1 month ago

vikramsubramanian commented 1 month ago

What happened?

I created an ACL for a standard kafka env and when I tried to order by "Team" the principal/username entry disapeared.

What did you expect to happen?

Screenshot 2024-08-02 at 1 13 15 PM

Rest Call /getTopicOverview?environmentId=2&groupBy=NONE&topicName=Release250 response { "topicExists": true, "schemaExists": false, "prefixAclsExists": false, "txnAclsExists": false, "createSchemaAllowed": false, "topicInfoList": ...... "aclInfoList": [ { "req_no": "1048", "aclPatternType": "LITERAL", "environment": "2", "environmentName": "TST", "kafkaFlavorType": "APACHE_KAFKA", "showDeleteAcl": true, "teamid": 1005, "teamname": "ralph", "topicname": "Release250", "topictype": "Producer", "acl_ip": "127.0.0.1", "acl_ssl": "User:" }, { "req_no": "1049", "aclPatternType": "LITERAL", "environment": "2", "environmentName": "TST", "kafkaFlavorType": "APACHE_KAFKA", "showDeleteAcl": true, "teamid": 1005, "teamname": "ralph", "topicname": "Release250", "topictype": "Consumer", "acl_ip": "127.0.0.1", "acl_ssl": "User:", "consumergroup": "releaseOne" } ], ......

Screenshot 2024-08-02 at 1 13 28 PM

returned json

Rest Call

response { "topicExists": true, "schemaExists": false, "prefixAclsExists": false, "txnAclsExists": false, "createSchemaAllowed": false, "topicInfoList": ....... "aclInfoList": [ { "req_no": "1049", "aclPatternType": "LITERAL", "environment": "2", "environmentName": "TST", "kafkaFlavorType": "APACHE_KAFKA", "showDeleteAcl": true, "teamid": 1005, "teamname": "ralph", "topicname": "Release250", "topictype": "Consumer", "acl_ips": [ "127.0.0.1" ], "acl_ssls": [], "consumergroup": "releaseOne" }, { "req_no": "1048", "aclPatternType": "LITERAL", "environment": "2", "environmentName": "TST", "kafkaFlavorType": "APACHE_KAFKA", "showDeleteAcl": true, "teamid": 1005, "teamname": "ralph", "topicname": "Release250", "topictype": "Producer", "acl_ips": [ "127.0.0.1" ], "acl_ssls": [] } ],

The principals should be combined and entries shown in one row item based on team and if it is a producer or consumer. The aclSSL array should have returned "acl_ssl": ["User:*"],

mayil-ai[bot] commented 1 month ago

To address the issue where the acl_ssl entry disappears when ordering ACLs by "Team," follow these actionable steps:

Code Changes:

  1. Update mergeReduceAcls method in BaseOverviewService.java:
private List<AclOverviewInfo> mergeReduceAcls(List<AclOverviewInfo> aclInfo) {
    AclOverviewInfo producerIp = null, producerPrincipal = null;
    AclOverviewInfo consumerIp = null, consumerPrincipal = null;

    for (AclOverviewInfo info : aclInfo) {
        if (info.getTopictype().equals(AclType.PRODUCER.value)) {
            if (info.getAcl_ip() != null && !info.getAcl_ip().isEmpty()) {
                producerIp = initializeAclInfo(producerIp, info);
                producerIp.getAcl_ips().add(info.getAcl_ip());
            } else if (info.getAcl_ssl() != null && !info.getAcl_ssl().isEmpty()) {
                producerPrincipal = initializeAclInfo(producerPrincipal, info);
                producerPrincipal.getAcl_ssls().add(info.getAcl_ssl());
            }
        } else if (info.getTopictype().equals(AclType.CONSUMER.value)) {
            if (info.getAcl_ip() != null && !info.getAcl_ip().isEmpty()) {
                consumerIp = initializeAclInfo(consumerIp, info);
                consumerIp.getAcl_ips().add(info.getAcl_ip());
            } else if (info.getAcl_ssl() != null && !info.getAcl_ssl().isEmpty()) {
                consumerPrincipal = initializeAclInfo(consumerPrincipal, info);
                consumerPrincipal.getAcl_ssls().add(info.getAcl_ssl());
            }
        }
    }

    return addToListIfNotNull(producerIp, producerPrincipal, consumerIp, consumerPrincipal);
}

private List<AclOverviewInfo> addToListIfNotNull(
    AclOverviewInfo producerIp,
    AclOverviewInfo producerPrincipal,
    AclOverviewInfo consumerIp,
    AclOverviewInfo consumerPrincipal) {
    List<AclOverviewInfo> buildList = new ArrayList<>();
    if (producerIp != null) {
        buildList.add(producerIp);
    }
    if (consumerIp != null) {
        buildList.add(consumerIp);
    }
    if (producerPrincipal != null) {
        buildList.add(producerPrincipal);
    }
    if (consumerPrincipal != null) {
        buildList.add(consumerPrincipal);
    }
    return buildList;
}

private AclOverviewInfo initializeAclInfo(AclOverviewInfo newAcl, AclOverviewInfo info) {
    if (newAcl == null) {
        newAcl = new AclOverviewInfo();
        copyProperties(info, newAcl);
        newAcl.setAcl_ips(new HashSet<>());
        newAcl.setAcl_ssls(new HashSet<>());
        // remove old information from the copy properties that is no longer needed to avoid confusion.
        newAcl.setAcl_ip(null);
        newAcl.setAcl_ssl(null);
    }
    return newAcl;
}
  1. Update sortAclInfo method in BaseOverviewService.java:
private List<AclOverviewInfo> sortAclInfo(List<AclOverviewInfo> aclInfo, AclGroupBy groupBy) {
    // merge reduce
    if (groupBy.equals(AclGroupBy.TEAM)) {
        aclInfo = mergeReduceAclInfo(aclInfo);
        aclInfo.sort(
            Comparator.comparing(AclOverviewInfo::getTeamname, nullSafeStringComparator)
                .thenComparing(AclOverviewInfo::getConsumergroup, nullSafeStringComparator));
    }

    return aclInfo;
}

By ensuring the acl_ssl field is correctly aggregated and handled in the merging and sorting methods, the principal/username information should be correctly displayed when grouping ACLs by team.

Here are some code snippets that may help you get started:

💡 To rerun Mayil, comment mayil-ai rerun. Mayil will incorporate any new context added to the ticket. Include details in your rerun comment to guide Mayil!