Skip to content

Commit

Permalink
Merge pull request #63 from datalust/dev
Browse files Browse the repository at this point in the history
New Preview
  • Loading branch information
nblumhardt authored Jun 13, 2018
2 parents 76eeb2f + dca3d89 commit 732f045
Show file tree
Hide file tree
Showing 23 changed files with 433 additions and 150 deletions.
12 changes: 7 additions & 5 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$ErrorActionPreference = 'Stop'

$framework = 'netcoreapp2.1'

function Clean-Output
{
if(Test-Path ./artifacts) { rm ./artifacts -Force -Recurse }
Expand All @@ -25,17 +27,17 @@ function Publish-Gzips($version)
{
$rids = @("linux-x64", "osx-x64")
foreach ($rid in $rids) {
& dotnet publish src/SeqCli/SeqCli.csproj -c Release -f netcoreapp2.0 -r $rid /p:VersionPrefix=$version /p:ShowLinkerSizeComparison=true
& dotnet publish src/SeqCli/SeqCli.csproj -c Release -f $framework -r $rid /p:VersionPrefix=$version /p:ShowLinkerSizeComparison=true
if($LASTEXITCODE -ne 0) { exit 4 }

# Make sure the archive contains a reasonable root filename
mv ./src/SeqCli/bin/Release/netcoreapp2.0/$rid/publish/ ./src/SeqCli/bin/Release/netcoreapp2.0/$rid/seqcli-$version-$rid/
mv ./src/SeqCli/bin/Release/$framework/$rid/publish/ ./src/SeqCli/bin/Release/$framework/$rid/seqcli-$version-$rid/

& ./build/7-zip/7za.exe a -ttar seqcli-$version-$rid.tar ./src/SeqCli/bin/Release/netcoreapp2.0/$rid/seqcli-$version-$rid/
& ./build/7-zip/7za.exe a -ttar seqcli-$version-$rid.tar ./src/SeqCli/bin/Release/$framework/$rid/seqcli-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }

# Back to the original directory name
mv ./src/SeqCli/bin/Release/netcoreapp2.0/$rid/seqcli-$version-$rid/ ./src/SeqCli/bin/Release/netcoreapp2.0/$rid/publish/
mv ./src/SeqCli/bin/Release/$framework/$rid/seqcli-$version-$rid/ ./src/SeqCli/bin/Release/$framework/$rid/publish/

& ./build/7-zip/7za.exe a -tgzip ./artifacts/seqcli-$version-$rid.tar.gz seqcli-$version-$rid.tar
if($LASTEXITCODE -ne 0) { exit 6 }
Expand All @@ -46,7 +48,7 @@ function Publish-Gzips($version)

function Publish-Msi($version)
{
& dotnet publish ./src/SeqCli/SeqCli.csproj -c Release -f netcoreapp2.0 -r win-x64 /p:VersionPrefix=$version /p:ShowLinkerSizeComparison=true
& dotnet publish ./src/SeqCli/SeqCli.csproj -c Release -f $framework -r win-x64 /p:VersionPrefix=$version /p:ShowLinkerSizeComparison=true
if($LASTEXITCODE -ne 0) { exit 7 }

& msbuild ./setup/SeqCli.Setup/SeqCli.Setup.wixproj /t:Build /p:Configuration=Release /p:Platform=x64 /p:SeqCliVersion=$version /p:BuildProjectReferences=false
Expand Down
6 changes: 3 additions & 3 deletions setup/SeqCli.Setup/SeqCli.Setup.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
</Target>
<Target Name="BeforeBuild">
<PropertyGroup>
<LinkerBaseInputPaths>..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.0\win-x64\publish</LinkerBaseInputPaths>
<DefineConstants>BasePath=..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.0\win-x64\publish;$(DefineConstants)</DefineConstants>
<LinkerBaseInputPaths>..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.1\win-x64\publish</LinkerBaseInputPaths>
<DefineConstants>BasePath=..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.1\win-x64\publish;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<HeatDirectory OutputFile="SeqCli.wxs" DirectoryRefId="INSTALLFOLDER" ComponentGroupName="SeqCli_Project" SuppressCom="true" Directory="..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.0\win-x64\publish" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" PreprocessorVariable="var.BasePath" Transforms="RemovePdbs.xslt" />
<HeatDirectory OutputFile="SeqCli.wxs" DirectoryRefId="INSTALLFOLDER" ComponentGroupName="SeqCli_Project" SuppressCom="true" Directory="..\..\src\SeqCli\bin\$(Configuration)\netcoreapp2.1\win-x64\publish" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" PreprocessorVariable="var.BasePath" Transforms="RemovePdbs.xslt" />
</Target>
</Project>
7 changes: 4 additions & 3 deletions src/SeqCli/Cli/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;

namespace SeqCli.Cli
{
Expand Down Expand Up @@ -87,11 +88,11 @@ protected virtual async Task<int> Run(string[] unrecognised)

protected virtual void ShowUsageErrors(IEnumerable<string> errors)
{
var header = "Error:";
foreach (var error in errors)
{
Printing.Define(header, error, 7, Console.Out);
header = new string(' ', header.Length);
#pragma warning disable Serilog004 // Constant MessageTemplate verifier
Log.Error(error);
#pragma warning restore Serilog004 // Constant MessageTemplate verifier
}
}

Expand Down
38 changes: 32 additions & 6 deletions src/SeqCli/Cli/Commands/ApiKey/ListCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using System;
// Copyright 2018 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Linq;
using System.Threading.Tasks;
using SeqCli.Cli.Features;
using SeqCli.Config;
Expand All @@ -7,11 +22,12 @@

namespace SeqCli.Cli.Commands.ApiKey
{
[Command("apikey", "list", "List API keys on the server", Example="seqcli apikey list")]
[Command("apikey", "list", "List available API keys", Example="seqcli apikey list")]
class ListCommand : Command
{
readonly SeqConnectionFactory _connectionFactory;


readonly EntityIdentityFeature _entityIdentity;
readonly ConnectionFeature _connection;
readonly OutputFormatFeature _output;

Expand All @@ -20,18 +36,28 @@ public ListCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
if (config == null) throw new ArgumentNullException(nameof(config));
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));

_entityIdentity = Enable(new EntityIdentityFeature("API key", "list"));
_output = Enable(new OutputFormatFeature(config.Output));
_connection = Enable<ConnectionFeature>();
}

protected override async Task<int> Run()
{
if (_entityIdentity.Title != null && _entityIdentity.Id != null)
{
Log.Error("Only one of either `title` or `id` can be specified");
return -1;
}

var connection = _connectionFactory.Connect(_connection);

var apiKeys = await connection.ApiKeys.ListAsync();
Log.Debug("Retrieved ApiKeys {@ApiKeys}", apiKeys);
var list = _entityIdentity.Id != null ?
new[] { await connection.ApiKeys.FindAsync(_entityIdentity.Id) } :
(await connection.ApiKeys.ListAsync())
.Where(ak => _entityIdentity.Title != null || _entityIdentity.Title == ak.Title)
.ToArray();

foreach (var apiKey in apiKeys)
foreach (var apiKey in list)
{
_output.WriteEntity(apiKey);
}
Expand Down
60 changes: 34 additions & 26 deletions src/SeqCli/Cli/Commands/ApiKey/RemoveCommand.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,68 @@
using System;
using System.Collections.Generic;
// Copyright 2018 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Seq.Api.Model.Inputs;
using SeqCli.Cli.Features;
using SeqCli.Connection;
using Serilog;

namespace SeqCli.Cli.Commands.ApiKey
{
[Command("apikey", "remove", "Remove an API key from the server",
Example="seqcli apikey remove -t TestApiKey")]
Example="seqcli apikey remove -t 'Test API Key'")]
class RemoveCommand : Command
{
readonly SeqConnectionFactory _connectionFactory;

readonly EntityIdentityFeature _entityIdentity;
readonly ConnectionFeature _connection;
string _title;
string _id;

public RemoveCommand(SeqConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));

_entityIdentity = Enable(new EntityIdentityFeature("API key", "remove"));
_connection = Enable<ConnectionFeature>();
Options.Add(
"t=|title=",
"Remove API Keys with the specified title",
(t) => _title = t);

Options.Add(
"i=|id=",
"Remove API Keys with the specified Id",
(t) => _id = t);
}

protected override async Task<int> Run()
{
if (_title != default && _id != default)
if (_entityIdentity.Title == null && _entityIdentity.Id == null)
{
Console.WriteLine("You can only specify \"title\" or \"id\" not both");
Log.Error("A `title` or `id` must be specified");
return -1;
}

var connection = _connectionFactory.Connect(_connection);

var apiKeys = await connection.ApiKeys.ListAsync();
var apiKeyToRemove = apiKeys.Where(ak => ak.Title == _title || ak.Id == _id).ToList();
if (!apiKeyToRemove.Any())
var toRemove = _entityIdentity.Id != null ?
new[] {await connection.ApiKeys.FindAsync(_entityIdentity.Id)} :
(await connection.ApiKeys.ListAsync())
.Where(ak => _entityIdentity.Title == ak.Title)
.ToArray();

if (!toRemove.Any())
{
Console.WriteLine($"\"{_title}\" API Key doesn't exist");
Log.Error("No matching API key was found");
return -1;
}

foreach (var apiKeyEntity in apiKeyToRemove)
{
foreach (var apiKeyEntity in toRemove)
await connection.ApiKeys.RemoveAsync(apiKeyEntity);
}

return 0;
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/SeqCli/Cli/Commands/IngestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class IngestCommand : Command
public IngestCommand(SeqConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
_fileInputFeature = Enable<FileInputFeature>();
_fileInputFeature = Enable(new FileInputFeature("CLEF file to ingest"));
_invalidDataHandlingFeature = Enable<InvalidDataHandlingFeature>();
_properties = Enable<PropertiesFeature>();

Expand Down Expand Up @@ -82,13 +82,8 @@ protected override async Task<int> Run()
filter = evt => true.Equals(eval(evt));
}

using (var inputFile = _fileInputFeature.InputFilename != null
? new StreamReader(File.Open(_fileInputFeature.InputFilename, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite))
: null)
using (var input = _fileInputFeature.OpenInput())
{
var input = inputFile ?? Console.In;

var reader = _json ?
(ILogEventReader)new JsonLogEventReader(input) :
new PlainTextLogEventReader(input, _pattern);
Expand Down
81 changes: 81 additions & 0 deletions src/SeqCli/Cli/Commands/Signal/ImportCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2018 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Seq.Api.Model.Signals;
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Signal
{
[Command("signal", "import", "Import signals in newline-delimited JSON format",
Example="seqcli signal import -i ./Exceptions.json")]
class ImportCommand : Command
{
readonly SeqConnectionFactory _connectionFactory;
readonly FileInputFeature _fileInputFeature;
readonly ConnectionFeature _connection;

readonly JsonSerializer _serializer = JsonSerializer.Create(
new JsonSerializerSettings{
Converters = { new StringEnumConverter() }
});

public ImportCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
if (config == null) throw new ArgumentNullException(nameof(config));
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
_fileInputFeature = Enable(new FileInputFeature("File to import"));
_connection = Enable<ConnectionFeature>();
}

protected override async Task<int> Run()
{
var connection = _connectionFactory.Connect(_connection);

using (var input = _fileInputFeature.OpenInput())
{
var line = input.ReadLine();
while (line != null)
{
if (!string.IsNullOrWhiteSpace(line))
{
// Explicitly copying fields here ensures we don't try copying links or ids; for other
// entity types it'll ensure we notice places that "referential integrity" has to be
// maintained.
var src = _serializer.Deserialize<SignalEntity>(new JsonTextReader(new StringReader(line)));
var dest = await connection.Signals.TemplateAsync();
dest.Title = src.Title;
dest.Description = src.Description;
dest.ExplicitGroupName = src.ExplicitGroupName;
dest.Grouping = src.Grouping;
dest.IsProtected = src.IsProtected;
dest.Filters = src.Filters;
dest.TaggedProperties = src.TaggedProperties;
await connection.Signals.AddAsync(dest);
}

line = input.ReadLine();
}
}

return 0;
}
}
}
Loading

0 comments on commit 732f045

Please sign in to comment.