Skip to content

Commit 70252f6

Browse files
authored
Merge pull request #279 from datalust/dev
2023.1 Maintenance Release
2 parents d848864 + cbcab86 commit 70252f6

26 files changed

+389
-70
lines changed

Build.Common.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function Get-SemVer($shortver)
2+
{
3+
# This script originally (c) 2016 Serilog Contributors - license Apache 2.0
4+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
5+
$suffix = @{ $true = ""; $false = ($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '[\/\+]','-').Trim("-")}[$branch -eq "main"]
6+
7+
if ($suffix) {
8+
$shortver + "-" + $suffix
9+
} else {
10+
$shortver
11+
}
12+
}

Build.Docker.ps1

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
Push-Location $PSScriptRoot
2+
3+
. ./Build.Common.ps1
4+
15
$IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER
26
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH
37

4-
$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
8+
$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
59
$framework = "net7.0"
610
$image = "datalust/seqcli"
711
$archs = @(
@@ -50,7 +54,20 @@ function Publish-DockerImage($arch)
5054
$ErrorActionPreference = "Stop"
5155
}
5256

53-
Push-Location $PSScriptRoot
57+
function Publish-DockerManifest($archs)
58+
{
59+
$images = ""
60+
foreach ($arch in $archs) {
61+
$images += "$image-ci:$version-$($arch.rid) "
62+
}
63+
64+
# We use `invoke-expression` here so each tag is treated as a separate arg
65+
invoke-expression "docker manifest create $image-ci:$version $images"
66+
if ($LASTEXITCODE) { exit 4 }
67+
68+
docker manifest push $image-ci:$version
69+
if ($LASTEXITCODE) { exit 4 }
70+
}
5471

5572
Execute-Tests
5673

@@ -62,4 +79,8 @@ foreach ($arch in $archs) {
6279
}
6380
}
6481

82+
if ($IsPublishedBuild) {
83+
Publish-DockerManifest($archs)
84+
}
85+
6586
Pop-Location

Build.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
Push-Location $PSScriptRoot
2+
3+
. ./Build.Common.ps1
4+
15
$ErrorActionPreference = 'Stop'
26

7+
$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
38
$framework = 'net7.0'
49
$windowsTfmSuffix = '-windows'
510

@@ -73,9 +78,6 @@ function Publish-Docs($version)
7378
if($LASTEXITCODE -ne 0) { throw "Build failed" }
7479
}
7580

76-
Push-Location $PSScriptRoot
77-
78-
$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
7981
Write-Output "Building version $version"
8082

8183
$env:Path = "$pwd/.dotnetcli;$env:Path"

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ for:
2525
- pwsh: ./Setup.ps1
2626

2727
build_script:
28-
- pwsh: ./Build.ps1 -shortver "$($env:APPVEYOR_BUILD_VERSION)"
28+
- pwsh: ./Build.ps1
2929

3030
deploy:
3131

@@ -53,4 +53,4 @@ for:
5353
- pwsh: ./setup.sh
5454

5555
build_script:
56-
- pwsh: $env:PATH = "$env:HOME/.dotnetcli:$env:PATH"; ./Build.Docker.ps1 -shortver "$($env:APPVEYOR_BUILD_VERSION)"
56+
- pwsh: $env:PATH = "$env:HOME/.dotnetcli:$env:PATH"; ./Build.Docker.ps1

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "7.0.102"
3+
"version": "7.0.201"
44
}
55
}

src/SeqCli/Cli/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected virtual async Task<int> Run(string[] unrecognized)
9191

9292
protected virtual Task<int> Run() { return Task.FromResult(0); }
9393

94-
protected virtual void ShowUsageErrors(IEnumerable<string> errors)
94+
protected static void ShowUsageErrors(IEnumerable<string> errors)
9595
{
9696
foreach (var error in errors)
9797
{

src/SeqCli/Cli/Commands/ApiKey/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ protected override async Task<int> Run()
4747
var list = _entityIdentity.Id != null ?
4848
new[] { await connection.ApiKeys.FindAsync(_entityIdentity.Id) } :
4949
(await connection.ApiKeys.ListAsync())
50-
.Where(ak => _entityIdentity.Title == null || _entityIdentity.Title == ak.Title)
51-
.ToArray();
50+
.Where(ak => _entityIdentity.Title == null || _entityIdentity.Title == ak.Title);
5251

53-
foreach (var apiKey in list)
54-
{
55-
_output.WriteEntity(apiKey);
56-
}
52+
_output.ListEntities(list);
5753

5854
return 0;
5955
}

src/SeqCli/Cli/Commands/App/DefineCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System.Threading.Tasks;
1717
using SeqCli.Apps;
1818
using SeqCli.Apps.Definitions;
19-
using SeqCli.Config;
2019
using SeqCli.Util;
2120

2221
namespace SeqCli.Cli.Commands.App;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using SeqCli.Cli.Features;
5+
using SeqCli.Config;
6+
using SeqCli.Connection;
7+
8+
namespace SeqCli.Cli.Commands.App;
9+
10+
[Command("app", "list", "List installed app packages", Example="seqcli app list")]
11+
class ListCommand : Command
12+
{
13+
readonly SeqConnectionFactory _connectionFactory;
14+
15+
string? _title, _id;
16+
readonly ConnectionFeature _connection;
17+
readonly OutputFormatFeature _output;
18+
19+
string? PackageId => string.IsNullOrWhiteSpace(_title) ? null : _title.Trim();
20+
string? Id => string.IsNullOrWhiteSpace(_id) ? null : _id.Trim();
21+
22+
public ListCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
23+
{
24+
if (config == null) throw new ArgumentNullException(nameof(config));
25+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
26+
27+
Options.Add(
28+
"package-id=",
29+
"The package id of the app(s) to list",
30+
t => _title = t);
31+
32+
Options.Add(
33+
"i=|id=",
34+
"The id of a single app to list",
35+
t => _id = t);
36+
37+
_output = Enable(new OutputFormatFeature(config.Output));
38+
_connection = Enable<ConnectionFeature>();
39+
}
40+
41+
protected override async Task<int> Run()
42+
{
43+
if (PackageId != null && Id != null)
44+
{
45+
ShowUsageErrors(new[] {"Only one of either `package-id` or `id` can be specified"});
46+
return 1;
47+
}
48+
49+
var connection = _connectionFactory.Connect(_connection);
50+
51+
var list = Id != null ?
52+
new[] { await connection.Apps.FindAsync(Id) } :
53+
(await connection.Apps.ListAsync())
54+
.Where(ak => PackageId == null || PackageId == ak.Package.PackageId);
55+
56+
_output.ListEntities(list);
57+
58+
return 0;
59+
}
60+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Seq.Api.Model.AppInstances;
6+
using SeqCli.Cli.Features;
7+
using SeqCli.Config;
8+
using SeqCli.Connection;
9+
using SeqCli.Util;
10+
using Serilog;
11+
12+
namespace SeqCli.Cli.Commands.AppInstance;
13+
14+
[Command("appinstance", "create", "Create an instance of an installed app",
15+
Example = "seqcli appinstance create -t 'Email Ops' --app hostedapp-314159 -p [email protected]")]
16+
class CreateCommand : Command
17+
{
18+
readonly SeqConnectionFactory _connectionFactory;
19+
20+
readonly ConnectionFeature _connection;
21+
readonly OutputFormatFeature _output;
22+
23+
string? _title, _appId;
24+
readonly Dictionary<string, string> _settings = new();
25+
readonly List<string> _overridable = new();
26+
27+
public CreateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
28+
{
29+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
30+
31+
Options.Add(
32+
"t=|title=",
33+
"A title for the app instance",
34+
t => _title = ArgumentString.Normalize(t));
35+
36+
Options.Add(
37+
"app=",
38+
"The id of the installed app package to instantiate",
39+
app => _appId = ArgumentString.Normalize(app));
40+
41+
Options.Add(
42+
"p={=}|property={=}",
43+
"Specify name/value settings for the app, e.g. `-p [email protected] -p Subject=\"Alert!\"`",
44+
(n, v) =>
45+
{
46+
var name = n.Trim();
47+
var valueText = v?.Trim();
48+
_settings.Add(name, valueText ?? "");
49+
});
50+
51+
Options.Add(
52+
"overridable=",
53+
"Specify setting names that may be overridden by users when invoking the app",
54+
s => _overridable.Add(s));
55+
56+
// The command doesn't yet implement "Stream incoming events".
57+
58+
_connection = Enable<ConnectionFeature>();
59+
_output = Enable(new OutputFormatFeature(config.Output));
60+
}
61+
62+
protected override async Task<int> Run()
63+
{
64+
var connection = _connectionFactory.Connect(_connection);
65+
66+
AppInstanceEntity instance = await connection.AppInstances.TemplateAsync(_appId)!;
67+
68+
bool ValidateSettingName(string settingName)
69+
{
70+
if (!instance.Settings!.ContainsKey(settingName))
71+
{
72+
Log.Error("The app does not accept a setting with name {SettingName}; available settings are: {AvailableSettings}", settingName, instance.Settings.Keys.ToArray());
73+
return false;
74+
}
75+
76+
return true;
77+
}
78+
79+
instance.Title = _title;
80+
81+
foreach (var setting in _settings)
82+
{
83+
if (!ValidateSettingName(setting.Key))
84+
return 1;
85+
86+
instance.Settings![setting.Key] = setting.Value;
87+
}
88+
89+
foreach (var overridable in _overridable)
90+
{
91+
if (!ValidateSettingName(overridable))
92+
return 1;
93+
94+
instance.InvocationOverridableSettings!.Add(overridable);
95+
}
96+
97+
instance = await connection.AppInstances.AddAsync(instance);
98+
99+
_output.WriteEntity(instance);
100+
101+
return 0;
102+
}
103+
}

0 commit comments

Comments
 (0)