-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* provider init Signed-off-by: Lee Benson <[email protected]> * http wip Signed-off-by: Lee Benson <[email protected]> * Update validation.rs * wip Signed-off-by: Lee Benson <[email protected]> * wip * wip * wip Signed-off-by: Lee Benson <[email protected]> * sources finished Signed-off-by: Lee Benson <[email protected]> * provider reload Signed-off-by: Lee Benson <[email protected]> * commentary Signed-off-by: Lee Benson <[email protected]> * reload event Signed-off-by: Lee Benson <[email protected]> * polling Signed-off-by: Lee Benson <[email protected]> * logs * compile Signed-off-by: Lee Benson <[email protected]> * fix error Signed-off-by: Lee Benson <[email protected]> * clippy Signed-off-by: Lee Benson <[email protected]> * more comments Signed-off-by: Lee Benson <[email protected]> * Update Cargo.lock * fix url serde Signed-off-by: Lee Benson <[email protected]> * fix event messages Signed-off-by: Lee Benson <[email protected]> * fix default features Signed-off-by: Lee Benson <[email protected]> * receiverstream Signed-off-by: Lee Benson <[email protected]> * providerS Signed-off-by: Lee Benson <[email protected]> * feature Signed-off-by: Lee Benson <[email protected]> * fix windows signals Signed-off-by: Lee Benson <[email protected]> * remove providers feature Signed-off-by: Lee Benson <[email protected]> * wip * provider refactor Signed-off-by: Lee Benson <[email protected]> * shutdown Signed-off-by: Lee Benson <[email protected]> * broadcast Signed-off-by: Lee Benson <[email protected]> * remove control Signed-off-by: Lee Benson <[email protected]> * tweaks Signed-off-by: Lee Benson <[email protected]> * -option Signed-off-by: Lee Benson <[email protected]> * comment cleanup Signed-off-by: Lee Benson <[email protected]> * fix merge Signed-off-by: Lee Benson <[email protected]> * wip * Revert "wip" This reverts commit b62d9ec. * configbuilder Signed-off-by: Lee Benson <[email protected]> * signal_rx Signed-off-by: Lee Benson <[email protected]> * bytes Signed-off-by: Lee Benson <[email protected]> * signal handling Signed-off-by: Lee Benson <[email protected]>
- Loading branch information
Showing
12 changed files
with
489 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use super::{component::ExampleError, GenerateConfig}; | ||
use crate::{providers, signal}; | ||
use async_trait::async_trait; | ||
use toml::Value; | ||
|
||
#[async_trait] | ||
#[typetag::serde(tag = "type")] | ||
pub trait ProviderConfig: core::fmt::Debug + Send + Sync + dyn_clone::DynClone { | ||
/// Builds a provider, returning a string containing the config. It's passed a signals | ||
/// channel to control reloading and shutdown, as applicable. | ||
async fn build(&mut self, signal_handler: &mut signal::SignalHandler) -> providers::Result; | ||
fn provider_type(&self) -> &'static str; | ||
} | ||
|
||
dyn_clone::clone_trait_object!(ProviderConfig); | ||
|
||
/// Describes a provider plugin storing its type name and an optional example config. | ||
pub struct ProviderDescription { | ||
pub type_str: &'static str, | ||
example_value: fn() -> Option<Value>, | ||
} | ||
|
||
impl ProviderDescription | ||
where | ||
inventory::iter<ProviderDescription>: | ||
std::iter::IntoIterator<Item = &'static ProviderDescription>, | ||
{ | ||
/// Creates a new provider plugin description. | ||
/// Configuration example is generated by the `GenerateConfig` trait. | ||
pub fn new<B: GenerateConfig>(type_str: &'static str) -> Self { | ||
Self { | ||
type_str, | ||
example_value: || Some(B::generate_config()), | ||
} | ||
} | ||
|
||
/// Returns an example config for a plugin identified by its type. | ||
pub fn example(type_str: &str) -> Result<Value, ExampleError> { | ||
inventory::iter::<ProviderDescription> | ||
.into_iter() | ||
.find(|t| t.type_str == type_str) | ||
.ok_or_else(|| ExampleError::DoesNotExist { | ||
type_str: type_str.to_owned(), | ||
}) | ||
.and_then(|t| (t.example_value)().ok_or(ExampleError::MissingExample)) | ||
} | ||
} | ||
|
||
inventory::collect!(ProviderDescription); |
Oops, something went wrong.