Esempio n. 1
0
        private Azure(RestClient restClient, string subscriptionId, string tenantId, IAuthenticated authenticated)
        {
            resourceManager          = ResourceManager.Fluent.ResourceManager.Authenticate(restClient).WithSubscription(subscriptionId);
            storageManager           = StorageManager.Authenticate(restClient, subscriptionId);
            computeManager           = ComputeManager.Authenticate(restClient, subscriptionId);
            networkManager           = NetworkManager.Authenticate(restClient, subscriptionId);
            batchManager             = BatchManager.Authenticate(restClient, subscriptionId);
            keyVaultManager          = KeyVaultManager.Authenticate(restClient, subscriptionId, tenantId);
            trafficManager           = TrafficManager.Fluent.TrafficManager.Authenticate(restClient, subscriptionId);
            dnsZoneManager           = DnsZoneManager.Authenticate(restClient, subscriptionId);
            sqlManager               = SqlManager.Authenticate(restClient, subscriptionId);
            redisManager             = RedisManager.Authenticate(restClient, subscriptionId);
            cdnManager               = CdnManager.Authenticate(restClient, subscriptionId);
            appServiceManager        = AppServiceManager.Authenticate(restClient, subscriptionId, tenantId);
            searchManager            = SearchManager.Authenticate(restClient, subscriptionId);
            serviceBusManager        = ServiceBusManager.Authenticate(restClient, subscriptionId);
            containerInstanceManager = ContainerInstanceManager.Authenticate(restClient, subscriptionId);
            registryManager          = RegistryManager.Authenticate(restClient, subscriptionId);
            containerServiceManager  = ContainerServiceManager.Authenticate(restClient, subscriptionId);
            cosmosDBManager          = CosmosDBManager.Authenticate(restClient, subscriptionId);
            authorizationManager     = AuthorizationManager.Authenticate(restClient, subscriptionId);
            msiManager               = MsiManager.Authenticate(restClient, subscriptionId);
            batchAIManager           = BatchAIManager.Authenticate(restClient, subscriptionId);
            monitorManager           = MonitorManager.Authenticate(restClient, subscriptionId);
            eventHubManager          = EventHubManager.Authenticate(restClient, subscriptionId);

            SubscriptionId     = subscriptionId;
            this.authenticated = authenticated;
        }
        public ServiceBusService()
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(Constant.CLIENT_ID, Constant.CLIENT_SECRET, Constant.TENANT_ID,
                                                                                      AzureEnvironment.AzureGlobalCloud);
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, Constant.SUBSCRIPTION_ID);

            serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(Constant.RESOURCE_GROUP, Constant.RESOURCE_NAME);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the service bus namespace
        /// </summary>
        /// <param name="configuration">IConfiguration</param>
        /// <returns></returns>
        public static IServiceBusNamespace GetServiceBusNamespace(this IConfiguration configuration)
        {
            var config = configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>();

            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(config.ClientId, config.ClientSecret, config.TenantId, AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId);

            return(serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName));
        }
        public static IServiceBusNamespace GetServiceBusNamespace(this IConfiguration configuration)
        {
            //ref: https://tomasherceg.com/blog/post/azure-servicebus-in-net-core-managing-topics-queues-and-subscriptions-from-the-code
            var config      = configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>();
            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(config.ClientId, config.ClientSecret,
                                                    config.TenantId, AzureEnvironment.AzureGlobalCloud);
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId);

            return(serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName));
        }
Esempio n. 5
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var clientID     = Environment.GetEnvironmentVariable("Azure_ClientID");
            var clientSecret = Environment.GetEnvironmentVariable("Azure_ClientSecret");
            var tenantId     = Environment.GetEnvironmentVariable("Azure_TenantID");
            var credentials  = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientID, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);

            var subscriptionId    = Environment.GetEnvironmentVariable("Azure_SubscriptionID");
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, subscriptionId);

            builder.Services.AddSingleton <IServiceBusManager>((s) => serviceBusManager);
        }
Esempio n. 6
0
        private IServiceBusNamespace GetServiceBusNamespace()
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                _configuration["serviceBus:clientId"],
                _configuration["serviceBus:clientSecret"],
                _configuration["serviceBus:tenantId"],
                AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager.Authenticate(credentials, _configuration["serviceBus:subscriptionId"]);

            return(serviceBusManager.Namespaces.GetByResourceGroup(_configuration["serviceBus:resourceGroup"], _configuration["serviceBus:namespaceName"]));
        }
