Files
Oded Viner 81a2cd8833 object: migrate sns topic provisioner to aws sdk v2
migrate the sns-based topic provisioner from aws-sdk-go (v1)
to aws-sdk-go-v2. replace v1 session, credentials, and
request handlers with v2 aws.Config, static credentials
provider, and endpoint resolver. convert the custom ceph rgw
v2 signer hack from a v1 handler swap to a smithy finalize
middleware. update sns api calls to use context-first
signatures, map[string]string attributes, and typed
snstypes.NotFoundException error handling via errors.As.
update unit tests accordingly.

Signed-off-by: Oded Viner <oviner@redhat.com>
2026-05-20 13:02:00 +03:00

150 lines
3.9 KiB
Go

/*
Copyright 2022 The Rook Authors. All rights reserved.
Licensed 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 topic to manage a rook bucket topics.
package topic
import (
"os"
"testing"
"github.com/coreos/pkg/capnslog"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestTopicAttributesCreation(t *testing.T) {
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
os.Setenv("ROOK_LOG_LEVEL", "DEBUG")
falseString := "false"
trueString := "true"
emptyString := ""
t.Run("test HTTP attributes", func(t *testing.T) {
uri := "http://localhost"
expectedAttrs := map[string]string{
"OpaqueData": emptyString,
"cloudevents": falseString,
"persistent": falseString,
"push-endpoint": uri,
"verify-ssl": trueString,
}
bucketTopic := &cephv1.CephBucketTopic{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
TypeMeta: metav1.TypeMeta{
Kind: "CephBucketTopic",
},
Spec: cephv1.BucketTopicSpec{
ObjectStoreName: store,
ObjectStoreNamespace: namespace,
Endpoint: cephv1.TopicEndpointSpec{
HTTP: &cephv1.HTTPEndpointSpec{
URI: uri,
},
},
},
}
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
require.NoError(t, err)
assert.Equal(t, expectedAttrs, attrs)
})
t.Run("test AMQP attributes", func(t *testing.T) {
uri := "amqp://my-rabbitmq-service:5672/vhost1"
ackLevel := "broker"
exchange := "ex1"
expectedAttrs := map[string]string{
"OpaqueData": emptyString,
"persistent": falseString,
"push-endpoint": uri,
"verify-ssl": trueString,
"amqp-exchange": exchange,
"amqp-ack-level": ackLevel,
}
bucketTopic := &cephv1.CephBucketTopic{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
TypeMeta: metav1.TypeMeta{
Kind: "CephBucketTopic",
},
Spec: cephv1.BucketTopicSpec{
ObjectStoreName: store,
ObjectStoreNamespace: namespace,
Endpoint: cephv1.TopicEndpointSpec{
AMQP: &cephv1.AMQPEndpointSpec{
URI: uri,
AckLevel: ackLevel,
Exchange: exchange,
},
},
},
}
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
require.NoError(t, err)
assert.Equal(t, expectedAttrs, attrs)
})
t.Run("test Kafka attributes", func(t *testing.T) {
uri := "kafka://my-kafka-service:9092"
ackLevel := "broker"
mechanism := "SCRAM-SHA-512"
expectedAttrs := map[string]string{
"OpaqueData": emptyString,
"persistent": falseString,
"push-endpoint": uri,
"verify-ssl": trueString,
"kafka-ack-level": ackLevel,
"use-ssl": trueString,
"mechanism": mechanism,
}
bucketTopic := &cephv1.CephBucketTopic{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
TypeMeta: metav1.TypeMeta{
Kind: "CephBucketTopic",
},
Spec: cephv1.BucketTopicSpec{
ObjectStoreName: store,
ObjectStoreNamespace: namespace,
Endpoint: cephv1.TopicEndpointSpec{
Kafka: &cephv1.KafkaEndpointSpec{
URI: uri,
AckLevel: ackLevel,
UseSSL: true,
Mechanism: mechanism,
},
},
},
}
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
require.NoError(t, err)
assert.Equal(t, expectedAttrs, attrs)
})
}