grafbase_sdk/types/
authentication.rs

1use crate::{types::Headers, wit};
2
3/// An HTTP endpoint exposed publicly on the Gateway. This is typically used to return metadata for authentication purposes, for example with the [OAuth 2.0 Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728) spec.
4#[non_exhaustive]
5pub struct PublicMetadataEndpoint {
6    /// The absolute path (without domain) of the endpoint. Example: "/.well-known/oauth-protected-resource".
7    path: String,
8    /// The contents of the response body that the endpoint will return. Example: '{"resource": "https://secure.example.com" }'.
9    response_body: Vec<u8>,
10    /// The headers sent from with the response by the public endpoint. Example: ["Content-Type: application/json"].
11    response_headers: Headers,
12}
13
14impl PublicMetadataEndpoint {
15    /// Constructor.
16    pub fn new(path: String, response_body: Vec<u8>) -> Self {
17        PublicMetadataEndpoint {
18            path,
19            response_body,
20            response_headers: Default::default(),
21        }
22    }
23
24    /// Set the response headers
25    pub fn with_headers(mut self, response_headers: Headers) -> Self {
26        self.response_headers = response_headers;
27        self
28    }
29
30    /// Access the response headers
31    pub fn response_headers_mut(&mut self) -> &mut Headers {
32        &mut self.response_headers
33    }
34}
35
36impl From<wit::PublicMetadataEndpoint> for PublicMetadataEndpoint {
37    fn from(
38        wit::PublicMetadataEndpoint {
39            path,
40            response_body,
41            response_headers,
42        }: wit::PublicMetadataEndpoint,
43    ) -> Self {
44        PublicMetadataEndpoint {
45            path,
46            response_body,
47            response_headers: response_headers.into(),
48        }
49    }
50}
51
52impl From<PublicMetadataEndpoint> for wit::PublicMetadataEndpoint {
53    fn from(
54        PublicMetadataEndpoint {
55            path,
56            response_body,
57            response_headers,
58        }: PublicMetadataEndpoint,
59    ) -> Self {
60        wit::PublicMetadataEndpoint {
61            path,
62            response_body,
63            response_headers: response_headers.into(),
64        }
65    }
66}