Ejemplo n.º 1
0
#pragma warning restore CA1051 // Do not declare visible instance fields

        protected LogServiceBase(IOptionsMonitor <Configuration.ColidStatisticsLogOptions> optionsAccessor, IHttpContextAccessor httpContextAccessor)
        {
            Contract.Requires(optionsAccessor != null);

            _httpContextAccessor = httpContextAccessor;
            var options = optionsAccessor.CurrentValue;

            _productName   = options.ProductName;
            _layerName     = options.LayerName;
            _anonymizerKey = options.AnonymizerKey;
            _sha256        = SHA256.Create();

            if (options.Enabled)
            {
                // if accessKey and secretKey are provided via configuration, use them. otherwise try to
                // determine by default AWS credentials resolution process see https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html#creds-assign
                if (!string.IsNullOrWhiteSpace(options.AccessKey) && !string.IsNullOrWhiteSpace(options.SecretKey))
                {
                    var creds  = new BasicAWSCredentials(options.AccessKey, options.SecretKey);
                    var region = RegionEndpoint.GetBySystemName(options.AwsRegion);
                    _awsHttpConnection = new AwsHttpConnection(creds, region);
                }
                else
                {
                    _awsHttpConnection = new AwsHttpConnection(options.AwsRegion);
                }
            }

            _logger = GetLogger(options);
        }
