Skip to content

Commit 1564f44

Browse files
committed
do not create ssh config if ssh_config.d dir doesn't exist
1 parent 4da49d3 commit 1564f44

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

clab/sshconfig.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package clab
22

33
import (
44
"os"
5+
"path"
56
"text/template"
67

8+
log "github.com/sirupsen/logrus"
79
"github.com/srl-labs/containerlab/types"
810
"github.com/srl-labs/containerlab/utils"
911
)
@@ -46,6 +48,12 @@ func (c *CLab) RemoveSSHConfig(topoPaths *types.TopoPaths) error {
4648

4749
// AddSSHConfig adds the lab specific ssh config file.
4850
func (c *CLab) AddSSHConfig() error {
51+
sshConfigDir := path.Dir(c.TopoPaths.SSHConfigPath())
52+
if !utils.FileOrDirExists(sshConfigDir) {
53+
log.Debugf("ssh config directory %s does not exist, skipping ssh config generation", sshConfigDir)
54+
return nil
55+
}
56+
4957
tmpl := &SSHConfigTmpl{
5058
TopologyName: c.Config.Name,
5159
Nodes: make([]SSHConfigNodeTmpl, 0, len(c.Nodes)),
@@ -68,7 +76,7 @@ func (c *CLab) AddSSHConfig() error {
6876
return err
6977
}
7078

71-
f, err := utils.CreateFileWithPath(c.TopoPaths.SSHConfigPath())
79+
f, err := os.Create(c.TopoPaths.SSHConfigPath())
7280
if err != nil {
7381
return err
7482
}

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,10 +2678,6 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
26782678
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
26792679
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 h1:lIOOHPEbXzO3vnmx2gok1Tfs31Q8GQqKLc8vVqyQq/I=
26802680
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
2681-
github.com/steiler/acls v0.0.0-20231106135104-9c34ae82c793 h1:lY8SggLL0JyttzcNEIRzbywKiKcIlVlF7ZPwTthG9eA=
2682-
github.com/steiler/acls v0.0.0-20231106135104-9c34ae82c793/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
2683-
github.com/steiler/acls v0.0.0-20231106152733-bb3d5d7b05c8 h1:RqP82h2DREJxj7AJbT0k7z2Jye6lweij5s14PUHic1o=
2684-
github.com/steiler/acls v0.0.0-20231106152733-bb3d5d7b05c8/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
26852681
github.com/steiler/acls v0.1.0 h1:fKVnEJ7ebghq2Ed5N1cU9fZrCCRj4xVRPrP7OswaRX8=
26862682
github.com/steiler/acls v0.1.0/go.mod h1:kS9/GuHDS4t2YmY2ijbaK3m1iU4+BgRZS7GoDTC9BfY=
26872683
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=

utils/file.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,3 @@ func AdjustFileACLs(fsPath string) error {
407407

408408
return a.Apply(fsPath, acls.PosixACLDefault)
409409
}
410-
411-
// CreateFileWithPath creates a file by the given path
412-
// and creates the directories if needed.
413-
func CreateFileWithPath(path string) (*os.File, error) {
414-
// create directories if needed, since we promise to create the file
415-
// if it doesn't exist
416-
err := os.MkdirAll(filepath.Dir(path), 0754)
417-
if err != nil {
418-
return nil, err
419-
}
420-
421-
return os.Create(path)
422-
}

0 commit comments

Comments
 (0)