-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from nblumhardt/update-commands
Implement `update` commands for commonly-used entities
- Loading branch information
Showing
22 changed files
with
405 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -285,3 +285,5 @@ __pycache__/ | |
*.btm.cs | ||
*.odx.cs | ||
*.xsd.cs | ||
|
||
.DS_Store |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.ApiKey; | ||
|
||
[Command("apikey", "update", | ||
"Update an existing API key", | ||
Example="seqcli apikey update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "apikey", nameof(SeqConnection.ApiKeys), "API key"); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.AppInstance; | ||
|
||
[Command("appinstance", "update", | ||
"Update an existing app instance", | ||
Example="seqcli appinstance update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "appinstance", nameof(SeqConnection.AppInstances), "app instance"); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.Feed; | ||
|
||
[Command("feed", "update", | ||
"Update an existing NuGet feed", | ||
Example="seqcli feed update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "feed", nameof(SeqConnection.Feeds), "NuGet feed"); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.RetentionPolicy; | ||
|
||
[Command("retention", "update", | ||
"Update an existing retention policy", | ||
Example="seqcli retention update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "retention", nameof(SeqConnection.RetentionPolicies), "retention policy"); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright © 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.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Connection; | ||
using SeqCli.Templates.Ast; | ||
using SeqCli.Templates.Import; | ||
using SeqCli.Templates.Parser; | ||
using SeqCli.Util; | ||
using Serilog; | ||
|
||
namespace SeqCli.Cli.Commands.Shared; | ||
|
||
abstract class UpdateCommand: Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly string _resourceGroupName; | ||
readonly string _entityName; | ||
|
||
string? _json; | ||
bool _jsonStdin; | ||
|
||
protected UpdateCommand(SeqConnectionFactory connectionFactory, string commandGroupName, string resourceGroupName, string? entityName = null) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
_resourceGroupName = resourceGroupName; | ||
_entityName = entityName ?? commandGroupName; | ||
|
||
Options.Add( | ||
"json=", | ||
$"The updated {_entityName} in JSON format; this can be produced using `seqcli {commandGroupName} list --json`", | ||
p => _json = ArgumentString.Normalize(p)); | ||
|
||
Options.Add( | ||
"json-stdin", | ||
$"Read the updated {_entityName} as JSON from `STDIN`", | ||
_ => _jsonStdin = true); | ||
|
||
_connection = Enable<ConnectionFeature>(); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
if (_json == null && !_jsonStdin) | ||
{ | ||
Log.Error("One of either `--json` or `--json-stdin` must be specified"); | ||
return 1; | ||
} | ||
|
||
var json = _json ?? await Console.In.ReadToEndAsync(); | ||
|
||
if (!JsonTemplateParser.TryParse(json, out var template, out var error, out _)) | ||
{ | ||
Log.Error("The {EntityName} JSON could not be parsed: {Error}", _entityName, error); | ||
return 1; | ||
} | ||
|
||
if (template is not JsonTemplateObject obj || | ||
!obj.Members.TryGetValue("Id", out var idValue) || | ||
idValue is not JsonTemplateString id) | ||
{ | ||
Log.Error("The {EntityName} JSON must be an object literal with a valid string `Id` property", _entityName); | ||
return 1; | ||
} | ||
|
||
var templateName = "JSON"; | ||
var entityTemplate = new EntityTemplate(_resourceGroupName, templateName, template); | ||
var state = new TemplateImportState(); | ||
state.AddOrUpdateCreatedEntityId(templateName, id.Value); | ||
await TemplateSetImporter.ImportAsync([entityTemplate], connection, new Dictionary<string, JsonTemplate>(), state, merge: false); | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.Signal; | ||
|
||
[Command("signal", "update", | ||
"Update an existing signal", | ||
Example="seqcli signal update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "signal", nameof(SeqConnection.Signals)); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.User; | ||
|
||
[Command("user", "update", | ||
"Update an existing user", | ||
Example="seqcli user update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "user", nameof(SeqConnection.Users)); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 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 Seq.Api; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.Workspace; | ||
|
||
[Command("workspace", "update", | ||
"Update an existing workspace", | ||
Example="seqcli workspace update --json '{...}'")] | ||
class UpdateCommand(SeqConnectionFactory connectionFactory): | ||
Shared.UpdateCommand(connectionFactory, "workspace", nameof(SeqConnection.Workspaces)); | ||
|
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"SeqCli": { | ||
"commandName": "Project", | ||
"commandLineArgs": "signal update --json-stdin" | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains 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 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.