Skip to content

Commit

Permalink
Align sources w/ common API
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Oct 14, 2024
1 parent 4de2fd4 commit db209ca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 166 deletions.
50 changes: 0 additions & 50 deletions pkg/apis/sources/v1alpha1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,56 +69,6 @@ type Timer struct {
RepeatCount int `json:"repeatCount,omitempty"` // Max number of fires (optional)
}

type AWSCommon struct {
// Auth is the S3 authentication (accessKey/secretKey) configuration.
Region string `json:"region,omitempty"` // AWS region
//UseDefaultCredentials bool `json:"useDefaultCredentials" default:"false"` // Use default credentials provider
//UseProfileCredentials bool `json:"useProfileCredentials" default:"false"` // Use profile credentials provider
ProfileCredentialsName string `json:"profileCredentialsName,omitempty"` // Profile name for profile credentials provider
// UseSessionCredentials bool `json:"useSessionCredentials" default:"false"` // Use session credentials
SessionToken string `json:"sessionToken,omitempty"` // Session token
URIEndpointOverride string `json:"uriEndpointOverride,omitempty"` // Override endpoint URI
OverrideEndpoint bool `json:"overrideEndpoint" default:"false"` // Override endpoint flag
}

type AWSS3 struct {
AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON
BucketNameOrArn string `json:"bucketNameOrArn,omitempty"` // S3 Bucket name or 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
QueueNameOrArn string `json:"queueNameOrArn,omitempty"` // SQS Queue name or ARN
DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete messages after reading
AutoCreateQueue bool `json:"autoCreateQueue" default:"false"` // Auto-create SQS queue
AmazonAWSHost string `json:"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 {
AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON
Table string `json:"table,omitempty"` // The name of the DynamoDB table
StreamIteratorType string `json:"streamIteratorType,omitempty" default:"FROM_LATEST"` // Defines where in the DynamoDB stream to start getting records
Delay int `json:"delay,omitempty" default:"500"` // Delay in milliseconds before the next poll from the database
}

type Aws struct {
S3 *common.AWSS3 `json:"s3,omitempty"` // S3 source configuration
SQS *common.AWSSQS `json:"sqs,omitempty"` // SQS source configuration
Expand Down
19 changes: 10 additions & 9 deletions pkg/apis/sources/v1alpha1/integration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"knative.dev/eventing/pkg/apis/common"
"testing"
)

Expand Down Expand Up @@ -53,8 +54,8 @@ func TestTimer(t *testing.T) {
}

func TestAWS(t *testing.T) {
s3 := AWSS3{
AWSCommon: AWSCommon{
s3 := common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
BucketNameOrArn: "example-bucket",
Expand All @@ -64,8 +65,8 @@ func TestAWS(t *testing.T) {
t.Errorf("AWSS3.Region = %v, want 'eu-north-1'", s3.Region)
}

sqs := AWSSQS{
AWSCommon: AWSCommon{
sqs := common.AWSSQS{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
QueueNameOrArn: "example-queue",
Expand All @@ -75,8 +76,8 @@ func TestAWS(t *testing.T) {
t.Errorf("AWSSQS.Region = %v, want 'eu-north-1'", sqs.Region)
}

ddbStreams := AWSDDBStreams{
AWSCommon: AWSCommon{
ddbStreams := common.AWSDDBStreams{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
Table: "example-table",
Expand All @@ -89,9 +90,9 @@ func TestAWS(t *testing.T) {

// TestAuthFieldAccess tests the HasAuth method and field access in Auth struct
func TestAuthFieldAccess(t *testing.T) {
auth := Auth{
Secret: &Secret{
Ref: &SecretReference{
auth := common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand Down
81 changes: 41 additions & 40 deletions pkg/apis/sources/v1alpha1/integration_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"context"
"knative.dev/eventing/pkg/apis/common"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -45,15 +46,15 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "valid AWS S3 source with auth and region",
spec: IntegrationSourceSpec{
Aws: &Aws{
S3: &AWSS3{
AWSCommon: AWSCommon{
S3: &common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
BucketNameOrArn: "example-bucket",
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -66,15 +67,15 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "valid AWS SQS source with auth and region",
spec: IntegrationSourceSpec{
Aws: &Aws{
SQS: &AWSSQS{
AWSCommon: AWSCommon{
SQS: &common.AWSSQS{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
QueueNameOrArn: "example-queue",
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -87,15 +88,15 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "valid AWS DDBStreams source with auth and region",
spec: IntegrationSourceSpec{
Aws: &Aws{
DDBStreams: &AWSDDBStreams{
AWSCommon: AWSCommon{
DDBStreams: &common.AWSDDBStreams{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
Table: "example-table",
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -113,8 +114,8 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
ContentType: "text/plain",
},
Aws: &Aws{
S3: &AWSS3{
AWSCommon: AWSCommon{
S3: &common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
BucketNameOrArn: "example-bucket",
Expand All @@ -127,21 +128,21 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "multiple AWS sources set (invalid)",
spec: IntegrationSourceSpec{
Aws: &Aws{
S3: &AWSS3{
AWSCommon: AWSCommon{
S3: &common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
BucketNameOrArn: "example-bucket",
},
SQS: &AWSSQS{
AWSCommon: AWSCommon{
SQS: &common.AWSSQS{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
QueueNameOrArn: "example-queue",
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -154,14 +155,14 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "AWS SQS source without QueueNameOrArn (invalid)",
spec: IntegrationSourceSpec{
Aws: &Aws{
SQS: &AWSSQS{
AWSCommon: AWSCommon{
SQS: &common.AWSSQS{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -174,14 +175,14 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "AWS DDBStreams source without Table (invalid)",
spec: IntegrationSourceSpec{
Aws: &Aws{
DDBStreams: &AWSDDBStreams{
AWSCommon: AWSCommon{
DDBStreams: &common.AWSDDBStreams{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand All @@ -199,8 +200,8 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "AWS source without auth (invalid)",
spec: IntegrationSourceSpec{
Aws: &Aws{
S3: &AWSS3{
AWSCommon: AWSCommon{
S3: &common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "us-east-1",
},
BucketNameOrArn: "example-bucket",
Expand All @@ -213,12 +214,12 @@ func TestIntegrationSourceSpecValidation(t *testing.T) {
name: "AWS S3 source without region (invalid)",
spec: IntegrationSourceSpec{
Aws: &Aws{
S3: &AWSS3{
S3: &common.AWSS3{
BucketNameOrArn: "example-bucket",
},
Auth: &Auth{
Secret: &Secret{
Ref: &SecretReference{
Auth: &common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
Expand Down
67 changes: 0 additions & 67 deletions pkg/apis/sources/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db209ca

Please sign in to comment.