public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager] fix #4758: ui: lxc wizard: allow multiple ssh keys
@ 2023-07-03 13:37 Dominik Csapak
  2023-07-03 14:24 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2023-07-03 13:37 UTC (permalink / raw)
  To: pve-devel

by converting the textfield into a textarea and validate the value
line wise (if there is more than one line)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/manager6/lxc/CreateWizard.js | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/www/manager6/lxc/CreateWizard.js b/www/manager6/lxc/CreateWizard.js
index 0b82cc1c..e74b0b5c 100644
--- a/www/manager6/lxc/CreateWizard.js
+++ b/www/manager6/lxc/CreateWizard.js
@@ -120,17 +120,29 @@ Ext.define('PVE.lxc.CreateWizard', {
 		    },
 		},
 		{
-		    xtype: 'proxmoxtextfield',
+		    xtype: 'textarea',
 		    name: 'ssh-public-keys',
 		    value: '',
-		    fieldLabel: gettext('SSH public key'),
+		    fieldLabel: gettext('SSH public key(s)'),
 		    allowBlank: true,
 		    validator: function(value) {
 			let pwfield = this.up().down('field[name=password]');
 			if (value.length) {
-			    let key = PVE.Parser.parseSSHKey(value);
-			    if (!key) {
-				return "Failed to recognize ssh key";
+			    if (value.indexOf('\n') !== -1) {
+				let err;
+				value.split('\n').forEach((key) => {
+				    if (key !== '' && !PVE.Parser.parseSSHKey(key)) {
+					err = "Failed to recognize ssh key";
+				    }
+				});
+				if (err) {
+				    return err;
+				}
+			    } else {
+				let key = PVE.Parser.parseSSHKey(value);
+				if (!key) {
+				    return "Failed to recognize ssh key";
+				}
 			    }
 			    pwfield.allowBlank = true;
 			} else {
@@ -166,7 +178,7 @@ Ext.define('PVE.lxc.CreateWizard', {
 		    listeners: {
 			change: function(btn, e, value) {
 			    e = e.event;
-			    let field = this.up().down('proxmoxtextfield[name=ssh-public-keys]');
+			    let field = this.up().down('textarea[name=ssh-public-keys]');
 			    PVE.Utils.loadSSHKeyFromFile(e.target.files[0], v => field.setValue(v));
 			    btn.reset();
 			},
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH manager] fix #4758: ui: lxc wizard: allow multiple ssh keys
  2023-07-03 13:37 [pve-devel] [PATCH manager] fix #4758: ui: lxc wizard: allow multiple ssh keys Dominik Csapak
@ 2023-07-03 14:24 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2023-07-03 14:24 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 03/07/2023 um 15:37 schrieb Dominik Csapak:
> by converting the textfield into a textarea and validate the value
> line wise (if there is more than one line)
> 

I hit reply to quick and only to you directly, sorry, so here my initial question and
your quick reply to it:

Am 03/07/2023 um 16:16 schrieb Dominik Csapak:
>> can I now also multiselect public keys through the file selector?
>> Probably not as I saw no change w.r.t. that, asking mostly if you looked into that already?
>>
> 
> no sorry did not work on that for now, but i'll look into it.
> is there an open bug for that too?
> 

no that I recall, but IMO they're quite related (and FWIW, I wished for the file one already
in the past personally), so if it isn't too complicated I'd do them in one series.

> --- a/www/manager6/lxc/CreateWizard.js
> +++ b/www/manager6/lxc/CreateWizard.js
> @@ -120,17 +120,29 @@ Ext.define('PVE.lxc.CreateWizard', {
>  		    },
>  		},
>  		{
> -		    xtype: 'proxmoxtextfield',
> +		    xtype: 'textarea',
>  		    name: 'ssh-public-keys',
>  		    value: '',
> -		    fieldLabel: gettext('SSH public key'),
> +		    fieldLabel: gettext('SSH public key(s)'),
>  		    allowBlank: true,
>  		    validator: function(value) {
>  			let pwfield = this.up().down('field[name=password]');
>  			if (value.length) {
> -			    let key = PVE.Parser.parseSSHKey(value);
> -			    if (!key) {
> -				return "Failed to recognize ssh key";
> +			    if (value.indexOf('\n') !== -1) {
> +				let err;
> +				value.split('\n').forEach((key) => {
> +				    if (key !== '' && !PVE.Parser.parseSSHKey(key)) {
> +					err = "Failed to recognize ssh key";
> +				    }
> +				});
> +				if (err) {
> +				    return err;
> +				}


above 9 lines could be

// check if any (non-empty) key fails to parse as SSH key
if (value.split('\n').every(key => key === '' || PVE.Parser.parseSSHKey(key))) {
    return "Failed to recognize ssh key";
}

> +			    } else {
> +				let key = PVE.Parser.parseSSHKey(value);


you could also merge the checking for the multiline and single line case:

let keys = value.indexOf('\n') !== -1 ? value.split('\n') : [ value ];

if (keys.every(key => key === '' || PVE.Parser.parseSSHKey(key))) {
    // ..

> +				if (!key) {
> +				    return "Failed to recognize ssh key";
> +				}
>  			    }
>  			    pwfield.allowBlank = true;
>  			} else {
> @@ -166,7 +178,7 @@ Ext.define('PVE.lxc.CreateWizard', {
>  		    listeners: {
>  			change: function(btn, e, value) {
>  			    e = e.event;
> -			    let field = this.up().down('proxmoxtextfield[name=ssh-public-keys]');
> +			    let field = this.up().down('textarea[name=ssh-public-keys]');
>  			    PVE.Utils.loadSSHKeyFromFile(e.target.files[0], v => field.setValue(v));
>  			    btn.reset();
>  			},





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-03 14:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 13:37 [pve-devel] [PATCH manager] fix #4758: ui: lxc wizard: allow multiple ssh keys Dominik Csapak
2023-07-03 14:24 ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal