Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions pkg/apis/common/integration/v1alpha1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ type AWSCommon struct {

type AWSS3 struct {
AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON
Arn string `json:"arn,omitempty" camel:"CAMEL_KAMELET_AWS_S3_SOURCE_BUCKETNAMEORARN"` // S3 ARN
DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete objects after reading
MoveAfterRead bool `json:"moveAfterRead" default:"false"` // Move objects after reading
DestinationBucket string `json:"destinationBucket,omitempty"` // Destination bucket for moved objects
DestinationBucketPrefix string `json:"destinationBucketPrefix,omitempty"` // Prefix for moved objects
DestinationBucketSuffix string `json:"destinationBucketSuffix,omitempty"` // Suffix for moved objects
AutoCreateBucket bool `json:"autoCreateBucket" default:"false"` // Auto-create S3 bucket
Prefix string `json:"prefix,omitempty"` // S3 bucket prefix for search
IgnoreBody bool `json:"ignoreBody" default:"false"` // Ignore object body
ForcePathStyle bool `json:"forcePathStyle" default:"false"` // Force path style for bucket access
Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds
MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"10"` // Max messages to poll per request
Arn string `json:"arn,omitempty" camel:"BUCKET_NAME_OR_ARN"` // S3 ARN
DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete objects after reading
MoveAfterRead bool `json:"moveAfterRead" default:"false"` // Move objects after reading
DestinationBucket string `json:"destinationBucket,omitempty"` // Destination bucket for moved objects
DestinationBucketPrefix string `json:"destinationBucketPrefix,omitempty"` // Prefix for moved objects
DestinationBucketSuffix string `json:"destinationBucketSuffix,omitempty"` // Suffix for moved objects
AutoCreateBucket bool `json:"autoCreateBucket" default:"false"` // Auto-create S3 bucket
Prefix string `json:"prefix,omitempty"` // S3 bucket prefix for search
IgnoreBody bool `json:"ignoreBody" default:"false"` // Ignore object body
ForcePathStyle bool `json:"forcePathStyle" default:"false"` // Force path style for bucket access
Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds
MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"10"` // Max messages to poll per request
}

type AWSSQS struct {
AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON
Arn string `json:"arn,omitempty" camel:"CAMEL_KAMELET_AWS_SQS_SOURCE_QUEUENAMEORARN"` // SQS ARN
DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete messages after reading
AutoCreateQueue bool `json:"autoCreateQueue" default:"false"` // Auto-create SQS queue
Host string `json:"host" camel:"CAMEL_KAMELET_AWS_SQS_SOURCE_AMAZONAWSHOST" default:"amazonaws.com"` // AWS host
Protocol string `json:"protocol" default:"https"` // Communication protocol (http/https)
QueueURL string `json:"queueURL,omitempty"` // Full SQS queue URL
Greedy bool `json:"greedy" default:"false"` // Greedy scheduler
Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds
MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"1"` // Max messages to return (1-10)
WaitTimeSeconds int `json:"waitTimeSeconds,omitempty"` // Wait time for messages
VisibilityTimeout int `json:"visibilityTimeout,omitempty"` // Visibility timeout in seconds
Arn string `json:"arn,omitempty" camel:"QUEUE_NAME_OR_ARN"` // SQS ARN
DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete messages after reading
AutoCreateQueue bool `json:"autoCreateQueue" default:"false"` // Auto-create SQS queue
Host string `json:"host" camel:"AMAZONAWSHOST" default:"amazonaws.com"` // AWS host
Protocol string `json:"protocol" default:"https"` // Communication protocol (http/https)
QueueURL string `json:"queueURL,omitempty"` // Full SQS queue URL
Greedy bool `json:"greedy" default:"false"` // Greedy scheduler
Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds
MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"1"` // Max messages to return (1-10)
WaitTimeSeconds int `json:"waitTimeSeconds,omitempty"` // Wait time for messages
VisibilityTimeout int `json:"visibilityTimeout,omitempty"` // Visibility timeout in seconds
}

type AWSDDBStreams struct {
Expand All @@ -71,6 +71,6 @@ type AWSDDBStreams struct {

type AWSSNS struct {
AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON
Arn string `json:"arn,omitempty" camel:"CAMEL_KAMELET_AWS_SNS_SINK_TOPICNAMEORARN"` // SNS ARN
AutoCreateTopic bool `json:"autoCreateTopic" default:"false"` // Auto-create SNS topic
Arn string `json:"arn,omitempty" camel:"TOPIC_NAME_OR_ARN"` // SNS ARN
AutoCreateTopic bool `json:"autoCreateTopic" default:"false"` // Auto-create SNS topic
}
4 changes: 3 additions & 1 deletion pkg/reconciler/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func GenerateEnvVarsFromStruct(prefix string, s interface{}) []corev1.EnvVar {

// First, check for the custom 'camel' tag
envVarName := fieldType.Tag.Get("camel")
if envVarName == "" {
if envVarName != "" {
envVarName = fmt.Sprintf("%s_%s", prefix, envVarName)
} else {
// If 'camel' tag is not present, fall back to the 'json' tag or Go field name
jsonTag := fieldType.Tag.Get("json")
tagName := strings.Split(jsonTag, ",")[0]
Expand Down
78 changes: 65 additions & 13 deletions pkg/reconciler/integration/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,77 @@ func TestGenerateEnvVarsFromStruct(t *testing.T) {

func TestGenerateEnvVarsFromStruct_S3WithCamelTag(t *testing.T) {
type AWSS3 struct {
Arn string `json:"arn,omitempty" camel:"CAMEL_KAMELET_AWS_S3_SOURCE_BUCKETNAMEORARN"`
Arn string `json:"arn,omitempty" camel:"BUCKETNAMEORARN"`
Region string `json:"region,omitempty"`
}

prefix := "CAMEL_KAMELET_AWS_S3_SOURCE"
input := AWSS3{
Arn: "arn:aws:s3:::example-bucket",
Region: "us-west-2",
type AWSSQS struct {
Arn string `json:"arn,omitempty" camel:"QUEUENAMEORARN"`
Region string `json:"region,omitempty"`
}

// Expected environment variables including SSL settings and camel tag for Arn
want := []corev1.EnvVar{
{Name: "CAMEL_KAMELET_AWS_S3_SOURCE_BUCKETNAMEORARN", Value: "arn:aws:s3:::example-bucket"},
{Name: "CAMEL_KAMELET_AWS_S3_SOURCE_REGION", Value: "us-west-2"},
tests := []struct {
name string
prefix string
input interface{}
want []corev1.EnvVar
}{
{
name: "S3 Source with Camel Tag",
prefix: "CAMEL_KAMELET_AWS_S3_SOURCE",
input: AWSS3{
Arn: "arn:aws:s3:::example-bucket",
Region: "us-west-2",
},
want: []corev1.EnvVar{
{Name: "CAMEL_KAMELET_AWS_S3_SOURCE_BUCKETNAMEORARN", Value: "arn:aws:s3:::example-bucket"},
{Name: "CAMEL_KAMELET_AWS_S3_SOURCE_REGION", Value: "us-west-2"},
},
},
{
name: "S3 Sink with Camel Tag",
prefix: "CAMEL_KAMELET_AWS_S3_SINK",
input: AWSS3{
Arn: "arn:aws:s3:::another-bucket",
Region: "eu-central-1",
},
want: []corev1.EnvVar{
{Name: "CAMEL_KAMELET_AWS_S3_SINK_BUCKETNAMEORARN", Value: "arn:aws:s3:::another-bucket"},
{Name: "CAMEL_KAMELET_AWS_S3_SINK_REGION", Value: "eu-central-1"},
},
},
{
name: "SQS Source with Camel Tag",
prefix: "CAMEL_KAMELET_AWS_SQS_SOURCE",
input: AWSSQS{
Arn: "arn:aws:sqs:::example-queue",
Region: "us-east-1",
},
want: []corev1.EnvVar{
{Name: "CAMEL_KAMELET_AWS_SQS_SOURCE_QUEUENAMEORARN", Value: "arn:aws:sqs:::example-queue"},
{Name: "CAMEL_KAMELET_AWS_SQS_SOURCE_REGION", Value: "us-east-1"},
},
},
{
name: "SQS Sink with Camel Tag",
prefix: "CAMEL_KAMELET_AWS_SQS_SINK",
input: AWSSQS{
Arn: "arn:aws:sqs:::another-queue",
Region: "ap-southeast-1",
},
want: []corev1.EnvVar{
{Name: "CAMEL_KAMELET_AWS_SQS_SINK_QUEUENAMEORARN", Value: "arn:aws:sqs:::another-queue"},
{Name: "CAMEL_KAMELET_AWS_SQS_SINK_REGION", Value: "ap-southeast-1"},
},
},
}

got := GenerateEnvVarsFromStruct(prefix, input)

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("generateEnvVarsFromStruct_S3WithCamelTag() mismatch (-want +got):\n%s", diff)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GenerateEnvVarsFromStruct(tt.prefix, tt.input)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("GenerateEnvVarsFromStruct() mismatch (-want +got):\n%s", diff)
}
})
}
}
Loading