snap_dataplane/session/
manager.rs

1// Copyright 2025 Anapaya Systems
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//! SNAP data plane session management.
15
16use snap_tokens::Pssid;
17use thiserror::Error;
18
19use crate::{session::state::SessionGrant, state::DataPlaneId};
20
21/// SessionManager is the interface to manage sessions.
22pub trait SessionManager {
23    /// Open a session for the given SNAP token claims and data plane ID.
24    fn open(
25        &mut self,
26        pssid: Pssid,
27        data_plane_id: DataPlaneId,
28    ) -> Result<SessionGrant, SessionOpenError>;
29}
30
31/// Errors that can occur during session management.
32#[derive(Debug, Error)]
33pub enum SessionOpenError {}
34
35/// TokenIssuer is the interface to issue session tokens.
36pub trait TokenIssuer {
37    /// Issues a session token for the given PSSID, data plane ID, and session grant.
38    fn issue(
39        &self,
40        pssid: Pssid,
41        data_plane_id: DataPlaneId,
42        session_grant: SessionGrant,
43    ) -> Result<String, SessionTokenError>;
44}
45
46/// Errors that can occur during session operations.
47#[derive(Debug, Error)]
48pub enum SessionTokenError {
49    /// JWT encoding error.
50    #[error("decoding session token: {0:?}")]
51    EncodingError(#[from] jsonwebtoken::errors::Error),
52}