Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Use apikey to access elastic search (#545)
Browse files Browse the repository at this point in the history
* Update ElasticsearchSinkOptions.cs

* Update ElasticsearchSinkState.cs

Use apikey to access elasticsearch

* Update ElasticsearchSinkOptions.cs

* Update Elasticsearch6XUsing7X.cs

for integration test

* Update Elasticsearch7XUsing6X.cs

For integration test
  • Loading branch information
qgbo authored Jun 14, 2023
1 parent 2182854 commit 0763a17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ public int QueueSizeLimit
/// </summary>
public RollingInterval BufferFileRollingInterval { get; set; }

/// <summary>
/// Apikey to access elasticsearch, the value is encoded
/// If your elasticsearch can be accessed using user and password, you access via url like this: http://user:password@localhost
/// For another choice, you can using a apiKey, which can be created in kibana: POST /security/api_key { "name": "aaa-apikeys", "role_descriptors": { "abc-shared-application": { "cluster": [ "all" ], "index": [ { "names": [ "abc_share*" ], "privileges": [ "all" ] } ] } } }
/// then you can get the apikey coded by base64 it like this: aFlBbDVvY0JOblduWHdpZnNLOUk6cEt2Y01tYVlRQ3FsWlF0MVVjRkN034==
/// For more detail about apiKey, see: https://www.elastic.co/guide/en/apm/server/7.15/api-key.html
/// </summary>
public string Apikey { get; set; }

/// <summary>
/// Configures the elasticsearch sink defaults
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ private ElasticsearchSinkState(ElasticsearchSinkOptions options)
if (options.ModifyConnectionSettings != null)
configuration = options.ModifyConnectionSettings(configuration);

if (!string.IsNullOrEmpty(options.Apikey))
configuration = configuration.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials(options.Apikey));

configuration.ThrowExceptions();

_client = new ElasticLowLevelClient(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public SetupSerilog()
o.DetectElasticsearchVersion = true;
o.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7;
o.AutoRegisterTemplate = true;
o.ApiKey = "aWQ6d3d3ZGRkZGRkZGRkZA==";
})
);
var logger = loggerConfig.CreateLogger();
Expand All @@ -68,4 +69,4 @@ public SetupSerilog()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public SetupSerilog()
o.DetectElasticsearchVersion = true;
o.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6;
o.AutoRegisterTemplate = true;
o.ApiKey = "aWQ6d3d3ZGRkZGRkZGRkZA==";
})
);
using (var logger = loggerConfig.CreateLogger())
Expand All @@ -65,4 +66,4 @@ public SetupSerilog()
}

}
}
}

0 comments on commit 0763a17

Please sign in to comment.