Skip to main content

cc_lb_plugin_wire/v2/
on_unauthorized.rs

1//! v2 is a fork of v1 to allow additive cache-related fields. v1 is FROZEN.
2
3extern crate alloc;
4
5use alloc::string::String;
6use serde::{Deserialize, Serialize};
7
8use crate::v2::common::UpstreamErrorWire;
9use crate::wire_function::{FallbackPolicy, WireFunction};
10
11#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
12#[serde(deny_unknown_fields)]
13pub struct OnUnauthorizedRequest {
14    pub error: UpstreamErrorWire,
15    pub signer_state: serde_json::Value,
16}
17
18impl OnUnauthorizedRequest {
19    pub fn dry_run_sample() -> Self {
20        Self {
21            error: UpstreamErrorWire::dry_run_sample(),
22            signer_state: serde_json::Value::Null,
23        }
24    }
25}
26
27#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
28#[serde(deny_unknown_fields)]
29pub struct OnUnauthorizedResponse {
30    pub decision: String,
31    pub signer_state: serde_json::Value,
32}
33
34impl OnUnauthorizedResponse {
35    pub fn dry_run_sample() -> Self {
36        Self {
37            decision: String::from("fail"),
38            signer_state: serde_json::Value::Null,
39        }
40    }
41}
42
43pub struct OnUnauthorizedFn;
44
45impl WireFunction for OnUnauthorizedFn {
46    const NAME: &'static str = "on_unauthorized";
47    const FALLBACK: FallbackPolicy = FallbackPolicy::PassThrough;
48    const SUPPORTED_VERSIONS: &'static [u32] = &[1];
49
50    type Request = OnUnauthorizedRequest;
51    type Response = OnUnauthorizedResponse;
52
53    fn dry_run_request() -> Self::Request {
54        OnUnauthorizedRequest::dry_run_sample()
55    }
56
57    fn dry_run_response() -> Self::Response {
58        OnUnauthorizedResponse::dry_run_sample()
59    }
60}