Skip to content

Commit

Permalink
feat(rover): output service title for whoami
Browse files Browse the repository at this point in the history
In our discussions we found that Name was not a useful piece of
information to show to Rover's users. Instead, this commit introduces
a Service title which is aligned with the information that Studio
displays for a user.
  • Loading branch information
lrlna committed Feb 22, 2021
1 parent ec435a5 commit fcfbc30
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 306 deletions.
4 changes: 3 additions & 1 deletion crates/rover-client/src/query/config/whoami.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
query WhoAmIQuery {
me {
__typename
name
... on Service {
title
}
id
asActor {
type
Expand Down
19 changes: 13 additions & 6 deletions crates/rover-client/src/query/config/whoami.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct WhoAmIQuery;

#[derive(Debug, PartialEq)]
pub struct RegistryIdentity {
pub name: String,
pub id: String,
pub service_title: String,
pub key_actor_type: Actor,
}

Expand Down Expand Up @@ -48,14 +48,21 @@ fn get_identity_from_response_data(
// graphs as api key actors, since that's all we _should_ get.
// I think it's safe to only include those two kinds of actors in the enum
// more here: https://studio-staging.apollographql.com/graph/engine/schema/reference/enums/ActorType?variant=prod

let key_actor_type = match me.as_actor.type_ {
who_am_i_query::ActorType::GRAPH => Actor::GRAPH,
who_am_i_query::ActorType::USER => Actor::USER,
_ => Actor::OTHER,
};

let title = match me.on {
who_am_i_query::WhoAmIQueryMeOn::Service(s) => s.title,
_ => "No Title".to_string(),
};

Ok(RegistryIdentity {
id: me.id,
name: me.name,
service_title: title,
key_actor_type,
})
} else {
Expand All @@ -72,7 +79,7 @@ mod tests {
let json_response = json!({
"me": {
"__typename": "User",
"name": "Yaboi",
"title": "SearchForTunaService",
"id": "gh.nobodydefinitelyhasthisusernamelol",
"asActor": {
"type": "USER"
Expand All @@ -83,8 +90,8 @@ mod tests {
let output = get_identity_from_response_data(data);

let expected_identity = RegistryIdentity {
name: "Yaboi".to_string(),
id: "gh.nobodydefinitelyhasthisusernamelol".to_string(),
service_title: "SearchForTunaService".to_string(),
key_actor_type: Actor::USER,
};
assert!(output.is_ok());
Expand All @@ -96,7 +103,7 @@ mod tests {
let json_response = json!({
"me": {
"__typename": "Service",
"name": "big-ol-graph",
"title": "GraphKeyService",
"id": "big-ol-graph-key-lolol",
"asActor": {
"type": "GRAPH"
Expand All @@ -107,8 +114,8 @@ mod tests {
let output = get_identity_from_response_data(data);

let expected_identity = RegistryIdentity {
name: "big-ol-graph".to_string(),
id: "big-ol-graph-key-lolol".to_string(),
service_title: "GraphKeyService".to_string(),
key_actor_type: Actor::GRAPH,
};
assert!(output.is_ok());
Expand Down
298 changes: 1 addition & 297 deletions installers/npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/command/config/whoami.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl WhoAmI {
let identity = whoami::run(whoami::who_am_i_query::Variables {}, &client)?;

tracing::info!(
"Key Info:\n- Name: {}\n- ID: {}\n- Key Type: {:?}",
identity.name,
"Key Info:\n- Service Title: {}\n- ID: {}\n- Key Type: {:?}",
identity.service_title,
identity.id,
identity.key_actor_type
);
Expand Down

0 comments on commit fcfbc30

Please sign in to comment.