Skip to content

Commit

Permalink
chore: Fix AWS SQS Kamelets
Browse files Browse the repository at this point in the history
- Bring back DuplicateNamingHeaders utils as it is being used by the AWS SQS Kamelet
- Add E2E tests for AWS SQS Kamelets
  • Loading branch information
christophd committed May 8, 2024
1 parent 0e81579 commit 40f26ea
Show file tree
Hide file tree
Showing 32 changed files with 467 additions and 504 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
yaks install --operator-image $YAKS_IMAGE_NAME:$YAKS_VERSION
- name: YAKS Tests
run: |
yaks run test/aws/sqs $YAKS_RUN_OPTIONS
yaks run test/transformation $YAKS_RUN_OPTIONS
yaks run test/extract-field $YAKS_RUN_OPTIONS
yaks run test/http-sink $YAKS_RUN_OPTIONS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.kamelets.utils.headers;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Processor;

public class DuplicateNamingHeaders implements Processor {

String prefix;
String renamingPrefix;
String selectedHeaders;
String mode = "all";

/**
* Default constructor.
*/
public DuplicateNamingHeaders() {
}

/**
* Constructor using fields.
*
* @param prefix a prefix to find all the headers to rename.
* @param renamingPrefix the renaming prefix to use on all the matching headers
*/
public DuplicateNamingHeaders(String prefix, String renamingPrefix, String selectedHeaders, String mode) {
this.prefix = prefix;
this.renamingPrefix = renamingPrefix;
this.selectedHeaders = selectedHeaders;
this.mode = mode;
}

public void process(Exchange ex) throws InvalidPayloadException {
Map<String, Object> originalHeaders = ex.getMessage().getHeaders();
Map<String, Object> newHeaders = new HashMap<>();
for (Map.Entry<String, Object> entry : originalHeaders.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
if (prefix != null && mode.equalsIgnoreCase("all")) {
if (key.startsWith(prefix)) {
String newKey = key.replaceFirst(prefix, renamingPrefix);
String subKey = newKey.substring(renamingPrefix.length());
String suffix = subKey.replaceAll(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])",
"(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), ".").toLowerCase();
newHeaders.put(renamingPrefix + suffix, val);
}
} else {
if (selectedHeaders != null && mode.equalsIgnoreCase("filtering")) {
List<String> headerList = Arrays.asList(selectedHeaders.split(","));
for (Iterator<String> iterator = headerList.iterator(); iterator.hasNext();) {
String header = iterator.next();
if (key.equalsIgnoreCase(header)) {
String newKey = key.replaceFirst(prefix, renamingPrefix);
String subKey = newKey.substring(renamingPrefix.length());
String suffix = subKey
.replaceAll(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])",
"(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), ".")
.toLowerCase();
newHeaders.put(renamingPrefix + suffix, val);
}
}

}
}
}
originalHeaders.putAll(newHeaders);
ex.getMessage().setHeaders(originalHeaders);
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

public void setRenamingPrefix(String renamingPrefix) {
this.renamingPrefix = renamingPrefix;
}

public void setSelectedHeaders(String selectedHeaders) {
this.selectedHeaders = selectedHeaders;
}

public void setMode(String mode) {
this.mode = mode;
}

}
3 changes: 0 additions & 3 deletions test/aws-sqs/.aws/config

This file was deleted.

3 changes: 0 additions & 3 deletions test/aws-sqs/.aws/credentials

This file was deleted.

28 changes: 0 additions & 28 deletions test/aws-sqs/aws-sqs-client.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions test/aws-sqs/aws-sqs-credentials.properties

This file was deleted.

42 changes: 0 additions & 42 deletions test/aws-sqs/aws-sqs-inmem-binding.feature

This file was deleted.

39 changes: 0 additions & 39 deletions test/aws-sqs/aws-sqs-source-property-conf.feature

This file was deleted.

34 changes: 0 additions & 34 deletions test/aws-sqs/aws-sqs-source-secret-conf.feature

This file was deleted.

39 changes: 0 additions & 39 deletions test/aws-sqs/aws-sqs-source-uri-conf.feature

This file was deleted.

37 changes: 0 additions & 37 deletions test/aws-sqs/aws-sqs-to-inmem.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions test/aws-sqs/aws-sqs-to-log-secret-based.groovy

This file was deleted.

Loading

0 comments on commit 40f26ea

Please sign in to comment.