Skip to content

Commit

Permalink
fix(whoami): $APOLLO_KEY works with no default profile (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper authored May 6, 2021
1 parent 693fe91 commit fbdb753
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
[pull/460]: https://github.com/apollographql/rover/pull/460
[issue/444]: https://github.com/apollographql/rover/issues/444

- **Fix credential retrieval in `rover config whoami` - [EverlastingBugstopper], [issue/514] [pull/516]**

`rover config whoami` no longer fails if `$APOLLO_KEY` is set but there is no default authentication profile.

[EverlastingBugstopper]: https://github.com/EverlastingBugstopper
[pull/516]: https://github.com/apollographql/rover/pull/516
[issue/514]: https://github.com/apollographql/rover/issues/514

## 📚 Documentation

# [0.0.10] - 2021-04-27
Expand Down
2 changes: 1 addition & 1 deletion crates/houston/src/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Profile {

/// Loads and deserializes configuration from the file system for a
/// specific profile.
pub fn load(
fn load(
profile_name: &str,
config: &Config,
opts: LoadOpts,
Expand Down
4 changes: 1 addition & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ impl Rover {
}

match &self.command {
Command::Config(command) => {
command.run(self.get_rover_config()?, self.get_client_config()?)
}
Command::Config(command) => command.run(self.get_client_config()?),
Command::Supergraph(command) => command.run(self.get_client_config()?),
Command::Docs(command) => command.run(),
Command::Graph(command) => {
Expand Down
18 changes: 6 additions & 12 deletions src/command/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ mod whoami;
use serde::Serialize;
use structopt::StructOpt;

use houston as config;

use crate::command::RoverStdout;
use crate::utils::client::StudioClientConfig;
use crate::Result;
Expand Down Expand Up @@ -38,17 +36,13 @@ pub enum Command {
}

impl Config {
pub fn run(
&self,
config: config::Config,
client_config: StudioClientConfig,
) -> Result<RoverStdout> {
pub fn run(&self, client_config: StudioClientConfig) -> Result<RoverStdout> {
match &self.command {
Command::Auth(command) => command.run(config),
Command::List(command) => command.run(config),
Command::Delete(command) => command.run(config),
Command::Clear(command) => command.run(config),
Command::Whoami(command) => command.run(config, client_config),
Command::Auth(command) => command.run(client_config.config),
Command::List(command) => command.run(client_config.config),
Command::Delete(command) => command.run(client_config.config),
Command::Clear(command) => command.run(client_config.config),
Command::Whoami(command) => command.run(client_config),
}
}
}
12 changes: 4 additions & 8 deletions src/command/config/whoami.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ pub struct WhoAmI {
}

impl WhoAmI {
pub fn run(
&self,
config: config::Config,
client_config: StudioClientConfig,
) -> Result<RoverStdout> {
pub fn run(&self, client_config: StudioClientConfig) -> Result<RoverStdout> {
let client = client_config.get_client(&self.profile_name)?;
eprintln!("Checking identity of your API key against the registry.");

Expand Down Expand Up @@ -74,12 +70,12 @@ impl WhoAmI {

message.push_str(&format!("{}: {}", Green.normal().paint("Origin"), &origin));

let opts = config::LoadOpts { sensitive: true };
let profile = config::Profile::load(&self.profile_name, &config, opts)?;
let credential =
config::Profile::get_credential(&self.profile_name, &client_config.config)?;
message.push_str(&format!(
"\n{}: {}",
Green.normal().paint("API Key"),
profile
credential.api_key
));

eprintln!("{}", message);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const STUDIO_PROD_API_ENDPOINT: &str = "https://graphql.api.apollographql.com/ap

pub struct StudioClientConfig {
uri: String,
config: config::Config,
pub config: config::Config,
version: String,
}

Expand Down

0 comments on commit fbdb753

Please sign in to comment.