Skip to content
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

Add management of Meadow.Cloud API keys #395

Merged
merged 1 commit into from
Jan 18, 2024
Merged

Conversation

stevenkuhn
Copy link
Contributor

@stevenkuhn stevenkuhn commented Nov 9, 2023

This adds the ability to manage your Meadow.Cloud API keys via the command line (V2 only).

The commands are:

meadow cloud apikey create <NAME> --duration|d <duration> --scopes|s <scopes>
meadow cloud apikey list
meadow cloud apikey update <NAME_OR_ID> --name|n <name> --scopes|s <scopes>
meadow cloud apikey delete <NAME_OR_ID>

This also utilizes the new Console spinner and implements a new ConsoleTable for displaying tabular data.

Examples

Create

> meadow cloud api create myapikey --duration 30 --scopes command
Creating an API key on Meadow.Cloud...
Your API key 'myapikey' (expiring 1/26/2024 5:40:30 PM UTC) is:

mc_xxxxxxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Make sure to copy this key now as you will not be able to see this again.
Done.

Update

❯ meadow cloud apikey update myapikey --scopes command search
Updating API key `myapikey` on Meadow.Cloud...
Done.

Delete

❯ meadow cloud apikey delete myapikey
Deleting API key `myapikey` on Meadow.Cloud...
Done.

List

When you have no API keys

❯ meadow cloud apikey list
Retrieving your API keys from Meadow.Cloud...
You have no API keys.
Done.

When you have a single API key

❯ meadow cloud apikey list
Retrieving your API keys from Meadow.Cloud...

---------------------------------+----------+----------------------+----------------
Id                               | Name     | Expires (UTC)        | Scopes
---------------------------------|----------|----------------------|----------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | myapikey | 1/26/2024 5:44:33 PM | command, search
---------------------------------+----------+----------------------+----------------

Done.

@stevenkuhn stevenkuhn marked this pull request as ready for review November 21, 2023 17:26
@adrianstevens
Copy link
Contributor

This PR looks great except we'll be removing the WithSpinner extension method.

@stevenkuhn
Copy link
Contributor Author

This PR looks great except we'll be removing the WithSpinner extension method.

Will the spinner be removed entirely or replaced with something else? Or is only the extension method going away?

@CartBlanche CartBlanche deleted the branch develop December 4, 2023 18:59
@CartBlanche CartBlanche closed this Dec 4, 2023
@CartBlanche CartBlanche reopened this Dec 4, 2023
@CartBlanche
Copy link
Collaborator

@adrianstevens The WithSpinner calls are't in the base classes, so it isn't mixing UI with functionality. It is specifically for the console UI, unless I've missed something.

@stevenkuhn due to me messing up the develop branch you may have to resolve some merge conflicts with this new develop branch.

@ctacke ctacke closed this Dec 7, 2023
@ctacke ctacke deleted the feature/mc-apikeys branch December 7, 2023 16:21
@stevenkuhn stevenkuhn restored the feature/mc-apikeys branch December 7, 2023 16:28
@stevenkuhn stevenkuhn reopened this Dec 7, 2023
@adrianstevens
Copy link
Contributor

Let's definitely talk about the spinner code but adding extension methods to tasks to trigger presentation is basically the opposite of separation-of-concerns. And if extinction methods on tasks are needed to give feedback to the user, it's a pretty good sign that we have some architecture issues to solve.

@stevenkuhn
Copy link
Contributor Author

stevenkuhn commented Dec 8, 2023

Let's definitely talk about the spinner code but adding extension methods to tasks to trigger presentation is basically the opposite of separation-of-concerns.

@adrianstevens Would you prefer something similar to what Spectre.Console does for its status indicators:

// Synchronous
AnsiConsole.Status()
    .Start("Thinking...", ctx => 
    {
        // Simulate some work
        AnsiConsole.MarkupLine("Doing some work...");
        Thread.Sleep(1000);
        
        // Update the status and spinner
        ctx.Status("Thinking some more");
        ctx.Spinner(Spinner.Known.Star);
        ctx.SpinnerStyle(Style.Parse("green"));

        // Simulate some work
        AnsiConsole.MarkupLine("Doing some more work...");
        Thread.Sleep(2000);
    });

// Asynchronous
await AnsiConsole.Status()
    .StartAsync("Thinking...", async ctx => 
    {
        // Omitted
    });

Instead of an extension method, it's more of a wrapper around the method(s) being executed? What's your feeling around using Spectre.Console for this instead of having our own implementation?

And if extinction methods on tasks are needed to give feedback to the user, it's a pretty good sign that we have some architecture issues to solve.

I'm not sure I understand what an extinction method is. Is there a problem adding an animation to status messages in the console?

@stevenkuhn stevenkuhn changed the base branch from develop to v2 December 19, 2023 17:27
@stevenkuhn stevenkuhn changed the base branch from v2 to develop December 28, 2023 16:22
@stevenkuhn
Copy link
Contributor Author

Updated my branch with the latest in develop and I removed the WithSpinner calls.

@stevenkuhn
Copy link
Contributor Author

@lamebrain If you want to test with the branch, you can run the command like this:

> dotnet run --framework net6.0 -- cloud apikey <command>

For example, to create an API key in production, it would be:

> dotnet run --framework net6.0 -- cloud api create myapikey --duration 30 --scopes command

@adrianstevens adrianstevens merged commit ee2551a into develop Jan 18, 2024
4 checks passed
@stevenkuhn stevenkuhn deleted the feature/mc-apikeys branch January 18, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants