Browse Source

bin: support kdialog in get-aws-login

Thomas Dy 3 years ago
parent
commit
31bce916a5
1 changed files with 18 additions and 2 deletions
  1. 18 2
      .local/bin/get-aws-login

+ 18 - 2
.local/bin/get-aws-login

@@ -6,6 +6,22 @@ function log {
   fi
 }
 
+function prompt_password {
+  if command -v kdialog >/dev/null; then
+    kdialog --password Password
+  else
+    zenity --password --timeout=60
+  fi
+}
+
+function prompt_mfa {
+  if command -v kdialog >/dev/null; then
+    kdialog --inputbox MFA
+  else
+    zenity --entry --text=MFA
+  fi
+}
+
 # ignore existing credentials
 unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
 
@@ -82,7 +98,7 @@ function get_long_term_credentials {
   local duration
   local password
   duration="$1"
-  if ! password=$(zenity --password --timeout=60 2> /dev/null); then
+  if ! password=$(prompt_password 2> /dev/null); then
     log "Failed to get password"
     return 1
   fi
@@ -110,7 +126,7 @@ function get_long_term_credentials {
 
     mfa_serial_number=$(aws configure get mfa_serial)
 
-    if ! mfa=$(zenity --entry --text=MFA 2> /dev/null); then
+    if ! mfa=$(prompt_mfa 2> /dev/null); then
       log "Failed to get MFA"
       return 1
     fi