nv_redfish/session_service/mod.rs
1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Session Service entities and helpers.
17//!
18//! This module provides typed access to Redfish `SessionService`, including
19//! listing, creating, and deleting sessions.
20
21mod collection;
22mod item;
23
24use crate::schema::redfish::session_service::SessionService as SessionServiceSchema;
25use crate::Error;
26use crate::NvBmc;
27use crate::ServiceRoot;
28use nv_redfish_core::Bmc;
29use std::sync::Arc;
30
31#[doc(inline)]
32pub use crate::schema::redfish::session::SessionCreate;
33#[doc(inline)]
34pub use crate::schema::redfish::session::SessionTypes;
35#[doc(inline)]
36pub use collection::SessionCollection;
37#[doc(inline)]
38pub use item::Session;
39
40/// Session service.
41///
42/// Provides access to the session collection and individual session resources.
43pub struct SessionService<B: Bmc> {
44 bmc: NvBmc<B>,
45 service: Arc<SessionServiceSchema>,
46}
47
48impl<B: Bmc> SessionService<B> {
49 /// Create a new session service handle.
50 pub(crate) async fn new(
51 bmc: &NvBmc<B>,
52 root: &ServiceRoot<B>,
53 ) -> Result<Option<Self>, Error<B>> {
54 if let Some(service_ref) = &root.root.session_service {
55 let service = service_ref.get(bmc.as_ref()).await.map_err(Error::Bmc)?;
56 Ok(Some(Self {
57 bmc: bmc.clone(),
58 service,
59 }))
60 } else {
61 Ok(None)
62 }
63 }
64
65 /// Get the raw schema data for this session service.
66 ///
67 /// Returns an `Arc` to the underlying schema, allowing cheap cloning
68 /// and sharing of the data.
69 #[must_use]
70 pub fn raw(&self) -> Arc<SessionServiceSchema> {
71 self.service.clone()
72 }
73
74 /// Get the sessions collection.
75 ///
76 /// # Errors
77 ///
78 /// Returns an error if retrieving session collection data fails.
79 pub async fn sessions(&self) -> Result<Option<SessionCollection<B>>, Error<B>> {
80 if let Some(collection_ref) = self.service.sessions.as_ref() {
81 SessionCollection::new(self.bmc.clone(), collection_ref)
82 .await
83 .map(Some)
84 } else {
85 Ok(None)
86 }
87 }
88}