private async Task <ApiInputParameters> ReadInputParameters(HttpRequestMessage request, string command) { var clientDisconnectedCancellationToken = request.GetOwinContext()?.Request?.CallCancelled ?? CancellationToken.None; //NOTE: this is not an in-memory way of doing the same thing //var root = HttpContext.Current.Server.MapPath("~/App_Data/"); //var streamProvider = new MultipartFormDataStreamProvider(root); var streamProvider = new InMemoryMultipartFormDataStreamProvider(); await request.Content.ReadAsMultipartAsync(streamProvider, clientDisconnectedCancellationToken); var querySegments = request.RequestUri.ParseQueryString(); List <string> args = new() { command }; foreach (var key in querySegments.AllKeys) { var value = querySegments[key]; args.Add($"-{key}={value}"); } ArgsInfo argsInfo = ArgsInfo.Parse(args.ToArray(), true, _settings.Signer.KnownThumbprints); var dataToSign = await ReadInputFile(streamProvider, ApiInputFileContants.DataToSignFileFormFieldName); if (dataToSign == null && argsInfo.Function != ProgramFunction.Describe) { Log.Error("File to sign is not found"); } var signatureBytes = await ReadInputFile(streamProvider, ApiInputFileContants.SignatureFileFormFieldName); var certificateBytes = await ReadInputFile( streamProvider, ApiInputFileContants.CertificateFileFormFieldName); ApiInputParameters ret = new() { ArgsInfo = argsInfo, DataToSign = dataToSign, SignatureFileBytes = signatureBytes, CertificateFileBytes = certificateBytes }; return(ret); }
private static void Main(string[] args) { if (args.Length <= 0) { ShowHelp(); return; } if (args[0] == @"\?" || args[0] == @"?" || args[0] == "help") { ShowHelp(); return; } var configuration = GetConfiguration(); InitializeLogger(configuration); WebApiHost = new WebApiHost(configuration); if (args[0] == "api") { ConfigureService(string.Empty); } if (args[0] == "install" || args[0] == "uninstall") { ConfigureService(args[0]); return; } ArgsInfo inputArguments = ArgsInfo.Parse(args, false, configuration.Signer.KnownThumbprints); var statusInfo = MainCore(inputArguments); Console.WriteLine(statusInfo.ToJsonString()); }