Esempio n. 7
0
        public IServiceBusNamespace GetServiceBusNamespace()
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                this.ClientId,
                this.ClientSecret,
                this.TenantId,
                AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager.Authenticate(credentials, this.SubscriptionId);

            return(serviceBusManager.Namespaces.GetByResourceGroup(this.ResourceGroup, this.NamespaceName));
        }
        private IServiceBusNamespace GetServiceBusNamespace(ServiceBusConfiguration configuration)
        {
            try
            {
                var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(configuration.ClientId, configuration.ClientSecret, configuration.TenantId, AzureEnvironment.AzureGlobalCloud);

                var serviceBusManager = ServiceBusManager.Authenticate(credentials, configuration.SubscriptionId);

                return(serviceBusManager.Namespaces.GetByResourceGroup(configuration.ResourceGroupName, configuration.ResourceName));
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public AzureServiceBus()
        {
            _messages       = new List <Message>();
            _taskExceptions = new List <Task>();

            var config      = ConfigurationManager.Configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>();
            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(config.ClientId,
                                                    config.ClientSecret,
                                                    config.TenantId,
                                                    AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId);

            _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName);
        }
Esempio n. 10
0
        public Deploy(ILogger Logger)
        {
            var Deploy_ClientId                = ConfigurationManager.AppSettings["Deploy_ClientId"];
            var Deploy_ClientSecret            = ConfigurationManager.AppSettings["Deploy_ClientSecret"];
            var Deploy_TenantId                = ConfigurationManager.AppSettings["Deploy_TenantId"];
            var Deploy_SubscriptionId          = ConfigurationManager.AppSettings["Deploy_SubscriptionId"];
            var Deploy_ResourceGroupName       = ConfigurationManager.AppSettings["Deploy_ResourceGroupName"];
            var Deploy_ServiceBusNamespaceName = ConfigurationManager.AppSettings["Deploy_ServiceBusNamespaceName"];

            var credentials       = SdkContext.AzureCredentialsFactory.FromServicePrincipal(Deploy_ClientId, Deploy_ClientSecret, Deploy_TenantId, AzureEnvironment.AzureGlobalCloud);
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, Deploy_SubscriptionId);

            _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(Deploy_ResourceGroupName, Deploy_ServiceBusNamespaceName);

            _log = Logger;
        }
Esempio n. 11
0
        static async Task Main()
        {
            // Build configuration
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json")
                          .Build();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", true, true)
                                           .Build();

            config = builder.GetSection("serviceBus").Get <ServiceBusConfiguration>();


            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(config.ClientId,
                                                    config.ClientSecret,
                                                    config.TenantId,
                                                    AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager
                                    .Authenticate(credentials, config.SubscriptionId);

            serviceBus = serviceBusManager.Namespaces
                         .GetByResourceGroup(config.ResourceGroup,
                                             config.NamespaceName);


            Console.WriteLine("Reconhecimento de Rotulos:");
            Console.Write("Insira o caminho completo da imagem e de enter");
            string imageFilePath = Console.ReadLine();

            if (File.Exists(imageFilePath))
            {
                Console.WriteLine("\n Aguarde os resultados.\n");
                await MakeOCRRequest(imageFilePath);
            }
            else
            {
                Console.WriteLine("\nCaminho inválido");
            }
            Console.WriteLine("\nPressione ENTER para sair...");
            Console.ReadLine();
        }
        private async Task <IServiceBusNamespace> GetNamespace(IServiceBusManagementConfiguration config)
        {
            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(
                config.ClientId,
                config.ClientSecret,
                config.TenantId,
                AzureEnvironment.AzureGlobalCloud);

            var manager = ServiceBusManager.Authenticate(
                credentials,
                config.SubscriptionId);

            return(await manager.Namespaces
                   .GetByResourceGroupAsync(
                       config.ResourceGroup,
                       config.ResourceName));
        }
Esempio n. 13
0
        public static IServiceBusNamespace GetNamespace(AzureMqSettingsBase settings)
        {
            var azureCredentials = SdkContext.AzureCredentialsFactory
                                   .FromServicePrincipal(
                clientId: settings.AzureSpAppId,
                clientSecret: settings.AzureSpPassword,
                tenantId: settings.AzureSpTenantId,
                environment: AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager = ServiceBusManager.Authenticate(azureCredentials, settings.AzureSubscriptionId);

            var @namespace = serviceBusManager.Namespaces.GetByResourceGroup(settings.AzureResourceGroup, settings.AzureNamespace);

            if (@namespace == null)
            {
                throw new InvalidOperationException($"Azure namespace '{settings.AzureNamespace}' not found.");
            }

            return(@namespace);
        }
Esempio n. 14
0
        public async void CreateQueue(IConfigurationRoot configuration)
        {
            try
            {
                var credentials         = SdkContext.AzureCredentialsFactory.FromServicePrincipal(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"], configuration["TenantId"], AzureEnvironment.AzureGlobalCloud);
                var serviceBusManager   = ServiceBusManager.Authenticate(credentials, configuration["SubscriptionId"]);
                var serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(configuration["ResourceGroupName"], configuration["ResourceName"]);

                var newqueue = serviceBusNamespace.Queues.Define("mynewqueue")
                               .WithDefaultMessageTTL(TimeSpan.FromMinutes(10))
                               .WithExpiredMessageMovedToDeadLetterQueue()
                               .WithMessageMovedToDeadLetterQueueOnMaxDeliveryCount(40)
                               .Create();
                Console.WriteLine(newqueue.Status);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 15
0
        private void EnsureTopicIsCreated()
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                _configuration["serviceBus:clientId"],
                _configuration["serviceBus:clientSecret"],
                _configuration["serviceBus:tenantId"],
                AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager   = ServiceBusManager.Authenticate(credentials, _configuration["serviceBus:subscriptionId"]);
            var serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(_configuration["serviceBus:resourceGroup"], _configuration["serviceBus:namespaceName"]);

            if (!serviceBusNamespace.Topics.List()
                .Any(topic => topic.Name
                     .Equals(Topic, StringComparison.InvariantCultureIgnoreCase)))
            {
                serviceBusNamespace.Topics.Define(Topic)
                .WithSizeInMB(1024)
                .Create();
            }
            ;
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceBusProvider" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="credentials">The credentials.</param>
        /// <param name="configuration">The configuration.</param>
        public ServiceBusProvider(
            ILogger <ServiceBusProvider> logger,
            AzureCredentials credentials,
            ServiceBusConfiguration configuration)
        {
            EnsureArg.IsNotNull(logger, nameof(logger));
            EnsureArg.IsNotNull(credentials, nameof(credentials));
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNullOrEmpty(configuration.SubscriptionId, nameof(configuration.SubscriptionId));
            EnsureArg.IsNotNullOrEmpty(configuration.ConnectionString, nameof(configuration.ConnectionString));
            EnsureArg.IsNotNullOrEmpty(configuration.ResourceGroup, nameof(configuration.ResourceGroup));
            EnsureArg.IsNotNullOrEmpty(configuration.NamespaceName, nameof(configuration.NamespaceName));
            EnsureArg.IsNotNullOrEmpty(configuration.EntityPath, nameof(configuration.EntityPath));

            this.logger = logger;
            this.ConnectionStringBuilder = new ServiceBusConnectionStringBuilder(configuration.ConnectionString)
            {
                EntityPath = configuration.EntityPath
            };
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, configuration.SubscriptionId);

            this.serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(configuration.ResourceGroup, configuration.NamespaceName);
            this.EntityPath          = configuration.EntityPath;
        }
Esempio n. 17
0
        private async Task EnsureTopicIsCreated()
        {
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                _configuration["serviceBus:clientId"],
                _configuration["serviceBus:clientSecret"],
                _configuration["serviceBus:tenantId"],
                AzureEnvironment.AzureGlobalCloud);

            var serviceBusManager   = ServiceBusManager.Authenticate(credentials, _configuration["serviceBus:subscriptionId"]);
            var serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(_configuration["serviceBus:resourceGroup"], _configuration["serviceBus:namespaceName"]);

            var topics = await serviceBusNamespace.Topics.ListAsync();

            var topicStoreCatalogReady = topics.FirstOrDefault(t => t.Name.Equals("StoreCatalogReady", StringComparison.InvariantCultureIgnoreCase));
            var topicUserWithLessOffer = topics.FirstOrDefault(t => t.Name.Equals("UserWithLessOffer", StringComparison.InvariantCultureIgnoreCase));

            var topicProductChanged        = topics.FirstOrDefault(t => t.Name.Equals("ProductChanged", StringComparison.InvariantCultureIgnoreCase));
            var topicProductionAreaChanged = topics.FirstOrDefault(t => t.Name.Equals("ProductionAreaChanged", StringComparison.InvariantCultureIgnoreCase));

            SubscriptionInner subscriptionInner = new SubscriptionInner()
            {
            };

            #region Send Messages
            if (topicStoreCatalogReady == null)
            {
                topicStoreCatalogReady = await serviceBusNamespace.Topics.Define("StoreCatalogReady")
                                         .WithSizeInMB(1024)
                                         .CreateAsync();
            }

            if (topicUserWithLessOffer == null)
            {
                topicUserWithLessOffer = await serviceBusNamespace.Topics.Define("UserWithLessOffer")
                                         .WithSizeInMB(1024)
                                         .CreateAsync();
            }
            #endregion

            #region Receive Messages
            if (topicProductChanged == null)
            {
                topicProductChanged = await serviceBusNamespace.Topics.Define("ProductChanged")
                                      .WithSizeInMB(1024)
                                      .CreateAsync();
            }

            if (topicProductionAreaChanged == null)
            {
                topicProductionAreaChanged = await serviceBusNamespace.Topics.Define("ProductionAreaChanged")
                                             .WithSizeInMB(1024)
                                             .CreateAsync();
            }
            #endregion

            /*Criação da subscrição no tópico de produção*/
            await topicProductChanged.Subscriptions.Define("StoreCatalog-ProductChanged").CreateAsync();

            /*Criação da subscrição no tópico de área de produção*/
            await topicProductionAreaChanged.Subscriptions.Define("StoreCatalog-ProductionAreaChanged").CreateAsync();
        }
        public async Task Invoke(HttpContext httpContext)
        {
            if (httpContext.Request.Path.HasValue && httpContext.Request.Path.Value == "/metrics")
            {
                _logger.LogTrace($"{DateTime.Now:o} - Start scraping");

                var status = 1;
                try
                {
                    //todo: validate settings

                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    var gaugeModels = new List <GaugeModel>();

                    if (_serviceBusNamespace == null)
                    {
                        var azureCredentials  = SdkContext.AzureCredentialsFactory.FromServicePrincipal(_config.Value.ClientId, _config.Value.ClientSecret, _config.Value.TenantId, AzureEnvironment.AzureGlobalCloud);
                        var serviceBusManager = ServiceBusManager.Authenticate(azureCredentials, _config.Value.SubscriptionId);
                        _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(_config.Value.ResourceGroupName, _config.Value.ResourceName);
                    }

                    gaugeModels.AddRange(_queueService.CreateMetricsAsync(_serviceBusNamespace).GetAwaiter().GetResult());
                    gaugeModels.AddRange(_topicService.CreateMetricsAsync(_serviceBusNamespace).GetAwaiter().GetResult());
                    gaugeModels.AddRange(_subscriptionService.CreateMetricsAsync(_serviceBusNamespace).GetAwaiter().GetResult());

                    gaugeModels.Add(new GaugeModel()
                    {
                        Name  = "scrape_duration_milliseconds",
                        Value = (sw.ElapsedMilliseconds),
                        Help  = "The duration of the scrape in seconds",
                    });

                    foreach (var gaugeModel in gaugeModels)
                    {
                        var gauge = Metrics.CreateGauge(gaugeModel.Name, gaugeModel.Help, new GaugeConfiguration()
                        {
                            LabelNames = gaugeModel.Labels
                        });

                        gauge.WithLabels(gaugeModel.LabelValues).Set(gaugeModel.Value);
                    }
                }
                catch (Exception e)
                {
                    status = 0;
                    _logger.LogError($"{DateTime.Now:o} - {e.Message}");
                }
                finally
                {
                    var gauge = Metrics.CreateGauge("azureservicebusexporter_up",
                                                    "The status if the scrape was successful", new GaugeConfiguration());
                    gauge.Set(status);

                    _logger.LogTrace($"{DateTime.Now:o} - End scraping");
                }
            }

            await _next.Invoke(httpContext);
        }
Esempio n. 19
0
        public ServiceBusProvisioningService(AzureCredentials credentials, ServiceBusConfiguration config)
        {
            var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId);

            serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName);
        }
Esempio n. 20
0
        public IServiceBusManager Authenticate(string clientId, string clientSecret, string tenantId, string subscriptionId)
        {
            var azureCredentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);

            return(ServiceBusManager.Authenticate(azureCredentials, subscriptionId));
        }