Skip to content

Commit 9886b21

Browse files
committed
Introduce KindSpecifics
1 parent 3f560f4 commit 9886b21

File tree

7 files changed

+63
-9
lines changed

7 files changed

+63
-9
lines changed

clab/sshconfig.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type SSHConfigTmpl struct {
1717
// SSHConfigNodeTmpl represents values for a single node
1818
// in the sshconfig template.
1919
type SSHConfigNodeTmpl struct {
20-
Name string
21-
Username string
22-
Kind string
20+
Name string
21+
Username string
22+
SSHSpecifics *types.SSHSpecifics
2323
}
2424

2525
// tmplSshConfig is the SSH config template.
@@ -32,8 +32,8 @@ Host {{ .Name }}
3232
{{- end }}
3333
StrictHostKeyChecking=no
3434
UserKnownHostsFile=/dev/null
35-
{{- if eq .Kind "sros" }}
36-
PubkeyAuthentication="unbound"
35+
{{- if ne .SSHSpecifics.PubkeyAuthentication "" }}
36+
PubkeyAuthentication={{ .SSHSpecifics.PubkeyAuthentication.String }}
3737
{{- end }}
3838
{{ end }}`
3939

@@ -60,9 +60,9 @@ func (c *CLab) AddSSHConfig(topoPaths *types.TopoPaths) error {
6060
// the kind registered Username
6161
NodeRegistryEntry := c.Reg.Kind(n.Config().Kind)
6262
nodeData := SSHConfigNodeTmpl{
63-
Name: n.Config().LongName,
64-
Username: NodeRegistryEntry.Credentials().GetUsername(),
65-
Kind: NodeRegistryEntry.GetMainKindName(),
63+
Name: n.Config().LongName,
64+
Username: NodeRegistryEntry.Credentials().GetUsername(),
65+
SSHSpecifics: n.GetKindSpecifics().SSHSpecifics,
6666
}
6767
tmpl.Nodes = append(tmpl.Nodes, nodeData)
6868
}

mocks/mocknodes/node.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodes/default_node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type DefaultNode struct {
3535
Mgmt *types.MgmtNet
3636
Runtime runtime.ContainerRuntime
3737
HostRequirements *types.HostRequirements
38+
KindSpecifics *types.KindSpecifics
3839
// Indicates that the node should not start without no license file defined
3940
LicensePolicy types.LicensePolicy
4041
// OverwriteNode stores the interface used to overwrite methods defined
@@ -57,6 +58,7 @@ func NewDefaultNode(n NodeOverwrites) *DefaultNode {
5758
HostRequirements: types.NewHostRequirements(),
5859
OverwriteNode: n,
5960
LicensePolicy: types.LicensePolicyNone,
61+
KindSpecifics: types.NewKindSpecifics(),
6062
}
6163

6264
return dn
@@ -509,3 +511,7 @@ func (d *DefaultNode) SetState(s state.NodeState) {
509511
defer d.statemutex.Unlock()
510512
d.state = s
511513
}
514+
515+
func (d *DefaultNode) GetKindSpecifics() *types.KindSpecifics {
516+
return d.KindSpecifics
517+
}

nodes/linux/linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type linux struct {
3434
func (n *linux) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
3535
// Init DefaultNode
3636
n.DefaultNode = *nodes.NewDefaultNode(n)
37-
3837
n.Cfg = cfg
3938
for _, o := range opts {
4039
o(n)

nodes/node.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ type Node interface {
107107
ExecFunction(func(ns.NetNS) error) error
108108
GetState() state.NodeState
109109
SetState(state.NodeState)
110+
// return the kind specifics
111+
GetKindSpecifics() *types.KindSpecifics
110112
}
111113

112114
type NodeOption func(Node)

nodes/vr_sros/vr-sros.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (s *vrSROS) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
6262
// set virtualization requirement
6363
s.HostRequirements.VirtRequired = true
6464
s.LicensePolicy = types.LicensePolicyWarn
65+
s.KindSpecifics.SSHSpecifics.PubkeyAuthentication = types.PubkeyAuthValueUnbound
6566

6667
s.Cfg = cfg
6768
for _, o := range opts {

types/kind_specifics.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package types
2+
3+
type PubkeyAuthValue string
4+
5+
const (
6+
PubkeyAuthValueYes PubkeyAuthValue = "yes"
7+
PubkeyAuthValueNo PubkeyAuthValue = "no"
8+
PubkeyAuthValueHostBound PubkeyAuthValue = "host-bound"
9+
PubkeyAuthValueUnbound PubkeyAuthValue = "unbound"
10+
)
11+
12+
func (p PubkeyAuthValue) String() string {
13+
return string(p)
14+
}
15+
16+
type KindSpecifics struct {
17+
SSHSpecifics *SSHSpecifics
18+
}
19+
20+
func NewKindSpecifics() *KindSpecifics {
21+
return &KindSpecifics{
22+
SSHSpecifics: NewSSHSpecifics(),
23+
}
24+
}
25+
26+
type SSHSpecifics struct {
27+
PubkeyAuthentication PubkeyAuthValue
28+
}
29+
30+
func NewSSHSpecifics() *SSHSpecifics {
31+
return &SSHSpecifics{}
32+
}

0 commit comments

Comments
 (0)