witchcraft_server/
extensions.rs

1// Copyright 2022 Palantir Technologies, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Types used with the extensions maps of requests or responses in a Witchcraft server.
16
17use std::net::SocketAddr;
18use std::ops::Deref;
19
20use crate::logging::api::objects::AuditLogV3;
21
22/// An extension containing the peer's socket address.
23///
24/// It will be present in the extensions of every request.
25#[derive(Copy, Clone)]
26pub struct PeerAddr(pub SocketAddr);
27
28impl Deref for PeerAddr {
29    type Target = SocketAddr;
30
31    #[inline]
32    fn deref(&self) -> &SocketAddr {
33        &self.0
34    }
35}
36
37/// An extension containing an audit log entry for a request.
38///
39/// If this is present in the response extensions of a request, it will be written to the audit log before the server
40/// sends the response to the client. An error logging the entry will cause the request to fail.
41#[derive(Clone)]
42pub struct AuditLogEntry(pub(crate) AuditLogV3);
43
44impl AuditLogEntry {
45    /// Creates a new `AuditLogEntry` containing a v3 audit log.
46    #[inline]
47    pub fn v3(entry: AuditLogV3) -> Self {
48        AuditLogEntry(entry)
49    }
50}