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

feat(rover): config api-key -> config profile auth #114

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions docs/source/usage/config/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ description: "Linking Rover to Apollo Studio with an API Key"


```
rover-config-api-key
🔑 Configure an account or graph API key
rover-config-profile-auth
🔑 Set a configuration profile's Apollo Studio API key

USAGE:
rover config api-key [OPTIONS]
rover config profile auth [OPTIONS]

FLAGS:
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
-l, --log <log-level> [default: debug] [possible values: error, warn, info,
debug, trace]
--profile <profile-name> [default: default]
```

Expand All @@ -43,30 +45,30 @@ a previously run `auth` command set.**
## Commands

```
rover config api-key [--profile <name>]
[INFO] Go to https://studio.apollographql.com/user-settings and create a new Personal API Key.
[INFO] Copy the key and paste it into the prompt below.
rover config profile auth [--profile <name>]
INFO Go to https://studio.apollographql.com/user-settings and create a new Personal API Key.
INFO Copy the key and paste it into the prompt below.

```

The `config api-key` command in the `rover` CLI will let you specify your API key
The `config profile auth` command lets you specify your API key
via an interactive command.

The `auth api-key` command is interactive to prevent API keys from being
By default, the command is interactive to prevent API keys from being
retained in terminal history.

We don't recommend using this method in automation or CI; We'd recommend using
environment variables (below).

`rover config` takes an optional `--profile` flag which takes a single argument
`rover config profile` commands all take an optional `--profile` flag which takes a single argument
representing the name of a profile. Profiles are how you can store and manage
different collections of settings and keys. For more information, read [Profiles].

[Profiles]: ../profiles.html

### Configuration

`rover` will store your api-key in a configuration file on your machine, and
`rover` will store your API Key in a configuration file on your machine, and
use it when making requests. By default, your configuration will be stored in
your operating system's default config dir, in a file called `.sensitive`.

Expand Down
16 changes: 9 additions & 7 deletions docs/source/usage/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ description: "Summary of all top-level config commands in Rover"

```
rover-config
🔐 Manage configuraiton
⚙️ Rover configuration

USAGE:
rover config <SUBCOMMAND>
rover config [OPTIONS] <SUBCOMMAND>

FLAGS:
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
-l, --log <log-level> [default: debug] [possible values: error, warn, info,
debug, trace]

SUBCOMMANDS:
api-key 🔑 Configure an account or graph API key
clear 🚮 Remove all configuration
clear 🗑 Clear ALL configuration
help Prints this message or the help of the given subcommand(s)
profile 💁 Operations for listing, viewing, and deleting configuration profiles
profile 👤 Manage configuration profiles
```

The `rover config` command allows you to set and manage configuration.

- `rover config api-key` will allow you to authenticate using an Apollo API key
- `rover config profile` will allow you to manage sets of configuration
- The `rover config profile` suite will allow you to manage sets of configuration
- `rover config clear` will allow you to remove all configuration related to the `rover` CLI
15 changes: 10 additions & 5 deletions docs/source/usage/config/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ description: "Setting and managing up configuration profiles for rover"

```
rover-config-profile
💁 Operations for listing, viewing, and deleting configuration profiles
👤 Manage configuration profiles

USAGE:
rover config profile <SUBCOMMAND>
rover config profile [OPTIONS] <SUBCOMMAND>

FLAGS:
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
-l, --log <log-level> [default: debug] [possible values: error, warn, info,
debug, trace]

SUBCOMMANDS:
delete 🪓 Delete a specific profile
auth 🔑 Set a configuration profile's Apollo Studio API key
delete 🗑 Delete a configuration profile
help Prints this message or the help of the given subcommand(s)
list 🎅 List all of your configuration profiles
view 👀 See a specific profile's values
list 👥 List all configuration profiles
show 👤 View a configuration profile's details
```

As your growth of `rover` grows, you may want to setup multiple sets of
Expand Down
15 changes: 11 additions & 4 deletions src/command/config/clear.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use anyhow::{Context, Result};
use serde::Serialize;
use structopt::StructOpt;

use crate::command::RoverStdout;
use houston as config;

