Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

[WIP] Add the HTTP REPL #468

Merged
merged 9 commits into from
Aug 28, 2018
Merged

Conversation

mlorbetske
Copy link
Contributor

Mainly looking for verification that the build process changes to include the HTTP REPL are correct and that style guidelines are being met

Before merge:

  • More tests
  • Cleanup help

@mlorbetske mlorbetske requested a review from natemcmaster July 29, 2018 21:38
Copy link
Contributor

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments about infrastructure. I didn't read the code. 7k lines is a bit much to bite off in one chunk. Is someone else reviewing the actual implementation here?

<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
<SystemDataSqlClientPackageVersion>4.5.1</SystemDataSqlClientPackageVersion>
<SystemSecurityCryptographyCngPackageVersion>4.5.0</SystemSecurityCryptographyCngPackageVersion>
<CommandLine_NewtonsoftJsonPackageVersion>10.0.1</CommandLine_NewtonsoftJsonPackageVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reasonly to use 10? The rest of the runtime uses 11.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe there was a particular reason, i'll try bumping to the latest patch of 11

@@ -0,0 +1,38 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the copyright header to all .cs files.


<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Description>A framework for creating REPLs in .NET Core.</Description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be a package that is distributed to NuGet.org for others to use? If so, there are a few more infrastructure hoops to jump through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, intended to be distributed via NuGet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked in person yesterday. Let's not ship Microsoft.Repl.dll as a package yet. The demand is unclear, and we don't want to be on the hook to support the package.

You can disable producing a nupkg by adding <IsPackable>false</IsPackable> to this .csproj file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


<ItemGroup>
<SignedPackageFile Include="tools/$(TargetFramework)/any/Microsoft.Repl.dll" Certificate="$(AssemblySigningCertName)" />
<SignedPackageFile Include="tools/$(TargetFramework)/any/Newtonsoft.Json.dll" Certificate="$(AssemblySigningCertName)" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change third party binaries to use Certificate="Microsoft3rdPartyAppComponentDual". If it uses $(AssemblySigningCertName), it would cause us to sign JSON.NET with the Microsoft cert, which is wrong. I see dotnet-user-secrets.csproj also has this wrong. We're not actually using this metadata yet, but will be in the next few weeks.

<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PackAsTool>true</PackAsTool>
<AssemblyName>dotnet-httprepl</AssemblyName>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this shipping as a package to nuget.org, a bundled command in the CLI, or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, only distribution is planned for NuGet.org, not as a bundled tool with the CLI, but that's really a question for @glennc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan right now is only to ship it on NuGet.org, I expect us to re-examine that decision at some point though.

Copy link
Contributor

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got through like half of the code. Here are some of the things I noticed so far. Some questions, a few pieces of feedback.

It might be nice to set down with Glenn and go over the design a little more. I'm a bit fuzzy on the requirements for the project w.r.t swagger, graphql, interaction with oauth, etc.

<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
<SystemDataSqlClientPackageVersion>4.5.1</SystemDataSqlClientPackageVersion>
<SystemSecurityCryptographyCngPackageVersion>4.5.0</SystemSecurityCryptographyCngPackageVersion>
<CommandLine_NewtonsoftJsonPackageVersion>11.0.2</CommandLine_NewtonsoftJsonPackageVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the variable name to NewtonsoftJsonPackageVersion? This will align it with the rest of our automation for managing dependencies.

inputManager.RegisterKeyHandler(ConsoleKey.Tab, Tab);

//Input manipulation
inputManager.RegisterKeyHandler(ConsoleKey.Escape, Escape);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered also adding other common bash/zsh key mappings? e.g. here are some common ones

  • CTRL+U - clear input (equivalent to Escape in this mapping)
  • CTRL+A - go to beginning of input (equivalent to Home)
  • CTRL+E - go to endof input (equivalent to End)

