DerGut commented on code in PR #2836: URL: https://github.com/apache/iceberg-rust/pull/2836#discussion_r3684663264
########## crates/iceberg/src/catalog/session.rs: ########## @@ -0,0 +1,264 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Session catalog API for Apache Iceberg. + +use std::collections::HashMap; +use std::fmt::Debug; +use std::future::Future; +use std::sync::Arc; + +use async_trait::async_trait; +use typed_builder::TypedBuilder; +use uuid::Uuid; +use zeroize::Zeroizing; + +use crate::io::StorageFactory; +use crate::runtime::Runtime; +use crate::table::Table; +use crate::{Namespace, NamespaceIdent, Result, TableCommit, TableCreation, TableIdent}; + +/// Context for a session. +#[derive(Debug, Clone, TypedBuilder)] +pub struct SessionContext { + /// The unique identifier for this session. + /// + /// Note that the session_id may be used for caching session-scoped state + /// and re-use of a session_id with different session context may result in + /// unexpected behavior. + session_id: String, + + /// An optional user or principal associated with the session. + #[builder(default, setter(strip_option))] + identity: Option<String>, + + #[builder(default)] + properties: HashMap<String, String>, + + #[builder(default)] + credentials: HashMap<String, Credential>, +} + +impl SessionContext { + /// Creates a new unique but empty session. + pub fn empty() -> Self { + Self { + session_id: Uuid::new_v4().to_string(), + identity: None, + properties: HashMap::new(), + credentials: HashMap::new(), + } + } + + /// Returns the identifier for this session. + /// + /// The identifier may be used for caching state within a session. + pub fn session_id(&self) -> &str { + &self.session_id + } + + /// Returns a string that identifies the current user or principal. + pub fn identity(&self) -> Option<&str> { + self.identity.as_deref() + } + + /// Returns a map of properties currently set for the session. + pub fn properties(&self) -> &HashMap<String, String> { + &self.properties + } + + /// Returns the session's credential map. + pub fn credentials(&self) -> &HashMap<String, Credential> { + &self.credentials + } +} + +/// A string-like type containing sensitive information such as passwords or tokens. +/// +/// It is redacted from logs and automatically zeroized. +#[derive(Clone)] +pub struct Credential(Zeroizing<String>); Review Comment: Yes, this is dual use! Sounds good to me. If you have a preference on the naming, `SensitiveString` is definitely the more generally plausible name. `Credential` works better in the current state where we're only dealing with credentials. I'll take a look through the Java codebase to see whether there's other places where sensitive strings could be handled. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
