-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement update
commands for commonly-used entities
#345
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you flipped the bool here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; yes, that one's the fix 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the condition "worked" because it failed to take different casings of "ExpressionIndexes" into account, and so happened to return the correct value for that case.