Skip to content

Commit

Permalink
Merge branch 'main' into npe
Browse files Browse the repository at this point in the history
  • Loading branch information
muralibasani authored Sep 26, 2022
2 parents b7793f2 + 1f70562 commit 8b3f7e3
Show file tree
Hide file tree
Showing 70 changed files with 1,232 additions and 2,348 deletions.
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/01_question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: ❓ Ask a question
about: Got stuck or missing something from the docs? Ask away!
---

# What can we help you with?

<!-- Try to explain your question with as much detail as you can provide. -->

# Where would you expect to find this information?

<!-- Feel free to point us where with links or even proposing new sections or pages in the documentation. -->
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/02_bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: 🐜 Report a bug
about: Spotted a problem? Let us know
---

# What happened?

<!-- Try to be as precise as possible. If you can a small reproducer example would be great! -->

# What did you expect to happen?

<!-- Please explain what would be the expected behavior for this particular case, ideally, with examples. -->

# What else do we need to know?

<!-- Include your platform, version, and any other information that seems relevant. -->
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/03_feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: 💡 Feature suggestion
about: What would make this even better?
---

# What is currently missing?

<!-- Please, describe what is currently missing and why should it be present in the project. -->

# How could this be improved?

<!-- If you already know how this could be approached, please provide some brief explanation about it. -->

# Is this a feature you would work on yourself?

* [ ] I plan to open a pull request for this feature
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Aiven Security Bug Bounty
url: https://hackerone.com/aiven_ltd
about: Our bug bounty program.
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
About this change - What it does

Resolves: #xxxxx
Why this way
1 change: 1 addition & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release Notes:
- Introduced 'kafka flavor' in the configuration of clusters
- Changes to manage Aiven Acls
- All occurences of Kafkawize renamed to Klaw
- Synchronize Aiven kafka acls from cluster to Klaw (for existing Kafka clusters)
- Few code enhancements

