-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: Metadata (headers) support (#115)
### Summary - Added gRPC Metadata support - Simplified the internal client-building logic ### Example When metadata (`{"wibble": "wobble"}`) is provided during both client initialization and CheckResources call, the cerbos audit logs show; ``` { "log.logger":"cerbos.audit", "log.kind":"access", "timestamp":"2023-12-13T17:26:56.614190Z", "callId":"01HHJ3F8B657J3PB3S6P21YY3X", "peer":{ "address":"127.0.0.1:50993", "userAgent":"grpc-dotnet/2.59.0 (.NET 6.0.5; CLR 6.0.5; net6.0; osx; x64)" }, "metadata":{ "wibble":{ "values":[ "wobble, wobble" ] } }, "method":"/cerbos.svc.v1.CerbosService/CheckResources" } ``` --------- Signed-off-by: Oğuzhan Durgun <[email protected]>
- Loading branch information
1 parent
7cdf828
commit fc5f369
Showing
4 changed files
with
86 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace Cerbos.Sdk.Utility | ||
{ | ||
public static class Metadata | ||
{ | ||
public static Grpc.Core.Metadata Merge(Grpc.Core.Metadata first, Grpc.Core.Metadata second) | ||
{ | ||
if (first == null && second == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (first != null && second == null) | ||
{ | ||
return first; | ||
} | ||
|
||
if (first == null) | ||
{ | ||
return second; | ||
} | ||
|
||
Grpc.Core.Metadata combined = new Grpc.Core.Metadata(); | ||
foreach (var m in first) | ||
{ | ||
combined.Add(m); | ||
} | ||
|
||
foreach (var m in second) | ||
{ | ||
combined.Add(m); | ||
} | ||
|
||
return combined; | ||
} | ||
} | ||
} |