Exemplo n.º 1
0
        // Get additional assemblies from azure storage
        private async Task <IEnumerable <Assembly> > GetDependencyAssembliesFromStorageAsync()
        {
            IEnumerable <Assembly> additionalAssemblies = new List <Assembly>();
            var mefStorageAccountName = ServiceFabricUtil.GetServiceFabricConfigSetting("MefStorageAccountName").Result.ToString();
            var mefContainerName      = ServiceFabricUtil.GetServiceFabricConfigSetting("MefContainerName").Result.ToString();

            if (string.IsNullOrEmpty(mefStorageAccountName) || string.IsNullOrEmpty(mefContainerName))
            {
                return(additionalAssemblies);
            }

            var mefBlobDirectory = ServiceFabricUtil.GetServiceFabricConfigSetting("MefBlobDirectory").Result.ToString();

            BlobStorageMSI blobStorage = new BlobStorageMSI(mefStorageAccountName);

            var dlls = blobStorage.GetCloudBlockBlobs(mefContainerName, mefBlobDirectory);

            foreach (var blob in dlls)
            {
                if (blob.Name.EndsWith(".dll"))
                {
                    using (var strm = new MemoryStream())
                    {
                        await blob.DownloadToStreamAsync(strm);

                        byte[] asseblyBytes = strm.ToArray();
                        var    assembly     = Assembly.Load(asseblyBytes);
                        additionalAssemblies = additionalAssemblies.Append(assembly);
                    }
                }
            }
            return(additionalAssemblies);
        }
Exemplo n.º 2
0
        static GatewayController()
        {
            WinHttpHandler handler = new WinHttpHandler();

            // We need to set timeout for handler first
            // Setting timeout for httpClient alone is not good enough
            var timeout = TimeSpan.FromSeconds(_DefaultHttpTimeoutSecs);

            handler.SendTimeout           = timeout;
            handler.ReceiveDataTimeout    = timeout;
            handler.ReceiveHeadersTimeout = timeout;

            _HttpClient = new HttpClient(handler)
            {
                // Default http timeout is 100s, increase it to 4 min since few key mainline scenarios
                // can take longer than default 100s
                Timeout = timeout
            };
            // Attach remote cert validation to ignore self-signed ssl cert error if reverseProxySslThumbprint is specified in the config
            handler.ServerCertificateValidationCallback = ValidateRemoteCert;

            _ReverseProxySslThumbprint = GetReverseProxySslThumbprintFromConfig();
            _AllowedUserRoles          = GetAllowedUserRolesFromConfig();
            var serviceKeyvaultName          = ServiceFabricUtil.GetServiceKeyVaultName().Result.ToString();
            var configPackage                = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
            var serviceEnvironmenConfig      = configPackage.Settings.Sections["ServiceEnvironment"];
            var appInsightsIntrumentationKey = serviceEnvironmenConfig.Parameters["AppInsightsIntrumentationKey"].Value;

            _IsUserInfoLoggingEnabled = IsUserInfoLoggingEnabled();
            _StaticLogger             = new ApplicationInsightsLogger("GatewayILogger", new Microsoft.ApplicationInsights.TelemetryClient(new TelemetryConfiguration(KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, appInsightsIntrumentationKey))), new ApplicationInsightsLoggerOptions());
        }
Exemplo n.º 3
0
        public static void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <ITelemetryInitializer, OperationParentIdTelemetryInitializer>();
            services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions()
            {
                EnableAdaptiveSampling = false,
                EnableDebugLogger      = false,
                InstrumentationKey     = KeyVault.KeyVault.GetSecretFromKeyvault(ServiceFabricUtil.GetServiceKeyVaultName().Result.ToString(), ServiceFabricUtil.GetServiceFabricConfigSetting("AppInsightsIntrumentationKey").Result.ToString())
            });
            services.AddSingleton <ITelemetryInitializer, OperationParentIdTelemetryInitializer>();
            services.AddLogging(logging =>
            {
                try
                {
                    // In order to log ILogger logs
                    logging.AddApplicationInsights();
                    // Optional: Apply filters to configure LogLevel Information or above is sent to
                    // ApplicationInsights for all categories.
                    logging.AddFilter <ApplicationInsightsLoggerProvider>("", LogLevel.Information);

                    // Additional filtering For category starting in "Microsoft",
                    // only Warning or above will be sent to Application Insights.
                    logging.AddFilter <ApplicationInsightsLoggerProvider>("Microsoft", LogLevel.Warning);
                }
                catch (Exception e)
                {
                    ServiceEventSource.Current.Message($"ApplicationInsights Error: {e.Message}");
                }
            });
        }
