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/// TokenIssuer is the interface to issue session tokens.
22pub trait TokenIssuer {
23 /// Issues a session token for the given PSSID, data plane ID, and session grant.
24 fn issue(
25 &self,
26 pssid: Pssid,
27 data_plane_id: DataPlaneId,
28 session_grant: SessionGrant,
29 ) -> Result<String, SessionTokenError>;
30}
31
32/// Errors that can occur during session operations.
33#[derive(Debug, Error)]
34pub enum SessionTokenError {
35 /// JWT encoding error.
36 #[error("decoding session token: {0:?}")]
37 EncodingError(#[from] jsonwebtoken::errors::Error),
38}