-----------------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/aiven/klaw/controller/AclController.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ public ResponseEntity<String> declineAclRequests(
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<TopicOverview> getAcls(
@RequestParam(value = "topicnamesearch") String topicNameSearch) {
return new ResponseEntity<>(aclControllerService.getAcls(topicNameSearch), HttpStatus.OK);
}

@RequestMapping(
value = "/getSchemaOfTopic",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<TopicOverview> getSchemaOfTopic(
@RequestParam(value = "topicnamesearch") String topicNameSearch,
@RequestParam(value = "schemaVersionSearch", defaultValue = "") String schemaVersionSearch) {
return new ResponseEntity<>(
aclControllerService.getAcls(topicNameSearch, schemaVersionSearch), HttpStatus.OK);
aclControllerService.getSchemaOfTopic(topicNameSearch, schemaVersionSearch), HttpStatus.OK);
}

@RequestMapping(
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/aiven/klaw/dao/Acl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.aiven.klaw.dao;

import io.aiven.klaw.model.AclIPPrincipleType;
import java.io.Serializable;
import javax.persistence.*;
import lombok.Getter;
Expand Down Expand Up @@ -61,4 +62,7 @@ public class Acl implements Serializable {

@Column(name = "jsonparams")
private String jsonParams;

@Column(name = "aclipprincipletype")
private AclIPPrincipleType aclIpPrincipleType;
}
47 changes: 29 additions & 18 deletions src/main/java/io/aiven/klaw/service/AclControllerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.aiven.klaw.model.AclInfo;
import io.aiven.klaw.model.AclRequestsModel;
import io.aiven.klaw.model.KafkaClustersType;
import io.aiven.klaw.model.KafkaFlavors;
import io.aiven.klaw.model.PermissionType;
import io.aiven.klaw.model.RequestStatus;
import io.aiven.klaw.model.SyncAclUpdates;
Expand Down Expand Up @@ -716,13 +717,15 @@ public String declineAclRequests(String req_no, String reasonToDecline) {

private List<Map<String, String>> getAclListFromCluster(
String bootstrapHost,
Env envSelected,
String protocol,
String clusterName,
String topicNameSearch,
int tenantId)
throws KlawException {
List<Map<String, String>> aclList;
aclList = clusterApiService.getAcls(bootstrapHost, protocol, clusterName, tenantId);
aclList =
clusterApiService.getAcls(bootstrapHost, envSelected, protocol, clusterName, tenantId);
return updateConsumerGroups(groupAcls(aclList, topicNameSearch, true), aclList);
}

Expand Down Expand Up @@ -849,7 +852,7 @@ private List<Topic> getFilteredTopicsForTenant(List<Topic> topicsFromSOT) {
return topicsFromSOT;
}

public TopicOverview getAcls(String topicNameSearch, String schemaVersionSearch) {
public TopicOverview getAcls(String topicNameSearch) {
log.debug("getAcls {}", topicNameSearch);
String userDetails = getUserName();
HandleDbRequests handleDb = manageDatabase.getHandleDbRequests();
Expand Down Expand Up @@ -1025,9 +1028,17 @@ public TopicOverview getAcls(String topicNameSearch, String schemaVersionSearch)
topicOverview.setPromotionDetails(hashMap);
}

return topicOverview;
}

public TopicOverview getSchemaOfTopic(String topicNameSearch, String schemaVersionSearch) {
HandleDbRequests handleDb = manageDatabase.getHandleDbRequests();
int tenantId = commonUtilsService.getTenantId(getUserName());
TopicOverview topicOverview = new TopicOverview();
topicOverview.setTopicExists(true);
boolean retrieveSchemas = true;
updateAvroSchema(
topicNameSearch, schemaVersionSearch, handleDb, retrieveSchemas, topicOverview, tenantId);

return topicOverview;
}

Expand Down Expand Up @@ -1147,22 +1158,16 @@ public List<AclInfo> getSyncAcls(
List<Map<String, String>> aclList;

Env envSelected = getEnvDetails(env, tenantId);
String bootstrapHost =
KwClusters kwClusters =
manageDatabase
.getClusters(KafkaClustersType.KAFKA.value, tenantId)
.get(envSelected.getClusterId())
.getBootstrapServers();
.get(envSelected.getClusterId());
aclList =
getAclListFromCluster(
bootstrapHost,
manageDatabase
.getClusters(KafkaClustersType.KAFKA.value, tenantId)
.get(envSelected.getClusterId())
.getProtocol(),
manageDatabase
.getClusters(KafkaClustersType.KAFKA.value, tenantId)
.get(envSelected.getClusterId())
.getClusterName(),
kwClusters.getBootstrapServers(),
envSelected,
kwClusters.getProtocol(),
kwClusters.getClusterName(),
topicNameSearch,
tenantId);

Expand All @@ -1172,7 +1177,8 @@ public List<AclInfo> getSyncAcls(
return getAclsList(
pageNo,
currentPage,
applyFiltersAcls(env, aclList, aclsFromSOT, isReconciliation, tenantId));
applyFiltersAcls(
env, aclList, aclsFromSOT, isReconciliation, tenantId, kwClusters.getKafkaFlavor()));
}

public List<AclInfo> getSyncBackAcls(
Expand Down Expand Up @@ -1233,7 +1239,8 @@ private List<AclInfo> applyFiltersAcls(
List<Map<String, String>> aclList,
List<Acl> aclsFromSOT,
boolean isReconciliation,
int tenantId) {
int tenantId,
String kafkaFlavor) {

List<AclInfo> aclListMap = new ArrayList<>();
List<String> teamList = new ArrayList<>();
Expand Down Expand Up @@ -1268,7 +1275,9 @@ else if ("READ".equals(tmpPermType)) {

if (acl_ssl == null || acl_ssl.equals("")) acl_ssl = "User:*";
else {
if (!"User:*".equals(acl_ssl) && !acl_ssl.startsWith("User:")) {
if (!KafkaFlavors.AIVEN_FOR_APACHE_KAFKA.value.equals(kafkaFlavor)
&& !"User:*".equals(acl_ssl)
&& !acl_ssl.startsWith("User:")) {
acl_ssl = "User:" + acl_ssl;
}
}
Expand All @@ -1292,6 +1301,8 @@ else if ("READ".equals(tmpPermType)) {
if ("Unknown".equals(mp.getTeamname()) || "".equals(mp.getTeamname())) aclListMap.add(mp);
} else {
if (teamList.contains(mp.getTeamname())) aclListMap.add(mp);
else if ("Unknown".equals(mp.getTeamname()) || "".equals(mp.getTeamname()))
aclListMap.add(mp);
}
}
return aclListMap;
Expand Down
54 changes: 43 additions & 11 deletions src/main/java/io/aiven/klaw/service/ClusterApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,56 @@ public Map<String, String> getTopicEvents(
}

public List<Map<String, String>> getAcls(
String bootstrapHost, String protocol, String clusterName, int tenantId)
String bootstrapHost, Env envSelected, String protocol, String clusterName, int tenantId)
throws KlawException {
log.info("getAcls {} {} {}", bootstrapHost, protocol, tenantId);
getClusterApiProperties(tenantId);

List<Map<String, String>> aclListOriginal;
try {
String URI_GET_ACLS = "/topics/getAcls/";
String uri =
clusterConnUrl
+ URI_GET_ACLS
+ bootstrapHost
+ "/"
+ protocol
+ "/"
+ clusterName
+ "-"
+ tenantId;
KwClusters kwClusters =
manageDatabase
.getClusters(KafkaClustersType.KAFKA.value, tenantId)
.get(envSelected.getClusterId());

String uri;
// aiven config
if (KafkaFlavors.AIVEN_FOR_APACHE_KAFKA.value.equals(kwClusters.getKafkaFlavor())) {
uri =
clusterConnUrl
+ URI_GET_ACLS
+ bootstrapHost
+ "/"
+ AclsNativeType.AIVEN.name()
+ "/"
+ protocol
+ "/"
+ clusterName
+ "-"
+ tenantId
+ "/"
+ kwClusters.getProjectName()
+ "/"
+ kwClusters.getServiceName();
} else {
uri =
clusterConnUrl
+ URI_GET_ACLS
+ bootstrapHost
+ "/"
+ AclsNativeType.NATIVE.name()
+ "/"
+ protocol
+ "/"
+ clusterName
+ "-"
+ tenantId
+ "/"
+ "na"
+ "/"
+ "na";
}
RestTemplate restTemplate = getRestTemplate();

HttpHeaders headers = createHeaders(clusterApiUser, clusterApiPwd);
Expand Down
Loading

0 comments on commit 8b3f7e3

Please sign in to comment.