Exemplo n.º 4
0
        // Get the required settings to bootstrap the config gen
        private void InitConfigSettings()
        {
            var cosmosDBConfigConnectionString = ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigConnectionString").Result.ToString();
            var cosmosDBConfigDatabaseName     = ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigDatabaseName").Result.ToString();
            var cosmosDBConfigCollectionName   = ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigCollectionName").Result.ToString();

            InitialConfiguration.Set(CosmosDbConfigurationProvider.ConfigSettingName_CosmosDBConfig_ConnectionString, cosmosDBConfigConnectionString);
            InitialConfiguration.Set(CosmosDbConfigurationProvider.ConfigSettingName_CosmosDBConfig_DatabaseName, cosmosDBConfigDatabaseName);
            InitialConfiguration.Set(CosmosDbConfigurationProvider.ConfigSettingName_CosmosDBConfig_CollectionName, cosmosDBConfigCollectionName);
            InitialConfiguration.Set(DataX.Config.ConfigDataModel.Constants.ConfigSettingName_ServiceKeyVaultName, _serviceKeyVaultName);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Moving the method that sets the various environment variables
        /// </summary>
        /// <returns>This returns the success or failure as understood by the frontend</returns>
        public async Task <ApiResult> GetEnvironmentVariables()
        {
            CosmosDBDatabaseName = "production";

            var response = ServiceFabricUtil.GetServiceKeyVaultName();

            if (response.Error.HasValue && response.Error.Value)
            {
                return(ApiResult.CreateError(response.Message));
            }
            string serviceKeyvaultName = response.Result.ToString();

            var cosmosCon = KeyVault.GetSecretFromKeyvault(ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigConnectionString").Result.ToString());

            CosmosDBDatabaseName = KeyVault.GetSecretFromKeyvault(ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigDatabaseName").Result.ToString());

            var namePassword = Helper.ParseCosmosDBUserNamePassword(cosmosCon);

            if (string.IsNullOrEmpty(cosmosCon) || string.IsNullOrEmpty(namePassword) || namePassword.Split(new char[] { ':' }).Count() != 2)
            {
                return(ApiResult.CreateError("Can't get UserName or Password from CosmosDB connection string"));
            }

            CosmosDBEndPoint = Helper.ParseCosmosDBEndPoint(cosmosCon);
            CosmosDBUserName = namePassword.Split(new char[] { ':' })[0];
            CosmosDBPassword = namePassword.Split(new char[] { ':' })[1];

            response = await CosmosDB.DownloadConfigFromDocumentDB(CosmosDBDatabaseName, CosmosDBEndPoint, CosmosDBUserName, CosmosDBPassword, ServiceFabricUtil.GetServiceFabricConfigSetting("cosmosDBConfigCollectionName").Result.ToString());

            if (response.Error.HasValue && response.Error.Value)
            {
                return(ApiResult.CreateError(response.Message));
            }

            var flowConfigObj = response.Result.ToObject <FlowConfigObject>();

            if (flowConfigObj != null)
            {
                EngineFlowConfig = flowConfigObj;
                ResourceCreation = flowConfigObj.ResourceCreation.ToLower().Equals("true") ? true : false;

                FlowBlobConnectionString = KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, flowConfigObj.ConfiggenSecretPrefix + flowConfigObj.StorageAccountName + "-blobconnectionstring");
                OpsBlobConnectionString  = KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, flowConfigObj.ConfiggenSecretPrefix + flowConfigObj.OpsStorageAccountName + "-blobconnectionstring");
                SparkConnInfo            = Helper.ParseConnectionString(Helper.PathResolver(flowConfigObj.SparkConnectionString));
                return(ApiResult.CreateSuccess(""));
            }

            return(ApiResult.CreateError("Failed to get environment variables"));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialze a new instance of the event process host
        /// </summary>
        /// <returns>event processor host</returns>
        private async Task <EventProcessorHost> InitalizeEventProcessorHostAsync()
        {
            // start listening to the event hub
            var eventHubName  = ServiceFabricUtil.GetServiceFabricConfigSetting("EventHubName").Result?.ToString();
            var consumerGroup = ServiceFabricUtil.GetServiceFabricConfigSetting("ConsumerGroupName").Result?.ToString();

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                consumerGroup,
                await SecretsStore.Instance.GetMetricsEventHubListenerConnectionStringAsync(),
                await SecretsStore.Instance.GetMetricsStorageConnectionStringAsync(),
                "metricsingestor");

            return(eventProcessorHost);
        }
        static GatewayController()
        {
            WinHttpHandler handler = new WinHttpHandler();

            // We need to set timeout for handler first
            // Setting timeout for httpClient alone is not good enough
            var timeout = TimeSpan.FromSeconds(_DefaultHttpTimeoutSecs);

            handler.SendTimeout           = timeout;
            handler.ReceiveDataTimeout    = timeout;
            handler.ReceiveHeadersTimeout = timeout;

            _HttpClient = new HttpClient(handler)
            {
                // Default http timeout is 100s, increase it to 4 min since few key mainline scenarios
                // can take longer than default 100s
                Timeout = timeout
            };
            // Attach remote cert validation to ignore self-signed ssl cert error if reverseProxySslThumbprint is specified in the config
            handler.ServerCertificateValidationCallback = ValidateRemoteCert;

            _ReverseProxySslThumbprint = GetReverseProxySslThumbprintFromConfig();
            _AllowedUserRoles          = GetAllowedUserRolesFromConfig();
            var serviceKeyvaultName          = ServiceFabricUtil.GetServiceKeyVaultName().Result.ToString();
            var configPackage                = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
            var serviceEnvironmenConfig      = configPackage.Settings.Sections["ServiceEnvironment"];
            var appInsightsIntrumentationKey = serviceEnvironmenConfig.Parameters["AppInsightsIntrumentationKey"].Value;
            var testClientId = serviceEnvironmenConfig.Parameters["TestClientId"].Value;

            _IsUserInfoLoggingEnabled = IsUserInfoLoggingEnabled();
            _StaticLogger             = new ApplicationInsightsLogger("GatewayILogger", new Microsoft.ApplicationInsights.TelemetryClient(new TelemetryConfiguration(KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, appInsightsIntrumentationKey))), new ApplicationInsightsLoggerOptions());
            try
            {
                // Each secret needs to be a list of unique Ids in the format {ObjectId}.{TenantId}
                List <string> userIdList = KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, testClientId).Split(new char[] { ',' }).ToList();
                foreach (string userId in userIdList)
                {
                    _ClientWhitelist.Add(userId);
                }
            }
            catch (Exception e)
            {
                // Do nothing in case the TestClientId is not set in the keyvault. This is set for testing purposes.
                var message = e.Message;
                _StaticLogger.LogError(e.Message);
            }
        }
