mirror of
https://github.com/gravitational/teleport
synced 2024-10-20 09:13:39 +00:00
Fix staticcheck findings in integration/ and tool/
Original finding list: ``` tool/tctl/common/node_command.go:163:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(string(out)) ^ tool/tctl/common/status_command.go:110:2: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(view()) ^ tool/tctl/common/status_command.go:126:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(view()) ^ tool/tctl/common/token_command.go:201:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(tokensView()) ^ tool/tctl/common/token_command.go:207:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(string(data)) ^ tool/tctl/common/user_command.go:248:2: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(string(out)) ^ tool/tctl/common/user_command.go:294:3: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Printf(string(out)) ^ integration/helpers.go:200:2: SA4006: this value of `err` is never used (staticcheck) cryptoPubKey, err := sshutils.CryptoPublicKey(cfg.Pub) ^ integration/helpers.go:399:3: SA4006: this value of `roles` is never used (staticcheck) roles = append(roles, role) ^ integration/helpers.go:597:4: SA4006: this value of `roles` is never used (staticcheck) roles = append(roles, role) ^ integration/helpers.go:599:4: SA4006: this value of `roles` is never used (staticcheck) roles = user.Roles ^ integration/integration_test.go:1625:2: SA4006: this value of `err` is never used (staticcheck) adminsRole, err := services.NewRole(mainAdmins, services.RoleSpecV3{ ^ integration/integration_test.go:2185:2: SA4006: this value of `output` is never used (staticcheck) output, err = runCommand(main, []string{"echo", "hello world"}, cfg, 1) ^ integration/integration_test.go:2340:2: SA4006: this value of `output` is never used (staticcheck) output, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 1) ^ integration/kube_integration_test.go:154:2: SA4006: this value of `err` is never used (staticcheck) role, err := services.NewRole("kubemaster", services.RoleSpecV3{ ^ integration/kube_integration_test.go:321:2: SA4006: this value of `err` is never used (staticcheck) role, err := services.NewRole("kubemaster", services.RoleSpecV3{ ^ integration/kube_integration_test.go:366:2: SA4006: this value of `err` is never used (staticcheck) role, err := services.NewRole("kubemaster", services.RoleSpecV3{ ^ integration/kube_integration_test.go:386:2: SA4006: this value of `err` is never used (staticcheck) pods, err := s.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{ ^ integration/kube_integration_test.go:465:2: SA4006: this value of `err` is never used (staticcheck) mainRole, err := services.NewRole("main-kube", services.RoleSpecV3{ ^ integration/kube_integration_test.go:579:2: SA4006: this value of `err` is never used (staticcheck) pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{ ^ integration/kube_integration_test.go:727:2: SA4006: this value of `err` is never used (staticcheck) mainRole, err := services.NewRole("main-kube", services.RoleSpecV3{ ^ integration/kube_integration_test.go:840:2: SA4006: this value of `err` is never used (staticcheck) pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{ ^ integration/kube_integration_test.go:1008:2: SA4006: this value of `err` is never used (staticcheck) role, err := services.NewRole("kubemaster", services.RoleSpecV3{ ^ tool/teleport/common/teleport_test.go:83:2: SA4006: this value of `cmd` is never used (staticcheck) cmd, conf := Run(Options{ ^ tool/teleport/common/teleport_test.go:91:2: SA4006: this value of `cmd` is never used (staticcheck) cmd, conf = Run(Options{ ^ tool/tsh/tsh.go:170:2: SA4006: this value of `cmdLine` is never used (staticcheck) cmdLine := []string{} ^ integration/helpers.go:399:11: SA4010: this result of append is never used, except maybe in other appends (staticcheck) roles = append(roles, role) ^ integration/helpers.go:597:12: SA4010: this result of append is never used, except maybe in other appends (staticcheck) roles = append(roles, role) ^ integration/integration_test.go:1092:7: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(b.Tunnel.GetSites()) < 2 && len(b.Tunnel.GetSites()) < 2 { ^ integration/integration_test.go:1426:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 { ^ integration/integration_test.go:1691:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 { ^ integration/integration_test.go:1895:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 { ^ integration/kube_integration_test.go:548:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 { ^ integration/kube_integration_test.go:814:6: SA4000: identical expressions on the left and right side of the '&&' operator (staticcheck) for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 { ^ ```
This commit is contained in:
parent
9d6c678fea
commit
28a7624244
|
@ -198,6 +198,7 @@ func NewInstance(cfg InstanceConfig) *TeleInstance {
|
|||
tlsCA, err := tlsca.New(tlsCACert, tlsCAKey)
|
||||
fatalIf(err)
|
||||
cryptoPubKey, err := sshutils.CryptoPublicKey(cfg.Pub)
|
||||
fatalIf(err)
|
||||
identity := tlsca.Identity{
|
||||
Username: fmt.Sprintf("%v.%v", cfg.HostID, cfg.ClusterName),
|
||||
Groups: []string{string(teleport.RoleAdmin)},
|
||||
|
@ -396,7 +397,6 @@ func SetupUser(process *service.TeleportProcess, username string, roles []servic
|
|||
return trace.Wrap(err)
|
||||
}
|
||||
teleUser.AddRole(role.GetMetadata().Name)
|
||||
roles = append(roles, role)
|
||||
} else {
|
||||
for _, role := range roles {
|
||||
err := auth.UpsertRole(role)
|
||||
|
@ -579,7 +579,6 @@ func (i *TeleInstance) CreateEx(trustedSecrets []*InstanceSecrets, tconf *servic
|
|||
}
|
||||
// set hardcode traits to trigger new style certificates
|
||||
teleUser.SetTraits(map[string][]string{"testing": []string{"integration"}})
|
||||
var roles []services.Role
|
||||
if len(user.Roles) == 0 {
|
||||
role := services.RoleForUser(teleUser)
|
||||
role.SetLogins(services.Allow, user.AllowedLogins)
|
||||
|
@ -594,9 +593,7 @@ func (i *TeleInstance) CreateEx(trustedSecrets []*InstanceSecrets, tconf *servic
|
|||
return trace.Wrap(err)
|
||||
}
|
||||
teleUser.AddRole(role.GetMetadata().Name)
|
||||
roles = append(roles, role)
|
||||
} else {
|
||||
roles = user.Roles
|
||||
for _, role := range user.Roles {
|
||||
err := auth.UpsertRole(role)
|
||||
if err != nil {
|
||||
|
|
|
@ -1089,7 +1089,7 @@ func (s *IntSuite) TestTwoClustersTunnel(c *check.C) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(b.Tunnel.GetSites()) < 2 && len(b.Tunnel.GetSites()) < 2 {
|
||||
for len(a.Tunnel.GetSites()) < 2 && len(b.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("Two clusters do not see each other: tunnels are not working.")
|
||||
|
@ -1423,7 +1423,7 @@ func (s *IntSuite) TestMapRoles(c *check.C) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(aux.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("two clusters do not see each other: tunnels are not working")
|
||||
|
@ -1627,6 +1627,7 @@ func (s *IntSuite) trustedClusters(c *check.C, test trustedClusterTest) {
|
|||
Logins: []string{"superuser"},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
main.AddUserWithRole(username, devsRole, adminsRole)
|
||||
|
||||
|
@ -1688,7 +1689,7 @@ func (s *IntSuite) trustedClusters(c *check.C, test trustedClusterTest) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(aux.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("two clusters do not see each other: tunnels are not working")
|
||||
|
@ -1892,7 +1893,7 @@ func (s *IntSuite) TestTrustedTunnelNode(c *check.C) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(aux.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("two clusters do not see each other: tunnels are not working")
|
||||
|
@ -2182,7 +2183,7 @@ func (s *IntSuite) TestDiscovery(c *check.C) {
|
|||
waitForActiveTunnelConnections(c, secondProxy, "cluster-remote", 1)
|
||||
|
||||
// Requests going via main proxy should fail.
|
||||
output, err = runCommand(main, []string{"echo", "hello world"}, cfg, 1)
|
||||
_, err = runCommand(main, []string{"echo", "hello world"}, cfg, 1)
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
// Requests going via second proxy should succeed.
|
||||
|
@ -2337,7 +2338,7 @@ func (s *IntSuite) TestDiscoveryNode(c *check.C) {
|
|||
output, err = runCommand(main, []string{"echo", "hello world"}, cfg, 1)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(output, check.Equals, "hello world\n")
|
||||
output, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 1)
|
||||
_, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 1)
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
// Add second proxy to LB, both should have a connection.
|
||||
|
|
|
@ -158,6 +158,7 @@ func (s *KubeSuite) TestKubeExec(c *check.C) {
|
|||
KubeUsers: []string{"alice@example.com"},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
t.AddUserWithRole(username, role)
|
||||
|
||||
err = t.CreateEx(nil, tconf)
|
||||
|
@ -329,6 +330,7 @@ func (s *KubeSuite) TestKubeDeny(c *check.C) {
|
|||
KubeUsers: []string{"alice@example.com"},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
t.AddUserWithRole(username, role)
|
||||
|
||||
err = t.CreateEx(nil, tconf)
|
||||
|
@ -369,6 +371,7 @@ func (s *KubeSuite) TestKubePortForward(c *check.C) {
|
|||
KubeGroups: []string{teleport.KubeSystemMasters},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
t.AddUserWithRole(username, role)
|
||||
|
||||
err = t.CreateEx(nil, tconf)
|
||||
|
@ -386,6 +389,7 @@ func (s *KubeSuite) TestKubePortForward(c *check.C) {
|
|||
pods, err := s.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
|
||||
LabelSelector: kubeDNSLabels.AsSelector().String(),
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(len(pods.Items), check.Not(check.Equals), int(0))
|
||||
|
||||
pod := pods.Items[0]
|
||||
|
@ -468,6 +472,7 @@ func (s *KubeSuite) TestKubeTrustedClustersClientCert(c *check.C) {
|
|||
KubeGroups: []string{teleport.KubeSystemMasters},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
main.AddUserWithRole(username, mainRole)
|
||||
|
||||
clusterAux := "cluster-aux"
|
||||
|
@ -545,7 +550,7 @@ func (s *KubeSuite) TestKubeTrustedClustersClientCert(c *check.C) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(aux.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("two clusters do not see each other: tunnels are not working")
|
||||
|
@ -579,6 +584,7 @@ func (s *KubeSuite) TestKubeTrustedClustersClientCert(c *check.C) {
|
|||
pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
|
||||
LabelSelector: kubeDNSLabels.AsSelector().String(),
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(len(pods.Items), check.Not(check.Equals), int(0))
|
||||
|
||||
// Exec through proxy and collect output
|
||||
|
@ -730,6 +736,7 @@ func (s *KubeSuite) TestKubeTrustedClustersSNI(c *check.C) {
|
|||
KubeGroups: []string{teleport.KubeSystemMasters},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
main.AddUserWithRole(username, mainRole)
|
||||
|
||||
clusterAux := "cluster-aux"
|
||||
|
@ -811,7 +818,7 @@ func (s *KubeSuite) TestKubeTrustedClustersSNI(c *check.C) {
|
|||
|
||||
// wait for both sites to see each other via their reverse tunnels (for up to 10 seconds)
|
||||
abortTime := time.Now().Add(time.Second * 10)
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(main.Tunnel.GetSites()) < 2 {
|
||||
for len(main.Tunnel.GetSites()) < 2 && len(aux.Tunnel.GetSites()) < 2 {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
if time.Now().After(abortTime) {
|
||||
c.Fatalf("two clusters do not see each other: tunnels are not working")
|
||||
|
@ -840,6 +847,7 @@ func (s *KubeSuite) TestKubeTrustedClustersSNI(c *check.C) {
|
|||
pods, err := proxyClient.CoreV1().Pods(kubeSystemNamespace).List(metav1.ListOptions{
|
||||
LabelSelector: kubeDNSLabels.AsSelector().String(),
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(len(pods.Items), check.Not(check.Equals), int(0))
|
||||
|
||||
// Exec through proxy and collect output
|
||||
|
@ -1012,6 +1020,7 @@ func (s *KubeSuite) runKubeDisconnectTest(c *check.C, tc disconnectTestCase) {
|
|||
KubeGroups: []string{teleport.KubeSystemMasters},
|
||||
},
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
t.AddUserWithRole(username, role)
|
||||
|
||||
err = t.CreateEx(nil, tconf)
|
||||
|
|
|
@ -160,7 +160,7 @@ func (c *NodeCommand) Invite(client auth.ClientI) error {
|
|||
if err != nil {
|
||||
return trace.Wrap(err, "failed to marshal token")
|
||||
}
|
||||
fmt.Printf(string(out))
|
||||
fmt.Print(string(out))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ func (c *StatusCommand) Status(client auth.ClientI) error {
|
|||
table.AddRow([]string{"CA pin", caPin})
|
||||
return table.AsBuffer().String()
|
||||
}
|
||||
fmt.Printf(view())
|
||||
fmt.Print(view())
|
||||
|
||||
// in debug mode, output mode of remote certificate authorities
|
||||
if c.config.Debug {
|
||||
|
@ -123,7 +123,7 @@ func (c *StatusCommand) Status(client auth.ClientI) error {
|
|||
}
|
||||
return "Remote clusters\n\n" + table.AsBuffer().String()
|
||||
}
|
||||
fmt.Printf(view())
|
||||
fmt.Print(view())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -198,13 +198,13 @@ func (c *TokenCommand) List(client auth.ClientI) error {
|
|||
}
|
||||
return table.AsBuffer().String()
|
||||
}
|
||||
fmt.Printf(tokensView())
|
||||
fmt.Print(tokensView())
|
||||
} else {
|
||||
data, err := json.MarshalIndent(tokens, "", " ")
|
||||
if err != nil {
|
||||
return trace.Wrap(err, "failed to marshal tokens")
|
||||
}
|
||||
fmt.Printf(string(data))
|
||||
fmt.Print(string(data))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ func printTokenAsJSON(token services.ResetPasswordToken) error {
|
|||
if err != nil {
|
||||
return trace.Wrap(err, "failed to marshal reset password token")
|
||||
}
|
||||
fmt.Printf(string(out))
|
||||
fmt.Print(string(out))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ func (u *UserCommand) List(client auth.ClientI) error {
|
|||
if err != nil {
|
||||
return trace.Wrap(err, "failed to marshal users")
|
||||
}
|
||||
fmt.Printf(string(out))
|
||||
fmt.Print(string(out))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ func (s *MainTestSuite) TestRolesFlag(c *check.C) {
|
|||
c.Assert(conf.SSH.Enabled, check.Equals, true)
|
||||
c.Assert(conf.Auth.Enabled, check.Equals, false)
|
||||
c.Assert(conf.Proxy.Enabled, check.Equals, false)
|
||||
c.Assert(cmd, check.Equals, "start")
|
||||
|
||||
cmd, conf = Run(Options{
|
||||
Args: []string{"start", "--roles=proxy"},
|
||||
|
@ -95,6 +96,7 @@ func (s *MainTestSuite) TestRolesFlag(c *check.C) {
|
|||
c.Assert(conf.SSH.Enabled, check.Equals, false)
|
||||
c.Assert(conf.Auth.Enabled, check.Equals, false)
|
||||
c.Assert(conf.Proxy.Enabled, check.Equals, true)
|
||||
c.Assert(cmd, check.Equals, "start")
|
||||
|
||||
cmd, conf = Run(Options{
|
||||
Args: []string{"start", "--roles=auth"},
|
||||
|
|
|
@ -167,7 +167,7 @@ type CLIConf struct {
|
|||
|
||||
func main() {
|
||||
cmdLineOrig := os.Args[1:]
|
||||
cmdLine := []string{}
|
||||
var cmdLine []string
|
||||
|
||||
// lets see: if the executable name is 'ssh' or 'scp' we convert
|
||||
// that to "tsh ssh" or "tsh scp"
|
||||
|
|
Loading…
Reference in a new issue