pub fn run() -> Result<RoverStdout> {
config::clear().context("Failed to clear profiles")?;
tracing::info!("Successfully cleared all configuration.");
Ok(RoverStdout::None)
#[derive(Debug, Serialize, StructOpt)]
pub struct Clear {}

impl Clear {
pub fn run(&self) -> Result<RoverStdout> {
config::clear().context("Failed to clear profiles")?;
tracing::info!("Successfully cleared all configuration.");
Ok(RoverStdout::None)
}
}
9 changes: 3 additions & 6 deletions src/command/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod api_key;
mod clear;
mod profile;

Expand All @@ -16,20 +15,18 @@ pub struct Config {

#[derive(Debug, Serialize, StructOpt)]
pub enum Command {
/// Set an Apollo Studio API key
ApiKey(api_key::ApiKey),
/// Manage configuration profiles
Profile(profile::Profile),

/// Clear ALL configuration
Clear,
Clear(clear::Clear),
}

impl Config {
pub fn run(&self) -> Result<RoverStdout> {
match &self.command {
Command::ApiKey(command) => command.run(),
Command::Profile(command) => command.run(),
Command::Clear => clear::run(),
Command::Clear(command) => command.run(),
}
}
}
83 changes: 0 additions & 83 deletions src/command/config/profile.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use houston as config;
use crate::command::RoverStdout;

#[derive(Debug, Serialize, StructOpt)]
pub struct ApiKey {
pub struct Auth {
#[structopt(long = "profile", default_value = "default")]
#[serde(skip_serializing)]
profile_name: String,
}

impl ApiKey {
impl Auth {
pub fn run(&self) -> Result<RoverStdout> {
let api_key = api_key_prompt().context("Failed to read API key from terminal")?;
Profile::set_api_key(&self.profile_name, &api_key)
Expand Down
21 changes: 21 additions & 0 deletions src/command/config/profile/delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use anyhow::{Context, Result};
use serde::Serialize;
use structopt::StructOpt;

use houston as config;

use crate::command::RoverStdout;

#[derive(Debug, Serialize, StructOpt)]
pub struct Delete {
#[serde(skip_serializing)]
name: String,
}

impl Delete {
pub fn run(&self) -> Result<RoverStdout> {
config::Profile::delete(&self.name).context("Could not delete profile.")?;
tracing::info!("Successfully deleted profile \"{}\"", &self.name);
Ok(RoverStdout::None)
}
}
25 changes: 25 additions & 0 deletions src/command/config/profile/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anyhow::{Context, Result};
use serde::Serialize;
use structopt::StructOpt;

use houston as config;

use crate::command::RoverStdout;

#[derive(Serialize, Debug, StructOpt)]
pub struct List {}

impl List {
pub fn run(&self) -> Result<RoverStdout> {
let profiles = config::Profile::list().context("Could not list profiles.")?;
if profiles.is_empty() {
tracing::info!("No profiles found.")
} else {
tracing::info!("Profiles:");
for profile in profiles {
tracing::info!("{}", profile);
}
}
Ok(RoverStdout::None)
}
}
42 changes: 42 additions & 0 deletions src/command/config/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mod auth;
mod delete;
mod list;
mod show;

use anyhow::Result;
use serde::Serialize;
use structopt::StructOpt;

use crate::command::RoverStdout;

#[derive(Debug, Serialize, StructOpt)]
pub struct Profile {
#[structopt(subcommand)]
command: Command,
}

impl Profile {
pub fn run(&self) -> Result<RoverStdout> {
match &self.command {
Command::Auth(command) => command.run(),
Command::List(command) => command.run(),
Command::Show(command) => command.run(),
Command::Delete(command) => command.run(),
}
}
}

#[derive(Debug, Serialize, StructOpt)]
pub enum Command {
/// 🔑 Set a configuration profile's Apollo Studio API key
Auth(auth::Auth),

/// 👥 List all configuration profiles
List(list::List),

/// 👤 View a configuration profile's details
Show(show::Show),

/// 🗑 Delete a configuration profile
Delete(delete::Delete),
}
Loading