edgedb / edgedb-net

The official .NET client library for EdgeDB
https://edgedb.com
Apache License 2.0
82 stars 9 forks source link

System.Security.Authentication.AuthenticationException on Insert #26

Closed jerebear12 closed 1 year ago

jerebear12 commented 1 year ago

Describe the bug

Connection and Query code below.

Reproduction Connection Code

private readonly EdgeDBClient _edgeDB;

public Edge() 
{
    var connection = new EdgeDBConnection();
    connection.Hostname = "localhost";
    connection.Database = "edgedb";
    connection.Port = 10700;
    //connection.Password = "password";

    _edgeDB = new EdgeDBClient(connection); 
}

Function being called:

public async Task AddItem(Item item)
{
    var insertItemQuery = $"insert Item {{ Id := \"{item.Id}\", Name := \"{item.Name}\", Description := \"{item.Description}\", User := (insert User {{ Id := \"{item.User.Id}\", Name := \"{item.User.Name}\", Password := \"{item.User.Password}\", UserName := \"{item.User.UserName}\", Email := \"{item.User.Email}\" }}) }} unless conflict on .Email";

    // Add item
    await _edgeDB.ExecuteAsync(insertItemQuery);
}

Screenshot of caller and error msg: error

Expected behavior I expect the item to be added to the database according to the insert command and schema. I at least expect the connection to be made and any errors with my query to be displayed if that's the case.

Versions (please complete the following information):

Additional context If you need more information let me know!

quinchs commented 1 year ago

This error is thrown because of the TLS security mode on your connection object. by default, connections are going to be strictly over SSL and the client uses the EdgeDBConnection.TLSCertificateAuthority property to verify the SSL connection.

If you're using projects, try creating the client without specifying the conncetion. The client will autoresolve your edgedb.toml file and pull the connection info from there:

edgeDB = new EdgeDBClient(); 

If your instance is remote, you can specify the certificate on the TLSCertificateAuthority prop. If you want to connect insecurely, you can specify the TLSSecurity like so:


connection.TLSSecurity = TLSSecurityMode.Insecure;
jerebear12 commented 1 year ago

I see. I'm getting a System.IO.FileNotFoundException: 'Couldn't resolve edgedb.toml file' without the connection object.

edgedb.toml is in the project directory:

term

quinchs commented 1 year ago

The autoresolve only works if the edgedb.toml file is in the executing directory of your app or a parent directory of your app.

If the instance is running on the same machine you can just specify the instance name like so:

_edgeDB = new EdgeDBClient(EdgeDBConnection.FromInstanceName("EdgeDB"));

Let me know if this works for you.

jerebear12 commented 1 year ago

It's working epic-ly. Thanks for the help!