-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PM-33436] Refactor setup shell commands #7494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+175
β54
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd65501
refactor setup shell commands
dereknance a5b2ac0
missed a directory update
dereknance 85a5b24
use local time for date comparison assert
dereknance 59cd2ee
fix a missed arg split
dereknance e0f7bd3
fix process output ingestion
dereknance 84eedb8
clean up temp dir
dereknance 9ed9c3b
validate domain arg
dereknance 2821af8
Merge branch 'main' into pm-33436-installer-shell-refactor
dereknance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
|
|
||
| using System.Diagnostics; | ||
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| using System.Security.Cryptography; | ||
| using System.Text; | ||
|
|
||
|
|
@@ -112,35 +111,37 @@ public static string GetValueFromEnvFile(Application config, string envFile, str | |
| return null; | ||
| } | ||
|
|
||
| public static string Exec(string cmd, bool returnStdout = false) | ||
| public static string Exec(string cmd, string[] arguments = null, bool returnStdout = false, bool returnStderr = false) | ||
| { | ||
| var process = new Process | ||
| var startInfo = new ProcessStartInfo(cmd, arguments ?? []) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is the main reason for this PR, passing arguments as an |
||
| { | ||
| StartInfo = new ProcessStartInfo | ||
| { | ||
| RedirectStandardOutput = true, | ||
| UseShellExecute = false, | ||
| CreateNoWindow = true, | ||
| WindowStyle = ProcessWindowStyle.Hidden | ||
| } | ||
| RedirectStandardOutput = returnStdout, | ||
| RedirectStandardError = returnStderr, | ||
| UseShellExecute = false, | ||
| CreateNoWindow = true, | ||
| WindowStyle = ProcessWindowStyle.Hidden | ||
| }; | ||
|
|
||
| if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| var process = new Process { StartInfo = startInfo }; | ||
|
|
||
| var result = new StringBuilder(); | ||
|
|
||
| process.OutputDataReceived += (_, e) => | ||
| { | ||
| var escapedArgs = cmd.Replace("\"", "\\\""); | ||
| process.StartInfo.FileName = "/bin/sh"; | ||
| process.StartInfo.Arguments = $"-c \"{escapedArgs}\""; | ||
| } | ||
| else | ||
| if (!returnStdout || e.Data == null) return; | ||
| result.Append(e.Data); | ||
| }; | ||
|
|
||
| process.ErrorDataReceived += (_, e) => | ||
| { | ||
| process.StartInfo.FileName = "powershell"; | ||
| process.StartInfo.Arguments = cmd; | ||
| } | ||
| if (!returnStderr || e.Data == null) return; | ||
| result.Append(e.Data); | ||
| }; | ||
|
|
||
| process.Start(); | ||
| var result = returnStdout ? process.StandardOutput.ReadToEnd() : null; | ||
| process.WaitForExit(); | ||
| return result; | ||
|
|
||
| return result.ToString(); | ||
| } | ||
|
|
||
| public static string ReadInput(string prompt) | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using an Ubuntu VM, this assert would fire seemingly because the cert's
NotAfterdate would include the timezone I set for the VM. This test may have originally been run in a Docker container with the timezone left as UTC, so comparing withUtcNowwasn't a problem. UsingNowinstead should still work for the container test scenario.