Skip to content

Add support for Listing and Removing API Keys#27

Merged
nblumhardt merged 3 commits into
datalust:devfrom
andymac4182:apikey
Feb 27, 2018
Merged

Add support for Listing and Removing API Keys#27
nblumhardt merged 3 commits into
datalust:devfrom
andymac4182:apikey

Conversation

@andymac4182

Copy link
Copy Markdown
Contributor

This is an initial idea for listing and removing of API Keys it is based on my work in #26. I plan on adding support for adding api keys.

@nblumhardt nblumhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Added a bunch of thoughts since it's the first feature like this and there's not much existing code to compare with, keen to know your thoughts. Cheers!

namespace SeqCli.Cli.Commands.ApiKey
{
[Command("apikey", "list", "Send a structured log event to the server", Example =
"seqcli log -m 'Hello, {Name}!' -p Name=World -p App=Test")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example/description is out of sync here

}

await connection.ApiKeys.RemoveAsync(apiKeyToRemove);
Console.WriteLine($"\"{_title}\" API Key removed");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far in this project we've taken the "unix" approach of not writing any output on success; keen to see how that goes, would be good to line this up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will remove the line.

_connection = Enable<ConnectionFeature>();
Options.Add(
"t=|title=",
"",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: param description here

{
_connectionFactory = connectionFactory;
_connection = Enable<ConnectionFeature>();
Options.Add(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is id a worthwhile option/alternative to title? Would help with the ambiguous ones where names overlap.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added Id and put a check in to ensure that they only specify a single value since both could be confusing as to if its removing only when both match or just one.

var connection = _connectionFactory.Connect(_connection);

var apiKeys = await connection.ApiKeys.ListAsync();
var apiKeyToRemove = apiKeys.FirstOrDefault(ak => ak.Title == _title);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make as much sense to remove all matches, instead of just the first, here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. I completely forgot you can have multiple with the same Title. I will fix that up.

});
foreach (var apiKey in data)
{
var apiKeyString = JsonConvert.SerializeObject(apiKey);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Log.Debug("Retrieved ApiKeys {@ApiKeys}", apiKeys);
var data = apiKeys.Select(a => new
{
a.AppliedProperties,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we listed Id and Title first here, it might be a bit quicker to visually parse the output.

@andymac4182

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @nblumhardt I wasn't sure exactly the best way to approach a few of these but this has given me good direction. I will try get this updated shortly.


namespace SeqCli.Cli.Commands.ApiKey
{
[Command("apikey", "list", "Send a structured log event to the server", Example =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of the command should be updated here :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tsimbalar I have fixed that up now.

@nblumhardt nblumhardt merged commit 003e541 into datalust:dev Feb 27, 2018
@nblumhardt

Copy link
Copy Markdown
Member

👍

We might want to think a bit more about how output/formatting could work consistently for multiple entity types, e.g. maybe we output plain text (or colorized CSV?) by default, and use --json to switch on JSON mode like the other commands?

The output could also be made Seq-version-agnostic by side-stepping the strongly-typed ListAsync method and retrieving the result set as dynamic instead; the output mechanism could then just strip off the Links property and output JSON-document-per-line.

Tough balance to strike between ergonomics and automation-friendliness, should be fun :-)

@nblumhardt nblumhardt mentioned this pull request Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants