This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/branch-1.9 by this push:
     new d70f8c58f [KYUUBI #6588] Get effective USER if env var is unavailable
d70f8c58f is described below

commit d70f8c58f71a704bd946cf5b034e634000bc36c4
Author: Cheng Pan <cheng...@apache.org>
AuthorDate: Wed Aug 7 17:44:42 2024 +0800

    [KYUUBI #6588] Get effective USER if env var is unavailable
    
    # :mag: Description
    
    In some cases, env var USER is unavailable, for example, docker container, 
we should evaluate it via `id -nu`
    
    ref: 
https://github.com/apache/hadoop/blob/rel/release-3.4.0/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh#L893-L896
    
    ## Types of changes :bookmark:
    
    - [x] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    ```
    $ docker run -t -i ubuntu:latest
    root1dbeaefd6cd4:/# echo $USER
    
    root1dbeaefd6cd4:/# id -nu
    root
    root1dbeaefd6cd4:/# exit
    ```
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [x] This patch was not authored or co-authored using [Generative 
Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6588 from pan3793/USER.
    
    Closes #6588
    
    a79786347 [Cheng Pan] Get effective USER if env var is unavailable
    
    Authored-by: Cheng Pan <cheng...@apache.org>
    Signed-off-by: Cheng Pan <cheng...@apache.org>
    (cherry picked from commit b90063942ab7d420fff85ecb8b9bcb3877f51f8d)
    Signed-off-by: Cheng Pan <cheng...@apache.org>
---
 bin/kyuubi              | 5 +++++
 build/kyuubi-build-info | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/bin/kyuubi b/bin/kyuubi
index 17ab717e5..00c95ad3b 100755
--- a/bin/kyuubi
+++ b/bin/kyuubi
@@ -35,6 +35,11 @@ if [[ "$*" = *--help ]] || [[ "$*" = *-h ]]; then
   exit 0
 fi
 
+# if for some reason the shell doesn't have $USER defined
+# (e.g., ssh'd in to execute a command)
+# let's get the effective username and use that
+USER=${USER:-$(id -nu)}
+
 function kyuubi_logo() {
   source ${KYUUBI_HOME}/bin/kyuubi-logo
 }
diff --git a/build/kyuubi-build-info b/build/kyuubi-build-info
index 8ac7ee2e2..e9a13edf1 100755
--- a/build/kyuubi-build-info
+++ b/build/kyuubi-build-info
@@ -30,7 +30,10 @@ echo_build_properties() {
   echo kyuubi_hadoop_version="$7"
   echo kyuubi_flink_version="$8"
   echo kyuubi_trino_version="$9"
-  echo user="$USER"
+  # if for some reason the shell doesn't have $USER defined
+  # (e.g., ssh'd in to execute a command)
+  # let's get the effective username and use that
+  echo user="${USER:-$(id -nu)}"
   echo revision=$(git rev-parse HEAD)
   echo revision_time=$(git show -s --format=%ci HEAD)
   echo branch=$(git rev-parse --abbrev-ref HEAD)

Reply via email to