From 66f07868d717b5c6aa410740b85b226189b009db Mon Sep 17 00:00:00 2001 From: Ryoga Saito Date: Sun, 19 Jan 2025 18:44:48 +0900 Subject: [PATCH] Add execCommandForAdmin subcommand --- cmd/access-helper/exec.go | 6 ++++-- cmd/access-helper/labels.go | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/access-helper/exec.go b/cmd/access-helper/exec.go index 4f7e924..9556654 100644 --- a/cmd/access-helper/exec.go +++ b/cmd/access-helper/exec.go @@ -22,10 +22,12 @@ func (h *ExecAccessHelper) access( ctx context.Context, nodeDefinition containerlab.NodeDefinition, containerDetails containerlab.ContainerDetails, - _isAdmin bool, + isAdmin bool, ) error { execCommand := defaultExecCommand - if v, ok := nodeDefinition.Labels[execCommandKey]; ok { + if v, ok := nodeDefinition.Labels[execCommandForAdminKey]; ok && isAdmin { + execCommand = v + } else if v, ok := nodeDefinition.Labels[execCommandKey]; ok { execCommand = v } diff --git a/cmd/access-helper/labels.go b/cmd/access-helper/labels.go index fe9fc76..c75e8bf 100644 --- a/cmd/access-helper/labels.go +++ b/cmd/access-helper/labels.go @@ -12,6 +12,10 @@ const ( // ref: https://uokada.hatenablog.jp/entry/2015/05/20/001208 defaultSSHPassword string = "clab@123" + defaultSSHPort uint16 = 22 + + defaultExecCommand = "sh" + // AccessMethodKey is the label key to specify the access method. // The possible values are either "ssh" or "exec". // With "ssh", access-helper will try to connect to the Node via SSH. @@ -40,11 +44,10 @@ const ( // sshPortKey is the label key to specify port number for SSH access. // The default value is defaultPort. - sshPortKey = "netcon.janog.gr.jp/sshPort" - defaultSSHPort uint16 = 22 + sshPortKey = "netcon.janog.gr.jp/sshPort" // execCommandKey is the label key to specify command for exec access. // The default value is defaultExecCommand. - execCommandKey = "netcon.janog.gr.jp/execCommand" - defaultExecCommand = "sh" + execCommandKey = "netcon.janog.gr.jp/execCommand" + execCommandForAdminKey = "netcon.janog.gr.jp/execCommandForAdmin" )