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

msciabarra pushed a commit to branch local-config
in repository https://gitbox.apache.org/repos/asf/openserverless-task.git

commit 18adae1b3fde08523866cf4c9bd899395864542c
Author: Michele Sciabarra <[email protected]>
AuthorDate: Fri Nov 7 03:27:36 2025 +0000

    implemented local cnfig
---
 ide/docopts.md  | 25 +++++++++++++--
 ide/opsfile.yml | 96 +++++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 103 insertions(+), 18 deletions(-)

diff --git a/ide/docopts.md b/ide/docopts.md
index fd1b68f..bb3be44 100644
--- a/ide/docopts.md
+++ b/ide/docopts.md
@@ -24,9 +24,9 @@ OpenServerless Ide Development Utilities.
 
 ```text
 Usage:
-    ide login [<username>] [<apihost>]
+    ide login [<username>] [<apihost>] [--local] [--pin]
     ide devel [--fast] [--dry-run]
-    ide deploy [<action>] [--dry-run]
+    ide deploy [<action>|--packages|--web] [--dry-run]
     ide undeploy [<action>] [--dry-run]
     ide clean
     ide setup 
@@ -60,6 +60,27 @@ Usage:
 ## Options
 
 ```
+--pin           Save the current key in .env as AUTH_CHECK to verify 
deployments use that key
+--local         Save the login as a local .wskprops instead of a global one
 --fast          Skip the initial deployment step and go in incremental update 
mode
 --dry-run       Simulates the execution without making any actual changes 
