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

msciabarra pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/openserverless-vscode-extension.git

commit bc4dcd8a0a058eed62951fac834ed78222f00fed
Author: William Grienti <[email protected]>
AuthorDate: Thu Mar 7 12:17:01 2024 +0100

    Environment fixes
    
    Fixed ENV variables persistance
---
 package.json        |  2 +-
 src/extension.ts    | 55 ++++++++++++++++++++++++++++++++++++++++++-----------
 src/webview/main.ts | 20 +++++++++----------
 3 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/package.json b/package.json
index 6669e6b..2142665 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
                "viewsWelcome": [
                        {
                                "view": "command-palette",
-                               "contents": 
"\n[Deploy](command:nuvolaris.deploy)\n[Devel](command:nuvolaris.devel)"
+                               "contents": 
"\n[Deploy](command:nuvolaris.deploy)\n[Devel](command:nuvolaris.devel)\n[Change
 User](command:nuvolaris.changeuser)"
                        }
                ]
        },
diff --git a/src/extension.ts b/src/extension.ts
index c4b0439..347ec52 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -4,28 +4,47 @@ import { LoginPanel } from "./panels/Login";
 
 
 let nuvLoginParams: NuvolarisLoginParams = {
-       nuvUser: process.env.NUV_USER,
-       nuvApiHost: process.env.NUV_APIHOST,
-       nuvPassword: process.env.NUV_PASSWORD
+       nuvUser: '',
+       nuvApiHost: '',
+       nuvPassword: ''
 }
-export async function activate(context: vscode.ExtensionContext) {
+let context: vscode.ExtensionContext | null = null;
+export async function activate(ctx: vscode.ExtensionContext) {
        try {
+               context = ctx;
+               let envUser = 
context.environmentVariableCollection.get('NUV_USER')?.value
+               let envPassword = 
context.environmentVariableCollection.get('NUV_PASSWORD')?.value
+               let envApiHost = 
context.environmentVariableCollection.get('NUV_APIHOST')?.value
+
+               updateNuvolarisLoginParams(envUser, envPassword, envApiHost)
                Object.entries(COMMANDS).forEach(([name, command]) =>
-                       
context.subscriptions.push(vscode.commands.registerCommand(`nuvolaris.${name.toLowerCase()}`,
 () => {
-                               if (loginIfNotAlreadyLoggedIn(context)) 
launchTerminal(command)
+                       
context!.subscriptions.push(vscode.commands.registerCommand(`nuvolaris.${name.toLowerCase()}`,
 () => {
+                               if (loginIfNotAlreadyLoggedIn()) 
launchTerminal(command)
                        }
                        )));
+
+               
context!.subscriptions.push(vscode.commands.registerCommand('nuvolaris.changeuser',
 () => {
+                       vscode.window.showInformationMessage("Are you sure you 
want to change user?", "Yes", "No")
+                               .then(answer => {
+                                       if (answer === "Yes") {
+                                               clearEnvironmentVariables();
+                                               loginIfNotAlreadyLoggedIn();
+                                       }
+                               })
+               }));
+
+
        } catch (error: any) {
                printError(error);
                throw error;
        }
 }
 
-function loginIfNotAlreadyLoggedIn(context: vscode.ExtensionContext) {
+function loginIfNotAlreadyLoggedIn() {
        try {
                let validCredentials = validateNuvolarisCredentials();
                if (validCredentials) launchLoginTerminal();
-               else LoginPanel.render(handleLogin, context.extensionUri);
+               else LoginPanel.render(handleLogin, context!.extensionUri);
                return validCredentials;
        } catch (error) {
                printError(error);
@@ -68,9 +87,22 @@ function updateNuvolarisLoginParams(nuvUser: string | 
undefined, nuvApiHost: str
                nuvApiHost: nuvApiHost,
                nuvPassword: nuvPassword
        }
-       process.env.NUV_USER = nuvUser;
-       process.env.NUV_APIHOST = nuvApiHost;
-       process.env.NUV_PASSWORD = nuvPassword
+       context!.environmentVariableCollection.append('NUV_USER', nuvUser + '')
+       context!.environmentVariableCollection.append('NUV_PASSWORD', 
nuvPassword + '')
+       context!.environmentVariableCollection.append('NUV_APIHOST', nuvApiHost 
+ '')
+
+}
+
+function clearEnvironmentVariables() {
+       nuvLoginParams = {
+               nuvUser: '',
+               nuvApiHost: '',
+               nuvPassword: ''
+       }
+       context!.environmentVariableCollection.delete('NUV_USER')
+       context!.environmentVariableCollection.delete('NUV_PASSWORD')
+       context!.environmentVariableCollection.delete('NUV_APIHOST')
+
 }
 
 function launchLoginTerminal() {
@@ -99,3 +131,4 @@ function launchTerminal(command: string) {
 function printError(error: any) {
        return vscode.window.showErrorMessage("Si รจ verificato un errore", 
error.toString());
 }
+
diff --git a/src/webview/main.ts b/src/webview/main.ts
index e6c44ee..af17af9 100644
--- a/src/webview/main.ts
+++ b/src/webview/main.ts
@@ -138,10 +138,10 @@ function validateUsername() {
     let fieldName = "Username";
     let input = LoginPage.getUsername();
     let assertions = [];
-    let shouldBeMin6 = Validators.minChars(input, 6, fieldName);
-    let shouldBeMax12 = Validators.maxChars(input, 12, fieldName);
-    assertions.push(shouldBeMin6);
-    assertions.push(shouldBeMax12);
+    let isNotEmpty = Validators.minChars(input, 1, fieldName);
+    // let shouldBeMax12 = Validators.maxChars(input, 12, fieldName);
+    assertions.push(isNotEmpty);
+    // assertions.push(shouldBeMax12);
     createErrorMessages(assertions);
     return assertions.filter(a => !a.isValid).length === 0;
   } catch (error: any) {
@@ -156,10 +156,10 @@ function validatePassword() {
     let fieldName = "Password";
     let input = LoginPage.getPassword();
     let assertions = [];
-    let shouldBeMin8 = Validators.minChars(input, 8, fieldName);
-    let shouldBeMax30 = Validators.maxChars(input, 30, fieldName);
-    assertions.push(shouldBeMin8);
-    assertions.push(shouldBeMax30);
+    let isNotEmpty = Validators.minChars(input, 1, fieldName);
+    // let shouldBeMax30 = Validators.maxChars(input, 30, fieldName);
+    assertions.push(isNotEmpty);
+    // assertions.push(shouldBeMax30);
     createErrorMessages(assertions);
     return assertions.filter(a => !a.isValid).length === 0;
   } catch (error: any) {
@@ -173,11 +173,11 @@ function validateApiHost() {
     let fieldName = "Api Host";
     let input = LoginPage.getApiHost();
     let assertions = [];
-    let shouldBeUrl = Validators.validUrl(input, fieldName);
+    let isNotEmpty = Validators.minChars(input, 1, fieldName);
     /*if(shouldBeUrl.isValid && !/^https?:\/\//i.test(input.value)){
         input.value = "https://"; + input.value;
     }*/
-    assertions.push(shouldBeUrl);
+    assertions.push(isNotEmpty);
     createErrorMessages(assertions);
     return assertions.filter(a => !a.isValid).length === 0;
   } catch (error: any) {

Reply via email to