1
- use std:: collections:: HashMap ;
1
+ use std:: collections:: { HashMap , HashSet } ;
2
2
use std:: future:: Future ;
3
3
use std:: pin:: Pin ;
4
4
use std:: sync:: { Arc , Mutex } ;
@@ -24,11 +24,12 @@ use crate::encore::parser::meta::v1::{self as meta, selector};
24
24
use crate :: log:: LogFromRust ;
25
25
use crate :: model:: StreamDirection ;
26
26
use crate :: names:: EndpointName ;
27
- use crate :: trace;
28
27
use crate :: { model, Hosted } ;
28
+ use crate :: { trace, EncoreName } ;
29
29
30
30
use super :: pvalue:: { PValue , PValues } ;
31
31
use super :: reqauth:: caller:: Caller ;
32
+ use super :: reqauth:: platform:: ValidationData ;
32
33
33
34
#[ derive( Debug ) ]
34
35
pub struct SuccessResponse {
@@ -162,8 +163,8 @@ pub struct Endpoint {
162
163
/// Whether this is a raw endpoint.
163
164
pub raw : bool ,
164
165
165
- /// Whether the service is exposed publicly .
166
- pub exposed : bool ,
166
+ /// Which gateways this endpoint is exposed through .
167
+ pub exposed : HashSet < EncoreName > ,
167
168
168
169
/// Whether the service requires authentication data.
169
170
pub requires_auth : bool ,
@@ -331,8 +332,8 @@ pub fn endpoints_from_meta(
331
332
}
332
333
let resp_schema = ep. response_schema . build ( & registry) ?;
333
334
334
- // We only support a single gateway right now.
335
- let exposed = ep . ep . expose . contains_key ( "api-gateway" ) ;
335
+ let exposed = ep . ep . expose . keys ( ) . map ( |gw_name| gw_name . into ( ) ) . collect ( ) ;
336
+
336
337
let raw =
337
338
rpc:: Protocol :: try_from ( ep. ep . proto ) . is_ok_and ( |proto| proto == rpc:: Protocol :: Raw ) ;
338
339
@@ -444,11 +445,7 @@ impl EndpointHandler {
444
445
. into_parts ( ) ;
445
446
446
447
// Authenticate the request from the platform, if applicable.
447
- #[ allow( clippy:: manual_unwrap_or_default) ]
448
- let platform_seal_of_approval = match self . authenticate_platform ( & parts) {
449
- Ok ( seal) => seal,
450
- Err ( _err) => None ,
451
- } ;
448
+ let platform_seal_of_approval = self . authenticate_platform ( & parts) . ok ( ) ;
452
449
453
450
let meta = CallMeta :: parse_with_caller (
454
451
& self . shared . inbound_svc_auth ,
@@ -546,8 +543,13 @@ impl EndpointHandler {
546
543
547
544
let internal_caller = request. internal_caller . clone ( ) ;
548
545
546
+ // check if this endpoint is exposed by the calling gateway
547
+ let exposed = internal_caller. as_ref ( ) . is_some_and ( |caller| {
548
+ matches ! ( caller, Caller :: Gateway { gateway } if self . endpoint. exposed. contains( gateway) )
549
+ } ) ;
550
+
549
551
// If the endpoint isn't exposed, return a 404.
550
- if !self . endpoint . exposed && !request. allows_private_endpoint_call ( ) {
552
+ if !exposed && !request. allows_private_endpoint_call ( ) {
551
553
return Error {
552
554
code : ErrCode :: NotFound ,
553
555
message : "endpoint not found" . into ( ) ,
@@ -662,32 +664,9 @@ impl EndpointHandler {
662
664
fn authenticate_platform (
663
665
& self ,
664
666
req : & axum:: http:: request:: Parts ,
665
- ) -> Result < Option < platform:: SealOfApproval > , platform:: ValidationError > {
666
- let Some ( x_encore_auth_header) = req. headers . get ( "x-encore-auth" ) else {
667
- return Ok ( None ) ;
668
- } ;
669
- let x_encore_auth_header = x_encore_auth_header
670
- . to_str ( )
671
- . map_err ( |_| platform:: ValidationError :: InvalidMac ) ?;
672
-
673
- let Some ( date_header) = req. headers . get ( "Date" ) else {
674
- return Err ( platform:: ValidationError :: InvalidDateHeader ) ;
675
- } ;
676
- let date_header = date_header
677
- . to_str ( )
678
- . map_err ( |_| platform:: ValidationError :: InvalidDateHeader ) ?;
679
-
680
- let request_path = req. uri . path ( ) ;
681
- let req = platform:: ValidationData {
682
- request_path,
683
- date_header,
684
- x_encore_auth_header,
685
- } ;
686
-
687
- self . shared
688
- . platform_auth
689
- . validate_platform_request ( & req)
690
- . map ( Some )
667
+ ) -> Result < platform:: SealOfApproval , platform:: ValidationError > {
668
+ let data = ValidationData :: from_req ( req) ?;
669
+ self . shared . platform_auth . validate_platform_request ( & data)
691
670
}
692
671
}
693
672
0 commit comments