Ejemplo n.º 2
0
        public void Init()
        {
            var stream = GetValidStream();

            var options = new CredentialProfileOptions
            {
                AccessKey = System.Environment.GetEnvironmentVariable("AWSACCESSKEY"),
                SecretKey = System.Environment.GetEnvironmentVariable("AWSSECRET")
            };

            var profile    = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options);
            var netSDKFile = new NetSDKCredentialsFile();
            var region     = Amazon.RegionEndpoint.GetBySystemName(stream.AwsRegion);

            var creds = AWSCredentialsFactory.GetAWSCredentials(profile, netSDKFile);

            var connection = new AwsHttpConnection(creds, region);

            var pool   = new SingleNodeConnectionPool(new Uri(stream.ElasticSearchDomainName));
            var config = new Nest.ConnectionSettings(pool, connection);
            var client = new ElasticClient(config);

            if (client.Indices.Exists(stream.ElasticSearchIndexName).Exists)
            {
                var res = client.Indices.Delete(stream.ElasticSearchIndexName);
                Console.WriteLine(res.DebugInformation);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This constructor instantiates a new ElasticClient using the AWSOptions and AWS cluster URI
        /// </summary>
        /// <param name="awsOptions">AWSOptions containing the credentials and region endpoint</param>
        /// <param name="esClusterUri">URI of the Elasticsearch cluster in AWS</param>
        /// <param name="defaultIndex">(Optional) default index to use for writing documents</param>
        /// <param name="numberOfBulkDocumentsToWriteAtOnce">
        ///     (Optional) number of documents to write to Elasticsearch
        ///     - set to 0 to write every record immediately, default is 5
        /// </param>
        /// <param name="rollingDate">(Optional) whether or not to use a rolling date pattern when writing to indices, default is false</param>
        /// <param name="logger">(Optional) ILogger to use</param>
        public Floe(
            AWSOptions awsOptions,
            Uri esClusterUri,
            string defaultIndex = null,
            int numberOfBulkDocumentsToWriteAtOnce = _defaultNumberOfBulkDocumentsToWriteAtOnce,
            bool rollingDate = false,
            ILogger logger   = null)
        {
            if (awsOptions == null)
            {
                throw new ArgumentNullException(nameof(awsOptions));
            }

            if (!string.IsNullOrEmpty(defaultIndex))
            {
                _defaultIndex = defaultIndex;
            }

            _rollingDate = rollingDate;

            if (numberOfBulkDocumentsToWriteAtOnce > -1)
            {
                _numberOfBulkDocumentsToWriteAtOnce = numberOfBulkDocumentsToWriteAtOnce;
            }

            AwsHttpConnection httpConnection = new AwsHttpConnection(awsOptions);

            SingleNodeConnectionPool connectionPool     = new SingleNodeConnectionPool(esClusterUri);
            ConnectionSettings       connectionSettings = new ConnectionSettings(connectionPool, httpConnection);

            _client = new ElasticClient(connectionSettings);

            _logger = logger;
        }
        public SampleElasticsearchClient(string endPoint, Amazon.RegionEndpoint regionEndPoint)
        {
            AWSCredentials    awsCredentials = FallbackCredentialsFactory.GetCredentials();
            AwsHttpConnection conn           = new AwsHttpConnection(regionEndPoint.SystemName,
                                                                     new StaticCredentialsProvider(new AwsCredentials()
            {
                AccessKey = awsCredentials.GetCredentials().AccessKey,
                SecretKey = awsCredentials.GetCredentials().SecretKey,
                Token     = awsCredentials.GetCredentials().Token
            }));

            var pool = new SingleNodeConnectionPool(new Uri(endPoint));
            ConnectionSettings settings = new ConnectionSettings(pool, conn)
                                          .DisableDirectStreaming()
                                          .InferMappingFor <LogEntry>(m => m.IndexName("logs"));

            //.DefaultMappingFor<LogEntry>(m => m.IndexName("logs"));

            _esClient = new ElasticClient(settings);

            IndexName logIndex = IndexName.From <LogEntry>();

            var req = new IndexExistsRequest(logIndex);
            var res = _esClient.IndexExists(req);

            if (!res.Exists)
            {
                _esClient.CreateIndex("logs", c => c
                                      .Mappings(md => md.Map <LogEntry>(m => m.AutoMap())));
            }
        }
        public static ElasticsearchSinkOptions CreateElasticsearchSinkOptions(ElasticSearchLogConfiguration elasticSearchLogConfiguration, ElasticSearchLogSecretConfiguration elasticSearchLogSecretConfiguration)
        {
            if (elasticSearchLogConfiguration == null || elasticSearchLogSecretConfiguration == null)
            {
                return(null);
            }

            var singleNodeConnectionPool = new SingleNodeConnectionPool(elasticSearchLogConfiguration.Uri);

            var awsHttpConnection = new AwsHttpConnection(elasticSearchLogConfiguration.Region, new StaticCredentialsProvider(
                                                              new AwsCredentials
            {
                AccessKey = elasticSearchLogSecretConfiguration.AccessKey,
                SecretKey = elasticSearchLogSecretConfiguration.SecretKey
            }));

            var options = new ElasticsearchSinkOptions(elasticSearchLogConfiguration.Uri)
            {
                IndexFormat              = elasticSearchLogConfiguration.IndexFormat,
                InlineFields             = elasticSearchLogConfiguration.InlineFields,
                MinimumLogEventLevel     = elasticSearchLogConfiguration.MinimumLogLevel,
                ModifyConnectionSettings = conn => new ConnectionConfiguration(singleNodeConnectionPool, awsHttpConnection)
            };

            return(options);
        }
Ejemplo n.º 6
0
        public async Task SeedData()
        {
            try
            {
                var httpConnection = new AwsHttpConnection(new AwsSettings
                {
                    AccessKey = "AKIAI63FYLJHOUAV7HQA",
                    SecretKey = "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",
                    Region    = "us-east-1",
                });

                var           indexName = _config["ConnectionStrings:IndexName"];
                var           node      = new Uri("https://search-bunee-test-hxpcuz56nhqazfwlwz75wtexh4.us-east-1.es.amazonaws.com");
                var           pool      = new SingleNodeConnectionPool(node);
                var           settings  = new ConnectionSettings(pool, httpConnection).DefaultIndex(indexName);
                ElasticClient client    = new ElasticClient(settings);

                var result = client.TypeExists(indexName, typeof(Persona));
                if (!result.Exists)
                {
                    var indexSettings = new IndexSettings();
                    indexSettings.NumberOfReplicas = 1;
                    indexSettings.NumberOfShards   = 1;

                    var indexState = new IndexState();
                    indexState.Settings = indexSettings;

                    await client.CreateIndexAsync(indexName, f => f.InitializeUsing(indexState));
                }
            }
            catch
            {
                Console.WriteLine("Error al conectar a BD");
            }
        }
Ejemplo n.º 7
0
        public EsRepository(IOptions <EsRepoConfiguration> esConfiguration)
        {
            var esConfig = esConfiguration.Value;

            var httpConnection = new AwsHttpConnection(new AwsSettings
            {
                AccessKey = esConfig.AwsConfiguration.AccessKey,
                SecretKey = esConfig.AwsConfiguration.SecretKey,
                Region    = esConfig.AwsConfiguration.Region
            });

            var pool = new SingleNodeConnectionPool(new Uri(esConfig.ServerUrl));

            // Configure the connection
            //  - Also hookup asyn logging of all API call details (EnableTrace not avaialble in NEST 2.x, yet.)
            var config = new ConnectionSettings(pool, httpConnection)
                         .DisableDirectStreaming()
                         .OnRequestCompleted(r => EsApiLog.LogEsApiCallDetailsAsync(r));

            // Default index mappings to types...
            // To bad there is no attribute based mapping for this
            // [TO_FILL register ElasticSearch index mapping here]
            config.MapDefaultTypeIndices(m => m
                                         .Add(typeof(MyProduct), "my_product_index")
                                         );

            // Create the client
            Client = new ElasticClient(config);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Instantiate client
        /// </summary>
        public Client( )
        {
            AWSCredentials credentials;
            string         json = File.ReadAllText(string.Format(@"{0}aws.config.json", AppDomain.CurrentDomain.BaseDirectory));

            credentials = JsonConvert.DeserializeObject <AWSCredentials>(json);

            if (credentials == null)
            {
                throw new Exception("Whoops...");
            }

            var httpConnection = new AwsHttpConnection(new AwsSettings
            {
                AccessKey = credentials.Key,
                SecretKey = credentials.Secret,
                Region    = credentials.Region
            });


            // create uri and connect to the service
            var pool   = new SingleNodeConnectionPool(new Uri(credentials.Uri));
            var config = new ConnectionSettings(pool, httpConnection);

            _client = new ElasticClient(config);
            // build indices and mappings
            CreateQuestIndices( );
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new ConnectionConfiguration(pool, httpConnection);

            _client    = new ElasticLowLevelClient(config);
            _indexName = $"unittest_{Guid.NewGuid().ToString("n")}";
        }
Ejemplo n.º 10
0
        private ElasticClient CreateAwsHostedElasticClient()
        {
            var httpConnection = new AwsHttpConnection(
                new BasicAWSCredentials(_awsAccessKeyId, _awsSecretAccessKey), RegionEndpoint.USEast2);
            var pool          = new SingleNodeConnectionPool(new Uri(_awsElasticSearchUrl));
            var config        = new ConnectionSettings(pool, httpConnection);
            var elasticClient = new ElasticClient(config);

            return(elasticClient);
        }
        public static void AddElasticSearch(this IServiceCollection services, IConfiguration configuration)
        {
            var options        = configuration.GetAWSOptions();
            var httpConnection = new AwsHttpConnection(options);
            var pool           = new SingleNodeConnectionPool(new Uri(configuration.GetSection("AWS:ElasticUrl").Value));
            var config         = new ConnectionSettings(pool, httpConnection);
            var client         = new ElasticClient(config);

            services.AddSingleton <IElasticClient>(client);
        }
Ejemplo n.º 12
0
        public void Ping_should_work()
        {
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new ConnectionConfiguration(pool, httpConnection);
            var client         = new ElasticLowLevelClient(config);
            var response       = client.Ping <object>();

            Assert.AreEqual(200, response.HttpStatusCode.GetValueOrDefault(-1));
        }
Ejemplo n.º 13
0
        public void NestPing_should_work()
        {
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new Nest.ConnectionSettings(pool, httpConnection);
            var client         = new Nest.ElasticClient(config);
            var response       = client.Ping();

            Assert.AreEqual(true, response.IsValid);
        }
Ejemplo n.º 14
0
        public void Asterisk_encoded_url_should_work()
        {
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new ConnectionConfiguration(pool, httpConnection);
            var client         = new ElasticLowLevelClient(config);
            var response       = client.Get <Stream>("index*", "type", "id");

            Assert.AreEqual(404, response.HttpStatusCode.GetValueOrDefault(-1));
        }
Ejemplo n.º 15
0
        public void Random_encoded_url_should_work()
        {
            var randomString   = Guid.NewGuid().ToString("N");
            var httpConnection = new AwsHttpConnection(Region, Credentials);
            var pool           = new SingleNodeConnectionPool(new Uri(TestConfig.Endpoint));
            var config         = new ConnectionConfiguration(pool, httpConnection);
            var client         = new ElasticLowLevelClient(config);
            var response       = client.Get <Stream>(randomString, string.Join(",", Enumerable.Repeat(randomString, 2)), randomString);

            Assert.AreEqual(404, response.HttpStatusCode.GetValueOrDefault(-1));
        }
Ejemplo n.º 16
0
        public void Initialize()
        {
            var httpConnection = new AwsHttpConnection(_awsRegion);
            var pool           = new SingleNodeConnectionPool(new Uri(_url));
            var settings       = new ConnectionSettings(pool, httpConnection);

            //var settings = new ConnectionSettings(new Uri(_url));
            AddDefaultMappings(settings);
            _client = new ElasticClient(settings);
            AddIndexMappings(_client);
        }
Ejemplo n.º 17
0
        public ElasticClient GetElasticClient()
        {
            var httpConnection = new AwsHttpConnection(_awsRegion, new StaticCredentialsProvider(new AwsCredentials()
            {
                AccessKey = _accessKey,
                SecretKey = _secretKey,
            }));

            var pool   = new SingleNodeConnectionPool(new Uri(_endpointES));
            var config = new ConnectionSettings(pool, httpConnection);

            config.DefaultIndex(_defaultIndex);
            return(new ElasticClient(config));
        }
        public Task <InvokeResult> InitAsync(DataStream stream)
        {
            _stream     = stream;
            _connection = new AwsHttpConnection(stream.AWSRegion, new StaticCredentialsProvider(new AwsCredentials
            {
                AccessKey = stream.AWSAccessKey,
                SecretKey = stream.AWSSecretKey
            }));

            var pool   = new SingleNodeConnectionPool(new Uri(stream.ESDomainName));
            var config = new ConnectionSettings(pool, _connection);

            _client = new ElasticClient(config);

            return(Task <InvokeResult> .FromResult(InvokeResult.Success));
        }
Ejemplo n.º 19
0
        public IElasticClient GetDeliveryStoreIndexElasticClient()
        {
            var url          = _config["Database:ElasticSearchUrl"];
            var defaultIndex = _config["Database:DeliveryStoreElasticIndex"];
            var profileName  = _config["Database:ProfileName"];

            var chain = new CredentialProfileStoreChain(_config["Database:ElasticKeysPath"]);

            chain.TryGetAWSCredentials(profileName, out AWSCredentials awsCredentials);
            var httpConnection = new AwsHttpConnection(awsCredentials, Amazon.RegionEndpoint.CACentral1);
            var pool           = new SingleNodeConnectionPool(new Uri(url));
            var settings       = new ConnectionSettings(pool, httpConnection).DefaultIndex(defaultIndex);
            var client         = new ElasticClient(settings);

            return(client);
        }
Ejemplo n.º 20
0
        public PersonaRepository(IConfigurationRoot config)
        {
            _config = config;

            var httpConnection = new AwsHttpConnection(new AwsSettings
            {
                AccessKey = "AKIAI63FYLJHOUAV7HQA",
                SecretKey = "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",
                Region    = "us-east-1",
            });

            var indexName = _config["ConnectionStrings:IndexName"];
            var node      = new Uri("https://search-bunee-test-hxpcuz56nhqazfwlwz75wtexh4.us-east-1.es.amazonaws.com");
            var pool      = new SingleNodeConnectionPool(node);
            var settings  = new ConnectionSettings(pool, httpConnection).DefaultIndex(indexName);

            client = new ElasticClient(settings);
        }
        public void Init()
        {
            var stream     = GetValidStream();
            var connection = new AwsHttpConnection(stream.AWSRegion, new StaticCredentialsProvider(new AwsCredentials
            {
                AccessKey = stream.AWSAccessKey,
                SecretKey = stream.AWSSecretKey
            }));

            var pool   = new SingleNodeConnectionPool(new Uri(stream.ESDomainName));
            var config = new Nest.ConnectionSettings(pool, connection);
            var client = new ElasticClient(config);

            if (client.IndexExists(stream.ESIndexName).Exists)
            {
                var res = client.DeleteIndex(stream.ESIndexName);
                Console.WriteLine(res.DebugInformation);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VehicleInventoryDbEventProcessor" /> class.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="dynamoDbContext">The dynamo database context.</param>
        public VehicleInventoryDbEventProcessor(IElasticClient client, IDynamoDBContext dynamoDbContext)
        {
            var config = new DynamoDBContextConfig {
                ConsistentRead = true, TableNamePrefix = $"dev_"
            };

            // this is used for more integratin level testing.
            if (client == null)
            {
                var creds =
                    new StaticCredentialsProvider(
                        new AwsCredentials
                {
                    AccessKey = string.Empty,
                    SecretKey = string.Empty,
                });

                var node =
                    new SingleNodeConnectionPool(
                        new Uri(string.Empty));

                this.awsHttpConnection = new AwsHttpConnection(RegionEndpoint.USEast1.SystemName, creds);

                // setup index settings for each strongly typed object
                var settings =
                    new ConnectionSettings(node, this.awsHttpConnection)
                    .DisableDirectStreaming()
                    .InferMappingFor <InventoryItem>(m => m.IdProperty(p => p.VIN))
                    .MapDefaultTypeIndices(m => m.Add(typeof(InventoryItem), "dev_vehicle_inventory"));

                this.elasticClient = new ElasticClient(settings);

                IAmazonDynamoDB dynamoDbClient = new AmazonDynamoDBClient(RegionEndpoint.USEast1);
                this.indexer = new ElasticSearchIndexer <InventoryItem>(dynamoDbClient, Environment.GetEnvironmentVariable("environment"), this.elasticClient);

                this.dynamoDbContext = new DynamoDBContext(dynamoDbClient, config);
            }
            else
            {
                this.elasticClient   = client;
                this.dynamoDbContext = dynamoDbContext;
            }
        }
        private static void CreateSinkOptions(LogConfiguration logConfiguration, LogSecretConfiguration logSecretConfiguration)
        {
            var singleNodeConnectionPool = new SingleNodeConnectionPool(logConfiguration.Uri);
            var awsHttpConnection        = new AwsHttpConnection(logConfiguration.Region, new StaticCredentialsProvider(
                                                                     new AwsCredentials
            {
                AccessKey = logSecretConfiguration.AccessKey,
                SecretKey = logSecretConfiguration.SecretKey
            }));

            elasticsearchSinkOptions = new ElasticsearchSinkOptions(logConfiguration.Uri)
            {
                IndexFormat              = logConfiguration.IndexFormat,
                InlineFields             = logConfiguration.InlineFields,
                MinimumLogEventLevel     = logConfiguration.MinimumLogLevel,
                ModifyConnectionSettings = conn =>
                {
                    return(new ConnectionConfiguration(singleNodeConnectionPool, awsHttpConnection));
                }
            };
        }
Ejemplo n.º 24
0
        public static void ConfigureSerilog(this BaseStartup _, IConfiguration configuration)
        {
            var index         = ServiceName.Replace(".", "-");
            var loggingConfig = configuration.GetSection(nameof(LoggingConfig)).Get <LoggingConfig>();

            var esConfig    = loggingConfig.ElasticSearch;
            var slackConfig = loggingConfig.Slack;

            var logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Warning();

            if (!string.IsNullOrEmpty(esConfig.ElasticUrl))
            {
                logger = logger.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(esConfig.ElasticUrl))
                {
                    ModifyConnectionSettings = conn =>
                    {
                        var awsCredentials =
                            new BasicAWSCredentials(esConfig.AwsAccessKeyId, esConfig.AwsSecretKey);
                        var httpConnection = new AwsHttpConnection(awsCredentials,
                                                                   RegionEndpoint.GetBySystemName(esConfig.AwsRegion));
                        var pool = new SingleNodeConnectionPool(new Uri(esConfig.ElasticUrl));

                        return(new ConnectionConfiguration(pool, httpConnection));
                    },
                    IndexFormat          = $"{index}-{{0:yyyy.MM}}",
                    AutoRegisterTemplate = true
                });
            }

            if (slackConfig.Channels.Length > 0 && !string.IsNullOrEmpty(slackConfig.Channels[0].WebhookUrl))
            {
                logger = logger.WriteTo.Slack(
                    (SlackChannelCollection)slackConfig.Channels.Select(c => new SlackChannel(c.WebhookUrl)), null,
                    slackConfig.LogLevel);
            }

            Log.Logger = logger.CreateLogger();
        }
        public ElasticSearchService(IConfiguration configuration, ILogger <ElasticSearchService> logger)
        {
            _logger = logger;
            string elasticSearchUrl = configuration["ElasticSearch:Url"] ?? "https://" + Environment.GetEnvironmentVariable("ElasticSearchUrl");

            var regionRegex = new Regex(@"\.([^\.]+)\.es\.amazonaws\.com/?$");
            var matches     = regionRegex.Matches(elasticSearchUrl);

            var elasticSearchRegion = matches.Count > 0 ? matches[0].Groups[1].Value : null;

            if (!string.IsNullOrWhiteSpace(elasticSearchUrl) && !string.IsNullOrWhiteSpace(elasticSearchRegion))
            {
                var httpConnection = new AwsHttpConnection(elasticSearchRegion);

                var pool   = new SingleNodeConnectionPool(new Uri(elasticSearchUrl));
                var config = new ConnectionSettings(pool, httpConnection)
                             .DisableDirectStreaming() //this line enables error messages from amazon
                             .DefaultMappingFor <Book>(m => m.IndexName(BookIndex));

                elasticClient = new ElasticClient(config);
            }
        }
Ejemplo n.º 26
0
        public Startup(IConfiguration configuration, IHostingEnvironment environment)
        {
            Configuration = configuration;

            Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", configuration.GetSection("AWS:AccessKey").Value);
            Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", configuration.GetSection("AWS:SecretKey").Value);
            Environment.SetEnvironmentVariable("AWS_REGION", configuration.GetSection("AWS:Region").Value);

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(configuration.GetSection("AWS:ElasticUrl").Value))
            {
                ModifyConnectionSettings = conn =>
                {
                    var httpConnection = new AwsHttpConnection(configuration.GetSection("AWS:Region").Value);
                    var pool           = new SingleNodeConnectionPool(new Uri(configuration.GetSection("AWS:ElasticUrl").Value));
                    var conf           = new ConnectionConfiguration(pool, httpConnection);
                    return(conf);
                },
                IndexFormat = "emrelog-{0:yyyy.MM}",
            })
                         .CreateLogger();
        }
Ejemplo n.º 27
0
        public ViewResult Index(string SearchString, string SearchString1, string SearchString2)
        {
            string esDomain = WebConfigurationManager.AppSettings["EsEndpoint"];

            var credentials    = new EnvironmentAWSCredentials();
            var httpConnection = new AwsHttpConnection(credentials, RegionEndpoint.USEast1);

            var pool   = new SingleNodeConnectionPool(new Uri(esDomain));
            var config = new ConnectionSettings(pool, httpConnection);
            var client = new ElasticClient(config);

            var getTableData = client.Search <DocumentAttributes>(s => s.Index("resume")); // you can get maximum 10000 records at a time

            List <DocumentAttributes> lstData = new List <DocumentAttributes>();

            foreach (var hit in getTableData.Hits)
            {
                lstData.Add(hit.Source);
            }

            return(View(lstData));
        }
        ElasticClient InitialiseClient()
        {
            // build the endpoint URL from its components to workaround apparent issue
            // with putting full URLs in AWS environment variables
            var b = new UriBuilder
            {
                Scheme = env.ES_ENDPOINT_SCHEME,
                Host   = env.ES_ENDPOINT_HOST,
                Port   = Convert.ToInt32(env.ES_ENDPOINT_PORT),
            };

            var endpoint = new Uri(b.ToString());
            var pool     = new SingleNodeConnectionPool(endpoint);

            if (endpoint.IsLoopback)
            {
                // support localhost for local development
                return(new ElasticClient(new ConnectionSettings(pool)));
            }
            else if (env.AWS_ACCESS_KEY_ID.IsNotBlank() && env.AWS_SECRET_ACCESS_KEY.IsNotBlank())
            {
                var connection = new AwsHttpConnection(env.AWS_DEFAULT_REGION,
                                                       new StaticCredentialsProvider(
                                                           new AwsCredentials
                {
                    AccessKey = env.AWS_ACCESS_KEY_ID,
                    SecretKey = env.AWS_SECRET_ACCESS_KEY,
                }));

                return(new ElasticClient(new ConnectionSettings(pool, connection)));
            }
            else
            {
                // attempt to use AWS instance profile (for production)
                var connection = new AwsHttpConnection(env.AWS_DEFAULT_REGION, new InstanceProfileCredentialProvider());
                return(new ElasticClient(new ConnectionSettings(pool, connection)));
            }
        }