+--packages      Only deploy packages, skip web
+--wen           Only deploy web, skip packages
 ```
+
+## Login 
+
+If you login with `ops ide login` it will read the .env and 
+login using env vars `OPS_USERNAME` `OPS_PASSWORD` `OPS_APIHOST`
+
+If you login with `ops ide login <username>` it will use, if not empty in 
preference:
+
+`OPS_<username>_USERNAME` `OPS_<username>_PASSWORD` `OPS_<username>_APIHOST`
+
+By default the credentials are stored in ~/.wskprops.
+If there is a local `.wskprops` in current directory it will used that instead.
+
+If you specify `--local` credentials are stored in the local file.
+Also if you login and there is already a local file will be used the local 
instead of the global.
+
+If you specify `--pin` an `AUTH_CHECK` variable will be added to your `.env` 
to verify deployments use the intended configurations and not a different one 
by mistake.
diff --git a/ide/opsfile.yml b/ide/opsfile.yml
index d518cad..a5eed1e 100644
--- a/ide/opsfile.yml
+++ b/ide/opsfile.yml
@@ -36,7 +36,15 @@ vars:
       then cat "$OPS_ROOT/ide/deploy/hash.lock"
       else echo "0"
       fi
-      
+
+env:
+  WSK_CONFIG_FILE:
+    sh: |
+        if test -e "$OPS_PWD/..wskprops"
+        then echo "$OPS_PWD/.wskprops"
+        else echo ~/.wskprops
+        fi
+
 tasks:
 
   prereq:
@@ -148,9 +156,28 @@ tasks:
         if test -e "$OPS_PWD/.env"
         then source "$OPS_PWD/.env"
         fi
+
+        # load user variables if any
+        if [ -n "{{._username_}}" ]
+        then
+          if [ -n "$OPS_{{._username_}}_USERNAME"]
+          then  OPS_USERNAME="$OPS_{{._username_}}_USERNAME"
+                echo Using username from $OPS_{{._username_}}_USERNAME for 
login  
+          fi
+          if [ -n "$OPS_{{._username_}}_APIHOST"]
+          then  OPS_APIHOST="$OPS_{{._username_}}_APIHOST"
+                echo Using apihost from $OPS_{{._username_}}_APIHOST for login 
 
+          fi
+          if [ -n "$OPS_{{._username_}}_PASSWORD"]
+          then  OPS_PASSWORD="$OPS_{{._username_}}_PASSWORD"
+                echo Using password from $OPS_{{._username_}}_PASSWORD for 
login  
+          fi
+        fi
+        
         if test -n "{{._apihost_}}"
         then OPSDEV_APIHOST="{{._apihost_}}"
         fi
+        
         echo "*** Configuring Access to OpenServerless ***"
         if test -z "{{._apihost_}}"
         then 
@@ -180,6 +207,16 @@ tasks:
         if test -n "$OPS_PASSWORD"
         then export "OPS_PASSWORD"
         fi
+
+        if {{.__local}}
+        then export WSK_CONFIG_FILE="$OPS_PWD/.wskprops"
+        fi
+
+        if test -n "$WSK_CONFIG_FILE"
+        then echo Using local credentials: "$WSK_CONFIG_FILE" 
+        else echo Using global credentials: "$WSK_CONFIG_FILE", use `--local` 
for local
+        fi
+
         if $OPS -login "$OPSDEV_APIHOST" "$OPSDEV_USERNAME"
         then
           OPSDEV_HOST_PROT="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print 
$1}')"
@@ -187,12 +224,21 @@ tasks:
           config OPSDEV_APIHOST="$OPSDEV_APIHOST"
           config OPSDEV_USERNAME="$OPSDEV_USERNAME"
           config 
OPSDEV_HOST="$OPSDEV_HOST_PROT://$OPSDEV_USERNAME.$OPSDEV_HOST_URL"
-          source ~/.wskprops
+          source "$WSK_CONFIG_FILE"
+          if {{.__pin}}
+          then 
+              echo "Pinning credentials to avoid deployment mistakes"
+              if rg .env "^AUTH_CHECK=" 
+              then awk -v v="$AUTH" 'BEGIN{FS=OFS="="} /^AUTH_CHECK=/{ $2=v 
}1' .env > .env.tmp$$ && mv .env.tmp$$ .env
+                  echo "Note: replaced existing pinned credentials"
+              else echo "$UTH_CHECK=$AUTH" >>.env
+              fi
+          fi
         else 
           false
         fi
-  
-  
+
+
 
   poll:
     silent: true
@@ -218,6 +264,9 @@ tasks:
       - task: prereq
       - |
         set -a
+        if test -e "$OPS_PWD/.wskprops"
+        then export WSK_CONFIG_FILE="$OPS_PWD/.wskprops"
+        fi
         if test -e $OPS_PWD/.env
         then source $OPS_PWD/.env
         fi
@@ -226,22 +275,40 @@ tasks:
         fi
         if test -n "$AUTH_CHECK"
         then if test "$AUTH_CHECK" != "$AUTH" 
-             then echo "WARNING: wrong deploy! You are logged in a different 
user than your configured AUTH_CHECK" ; exit 1
+             then echo "WARNING: wrong deploy! You are logged in a different 
user than your pinned one and configured in .env as AUTH_CHECK" ; exit 1
              fi
         fi
+
         if {{.__dry_run}}
         then DRY="--dry-run" ; ECHO='echo'
         else DRY="" ; ECHO=""
         fi
-        if test -z "{{._action_}}"
-        then
-            bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY
-            OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web`
-            echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}"
-            $ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web}
-            echo "URL: $OPSDEV_HOST"
+
+        if {{.__web}}
+        then deploy_packages=""
+        else deploy_packages="1"
+        fi
+
+        if {{.__packages}}
+        then deploy_web=""
+        else deploy_web="1"
+        fi
+
+        if test -n "{{._action_}}"
+        then 
+            bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s 
"{{._action_}}" $DRY  
         else
-            bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s 
"{{._action_}}" $DRY            
+            if [ -n "$deploy_packages"]
+            then 
+                bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY
+            fi
+            if [-n "$deploy_web"]
+            then
+              OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload 
web`
+              echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}"
+              $ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web}
+              echo "URL: $OPSDEV_HOST"
+            fi
         fi
 
   undeploy:
@@ -254,7 +321,6 @@ tasks:
         then DRY="--dry-run"
         else DRY=""
         fi
-
         # Check if an action argument is provided
         if test -n "{{._action_}}"
         then
@@ -288,7 +354,6 @@ tasks:
         else die "no packages in current directory"
         fi
 
-
   devel:
     interactive: true
     silent: true
@@ -333,7 +398,6 @@ tasks:
         bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -w $FAST $DRY
         true
 
-
   shell:
     desc: open a bash shell with the current environment
     interactive: true

Reply via email to