| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using System.Threading; |
| | 4 | | using Decentraland.Renderer.KernelServices; |
| | 5 | | using Google.Protobuf.Collections; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using SignBodyRequest = Decentraland.Renderer.KernelServices.SignBodyRequest; |
| | 9 | | using SignBodyResponse = Decentraland.Renderer.KernelServices.SignBodyResponse; |
| | 10 | |
|
| | 11 | | public class RPCSignRequest : IRPCSignRequest |
| | 12 | | { |
| | 13 | | private const int REQUEST_TIMEOUT = 30; |
| | 14 | |
|
| | 15 | | private readonly IRPC rpc; |
| | 16 | |
|
| 425 | 17 | | public RPCSignRequest(IRPC rpc) |
| | 18 | | { |
| 425 | 19 | | this.rpc = rpc; |
| 425 | 20 | | } |
| | 21 | |
|
| | 22 | | public async UniTask<SignBodyResponse> RequestSignedRequest(RequestMethod method, string url, string metadata, Cance |
| | 23 | | { |
| 0 | 24 | | SignBodyResponse response = await rpc.SignRequestKernelService() |
| | 25 | | .GetRequestSignature(new SignBodyRequest() |
| | 26 | | { |
| | 27 | | Method = method, |
| | 28 | | Url = url, |
| | 29 | | Metadata = string.IsNullOrEmpty(metadata) ? "{}" : metadata |
| | 30 | | }) |
| | 31 | | .AttachExternalCancellation(cancellationToken) |
| | 32 | | .Timeout(TimeSpan.FromSeconds(REQUEST_TIMEOUT)); |
| 0 | 33 | | return response; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public async UniTask<string> RequestSignedHeaders(string url, IDictionary<string, string> metadata, CancellationToke |
| | 37 | | { |
| 0 | 38 | | var request = new GetSignedHeadersRequest() { Url = url }; |
| 0 | 39 | | request.Metadata.Add(metadata); |
| 0 | 40 | | var response = await rpc.SignRequestKernelService() |
| | 41 | | .GetSignedHeaders(request) |
| | 42 | | .AttachExternalCancellation(cancellationToken); |
| 0 | 43 | | return response.Message; |
| 0 | 44 | | } |
| | 45 | | } |