@@ -55,6 +55,7 @@ pub(super) struct RegistryCrate {
5555 registry : Registry ,
5656 name : String ,
5757 version : String ,
58+ key : Option < String > ,
5859}
5960
6061#[ derive( serde:: Deserialize ) ]
@@ -63,11 +64,12 @@ struct IndexConfig {
6364}
6465
6566impl RegistryCrate {
66- pub ( super ) fn new ( registry : Registry , name : & str , version : & str ) -> Self {
67+ pub ( super ) fn new ( registry : Registry , name : & str , version : & str , key : Option < String > ) -> Self {
6768 RegistryCrate {
6869 registry,
6970 name : name. into ( ) ,
7071 version : version. into ( ) ,
72+ key : key. map ( Into :: into) ,
7173 }
7274 }
7375
@@ -92,7 +94,27 @@ impl RegistryCrate {
9294 . join ( alt. index_folder ( ) ) ;
9395 if !index_path. exists ( ) {
9496 let url = alt. index ( ) ;
95- git2:: Repository :: clone ( url, index_path. clone ( ) )
97+ let mut fo = git2:: FetchOptions :: new ( ) ;
98+ if let Some ( key) = self . key . as_deref ( ) {
99+ fo. remote_callbacks ( {
100+ let mut callbacks = git2:: RemoteCallbacks :: new ( ) ;
101+ callbacks. credentials (
102+ move |_url, username_from_url, _allowed_types| {
103+ git2:: Cred :: ssh_key_from_memory (
104+ username_from_url. unwrap ( ) ,
105+ None ,
106+ key,
107+ None ,
108+ )
109+ } ,
110+ ) ;
111+ callbacks
112+ } ) ;
113+ }
114+
115+ git2:: build:: RepoBuilder :: new ( )
116+ . fetch_options ( fo)
117+ . clone ( url, & index_path)
96118 . with_context ( |_| format ! ( "unable to update_index at {}" , url) ) ?;
97119 info ! ( "cloned registry index" ) ;
98120 }
0 commit comments