Skip to content

Commit a0d41e9

Browse files
authored
Merge pull request #2795 from srl-labs/chore/more-linters-and-housekeeping
Chore/more linters and housekeeping
2 parents 2b3166d + 15b0c67 commit a0d41e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+776
-217
lines changed

.golangci.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ linters:
7272
alias: clab$1
7373
- pkg: github.com/srl-labs/containerlab/(\w+)/(\w+)
7474
alias: clab$1$2
75+
- pkg: github.com/srl-labs/containerlab/(\w+)/(\w+)/(\w+)
76+
alias: clab$1$2$3
7577
no-unaliased: true
7678
lll:
7779
line-length: 100
@@ -95,12 +97,27 @@ linters:
9597
- linters:
9698
- staticcheck
9799
text: could remove embedded field
98-
# currently slowly enforcing some things, starting with cmd package
100+
# ssh bits have a lot of mnd that is pretty clear what it is for/doing, so just ignore
99101
- linters:
100-
- lll
101102
- mnd
102-
- wsl_v5
103-
path-except: cmd
103+
path: core/config/transport/
104+
# slowly enforcing things, excluding these packages (for now!)
105+
paths:
106+
- cert
107+
- errors
108+
- exec
109+
- git
110+
- internal
111+
- labels
112+
- links
113+
- mocks
114+
- netconf
115+
- nodes
116+
- runtime
117+
- schemas
118+
- types
119+
- utils
120+
- virt
104121
formatters:
105122
enable:
106123
- gofmt

cert/local_dir_cert_storage.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ func (c *LocalDirCertStorage) LoadNodeCert(nodeName string) (*Certificate, error
3636
func (c *LocalDirCertStorage) StoreCaCert(cert *Certificate) error {
3737
// CA cert/key/csr can only be stored in the labdir/.tls/ca dir,
3838
// so we need to create it if it does not exist.
39-
clabutils.CreateDirectory(filepath.Dir(c.paths.CaCertAbsFilename()), 0o777)
39+
clabutils.CreateDirectory(filepath.Dir(c.paths.CaCertAbsFilename()),
40+
clabutils.PermissionsOpen)
4041

4142
return cert.Write(c.paths.CaCertAbsFilename(), c.paths.CaKeyAbsFilename(), c.paths.CaCSRAbsFilename())
4243
}
4344

4445
// StoreNodeCert stores the given certificate in a file in the baseFolder.
4546
func (c *LocalDirCertStorage) StoreNodeCert(nodeName string, cert *Certificate) error {
4647
// create a folder for the node if it does not exist
47-
clabutils.CreateDirectory(c.paths.NodeTLSDir(nodeName), 0o777)
48+
clabutils.CreateDirectory(c.paths.NodeTLSDir(nodeName),
49+
clabutils.PermissionsOpen)
4850

4951
// write cert files
5052
return cert.Write(c.paths.NodeCertAbsFilename(nodeName),

cmd/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/spf13/cobra"
99
clabcore "github.com/srl-labs/containerlab/core"
1010
clabcoreconfig "github.com/srl-labs/containerlab/core/config"
11-
"github.com/srl-labs/containerlab/core/config/transport"
1211
clabnodes "github.com/srl-labs/containerlab/nodes"
1312

1413
"github.com/charmbracelet/log"
@@ -132,7 +131,6 @@ func configSubCmds(c *cobra.Command, o *Options) {
132131
func configRun(_ *cobra.Command, args []string, o *Options) error {
133132
var err error
134133

135-
transport.DebugCount = o.Global.DebugCount
136134
clabcoreconfig.DebugCount = o.Global.DebugCount
137135

138136
c, err := clabcore.NewContainerLab(o.ToClabOptions()...)
@@ -181,7 +179,7 @@ func configRun(_ *cobra.Command, args []string, o *Options) error {
181179
return
182180
}
183181

184-
err = clabcoreconfig.Send(cs, action)
182+
err = clabcoreconfig.Send(cs, action, o.Global.DebugCount > 0)
185183
if err != nil {
186184
log.Warnf("%s: %s", cs.TargetNode.ShortName, err)
187185
}

cmd/tools_cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func createCA(o *Options) error {
229229

230230
clabutils.CreateDirectory(
231231
o.ToolsCert.Path,
232-
clabutils.PermissionsEveryoneAllPermissions,
232+
clabutils.PermissionsOpen,
233233
) // skipcq: GSC-G302
234234

235235
err = caCert.Write(
@@ -306,7 +306,7 @@ func signCert(o *Options) error {
306306

307307
clabutils.CreateDirectory(
308308
o.ToolsCert.Path,
309-
clabutils.PermissionsEveryoneAllPermissions,
309+
clabutils.PermissionsOpen,
310310
) // skipcq: GSC-G302
311311

312312
err = nodeCert.Write(

core/authz_keys.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ func (c *CLab) createAuthzKeysFile() error {
4141
}
4242

4343
// ensure authz_keys will have the permissions allowing it to be read by anyone
44-
return os.Chmod(clabAuthzKeysFPath, 0o644) // skipcq: GSC-G302
44+
return os.Chmod(
45+
clabAuthzKeysFPath,
46+
clabutils.PermissiosnFileDefault,
47+
) // skipcq: GSC-G302
4548
}
4649

4750
// RetrieveSSHPubKeysFromFiles retrieves public keys from the ~/.ssh/*.authorized_keys
4851
// and ~/.ssh/*.pub files.
4952
func RetrieveSSHPubKeysFromFiles() ([]ssh.PublicKey, error) {
5053
var keys []ssh.PublicKey
54+
5155
p := clabutils.ResolvePath(pubKeysGlob, "")
5256

5357
all, err := filepath.Glob(p)
@@ -115,12 +119,14 @@ func RetrieveSSHAgentKeys() ([]ssh.PublicKey, error) {
115119
log.Debug("SSH_AUTH_SOCK not set, skipping pubkey fetching")
116120
return nil, nil
117121
}
122+
118123
conn, err := net.Dial("unix", socket)
119124
if err != nil {
120125
return nil, fmt.Errorf("failed to open SSH_AUTH_SOCK: %w", err)
121126
}
122127

123128
agentClient := agent.NewClient(conn)
129+
124130
keys, err := agentClient.List()
125131
if err != nil {
126132
return nil, fmt.Errorf("error listing agent's pub keys %w", err)
@@ -135,6 +141,7 @@ func RetrieveSSHAgentKeys() ([]ssh.PublicKey, error) {
135141
if err != nil {
136142
return nil, err
137143
}
144+
138145
pubKeys = append(pubKeys, pkey)
139146
}
140147

0 commit comments

Comments
 (0)