mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 21:08:31 +02:00
New tutorial: "Secure a Self-Hosted Qdrant Instance" (#2385)
* Initial commit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Edits * Edits * Fix links * Use 'true' instead of '1' in QDRANT__SERVICE__ENABLE_TLS example * Review feedback * Add link from Security page * Update stack designation on overview page * Update qdrant-landing/content/documentation/tutorials-operations/secure-qdrant.md Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
István Zoltán Szabó
parent
bde1efaf72
commit
9ba29ff4fa
+93
@@ -0,0 +1,93 @@
|
||||
// @block-start upsert-no-auth
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient(host: "localhost", port: 6334, https: true);
|
||||
|
||||
try
|
||||
{
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "my_collection",
|
||||
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "my_collection",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message); // Unauthenticated
|
||||
}
|
||||
// @block-end upsert-no-auth
|
||||
|
||||
// @block-start upsert-admin-key
|
||||
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-admin-key");
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "my_collection",
|
||||
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "my_collection",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
|
||||
}
|
||||
);
|
||||
// @block-end upsert-admin-key
|
||||
|
||||
// @block-start delete-read-only-key
|
||||
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-read-only-key");
|
||||
|
||||
try
|
||||
{
|
||||
await client.DeleteAsync(collectionName: "my_collection", ids: (ulong[])[1]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message); // PermissionDenied
|
||||
}
|
||||
// @block-end delete-read-only-key
|
||||
|
||||
// @block-start upsert-jwt-rw-collection
|
||||
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "my_collection",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
|
||||
}
|
||||
);
|
||||
// @block-end upsert-jwt-rw-collection
|
||||
|
||||
// @block-start upsert-jwt-ro-collection
|
||||
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
|
||||
|
||||
try
|
||||
{
|
||||
await client.UpsertAsync(
|
||||
collectionName: "other_collection",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message); // PermissionDenied
|
||||
}
|
||||
// @block-end upsert-jwt-ro-collection
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user