Struct SecuritySchemeBuilder

Source
pub struct SecuritySchemeBuilder<S> { /* private fields */ }
Expand description

Builder for the Security Scheme

Implementations§

Source§

impl SecuritySchemeBuilder<()>

Source

pub fn no_sec(self) -> SecuritySchemeBuilder<SecuritySchemeNoSecTag>

Default no-security scheme

Source

pub fn auto(self) -> SecuritySchemeBuilder<SecuritySchemeAutoTag>

Auto security scheme

Source

pub fn combo(self) -> SecuritySchemeBuilder<EmptyComboSecuritySchemeTag>

Combo security scheme

Source

pub fn basic(self) -> SecuritySchemeBuilder<BasicSecurityScheme>

Basic Authentication RFC7617

Source

pub fn digest(self) -> SecuritySchemeBuilder<DigestSecurityScheme>

Digest Assess Authentication RFC7616

Source

pub fn bearer(self) -> SecuritySchemeBuilder<BearerSecurityScheme>

Bearer Token RFC6750

Source

pub fn psk(self) -> SecuritySchemeBuilder<PskSecurityScheme>

Pre-shared key authentication

Source

pub fn oauth2( self, flow: impl Into<String>, ) -> SecuritySchemeBuilder<OAuth2SecurityScheme>

OAuth2 authentication RFC6749 and RFC8252

Source

pub fn apikey(self) -> SecuritySchemeBuilder<ApiKeySecurityScheme>

API key authentication

Source

pub fn custom( self, scheme: impl Into<String>, ) -> SecuritySchemeBuilder<UnknownSecuritySchemeSubtype>

Security scheme defined by an additional Vocabulary

NOTE: Its definition MUST be in the Thing @context.

Source§

impl<T> SecuritySchemeBuilder<T>

Source

pub fn description(self, value: impl Into<String>) -> SecuritySchemeBuilder<T>

Sets the value of the description field.

Source

pub fn proxy(self, value: impl Into<String>) -> SecuritySchemeBuilder<T>

Sets the value of the proxy field.

Source

pub fn attype(self, ty: impl Into<String>) -> SecuritySchemeBuilder<T>

JSON-LD @type

Source

pub fn descriptions<F>(self, f: F) -> SecuritySchemeBuilder<T>

Multi-language descriptions

See ThingBuilder::titles for examples.

Source

pub fn with_key(self, name: impl Into<String>) -> SecuritySchemeBuilder<T>

Sets the key to be used for referring to the security scheme in the Thing::security and Form::security fields.

Source

pub fn required(self) -> SecuritySchemeBuilder<T>

Makes the security scheme required.

Source§

impl<T> SecuritySchemeBuilder<T>
where T: HasNameLocation,

Source

pub fn name(self, value: impl Into<String>) -> SecuritySchemeBuilder<T>

Name for query, header or cookie parameter

Source

pub fn location( self, value: SecurityAuthenticationLocation, ) -> SecuritySchemeBuilder<T>

Location of the security authentication information

Source§

impl SecuritySchemeBuilder<EmptyComboSecuritySchemeTag>

Source

pub fn all_of<I, T>( self, iter: I, ) -> SecuritySchemeBuilder<(AllOfComboSecuritySchemeTag, Vec<String>)>
where I: IntoIterator<Item = T>, T: Into<String>,

Require all the specified schema definitions for the security combo.

§Examples
let thing = Thing::builder("Thing name")
    .finish_extend()
    .security(|builder| builder.combo().all_of(["basic", "nosec"]))
    .security(|builder| builder.basic())
    .security(|builder| builder.no_sec())
    .build()
    .unwrap();

assert_eq!(
    serde_json::to_value(thing).unwrap(),
    json!({
        "title": "Thing name",
        "@context": "https://www.w3.org/2022/wot/td/v1.1",
        "security": [],
        "securityDefinitions": {
            "combo": {
                "scheme": "combo",
                "allOf": ["basic", "nosec"],
            },
            "basic": {
                "scheme": "basic",
                "in": "header",
            },
            "nosec": {
                "scheme": "nosec",
            },
        },
    })
);

If one the security identifier specified in .all_of does not exist across other security definitions, Thing::build returns an error:

let error = Thing::builder("Thing name")
    .finish_extend()
    .security(|builder| builder.combo().all_of(["basic", "nosec"]))
    .security(|builder| builder.no_sec())
    .build()
    .unwrap_err();

