Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ if (!(Test-Path $CAKE_EXE)) {
[System.Net.ServicePointManager]::SecurityProtocol = $previousSecurityProtocol


$scpt="${PSScriptRoot}/${Script}"

# Build Cake arguments
$cakeArguments = @("$Script");
$cakeArguments = @("$scpt");
if ($Target) { $cakeArguments += "--target=$Target" }
if ($Configuration) { $cakeArguments += "--configuration=$Configuration" }
if ($Version) { $cakeArguments += "--version=$Version" }
Expand All @@ -157,6 +158,6 @@ if ($Pre) { $cakeArguments += "--pre=true" }
$cakeArguments += $ScriptArgs

# Start Cake
Write-Host "Running build script..."
Write-Host "Running build script for Scalus..."
&$CAKE_EXE $cakeArguments
exit $LASTEXITCODE
4 changes: 2 additions & 2 deletions polaris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ project:
capture:
build:
cleanCommands:
- shell: [powershell, ./build.ps1, "-Target clean"]
- shell: [powershell, "${project.projectDir}/build.ps1", "-Target clean"]
buildCommands:
- shell: [powershell, ./build.ps1]
- shell: [powershell, "${project.projectDir}/build.ps1"]
fileSystem:
ears:
extensions: [ear]
Expand Down
13 changes: 5 additions & 8 deletions scripts/Win/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)"
Name="scalus" Version="$(var.Version)" Manufacturer="One Identity" Language="1033">
<Package InstallerVersion="$(var.Minimum_Version)" Compressed="yes" Comments="Windows Installer Package" InstallScope="perMachine" />
<Package InstallerVersion="$(var.Minimum_Version)" Compressed="yes" Comments="Windows Installer Package" InstallScope="perMachine"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>

<Upgrade Id="$(var.ProductUpgradeCode)">
<UpgradeVersion Minimum="$(var.Version)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED"/>
<UpgradeVersion Minimum="0.0.0" Maximum="$(var.Version)" IncludeMinimum="yes" IncludeMaximum="no" Property="OLDERVERSIONBEINGUPGRADED"/>
<UpgradeVersion Minimum="$(var.Version)" IncludeMinimum="no" OnlyDetect="no" Property="NEWERVERSIONDETECTED"/>
<UpgradeVersion Minimum="0.0.0.0" Maximum="$(var.Version)" IncludeMinimum="yes" IncludeMaximum="yes" Property="OLDERVERSIONBEINGUPGRADED"/>
</Upgrade>
<Condition Message="A newer version of this software is already installed.">NOT NEWERVERSIONDETECTED</Condition>
<MajorUpgrade AllowSameVersionUpgrades="yes" AllowDowngrades="no" DowngradeErrorMessage="A newer version of [ProductName] is already installed. If you are sure you want to downgrade, remove the existing installation via Programs and Features." Schedule="afterInstallFinalize"/>

<WixVariable Id="WixUILicenseRtf" Value="$(var.tmpdir)\license.rtf" />

Expand Down Expand Up @@ -65,15 +66,11 @@
<Property Id="WixShellExecReadFile" Value="[#AppFile5]" />
<CustomAction Id="LaunchFile" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />


<InstallExecuteSequence>
<RemoveExistingProducts After="InstallValidate"/>
</InstallExecuteSequence>

<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="ApplicationFiles"/>
<ComponentRef Id="ExampleFiles"/>
<ComponentRef Id="ApplicationShortcuts"/>
</Feature>

</Product>
</Wix>
29 changes: 15 additions & 14 deletions src/CommandLineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ public CommandLineHandler(IEnumerable<IVerb> verbs)

public IApplication Build(string[] args, Func<object, IApplication> appResolver)
{
var parser = new CommandLine.Parser(with => {
using (var parser = new CommandLine.Parser(with => {
with.HelpWriter = null;
});

var verbTypes = Verbs.Select(x => x.GetType()).OrderBy(x => x.GetCustomAttribute<VerbAttribute>().Name).ToArray();
var parserResult = parser.ParseArguments(args, verbTypes);
}))
{
var verbTypes = Verbs.Select(x => x.GetType()).OrderBy(x => x?.GetCustomAttribute<VerbAttribute>()?.Name)?.ToArray();
var parserResult = parser.ParseArguments(args, verbTypes);

IApplication application = null;
parserResult
.WithParsed(x =>
{
application = appResolver(x);
})
.WithNotParsed(x => HandleErrors(parserResult, x));
return application;
IApplication application = null;
parserResult
.WithParsed(x =>
{
application = appResolver(x);
})
.WithNotParsed(x => HandleErrors(parserResult, x));
return application;
}
}

