Skip to content

Commit 92c385d

Browse files
authored
fix(cli): avoid auth for completion cmds (#1183)
Closes #1182 Signed-off-by: Salim Afiune Maya <[email protected]>
1 parent 5c2f8bc commit 92c385d

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

cli/cmd/root.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ func cliPersistentPreRun(cmd *cobra.Command, args []string) error {
8888
case "help [command]", "configure", "version", "docs <directory>", "generate-pkg-manifest":
8989
return nil
9090
default:
91-
// @afiune no need to create a client for any configure command
92-
if cmd.HasParent() && cmd.Parent().Use == "configure" {
93-
return nil
91+
if cmd.HasParent() {
92+
switch cmd.Parent().Use {
93+
case "configure", "completion":
94+
// @afiune no need to create a client for any configure
95+
// command or any completion command
96+
return nil
97+
}
9498
}
9599
if err := cli.NewClient(); err != nil {
96100
if !strings.Contains(err.Error(), "Invalid Account") {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build !windows
2+
3+
//
4+
// Author:: Salim Afiune Maya (<[email protected]>)
5+
// Copyright:: Copyright 2023, Lacework Inc.
6+
// License:: Apache License, Version 2.0
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
21+
package integration
22+
23+
import (
24+
"testing"
25+
26+
"github.com/stretchr/testify/assert"
27+
)
28+
29+
func TestCompletionCommandNoAuth(t *testing.T) {
30+
// running the Lacework CLI without toml config, which means no auth
31+
_, err, exitcode := LaceworkCLI("completion", "bash")
32+
assert.Empty(t, err.String(), "STDERR should be empty")
33+
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build windows
2+
3+
//
4+
// Author:: Salim Afiune Maya (<[email protected]>)
5+
// Copyright:: Copyright 2023, Lacework Inc.
6+
// License:: Apache License, Version 2.0
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
21+
package integration
22+
23+
import (
24+
"testing"
25+
26+
"github.com/stretchr/testify/assert"
27+
)
28+
29+
func TestCompletionCommandNoAuth(t *testing.T) {
30+
// running the Lacework CLI without toml config, which means no auth
31+
_, err, exitcode := LaceworkCLI("completion", "powershell")
32+
assert.Empty(t, err.String(), "STDERR should be empty")
33+
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
34+
}

0 commit comments

Comments
 (0)