forked from aws/aws-lambda-rust-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
96 lines (86 loc) · 3.48 KB
/
Copy pathmod.rs
File metadata and controls
96 lines (86 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::{custom_serde::serialize_headers, encodings::Base64Data, iam::IamPolicyDocument};
use http::HeaderMap;
use serde::{Deserialize, Serialize};
/// `IoTCoreCustomAuthorizerRequest` represents the request to an IoT Core custom authorizer.
/// See <https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html>
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreCustomAuthorizerRequest {
#[serde(default)]
pub token: Option<String>,
pub signature_verified: bool,
pub protocols: Vec<String>,
pub protocol_data: Option<IoTCoreProtocolData>,
pub connection_metadata: Option<IoTCoreConnectionMetadata>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreProtocolData {
pub tls: Option<IoTCoreTlsContext>,
pub http: Option<IoTCoreHttpContext>,
pub mqtt: Option<IoTCoreMqttContext>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreTlsContext {
#[serde(default)]
pub server_name: Option<String>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreHttpContext {
#[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
#[serde(serialize_with = "serialize_headers")]
pub headers: HeaderMap,
#[serde(default)]
pub query_string: Option<String>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreMqttContext {
#[serde(default)]
pub client_id: Option<String>,
pub password: Base64Data,
#[serde(default)]
pub username: Option<String>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreConnectionMetadata {
#[serde(default)]
pub id: Option<String>,
}
/// `IoTCoreCustomAuthorizerResponse` represents the response from an IoT Core custom authorizer.
/// See <https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html>
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IoTCoreCustomAuthorizerResponse {
pub is_authenticated: bool,
#[serde(default)]
pub principal_id: Option<String>,
pub disconnect_after_in_seconds: u32,
pub refresh_after_in_seconds: u32,
pub policy_documents: Vec<Option<IamPolicyDocument>>,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
#[cfg(feature = "iot")]
fn example_iot_custom_auth_request() {
let data = include_bytes!("../../fixtures/example-iot-custom-auth-request.json");
let parsed: IoTCoreCustomAuthorizerRequest = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: IoTCoreCustomAuthorizerRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "iot")]
fn example_iot_custom_auth_response() {
let data = include_bytes!("../../fixtures/example-iot-custom-auth-response.json");
let parsed: IoTCoreCustomAuthorizerResponse = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: IoTCoreCustomAuthorizerResponse = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}