blob: 9f5a828a50488dac05559a0781ad097a83ccd54e [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
crate::manager::SshKeyManager,
anyhow::{Context, Error},
fidl_fuchsia_ssh::AuthorizedKeysRequestStream,
fuchsia_component::server::ServiceFs,
futures::prelude::*,
tracing::*,
};
mod keys;
mod manager;
enum Services {
AuthorizedKeys(AuthorizedKeysRequestStream),
}
async fn run() -> Result<(), Error> {
let mut fs = ServiceFs::new();
let manager = SshKeyManager::new("/ssh/authorized_keys")?;
fs.dir("svc").add_fidl_service(Services::AuthorizedKeys);
fs.take_and_serve_directory_handle().context("serving directory handle")?;
fs.for_each_concurrent(None, |item| match item {
Services::AuthorizedKeys(stream) => manager
.handle_requests(stream)
.unwrap_or_else(|e| error!(?e, "Failed to handle stream")),
})
.await;
Ok(())
}
#[fuchsia::main]
async fn main() {
run().await.unwrap_or_else(|e| error!(?e, "Failed to run ssh-key-manager"));
}