Skip to content

Commit 5a722f7

Browse files
committed
sync with master
1 parent 1787def commit 5a722f7

File tree

5 files changed

+23
-27
lines changed

5 files changed

+23
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a Client SDK for RelationalAI
44

5-
- API version: 1.2.3
5+
- API version: 1.2.4
66

77
## Frameworks supported
88

RelationalAI/Connection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public abstract class Connection
1717
public const bool DEFAULT_VERIFY_SSL = true;
1818
public const int DEFAULT_DEBUG_LEVEL = 0;
1919
public const int DEFAULT_CONNECTION_TIMEOUT = 300; // seconds
20+
public const IDictionary<String, String> DEFAULT_EXTRA_HEADERS = null;
2021

2122
public virtual string DbName => throw new InvalidOperationException();
2223

@@ -46,6 +47,8 @@ public Uri BaseUrl {
4647

4748
public int ConnectionTimeout { get; set; }
4849

50+
public IDictionary<String, String> ExtraHeaders { get; set; }
51+
4952
public KGMSClient Client { get; set; }
5053
public ManagementClient CloudClient { get; set; }
5154

@@ -79,7 +82,8 @@ public LocalConnection(
7982
string scheme = DEFAULT_SCHEME,
8083
string host = DEFAULT_HOST,
8184
int port = DEFAULT_PORT,
82-
int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT
85+
int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,
86+
IDictionary<String, String> extraHeaders = DEFAULT_EXTRA_HEADERS
8387
)
8488
{
8589
this.DbName = dbname;
@@ -88,6 +92,7 @@ public LocalConnection(
8892
this.Host = host;
8993
this.Port = port;
9094
this.ConnectionTimeout = connectionTimeout;
95+
this.ExtraHeaders = extraHeaders == null ? new Dictionary<String, String>() : extraHeaders;
9196

9297
if(this.GetType() == typeof(LocalConnection))
9398
{

RelationalAI/KGMSClient.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class GeneratedRelationalAIClient
2121

2222
public const string JSON_CONTENT_TYPE = "application/json";
2323
public const string CSV_CONTENT_TYPE = "text/csv";
24-
public const string USER_AGENT_HEADER = "KGMSClient/1.2.3/csharp";
24+
public const string USER_AGENT_HEADER = "KGMSClient/1.2.4/csharp";
2525

2626
public int DebugLevel = Connection.DEFAULT_DEBUG_LEVEL;
2727

@@ -55,10 +55,10 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess
5555
// Note:
5656
// We need to send the gzip content encoding header and a gzip compressed body only in case of a CloudConnection.
5757
// Local rai-server cannot handle gzip encoding, only infra server support does.
58-
59-
// Compress the contents (request body) as gzipped byte array. C# httpclient does not implicitly compress the content over the wire
58+
59+
// Compress the contents (request body) as gzipped byte array. C# httpclient does not implicitly compress the content over the wire
6060
// if content encoding is gzip; we need to manually compress the body.
61-
// Note: If the client sends content-encoding as gzip but does not encode the content to gzip, then the server will return 400 Bad Request.
61+
// Note: If the client sends content-encoding as gzip but does not encode the content to gzip, then the server will return 400 Bad Request.
6262
request.Content = CompressionUtils.CompressRequestContentAsGzip(request.Content);
6363
//Set the content encoding type header as gzip. It will tell the server that the content is gzip encoded.
6464
request.Content.Headers.Add("content-encoding", "gzip");
@@ -70,7 +70,7 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess
7070
request.Headers.Host = request.RequestUri.Host;
7171
//Set the content type header
7272
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
73-
73+
7474
// Set Auth here
7575
var raiRequest = new RAIRequest(request, conn);
7676
raiRequest.SetAuth();
@@ -85,7 +85,7 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess
8585
AsyncLocalKeepAliveCancellationTokenSource.Value = tokenSource;
8686
CancellationToken ct = tokenSource.Token;
8787

88-
/**
88+
/**
8989
* TODO: currently we swallo exceptions in KeepClientAlive.
9090
* If we want to throw, then we need to change this to asynchronously handle the throw
9191
* e.g.
@@ -347,6 +347,7 @@ public override string ToString()
347347
public class KGMSClient : GeneratedRelationalAIClient
348348
{
349349
public static ILogger DefaultLogger = new ConsoleLogger();
350+
public static IDictionary<String, String> extraHeaders = new Dictionary<String, String>();
350351

351352
public ILogger Logger
352353
{
@@ -366,7 +367,7 @@ public override async Task KeepClientAlive(HttpClient client_, String url, Cance
366367
try {
367368
await Task.Run(() => this.KeepAliveProbe(client_, ct));
368369
} catch (Exception e) {
369-
// ignore. But I think we might want to throw?
370+
// ignore. But I think we might want to throw?
370371
Logger.Error("KeepAliveProbe failed with exception: " + e.Message);
371372
}
372373
}
@@ -400,6 +401,11 @@ public static void AddExtraHeaders(HttpRequestMessage request)
400401
{
401402
// host & content-type header for signature verification, more headers here
402403
request.Headers.UserAgent.TryParseAdd(USER_AGENT_HEADER);
404+
// add extra headers
405+
foreach(var item in extraHeaders)
406+
{
407+
request.Headers.Add(item.Key, item.Value);
408+
}
403409
}
404410

405411
private static bool httpClientVerifySSL = Connection.DEFAULT_VERIFY_SSL;
@@ -434,6 +440,7 @@ protected internal static HttpClient GetHttpClient(
434440
public KGMSClient(Connection conn) : base(KGMSClient.GetHttpClient(conn.BaseUrl, conn.VerifySSL, conn.ConnectionTimeout))
435441
{
436442
this.conn = conn;
443+
extraHeaders = conn.ExtraHeaders;
437444
conn.Client = this;
438445
this.BaseUrl = conn.BaseUrl.ToString();
439446
}
@@ -479,23 +486,9 @@ public ActionResult RunAction(String name, Action action, out bool success, bool
479486
xact.Actions = new List<LabeledAction>();
480487
xact.Actions.Add(labeledAction);
481488
xact.Readonly = isReadOnly;
482-
xact.Version = this.conn.Version;
483489

484490
TransactionResult response = RunTransaction(xact);
485491

486-
// Sync the reported database version to our local
487-
// connection version. Important, as we want to ensure
488-
// that in subsequent transactions this will be the
489-
// minimum required version of the database. Note that
490-
// only write transactions bump the version.
491-
lock(this.conn) {
492-
int currentVersion = conn.Version;
493-
int responseVersion = response.Version.GetValueOrDefault(0);
494-
if(responseVersion > currentVersion) {
495-
conn.Version = responseVersion;
496-
}
497-
}
498-
499492
success = IsSuccess(response);
500493
foreach (LabeledActionResult act in response.Actions)
501494
{
@@ -521,7 +514,6 @@ public bool CloneDatabase(string sourceDbname, bool overwrite = false)
521514
xact.Actions = new LinkedList<LabeledAction>();
522515
xact.Source_dbname = sourceDbname;
523516
xact.Readonly = false;
524-
xact.Version = this.conn.Version;
525517
TransactionResult response = RunTransaction(xact);
526518

527519
if(response.Problems.Count > 0) {
@@ -538,7 +530,6 @@ public bool CreateDatabase(bool overwrite = false)
538530
xact.Dbname = conn.DbName;
539531
xact.Actions = new LinkedList<LabeledAction>();
540532
xact.Readonly = false;
541-
xact.Version = this.conn.Version;
542533

543534
TransactionResult response = RunTransaction(xact);
544535

RelationalAI/RelationalAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>1.2.3</Version>
4+
<Version>1.2.4</Version>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<PackageId>RelationalAI</PackageId>
77
<Authors>RelationalAI</Authors>

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let
99
in
1010
stdenv.mkDerivation rec {
1111
name = "rai-server-csharp-client-sdk-${version}";
12-
version = "1.2.3";
12+
version = "1.2.4";
1313
buildInputs = [
1414
raiserverBinary
1515
dotnet-sdk_3

0 commit comments

Comments
 (0)