grafbase_sdk/types/
authentication.rs

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