Skip to content

Commit

Permalink
Fix authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
gloomweaver committed Jun 11, 2024
1 parent 0eae03b commit 7f4cd89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 15 additions & 3 deletions Spice/src/flight/SpiceFlightClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Text;
using Apache.Arrow;
Expand Down Expand Up @@ -27,7 +28,7 @@ internal SpiceFlightClient(string address, string? appId, string? apiKey)
Authorization = AuthenticationHeaderValue.Parse("Basic " +
System.Convert.ToBase64String(Encoding
.UTF8
.GetBytes(appId + ":" + apiKey)))
.GetBytes($"{appId}:{apiKey}")))
}
}
};
Expand All @@ -38,14 +39,25 @@ internal SpiceFlightClient(string address, string? appId, string? apiKey)
}

_flightClient = new FlightClient(GrpcChannel.ForAddress(address, options));
_flightClient.Handshake();
var stream = _flightClient.Handshake();

stream.ResponseHeadersAsync.Wait();
var md = stream.ResponseHeadersAsync.Result;
var token = md.Get("authorization");
if (token == null || options.HttpClient == null)
{
throw new Exception("Failed to authenticate token");
}

options.HttpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse(token.Value);
}



internal async IAsyncEnumerator<RecordBatch> Query(string sql)
{
var descriptor = FlightDescriptor.CreateCommandDescriptor(sql);

var flightInfo = await _flightClient.GetInfo(descriptor);
var endpoint = flightInfo.Endpoints.FirstOrDefault();
if (endpoint == null)
Expand Down
3 changes: 2 additions & 1 deletion SpiceTest/FlightQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public async Task Test1()

while (await result.MoveNextAsync())
{
Console.WriteLine(result.Current);
var batch = result.Current;
Assert.That(batch.Length, Is.EqualTo(10));
}
}
}

0 comments on commit 7f4cd89

Please sign in to comment.