[][src]Struct tenable::Tenable

pub struct Tenable<'a> {
    pub auth: String,
    pub uri: Cow<'a, str>,
}

Tenable Client which allows requests against the tenable API

Fields

auth: String

Authentication string

uri: Cow<'a, str>

Uri to send requests against

Implementations

impl<'_> Tenable<'_>[src]

#[must_use]pub fn new(access_key: &str, secret_key: &str) -> Self[src]

Creates a new Tenable client with the given credentials

Arguments

  • access_key: Tenable User Access Key
  • secret_key: Tenable User Access Key

Example

use tenable::Tenable;
let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000"
);

pub fn request<'a, O, R, CR, RE, F>(request: CR, fun: F) -> Result<O, Error<RE>> where
    CR: Into<Cow<'a, R>>,
    R: 'a + HttpRequest<RE, Output = O>,
    RE: Debug,
    F: FnOnce(Request<Vec<u8>>) -> Result<Response, Error<RE>>, 
[src]

Executes a synchronous http request using the given function

Arguments

  • request: Request to send. Use one of the functions in the requests module to create a request
  • fun: Function which implements sending synchronous requests.

Errors

Fails in the following cases:

  • Unable to create a valid Request
  • Server responded with error code
  • Unable to deserialize the server response
  • Custom Errors returned by the function given as fun parameter

Example

use std::convert::Infallible;
use tenable::{requests::AssetReq, Error, Response, Tenable};
let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request(req, |_| {
    Result::<Response, Error<Infallible>>::Ok(todo!("Define a method to send http requests"))
}).expect("Unable to list all assets");

pub fn request_with_backoff<'a, O, R, CR, RE, F, BF>(
    request: CR,
    fun: F,
    backoff_fun: BF
) -> Result<O, Error<RE>> where
    CR: Into<Cow<'a, R>>,
    R: 'a + HttpRequest<RE, Output = O>,
    RE: Debug,
    F: Fn(Request<Vec<u8>>) -> Result<Response, Error<RE>>,
    BF: Fn(Duration), 
[src]

Executes a synchronous http request using the given function. Automatically backs off when a Rate Limit is hit

Arguments

  • request: Request to send. Use one of the functions in the requests module to create a request
  • fun: Function which implements sending synchronous requests.
  • backoff_fun: Function which waits for the given Duration

Errors

Fails in the following cases:

  • Unable to create a valid Request
  • Server responded with error code
  • Unable to deserialize the server response
  • Custom Errors returned by the function given as fun parameter

Example

use std::{convert::Infallible, thread::sleep};
use tenable::{requests::AssetReq, Error, Response, Tenable};
let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request_with_backoff(req, |_| {
    Result::<Response, Error<Infallible>>::Ok(todo!("Define a method to send http requests"))
}, sleep).expect("Unable to list all assets");

pub async fn request_async<'a, O, R, CR, RE, F, Fut>(
    request: CR,
    fun: F
) -> Result<O, Error<RE>> where
    CR: Into<Cow<'a, R>>,
    R: 'a + HttpRequest<RE, Output = O>,
    RE: Debug,
    F: FnOnce(Request<Vec<u8>>) -> Fut,
    Fut: Future<Output = Result<Response, Error<RE>>>, 
[src]

Executes an asynchronous http request using the given function

Arguments

  • request: Request to send. Use one of the functions in the requests module to create a request
  • fun: Function which implements sending asynchronous requests.

Errors

Fails in the following cases:

  • Unable to create a valid Request
  • Server responded with error code
  • Unable to deserialize the server response
  • Custom Errors returned by the function given as fun parameter

Example

tokio

use http::Request;
use std::convert::Infallible;
use tenable::{requests::AssetReq, Error, Response, Tenable};
async fn request(_req: Request<Vec<u8>>) -> Result::<Response, Error<Infallible>> { Ok(todo!("Define a method to send http requests")) }

let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request_async(req, request).await
    .expect("Unable to list all assets");

async_std

use http::Request;
use std::convert::Infallible;
use tenable::{requests::AssetReq, Error, Response, Tenable};
async fn request(_req: Request<Vec<u8>>) -> Result::<Response, Error<Infallible>> { Ok(todo!("Define a method to send http requests")) }

let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request_async(req, request).await
    .expect("Unable to list all assets");

pub async fn request_with_backoff_async<'a, O, R, CR, RE, F, Fut, BF, FutBF>(
    request: CR,
    fun: F,
    backoff_fun: BF
) -> Result<O, Error<RE>> where
    CR: Into<Cow<'a, R>>,
    R: 'a + HttpRequest<RE, Output = O>,
    RE: Debug,
    F: Fn(Request<Vec<u8>>) -> Fut,
    Fut: Future<Output = Result<Response, Error<RE>>>,
    BF: Fn(Duration) -> FutBF,
    FutBF: Future<Output = ()>, 
[src]

Executes an asynchronous http request using the given function. Automatically backs off when a Rate Limit is hit

Arguments

  • request: Request to send. Use one of the functions in the requests module to create a request
  • fun: Function which implements sending asynchronous requests.
  • backoff_fun: Function which waits for the given Duration

Errors

Fails in the following cases:

  • Unable to create a valid Request
  • Server responded with error code
  • Unable to deserialize the server response
  • Custom Errors returned by the function given as fun parameter

Example

tokio

use tokio::time::delay_for;
use http::Request;
use std::convert::Infallible;
use tenable::{requests::AssetReq, Error, Response, Tenable};
async fn request(_req: Request<Vec<u8>>) -> Result::<Response, Error<Infallible>> { Ok(todo!("Define a method to send http requests")) }

let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request_with_backoff_async(req, request, delay_for).await
    .expect("Unable to list all assets");

async_std

use async_std::task;
use http::Request;
use std::convert::Infallible;
use tenable::{requests::AssetReq, Error, Response, Tenable};
async fn request(_req: Request<Vec<u8>>) -> Result::<Response, Error<Infallible>> { Ok(todo!("Define a method to send http requests")) }

let tenable = Tenable::new(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "0000000000000000000000000000000000000000000000000000000000000000",
);
let req = tenable.assets();
let _assets = Tenable::request_with_backoff_async(req, request, task::sleep).await
    .expect("Unable to list all assets");

Trait Implementations

impl<'_> AssetReq for Tenable<'_>[src]

impl<'a> Clone for Tenable<'a>[src]

impl<'a> Debug for Tenable<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Tenable<'a>

impl<'a> Send for Tenable<'a>

impl<'a> Sync for Tenable<'a>

impl<'a> Unpin for Tenable<'a>

impl<'a> UnwindSafe for Tenable<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.