Skip to content

Commit

Permalink
💄 Avoid using twice hardcoded strings for the names of the Kubescret …
Browse files Browse the repository at this point in the history
…keys, for AWS access/secret key vals

Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Nov 27, 2024
1 parent 65da6fc commit c695150
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/common/integration/v1alpha1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ limitations under the License.

package v1alpha1

const (

// AwsAccessKey is the name of the expected key on the secret for accessing the actual AWS access key value.
AwsAccessKey = "aws.accessKey"
// AwsSecretKey is the name of the expected key on the secret for accessing the actual AWS secret key value.
AwsSecretKey = "aws.secretKey"
)

type AWSCommon struct {
// Auth is the S3 authentication (accessKey/secretKey) configuration.
Region string `json:"region,omitempty"` // AWS region
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciler/integration/sink/resources/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
commonv1a1 "knative.dev/eventing/pkg/apis/common/integration/v1alpha1"
"knative.dev/eventing/pkg/apis/sinks/v1alpha1"
"knative.dev/eventing/pkg/reconciler/integration"
"knative.dev/pkg/kmeta"
Expand Down Expand Up @@ -123,8 +124,8 @@ func makeEnv(sink *v1alpha1.IntegrationSink) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_S3_SINK", *sink.Spec.Aws.S3)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_ACCESSKEY", "aws.accessKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_SECRETKEY", "aws.secretKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -135,8 +136,8 @@ func makeEnv(sink *v1alpha1.IntegrationSink) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_SQS_SINK", *sink.Spec.Aws.SQS)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_ACCESSKEY", "aws.accessKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_SECRETKEY", "aws.secretKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand Down
18 changes: 7 additions & 11 deletions pkg/reconciler/integration/source/resources/containersource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ package resources
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
commonv1a1 "knative.dev/eventing/pkg/apis/common/integration/v1alpha1"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/pkg/apis/sources/v1alpha1"
"knative.dev/eventing/pkg/reconciler/integration"
"knative.dev/pkg/kmeta"
)

const (
awsAccessKey = "aws.accessKey"
awsSecretKey = "aws.secretKey"
)

func NewContainerSource(source *v1alpha1.IntegrationSource) *sourcesv1.ContainerSource {
return &sourcesv1.ContainerSource{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -79,8 +75,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_S3_SOURCE", *source.Spec.Aws.S3)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -91,8 +87,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_SQS_SOURCE", *source.Spec.Aws.SQS)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -103,8 +99,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE", *source.Spec.Aws.DDBStreams)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand Down

0 comments on commit c695150

Please sign in to comment.