Ejemplo n.º 29
0
        public Task <InvokeResult> InitAsync(DataStream stream)
        {
            var options = new CredentialProfileOptions
            {
                AccessKey = stream.AwsAccessKey,
                SecretKey = stream.AwsSecretKey
            };

            var profile    = new CredentialProfile("basic_profile", options);
            var netSDKFile = new NetSDKCredentialsFile();
            var region     = Amazon.RegionEndpoint.GetBySystemName(stream.AwsRegion);

            var creds = AWSCredentialsFactory.GetAWSCredentials(profile, netSDKFile);

            _connection = new AwsHttpConnection(creds, region);
            _stream     = stream;

            var pool   = new SingleNodeConnectionPool(new Uri(stream.ElasticSearchDomainName));
            var config = new ConnectionSettings(pool, _connection);

            _client = new ElasticClient(config);

            return(Task <InvokeResult> .FromResult(InvokeResult.Success));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VehicleInventoryScheduledEventProcessor"/> class.
        /// </summary>
        public VehicleInventoryScheduledEventProcessor()
        {
            this.awsHttpConnection = new AwsHttpConnection(RegionEndpoint.USEast1.SystemName);

            var node = new SingleNodeConnectionPool(new Uri(Environment.GetEnvironmentVariable("elasticSearchURL")));

            // setup index settings for each strongly typed object
            var settings = new ConnectionSettings(node, this.awsHttpConnection)
                           .DisableDirectStreaming()
                           .InferMappingFor <InventoryItem>(m => m.IdProperty(p => p.VIN))
                           .MapDefaultTypeIndices(m => m.Add(typeof(InventoryItem), "dev_vehicle_inventory"));

            this.elasticClient = new ElasticClient(settings);

            IAmazonDynamoDB dynamoDbClient = new AmazonDynamoDBClient();

            this.indexer = new ElasticSearchIndexer <InventoryItem>(dynamoDbClient, Environment.GetEnvironmentVariable("environment"), this.elasticClient);

            var config = new DynamoDBContextConfig {
                ConsistentRead = true, TableNamePrefix = $"{Environment.GetEnvironmentVariable("environment")}_"
            };

            this.dynamoDbContext = new DynamoDBContext(dynamoDbClient, config);
        }