Skip to content

Commit

Permalink
Support relative paths for client when running on .NET Core 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oren Novotny committed Dec 6, 2017
1 parent 24f027b commit 2c0fd02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ After signing contents of the archive, the archive itself is signed if supported
usage: SignClient sign [-c <arg>] [-i <arg>] [-o <arg>] [-h <arg>]
[-f <arg>] [-s <arg>] [-n <arg>] [-d <arg>] [-u <arg>]
-c, --config <arg> Full path to config json file
-i, --input <arg> Full path to input file
-o, --output <arg> Full path to output file. May be same
-c, --config <arg> Path to config json file
-i, --input <arg> Path to input file
-o, --output <arg> Path to output file. May be same
as input to overwrite
-h, --hashmode <arg> Hash mode: Sha256.
-f, --filter <arg> Full path to file containing paths of
-f, --filter <arg> Path to file containing paths of
files to sign within an archive
-s, --secret <arg> Client Secret
-n, --name <arg> Name of project for tracking
Expand Down
33 changes: 25 additions & 8 deletions src/SignClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ static async Task<int> DoMain(string[] args)
ArgumentSyntax.Parse(args, syntax =>
{
syntax.DefineCommand("sign", ref command, Command.Sign, "Sign a file");
syntax.DefineOption("c|config", ref configFile, "Full path to config json file");
syntax.DefineOption("i|input", ref iFile, "Full path to input file");
syntax.DefineOption("o|output", ref oFile, "Full path to output file. May be same as input to overwrite");
syntax.DefineOption("c|config", ref configFile, "Path to config json file");
syntax.DefineOption("i|input", ref iFile, "Path to input file");
syntax.DefineOption("o|output", ref oFile, "Path to output file. May be same as input to overwrite");
syntax.DefineOption("h|hashmode", ref hashMode, s => (HashMode)Enum.Parse(typeof(HashMode), s, true), "Hash mode: either dual or Sha256. Default is dual, to sign with both Sha-1 and Sha-256 for files that support it. For files that don't support dual, Sha-256 is used");
syntax.DefineOption("f|filelist", ref fFile, "Full path to file containing paths of files to sign within an archive");
syntax.DefineOption("s|secret", ref clientSecret, "Client Secret");
Expand Down Expand Up @@ -75,9 +75,9 @@ static async Task<int> DoMain(string[] args)
{
oFile = iFile;
}

var builder = new ConfigurationBuilder()
.AddJsonFile(configFile)
.AddJsonFile(ExpandFilePath(configFile))
.AddEnvironmentVariables();

var configuration = builder.Build();
Expand Down Expand Up @@ -133,8 +133,8 @@ static async Task<int> DoMain(string[] args)
var client = RestService.For<ISignService>(configuration["SignClient:Service:Url"], settings);

// Prepare input/output file
var input = new FileInfo(iFile);
var output = new FileInfo(oFile);
var input = new FileInfo(ExpandFilePath(iFile));
var output = new FileInfo(ExpandFilePath(oFile));
Directory.CreateDirectory(output.DirectoryName);


Expand All @@ -143,7 +143,7 @@ static async Task<int> DoMain(string[] args)
HttpResponseMessage response;
if (command == Command.Sign)
{
response = await client.SignFile(input, !string.IsNullOrWhiteSpace(fFile) ? new FileInfo(fFile) : null, hashMode, name, desc, descUrl);
response = await client.SignFile(input, !string.IsNullOrWhiteSpace(fFile) ? new FileInfo(ExpandFilePath(fFile)) : null, hashMode, name, desc, descUrl);
}
else
{
Expand Down Expand Up @@ -176,6 +176,23 @@ static async Task<int> DoMain(string[] args)
return 0;
}

static string ExpandFilePath(string file)
{
#if NETCOREAPP2_0
if (!Path.IsPathRooted(file))
{
return $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}{file}";
}
return file;
#else
if (!Path.IsPathRooted(file))
{
throw new ArgumentException("Path must be rooted on .NET Core App 1.1.");
}
return file;
#endif
}

enum Command
{
Sign
Expand Down

0 comments on commit 2c0fd02

Please sign in to comment.