public async Task DeleteTopic(PatConfigCommand configCommand, string azureSubscriptionId, string resourceGroupName)
        {
            if (!await TopicExists(configCommand, azureSubscriptionId, resourceGroupName))
            {
                return;
            }

            var path = ApiRouteBuilder.Build(azureSubscriptionId, resourceGroupName, configCommand.Namespace, configCommand.EffectiveTopicName);
            await _azureHttpClient.Delete(new Uri(path, UriKind.Relative));
        }
        private async Task <bool> TopicExists(PatConfigCommand configCommand, string azureSubscriptionId, string resourceGroupName)
        {
            var path   = ApiRouteBuilder.Build(azureSubscriptionId, resourceGroupName, configCommand.Namespace, configCommand.EffectiveTopicName);
            var result = await _azureHttpClient.GetStatusCode(new Uri(path, UriKind.Relative));

            if (result == HttpStatusCode.OK)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public async Task CreateSubscription(PatConfigCommand configCommand, string azureSubscriptionId, string resouceGroupName)
        {
            var payload = new
            {
                name       = configCommand.Subscription,
                properties = new
                {
                    maxDeliveryCount = 10,
                    status           = "Active"
                }
            };

            var path = BuildSubscriptionPath(configCommand, azureSubscriptionId, resouceGroupName);
            await _azureHttpClient.Put(new Uri(path, UriKind.Relative), payload);
        }
Ejemplo n.º 4
0
        public async Task <int> DeleteTopic(PatConfigCommand configCommand)
        {
            ConfigureAuth(configCommand);

            (var azureSubscriptionId, var resourceGroup) = await GetAzureSubscriptionFor(configCommand);

            if (string.IsNullOrEmpty(azureSubscriptionId) || string.IsNullOrEmpty(resourceGroup))
            {
                return(-1);
            }

            await _topicApiClient.DeleteTopic(configCommand, azureSubscriptionId, resourceGroup);

            Console.WriteLine($"delete complete {configCommand.Namespace} {configCommand.EffectiveTopicName}\\{configCommand.Subscription}");
            return(0);
        }
        public async Task CreateTopic(PatConfigCommand configCommand, string azureSubscriptionId, string resourceGroupName)
        {
            if (await TopicExists(configCommand, resourceGroupName, azureSubscriptionId))
            {
                return;
            }

            var payload = new
            {
                properties = new
                {
                    enablePartitioning = configCommand.EnablePartitioning,
                    maxSizeInMegabytes = configCommand.MaxSizeInMegabytes
                }
            };

            var path = ApiRouteBuilder.Build(azureSubscriptionId, resourceGroupName, configCommand.Namespace, configCommand.EffectiveTopicName);
            await _azureHttpClient.Put(new Uri(path, UriKind.Relative), payload);
        }
Ejemplo n.º 6
0
 private static string BuildRulePath(PatConfigCommand configCommand, string azureSubscriptionId, string resouceGroupName, string ruleName)
 {
     return(ApiRouteBuilder.Build(azureSubscriptionId, resouceGroupName, configCommand.Namespace, configCommand.EffectiveTopicName, configCommand.Subscription, ruleName));
 }
Ejemplo n.º 7
0
 public async Task DeleteSubscription(PatConfigCommand configCommand, string azureSubscriptionId, string resouceGroupName)
 {
     var path = BuildSubscriptionPath(configCommand, azureSubscriptionId, resouceGroupName);
     await _azureHttpClient.Delete(new Uri(path, UriKind.Relative));
 }
Ejemplo n.º 8
0
 public async Task RemoveDefaultFilter(PatConfigCommand configCommand, string azureSubscriptionId, string resouceGroupName)
 {
     var path = BuildRulePath(configCommand, azureSubscriptionId, resouceGroupName, "%24Default");
     await _azureHttpClient.Delete(new Uri(path, UriKind.Relative));
 }
Ejemplo n.º 9
0
        private async Task <(string subscriptionId, string resourceGroup)> GetAzureSubscriptionFor(PatConfigCommand configCommand)
        {
            var subscriptions = await _azureSubscriptionApiClient.GetSubscriptions();

            if (subscriptions.Any())
            {
                foreach (var subscription in subscriptions)
                {
                    var resourceGroup = await _namespaceApiClient.GetResourceGroupFor(configCommand.Namespace, subscription);

                    if (resourceGroup != null)
                    {
                        return(subscription, resourceGroup);
                    }
                }

                Console.Error.WriteError($"Error: Unable to find namespace {configCommand.Namespace} in any azure subscriptions");
            }

            return(null, null);
        }
Ejemplo n.º 10
0
 private void ConfigureAuth(PatConfigCommand configCommand)
 {
     _azureHttpClient.SetServicePrincipal(configCommand.ClientId, configCommand.ClientSecret, configCommand.TenantId);
 }