assert_eq!(error, Error::MissingSchemaDefinition("basic".to_string()));
Source

pub fn one_of<I, T>( self, iter: I, ) -> SecuritySchemeBuilder<(OneOfComboSecuritySchemeTag, Vec<String>)>
where I: IntoIterator<Item = T>, T: Into<String>,

Require one of the specified schema definitions for the security combo.

§Examples
let thing = Thing::builder("Thing name")
    .finish_extend()
    .security(|builder| builder.combo().one_of(["basic", "nosec"]))
    .security(|builder| builder.basic())
    .security(|builder| builder.no_sec())
    .build()
    .unwrap();

assert_eq!(
    serde_json::to_value(thing).unwrap(),
    json!({
        "title": "Thing name",
        "@context": "https://www.w3.org/2022/wot/td/v1.1",
        "security": [],
        "securityDefinitions": {
            "combo": {
                "scheme": "combo",
                "oneOf": ["basic", "nosec"],
            },
            "basic": {
                "scheme": "basic",
                "in": "header",
            },
            "nosec": {
                "scheme": "nosec",
            },
        },
    })
);

If one the security identifier specified in .one_of does not exist across other security definitions, Thing::build returns an error:

let error = Thing::builder("Thing name")
    .finish_extend()
    .security(|builder| builder.combo().one_of(["basic", "nosec"]))
    .security(|builder| builder.no_sec())
    .build()
    .unwrap_err();

assert_eq!(error, Error::MissingSchemaDefinition("basic".to_string()));
Source

pub fn name( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<EmptyComboSecuritySchemeTag>

Name for query, header or cookie parameter

Source§

impl<T> SecuritySchemeBuilder<(T, Vec<String>)>

Source

pub fn extend<I, U>(self, iter: I) -> SecuritySchemeBuilder<(T, Vec<String>)>
where I: IntoIterator<Item = U>, U: Into<String>,

Extends the security scheme subtype with a variable amount of items.

This is useful for combo security schemes, which require a set of names as references.

Source

pub fn push( self, security_name: impl Into<String>, ) -> SecuritySchemeBuilder<(T, Vec<String>)>

Extends the security scheme subtype with an items.

This is useful for combo security schemes, which require a set of names as references.

Source

pub fn name( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<(T, Vec<String>)>

Name for query, header or cookie parameter

Source§

impl SecuritySchemeBuilder<DigestSecurityScheme>

Source

pub fn qop( self, value: QualityOfProtection, ) -> SecuritySchemeBuilder<DigestSecurityScheme>

Quality of protection

Source§

impl SecuritySchemeBuilder<BearerSecurityScheme>

Source

pub fn authorization( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<BearerSecurityScheme>

URI of the authorization server

Source

pub fn alg( self, value: impl Into<Cow<'static, str>>, ) -> SecuritySchemeBuilder<BearerSecurityScheme>

Encoding, encryption or digest algorithm

Source

pub fn format( self, value: impl Into<Cow<'static, str>>, ) -> SecuritySchemeBuilder<BearerSecurityScheme>

Format of the security authentication information

Source§

impl SecuritySchemeBuilder<OAuth2SecurityScheme>

Source

pub fn authorization( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<OAuth2SecurityScheme>

URI of the authorization server

Source

pub fn token( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<OAuth2SecurityScheme>

URI of the token server

Source

pub fn refresh( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<OAuth2SecurityScheme>

URI of the refresh server

Source

pub fn scope( self, value: impl Into<String>, ) -> SecuritySchemeBuilder<OAuth2SecurityScheme>

Authorization scope identifier

Source§

impl SecuritySchemeBuilder<UnknownSecuritySchemeSubtype>

Source

pub fn data( self, value: impl Into<Value>, ) -> SecuritySchemeBuilder<UnknownSecuritySchemeSubtype>

JSON Value to be merged into the Scheme

Auto Trait Implementations§

§

impl<S> Freeze for SecuritySchemeBuilder<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for SecuritySchemeBuilder<S>
where S: RefUnwindSafe,

§

impl<S> Send for SecuritySchemeBuilder<S>
where S: Send,

§

impl<S> Sync for SecuritySchemeBuilder<S>
where S: Sync,

§

impl<S> Unpin for SecuritySchemeBuilder<S>
where S: Unpin,

§

impl<S> UnwindSafe for SecuritySchemeBuilder<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more