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): output service title for whoami #299

Merged
merged 9 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to have No Title as something else, if that doesn't sound suitable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt we'll see this case often (if ever?), but regardless, I think this is fine :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what's going on here. It's printing service title regardless of whether it's a service key or not. I think I'm going to push a commit changing that, feel free to reject it or push back tomorrow :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yea this new commit you pushed works well. Merging the PR in.

};

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: "No Title".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