示例#1
0
        /// <inheritdoc />
        void IPublicationBuilder <T> .Configure(
            JustSayingBus bus,
            IAwsClientFactoryProxy proxy,
            ILoggerFactory loggerFactory)
        {
            var logger = loggerFactory.CreateLogger <TopicPublicationBuilder <T> >();

            logger.LogInformation("Adding SNS publisher for message type '{MessageType}'.",
                                  typeof(T));

            var config = bus.Config;

            var readConfiguration  = new SqsReadConfiguration(SubscriptionType.ToTopic);
            var writeConfiguration = new SnsWriteConfiguration();

            ConfigureWrites?.Invoke(writeConfiguration);
            readConfiguration.ApplyTopicNamingConvention <T>(config.TopicNamingConvention);

            bus.SerializationRegister.AddSerializer <T>();

            foreach (var region in config.Regions)
            {
                // TODO pass region down into topic creation for when we have foreign topics so we can generate the arn
                var eventPublisher = new SnsTopicByName(
                    readConfiguration.TopicName,
                    proxy.GetAwsClientFactory().GetSnsClient(RegionEndpoint.GetBySystemName(region)),
                    bus.SerializationRegister,
                    loggerFactory,
                    writeConfiguration,
                    config.MessageSubjectProvider)
                {
                    MessageResponseLogger = config.MessageResponseLogger
                };

                async Task StartupTask()
                {
                    if (writeConfiguration.Encryption != null)
                    {
                        await eventPublisher.CreateWithEncryptionAsync(writeConfiguration.Encryption)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await eventPublisher.CreateAsync().ConfigureAwait(false);
                    }

                    await eventPublisher.EnsurePolicyIsUpdatedAsync(config.AdditionalSubscriberAccounts)
                    .ConfigureAwait(false);
                }

                bus.AddStartupTask(StartupTask());

                bus.AddMessagePublisher <T>(eventPublisher, region);
            }

            logger.LogInformation(
                "Created SNS topic publisher on topic '{TopicName}' for message type '{MessageType}'.",
                readConfiguration.TopicName,
                typeof(T));
        }
示例#2
0
 private static void CreatePublisher(SnsTopicByName eventPublisher, SnsWriteConfiguration snsWriteConfig)
 {
     if (snsWriteConfig.Encryption != null)
     {
         eventPublisher.CreateWithEncryptionAsync(snsWriteConfig.Encryption).GetAwaiter().GetResult();
     }
     else
     {
         eventPublisher.CreateAsync().GetAwaiter().GetResult();
     }
 }
示例#3
0
        public async Task Can_Update_Encryption_For_Existing_Topic()
        {
            // Arrange
            ILoggerFactory    loggerFactory = OutputHelper.ToLoggerFactory();
            IAwsClientFactory clientFactory = CreateClientFactory();

            var client = clientFactory.GetSnsClient(Region);

            var topic = new SnsTopicByName(
                UniqueName,
                client,
                loggerFactory);

            await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = "previousKeyId" }, CancellationToken.None);

            // Act
            await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId }, CancellationToken.None);

            // Assert
            topic.ServerSideEncryption.KmsMasterKeyId.ShouldBe(JustSayingConstants.DefaultSnsAttributeEncryptionKeyId);
        }
示例#4
0
    public async Task Can_Remove_Encryption()
    {
        // Arrange
        ILoggerFactory    loggerFactory = OutputHelper.ToLoggerFactory();
        IAwsClientFactory clientFactory = CreateClientFactory();

        var client = clientFactory.GetSnsClient(Region);

        var topic = new SnsTopicByName(
            UniqueName,
            client,
            loggerFactory);

        await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId }, CancellationToken.None);

        // Act
        await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = String.Empty }, CancellationToken.None);

        // Assert
        topic.ServerSideEncryption.ShouldBeNull();
    }
示例#5
0
        public async Task Can_Create_Topic_With_Encryption()
        {
            // Arrange
            ILoggerFactory    loggerFactory = OutputHelper.ToLoggerFactory();
            IAwsClientFactory clientFactory = CreateClientFactory();

            var client = clientFactory.GetSnsClient(Region);

            var topic = new SnsTopicByName(
                UniqueName,
                client,
                null,
                loggerFactory,
                null);

            // Act
            await topic.CreateWithEncryptionAsync(new ServerSideEncryption { KmsMasterKeyId = JustSayingConstants.DefaultSnsAttributeEncryptionKeyId });

            // Assert
            topic.ServerSideEncryption.KmsMasterKeyId.ShouldBe(JustSayingConstants.DefaultSnsAttributeEncryptionKeyId);
        }