static void HandleErrors<T>(ParserResult<T> parserResult, IEnumerable<Error> errs)
Expand All @@ -48,7 +49,7 @@ static void HandleErrors<T>(ParserResult<T> parserResult, IEnumerable<Error> err
// Handle version
if (errs.IsVersion())
{
Console.WriteLine($"{header}\r\n{copyright}\r\nVersion: {Assembly.GetEntryAssembly().GetName().Version}\r\n");
Console.WriteLine($"{header}\r\n{copyright}\r\nVersion: {Assembly.GetEntryAssembly()?.GetName()?.Version}\r\n");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Dto/ApplicationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public void Validate(List<string> errors)
{
errors.Add($"An Exec must be configured for application:{Name}({Id})");
}
if (string.IsNullOrEmpty(Protocol))
if (!ProtocolMapping.ValidateProtocol(Protocol, out string err))
{
errors.Add($"A protocol must be configured for application:{Name}({Id})");
errors.Add(err);
}
if (string.IsNullOrEmpty(Name))
{
Expand Down
23 changes: 20 additions & 3 deletions src/Dto/ProtocolMapping.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Newtonsoft.Json;

namespace scalus.Dto
{
public class ProtocolMapping
{
public static bool ValidateProtocol(string val, out string err)
{
err=null;
if (string.IsNullOrEmpty(val))
{
err =("Protocol name must be configured");
return false;
}
if (Regex.IsMatch(val, "^[a-zA-Z][a-zA-Z0-9-+.]+$"))
{
return true;
}
err =($"Protocol name contains invalid chars:{val}");
return false;
}

[JsonRequired]
public string Protocol { get; set; }
public string Protocol { get;set; }
public string AppId { get; set; }

private static readonly Dictionary<string, string> _dtoPropertyDescription = new Dictionary<string, string>
Expand All @@ -20,9 +37,9 @@ public class ProtocolMapping

public void Validate(List<string> errors)
{
if (string.IsNullOrEmpty(Protocol))
if (!ValidateProtocol(Protocol, out string err))
{
errors.Add("Protocol name must be configured");
errors.Add(err);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/IScalusConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace scalus
{
Expand All @@ -22,7 +23,7 @@ interface IScalusConfiguration
public interface IScalusApiConfiguration
{
ScalusConfig GetConfiguration();
ScalusConfig SaveConfiguration(ScalusConfig configuration);
List<string> SaveConfiguration(ScalusConfig configuration);
List<string> ValidationErrors { get; }
}

Expand Down
50 changes: 26 additions & 24 deletions src/Info/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,39 @@ private void ShowConfig()
");
Console.WriteLine(" {0,-10} {1,-10} {2,-20} {3}", "Protocol", "Registered", "Description", "Configured Command");
Console.WriteLine(" ------------------------------------------------------------------------------------------------");
if (config?.Protocols?.Count > 0)
if (config == null || config.Protocols == null || config.Protocols.Count == 0)
return;

foreach (var one in config.Protocols)
{
foreach (var one in config.Protocols)
if (one == null)
continue;
Console.Write(" {0,-10} ", one.Protocol);
ApplicationConfig appConfig = null;
if (config.Applications?.Count > 0)
{
Console.Write(" {0,-10} ", one.Protocol);
ApplicationConfig appConfig = null;
if (config?.Applications?.Count > 0)
{
foreach (var a in from a in config.Applications
where a.Id == one.AppId
foreach (var a in from a in config.Applications
where a.Id == one.AppId
select a)
{
appConfig = a;
break;
}
}

if (appConfig != null)
{
Console.Write("{0,-10} {1,-20} ({2} {3})",
Registration.IsRegistered(one.Protocol) ? "yes" : "no", appConfig.Description,
appConfig.Exec, string.Join(' ', appConfig.Args));
}
else
{
Console.Write("{0,-10} {1,-20}", Registration.IsRegistered(one.Protocol) ? "yes" : "no",
"Not configured");
appConfig = a;
break;
}
}

Console.WriteLine();
if (appConfig != null)
{
Console.Write("{0,-10} {1,-20} ({2} {3})",
Registration.IsRegistered(one.Protocol) ? "yes" : "no", appConfig.Description,
appConfig.Exec, string.Join(' ', appConfig.Args));
}
else
{
Console.Write("{0,-10} {1,-20}", Registration.IsRegistered(one.Protocol) ? "yes" : "no",
"Not configured");
}

Console.WriteLine();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Launch/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void HandleLaunchError(Exception ex, string url)

ApplicationId: {application?.Id ?? "<none>"}
Command: {application?.Exec ?? "<none>"}
Args: {(application.Args != null ? string.Join(" ", application.Args) : "<none>")}
Args: {(application?.Args != null ? string.Join(" ", application?.Args) : "<none>")}

Config File: {scalusJsonPath}

Expand Down
20 changes: 13 additions & 7 deletions src/Platform/OsServicesBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Process Execute(string command, IEnumerable<string> args)
}
Log.Logger.Information($"Running process:{command} with args:{string.Join(' ', args)}");
var process = Process.Start(startupInfo);
Log.Logger.Information($"Started process, id:{process.Id}, exited:{process.HasExited}");
Log.Logger.Information($"Started process, id:{process?.Id}, exited:{process?.HasExited}");
return process;
}
//execute a command, wait for it to end, return the exit code and retrieve the stdout & stderr
Expand Down Expand Up @@ -124,13 +124,19 @@ public void OpenText(string message)
File.WriteAllText(tempFile, message);
var l = File.ReadAllText(tempFile);
var process = OpenDefault(tempFile);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (process == null)
{
process.WaitForExit();
}
else
{
Task.Delay(10* 1000).Wait();
Log.Error($"Failed to report warning:{message}");
}
else {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
process.WaitForExit();
}
else
{
Task.Delay(10* 1000).Wait();
}
}
}
catch (System.Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static int Main(string[] args)
var application = parser.Build(args, x =>
{
var type = x.GetType();
var verb = type.GetCustomAttribute<VerbAttribute>().Name;
return lifetimeScope.ResolveNamed<IApplication>(verb, new TypedParameter(type, x));
var verb = type?.GetCustomAttribute<VerbAttribute>()?.Name;
return verb == null ? null : lifetimeScope.ResolveNamed<IApplication>(verb, new TypedParameter(type, x));
});

// If application is null, then they ran help or version commands, just return
Expand Down
5 changes: 5 additions & 0 deletions src/ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void Run(bool preview = false)
return;
}
var process = OsServices.Execute(cmd, args);
if (process == null)
{
Serilog.Log.Error("Failed to create process for cmd:{cmd}");
throw new Exception($"Failed to create process for cmd:{cmd}");
}
Serilog.Log.Debug("Post execute starting.");

Parser.PostExecute(process);
Expand Down
21 changes: 20 additions & 1 deletion src/Registration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ IOsServices osServices

public bool IsRegistered(string protocol, bool useSudo = false)
{
if (!ProtocolMapping.ValidateProtocol(protocol, out string err))
{
Serilog.Log.Error($"Invalid protocol:{protocol}");
UserInteraction.Message($"{protocol}: The protocol is invalid.");
return false;
}
var registered = true;
foreach (var registrar in Registrars)
{
Expand All @@ -37,10 +43,16 @@ public bool IsRegistered(string protocol, bool useSudo = false)
public bool Register(IEnumerable<string> protocols, bool force, bool rootMode = false, bool useSudo=false)
{
var retval = false;

foreach (var protocol in protocols)
{
retval = true;
if (!ProtocolMapping.ValidateProtocol(protocol, out string err))
{
retval = false;
Serilog.Log.Error($"{err}");
UserInteraction.Message($"{protocol}: {err}");
continue;
}

foreach (var registrar in Registrars)
{
Expand Down Expand Up @@ -89,6 +101,13 @@ public bool UnRegister(IEnumerable<string> protocols, bool rootMode = false, boo
{
foreach (var protocol in protocols)
{
if (!ProtocolMapping.ValidateProtocol(protocol, out string err))
{
Serilog.Log.Error($"{err}");
UserInteraction.Message($"{protocol}: {err}");
continue;
}

foreach (var registrar in Registrars)
{
if (rootMode)
Expand Down
5 changes: 3 additions & 2 deletions src/ScalusConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using scalus.Util;
using System.Threading.Tasks;

namespace scalus
{
Expand Down Expand Up @@ -105,7 +106,7 @@ public ScalusApiConfiguration(string json)
{
}

public ScalusConfig SaveConfiguration(ScalusConfig configuration)
public List<string> SaveConfiguration(ScalusConfig configuration)
{
ValidationErrors = new List<string>();

Expand All @@ -125,7 +126,7 @@ public ScalusConfig SaveConfiguration(ScalusConfig configuration)
Serilog.Log.Error($"*** Validation errors: {string.Join(", ", ValidationErrors)}");
}

return Config;
return ValidationErrors;
}


Expand Down
Loading