@@ -3,33 +3,46 @@ use chrono::Utc;
33use cis_profile:: crypto:: SecretStore ;
44use cis_profile:: crypto:: Signer ;
55use cis_profile:: schema:: Display ;
6+ use cis_profile:: schema:: KeyValue ;
67use cis_profile:: schema:: Profile ;
78use cis_profile:: schema:: PublisherAuthority ;
89use cis_profile:: schema:: StandardAttributeString ;
10+ use cis_profile:: schema:: StandardAttributeValues ;
911use failure:: Error ;
1012
13+ fn create_usernames_key ( typ : & str ) -> String {
14+ format ! ( "HACK#{}" , typ)
15+ }
16+
1117pub fn update_github (
1218 github_v4_id : String ,
1319 github_v3_id : String ,
1420 github_email : Option < String > ,
21+ github_login : String ,
1522 mut profile : Profile ,
1623 store : & SecretStore ,
1724) -> Result < Profile , Error > {
1825 let now = & Utc :: now ( ) . to_rfc3339_opts ( SecondsFormat :: Secs , true ) ;
19- update_and_sign (
26+ update_and_sign_string_field (
2027 & mut profile. identities . github_id_v3 ,
2128 github_v3_id,
2229 store,
2330 & now,
2431 ) ?;
25- update_and_sign (
32+ update_and_sign_string_field (
2633 & mut profile. identities . github_id_v4 ,
2734 github_v4_id,
2835 store,
2936 & now,
3037 ) ?;
38+ update_and_sign_values_field (
39+ & mut profile. usernames ,
40+ vec ! [ ( create_usernames_key( "GITHUB" ) , github_login) ] ,
41+ store,
42+ & now,
43+ ) ?;
3144 if let Some ( email) = github_email {
32- update_and_sign (
45+ update_and_sign_string_field (
3346 & mut profile. identities . github_primary_email ,
3447 email,
3548 store,
@@ -42,26 +55,52 @@ pub fn update_github(
4255pub fn update_bugzilla (
4356 bugzilla_id : String ,
4457 bugzilla_email : String ,
58+ bugzilla_nick : Option < String > ,
4559 mut profile : Profile ,
4660 store : & SecretStore ,
4761) -> Result < Profile , Error > {
4862 let now = & Utc :: now ( ) . to_rfc3339_opts ( SecondsFormat :: Secs , true ) ;
49- update_and_sign (
63+ update_and_sign_string_field (
5064 & mut profile. identities . bugzilla_mozilla_org_id ,
5165 bugzilla_id,
5266 store,
5367 & now,
5468 ) ?;
55- update_and_sign (
69+ update_and_sign_string_field (
5670 & mut profile. identities . bugzilla_mozilla_org_primary_email ,
57- bugzilla_email,
71+ bugzilla_email. clone ( ) ,
5872 store,
5973 & now,
6074 ) ?;
75+
76+ let mut kv_pairs = vec ! [ ( create_usernames_key( "BMOMAIL" ) , bugzilla_email) ] ;
77+ if let Some ( nick) = bugzilla_nick {
78+ kv_pairs. push ( ( create_usernames_key ( "BMONICK" ) , nick) ) ;
79+ }
80+ update_and_sign_values_field ( & mut profile. usernames , kv_pairs, store, & now) ?;
6181 Ok ( profile)
6282}
6383
64- fn update_and_sign (
84+ fn update_and_sign_values_field (
85+ field : & mut StandardAttributeValues ,
86+ kv_pairs : Vec < ( String , String ) > ,
87+ store : & SecretStore ,
88+ now : & str ,
89+ ) -> Result < ( ) , Error > {
90+ if let Some ( KeyValue ( ref mut values) ) = & mut field. values {
91+ for ( k, v) in kv_pairs. into_iter ( ) {
92+ values. insert ( k, Some ( v) ) ;
93+ }
94+ }
95+ if field. metadata . display . is_none ( ) {
96+ field. metadata . display = Some ( Display :: Staff ) ;
97+ }
98+ field. metadata . last_modified = now. to_owned ( ) ;
99+ field. signature . publisher . name = PublisherAuthority :: Mozilliansorg ;
100+ store. sign_attribute ( field)
101+ }
102+
103+ fn update_and_sign_string_field (
65104 field : & mut StandardAttributeString ,
66105 value : String ,
67106 store : & SecretStore ,
0 commit comments