shell.ShellState.InputManager.SetInput(shell.ShellState, $"set base \"{args[0]}\"");
await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false);
}
Task result = shell.RunAsync(source.Token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to check Console.IsOutputRedirected and exit with an error before launching the shell? I'm assuming piping the repl should never work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CancellationTokenSource source = new CancellationTokenSource();
var shell = new Shell(dispatcher);
shell.ShellState.ConsoleManager.AddBreakHandler(() => source.Cancel());
if (args.Length > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should support a --help option which prints usage and exits. This is a standard for almost every dotnet command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}

#region JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally dislike regions, so if you don't feel strongly about this, would be nice to remove. But I'm also not a militant anti-region-legion-er so I'll let it slide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally pretty anti-region as well, but wanted these out of the way as I was adding more settings, will remove the region

return toResolve;
}

//public static async Task<JToken> ResolvePointerAsync(this JToken root, HttpClient client, string pointer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a TODO for this block?

}
}

shellState.ConsoleManager.Error.WriteLine("No matching command found".Red().Bold());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also printing to output a message like "Execute 'help' to see available commands".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

|| contentType.EndsWith("-JAVASCRIPT", StringComparison.OrdinalIgnoreCase)
|| contentType.EndsWith("+JAVASCRIPT", StringComparison.OrdinalIgnoreCase))
{
if (await FormatJsonAsync(programState, consoleManager, content, bodyFileWriter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone disable formatting? It seems like it may be useful to see the actual response, unmodified, with the option to have the repl
pretty-print.

I'm also a little concerned about how this will behave if someone uses the repl to hit an endpoint that dumps a large XML or JSON response.
Hopefully that's not super common, but when someone inevitably downloads a 1000 line JSON file, it's going to bombard console output. Have
we considered using a pager for large responses?

break;
}

string str = new string(buffer.Span.Slice(0, readTask.Result));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may run into trouble here with encoding and charsets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought of this too, with this being the streaming scenario & the end of the chunk being determined by the server, no good ways around it are coming to mind.

Pagination hasn't been dealt with yet

mac keybindings may be able to be simplified, pending some additional verification

Fix 3rd party signing cert

Bind a few common bash/zsh mappings

Check for output redirection

Make package version variable name consistent

Add --help option for the command line

Remove regions

Remove old pointer resolution code

Make command not found message more friendly

Fix issue where base address was required for requests to absolute URIs

Add options to suppress response formatting and streaming

Turn off packing for the REPL project
Copy link
Contributor

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating in response to PR feedback. You already called out the last concern I have - low test coverage. Before merging, can you file an issue to follow-up on this?

No additional engineering concerns right now. I'll let @glennc sign off on experience review.

@@ -156,6 +156,7 @@ private async Task ExecuteCommandInternalAsync(IShellState shellState, Cancellat
}

shellState.ConsoleManager.Error.WriteLine("No matching command found".Red().Bold());
shellState.ConsoleManager.Error.WriteLine("Execute 'help' to se available commands".Red().Bold());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "to see"

"Microsoft.AspNetCore.DeveloperCertificates.XPlat": {
"Exclusions": {
"DOC_MISSING": {
"lib/netcoreapp2.2/Microsoft.AspNetCore.DeveloperCertificates.XPlat.dll": "Docs not required to shipoob package"
}
}
},
"Microsoft.Repl": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this should make builds happy :)

Default to requerying swagger for each exec

Auto-set the content-type if not yet set for requests based on swagger

Fix swagger UI command

Make error and warning colors configurable

Allow aliases to be specified in structured input based commands

Have delete not require a body

Show allowed methods for . and ..

Show verbs on the announced path after CD

Issue a request on set base and warn if there's a socket error
@mlorbetske
Copy link
Contributor Author

I believe we're waiting on some additional changes from @glennc around some of the experiences before merging

@mlorbetske
Copy link
Contributor Author

Merging per Glenn

@mlorbetske mlorbetske merged commit 624c2ec into aspnet:release/2.2 Aug 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants