iggy-rs / iggy

Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second.
https://iggy.rs
MIT License
1.82k stars 86 forks source link

Add login / logout commands to `iggy` cli to reduce credentials related args / flags #595

Open BartoszCiesla opened 7 months ago

BartoszCiesla commented 7 months ago

Introduce similar solution to docker login / docker logout - which would allow user to use iggy command line tool without a need of putting credentials for each command. (See https://docs.docker.com/engine/reference/commandline/login/ and https://docs.docker.com/engine/reference/commandline/logout/)

melbourne2991 commented 7 months ago

Here's my thinking (happy to contribute to the below - have already started a rough draft).

It's similar to docker's login/logout concept, but closer to docker's concept of "contexts".

Keen to get your thoughts.

"Contexts"

This pattern is used in many products to minimize having to repeat arguments when interacting with a CLI, for instance:

At a high level, you have a configuration file in a known location that maps a specific “context” or “profile” identifier to a piece of configuration. This configuration is then used implicitly in CLI interactions.

CLIs will often provide additional commands for managing contexts themselves. At a minimum there will typically be a command for “setting” the active context, to allow users to switch easily between them. 

Proposed implementation

Context config

Key value pairs (context name -> config) in TOML. The config schema should (approximately) combine sdk/src/args.rs with username, password, token, token_name - with all fields optional. Absence of any field should behave as the CLI does today.

Two contexts:

# ~/.iggy/contexts.toml

[dev]
transport = "http"
username = "iggy"
password = "iggy" # Maybe not encouraged but permitted.
http_api_url = "http://localhost:3000"

[production]
transport = "tcp"
token_name = "token_ref"
tcp_server_address = "127.0.0.1:8090"
tcp_tls_enabled = "true"

To be set with:

iggy context set dev
iggy context set production

Additional considerations

How should the cli behave when contexts.toml / .active_context is undefined?

Possibly:

Should there be an "unset" command?

Initial implementation

As a first cut I would suggest:

Nice to have(s)

T1B0 commented 7 months ago

@melbourne299 aws cli use '--profile' explicitely on command, only the "default" is persisting. i think "profile" are an override applied over default (e.g. if your profile does not override say 'region', default region will be used). I don't see how context persistence would work with different cli instances running in parallel from the same user, seems tricky/footgun-ish too imo.

melbourne2991 commented 7 months ago

@melbourne299 aws cli use '--profile' explicitely on command, only the "default" is persisting. i think "profile" are an override applied over default (e.g. if your profile does not override say 'region', default region will be used).

Yes, AWS's implementation is a little different. The NATS and Docker examples are closer aligned to what is proposed.

I don't see how context persistence would work with different cli instances running in parallel from the same user, seems tricky/footgun-ish too imo.

Taking docker & nats as an example, both have a global --context flag, so you can override the context for a specific interaction.

BartoszCiesla commented 5 months ago

@melbourne2991 do you want to continue with store / save commands as discussed in #612 ?