Exemplo n.º 8
0
        public KafkaMessageBus(string brokerList, string connectionString, List <string> topics, string consumerGroup, string inputType, ILogger logger)
        {
            if (!File.Exists(_cacertLocation))
            {
                var certSource = KeyVault.GetSecretFromKeyvault(ServiceFabricUtil.GetServiceFabricConfigSetting("CACertificateLocation").Result.ToString());

                WebClient webClient = new WebClient();
                webClient.DownloadFile(certSource, _cacertLocation);
            }

            _brokerList       = brokerList;
            _connectionString = connectionString;
            _topics           = topics;
            _consumerGroup    = consumerGroup;
            _inputType        = inputType;
            _logger           = logger;
        }
Exemplo n.º 9
0
        // Get additional assemblies from azure storage
        private async Task <IEnumerable <Assembly> > GetDependencyAssembliesFromStorageAsync()
        {
            IEnumerable <Assembly> additionalAssemblies = new List <Assembly>();
            var mefStorageAccountName = ServiceFabricUtil.GetServiceFabricConfigSetting("MefStorageAccountName").Result.ToString();
            var mefContainerName      = ServiceFabricUtil.GetServiceFabricConfigSetting("MefContainerName").Result.ToString();

            if (string.IsNullOrEmpty(mefStorageAccountName) || string.IsNullOrEmpty(mefContainerName))
            {
                return(additionalAssemblies);
            }

            var mefBlobDirectory = ServiceFabricUtil.GetServiceFabricConfigSetting("MefBlobDirectory").Result.ToString();

            BlobStorageMSI blobStorage = new BlobStorageMSI(mefStorageAccountName);

            var dlls = blobStorage.GetCloudBlockBlobs(mefContainerName, mefBlobDirectory);

            // Configure and create a logger instance
            var logger = _loggerFactory.CreateLogger <Startup>();

            foreach (var blob in dlls)
            {
                if (blob.Name.EndsWith(".dll"))
                {
                    using (var strm = new MemoryStream())
                    {
                        await blob.DownloadToStreamAsync(strm);

                        byte[] asseblyBytes = strm.ToArray();
                        try
                        {
                            var assembly = Assembly.Load(asseblyBytes);
                            additionalAssemblies = additionalAssemblies.Append(assembly);
                        }
                        catch (BadImageFormatException be)
                        {
                            // Do nothing and skip the assembly to load as it might be a native assembly
                            logger.LogError(be, "Unable to load Assembly: {0} from the StorageAccount", blob.Name);
                        }
                    }
                }
            }
            return(additionalAssemblies);
        }
Exemplo n.º 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            _serviceKeyVaultName = ServiceFabricUtil.GetServiceKeyVaultName().Result.ToString();
            StartUpUtil.ConfigureServices(services);

            // Configure and create a logger instance to add it to MEF container
            var logger = _loggerFactory.CreateLogger <RuntimeConfigGeneration>();

            // Initialize the settings by getting the values from settings file
            InitConfigSettings();

            // Export the Config dependencies
            Type[] exportTypes = new Type[] { typeof(FlowOperation), typeof(RuntimeConfigGeneration), typeof(JobOperation) };

            IEnumerable <Assembly> cloudModeDependencyAssemblies = GetCloudModeDependencyAssemblies();
            IEnumerable <Assembly> additionalAssemblies          = GetDependencyAssembliesFromStorageAsync().Result;

            var allAssemblies = cloudModeDependencyAssemblies.Union(additionalAssemblies);

            services.AddMefExportsFromAssemblies(ServiceLifetime.Scoped, allAssemblies, exportTypes, new object[] { logger });
        }
Exemplo n.º 11
0
 /// <summary>
 /// A helper method that Adds the test client user id to the white list from keyvault if it exists
 /// TODO: Support adding this whitelist on Kubernetes using IConfiguration object
 /// </summary>
 private static void AddWhitelistedTestClientUserId()
 {
     if (HostUtil.InServiceFabric)
     {
         var serviceKeyvaultName     = ServiceFabricUtil.GetServiceKeyVaultName().Result.ToString();
         var configPackage           = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config");
         var serviceEnvironmenConfig = configPackage.Settings.Sections["ServiceEnvironment"];
         var testClientId            = serviceEnvironmenConfig.Parameters["TestClientId"].Value;
         try
         {
             // Each secret needs to be in the format {ObjectId}.{TenantId}
             List <string> userIdList = KeyVault.KeyVault.GetSecretFromKeyvault(serviceKeyvaultName, testClientId).Split(new char[] { ',' }).ToList();
             foreach (string userId in userIdList)
             {
                 _ClientWhitelist.Add(userId);
             }
         }
         catch (Exception e)
         {
             // Do nothing in case the secret does not exist.
             var message = e.Message;
         }
     }
 }
Exemplo n.º 12
0
 private SecretsStore()
 {
     _keyVaultName = (string)ServiceFabricUtil.GetServiceKeyVaultName().Result;
 }
Exemplo n.º 13
0
 public async Task <string> GetMetricsRedisConnectionStringAsync()
 {
     return(await GetSecretAsync(ServiceFabricUtil.GetServiceFabricConfigSetting("RedisCacheConnectionstring")));
 }
Exemplo n.º 14
0
 public async Task <string> GetMetricsStorageConnectionStringAsync()
 {
     return(await GetSecretAsync(ServiceFabricUtil.GetServiceFabricConfigSetting("StorageAccountConnectionstring")));
 }
Exemplo n.º 15
0
 public async Task <string> GetMetricsEventHubListenerConnectionStringAsync()
 {
     return(await GetSecretAsync(ServiceFabricUtil.GetServiceFabricConfigSetting("EventhubNamespaceConnectionstring")));
 }
Exemplo n.º 16
0
 private SecretsStore()
 {
     _keyVaultName = ServiceFabricUtil.GetServiceKeyVaultName().Result?.ToString();
 }