diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-10-27 23:04:59 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-10-27 23:04:59 +1000 |
| commit | ecd5f5d13936dd097b12766cb95a568ad5b073a9 (patch) | |
| tree | f360b08e656a98faca4f2b9f10dc44602e6ca289 /src/marlin.agents.shell/MarlinApiClient.cs | |
| parent | 88ee626cb3686dc176cd7911b073c4e65fa54d34 (diff) | |
feat: lots of stuff
Diffstat (limited to 'src/marlin.agents.shell/MarlinApiClient.cs')
| -rw-r--r-- | src/marlin.agents.shell/MarlinApiClient.cs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/marlin.agents.shell/MarlinApiClient.cs b/src/marlin.agents.shell/MarlinApiClient.cs index aa4f013..900101c 100644 --- a/src/marlin.agents.shell/MarlinApiClient.cs +++ b/src/marlin.agents.shell/MarlinApiClient.cs @@ -1,16 +1,28 @@ namespace marlin.agents.shell; using System.Net.Http.Json; +using core.contracts; using core.models; +using Grpc.Core; +using Grpc.Net.Client; +using ProtoBuf.Grpc.Client; public class MarlinApiClient { + private readonly string _baseUrl; + private readonly Guid _agentId; + private readonly string _agentToken; + private readonly HttpClient _http; public MarlinApiClient(string baseUrl, Guid agentId, string agentToken) { - _http = new HttpClient { BaseAddress = new Uri(baseUrl) }; - _http.DefaultRequestHeaders.Add("Agent", $"{agentId} {agentToken}"); + this._baseUrl = baseUrl; + this._agentId = agentId; + this._agentToken = agentToken; + + _http = new HttpClient { BaseAddress = new Uri(this._baseUrl) }; + _http.DefaultRequestHeaders.Add("Agent", $"{this._agentId} {this._agentToken}"); } public static MarlinApiClient FromEnvironment() @@ -35,4 +47,21 @@ public class MarlinApiClient public async Task<DispatchJob?> QueueNextJob(CancellationToken ct = default) => await _http.GetFromJsonAsync<DispatchJob?>("api/dispatch/queue", ct); + + public GrpcChannel CreateJobScopedRpc(DispatchJob job) + { + var credentials = CallCredentials.FromInterceptor( + async (_, metadata) => + { + metadata.Add("Agent", $"{this._agentId} {this._agentToken}"); + metadata.Add("Job", $"{job.Id} {job.Token}"); + }); + + var channel = GrpcChannel.ForAddress(this._baseUrl, new GrpcChannelOptions + { + Credentials = ChannelCredentials.Create(new SslCredentials(), credentials) + }); + + return channel; + } } |
