in core/src/services/sftp/backend.rs [147:225]
fn build(self) -> Result<impl Access> {
debug!("sftp backend build started: {:?}", &self);
let endpoint = match self.config.endpoint.clone() {
Some(v) => v,
None => return Err(Error::new(ErrorKind::ConfigInvalid, "endpoint is empty")),
};
let user = self.config.user.clone();
let root = self
.config
.root
.clone()
.map(|r| normalize_root(r.as_str()))
.unwrap_or_default();
let known_hosts_strategy = match &self.config.known_hosts_strategy {
Some(v) => {
let v = v.to_lowercase();
if v == "strict" {
KnownHosts::Strict
} else if v == "accept" {
KnownHosts::Accept
} else if v == "add" {
KnownHosts::Add
} else {
return Err(Error::new(
ErrorKind::ConfigInvalid,
format!("unknown known_hosts strategy: {}", v).as_str(),
));
}
}
None => KnownHosts::Strict,
};
let info = AccessorInfo::default();
info.set_root(root.as_str())
.set_scheme(Scheme::Sftp)
.set_native_capability(Capability {
stat: true,
stat_has_content_length: true,
stat_has_last_modified: true,
read: true,
write: true,
write_can_multi: true,
create_dir: true,
delete: true,
list: true,
list_with_limit: true,
list_has_content_length: true,
list_has_last_modified: true,
copy: self.config.enable_copy,
rename: true,
shared: true,
..Default::default()
});
let accessor_info = Arc::new(info);
let core = Arc::new(SftpCore {
info: accessor_info,
endpoint,
root,
user,
key: self.config.key.clone(),
known_hosts_strategy,
client: OnceCell::new(),
});
debug!("sftp backend finished: {:?}", &self);
Ok(SftpBackend { core })
}