1
1
use crate :: blocking:: StudioClient ;
2
2
use crate :: RoverClientError ;
3
+ use houston:: CredentialOrigin ;
4
+
3
5
use graphql_client:: * ;
4
6
5
7
#[ derive( GraphQLQuery ) ]
@@ -21,6 +23,7 @@ pub struct RegistryIdentity {
21
23
pub id : String ,
22
24
pub graph_title : Option < String > ,
23
25
pub key_actor_type : Actor ,
26
+ pub credential_origin : CredentialOrigin ,
24
27
}
25
28
26
29
#[ derive( Debug , PartialEq ) ]
@@ -37,11 +40,12 @@ pub fn run(
37
40
client : & StudioClient ,
38
41
) -> Result < RegistryIdentity , RoverClientError > {
39
42
let response_data = client. post :: < WhoAmIQuery > ( variables) ?;
40
- get_identity_from_response_data ( response_data)
43
+ get_identity_from_response_data ( response_data, client . credential . origin . clone ( ) )
41
44
}
42
45
43
46
fn get_identity_from_response_data (
44
47
response_data : who_am_i_query:: ResponseData ,
48
+ credential_origin : CredentialOrigin ,
45
49
) -> Result < RegistryIdentity , RoverClientError > {
46
50
if let Some ( me) = response_data. me {
47
51
// I believe for the purposes of the CLI, we only care about users and
@@ -64,6 +68,7 @@ fn get_identity_from_response_data(
64
68
id : me. id ,
65
69
graph_title,
66
70
key_actor_type,
71
+ credential_origin,
67
72
} )
68
73
} else {
69
74
Err ( RoverClientError :: InvalidKey )
@@ -87,12 +92,13 @@ mod tests {
87
92
}
88
93
} ) ;
89
94
let data: who_am_i_query:: ResponseData = serde_json:: from_value ( json_response) . unwrap ( ) ;
90
- let output = get_identity_from_response_data ( data) ;
95
+ let output = get_identity_from_response_data ( data, CredentialOrigin :: EnvVar ) ;
91
96
92
97
let expected_identity = RegistryIdentity {
93
98
id : "gh.nobodydefinitelyhasthisusernamelol" . to_string ( ) ,
94
99
graph_title : None ,
95
100
key_actor_type : Actor :: USER ,
101
+ credential_origin : CredentialOrigin :: EnvVar ,
96
102
} ;
97
103
assert ! ( output. is_ok( ) ) ;
98
104
assert_eq ! ( output. unwrap( ) , expected_identity) ;
@@ -111,12 +117,13 @@ mod tests {
111
117
}
112
118
} ) ;
113
119
let data: who_am_i_query:: ResponseData = serde_json:: from_value ( json_response) . unwrap ( ) ;
114
- let output = get_identity_from_response_data ( data) ;
120
+ let output = get_identity_from_response_data ( data, CredentialOrigin :: EnvVar ) ;
115
121
116
122
let expected_identity = RegistryIdentity {
117
123
id : "big-ol-graph-key-lolol" . to_string ( ) ,
118
124
graph_title : Some ( "GraphKeyService" . to_string ( ) ) ,
119
125
key_actor_type : Actor :: GRAPH ,
126
+ credential_origin : CredentialOrigin :: EnvVar ,
120
127
} ;
121
128
assert ! ( output. is_ok( ) ) ;
122
129
assert_eq ! ( output. unwrap( ) , expected_identity) ;
0 commit comments