Skip to content

Commit 6bc5ad3

Browse files
committed
fix naming
1 parent 14aa81d commit 6bc5ad3

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

cmd/atlas/atlas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func execute(rootCmd *cobra.Command) {
3737
3838
To learn more, see our documentation: https://www.mongodb.com/docs/atlas/cli/stable/connect-atlas-cli/`
3939
if cmd, err := rootCmd.ExecuteContextC(ctx); err != nil {
40-
errMsg := commonerrors.CheckHTTPError(err)
40+
errMsg := commonerrors.CheckHTTPErrors(err)
4141
if errMsg != nil {
4242
fmt.Println(errMsg)
4343
}

internal/cli/commonerrors/errors.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ var (
2525
errClusterUnsupported = errors.New("atlas supports this command only for M10+ clusters. You can upgrade your cluster by running the 'atlas cluster upgrade' command")
2626
errOutsideVPN = errors.New("forbidden action outside access allow list, if you are a MongoDB employee double check your VPN connection")
2727
errAsymmetricShardUnsupported = errors.New("trying to run a cluster wide scaling command on an independent shard scaling cluster. Use --autoScalingMode 'independentShardScaling' instead")
28-
errUnauthorized = errors.New(`this action requires authentication
28+
ErrUnauthorized = errors.New(`this action requires authentication
2929
30-
To log in using your Atlas username and password or to set credentials using API key, run: atlas auth login`)
30+
To log in using your Atlas username and password, run: atlas auth login
31+
To set credentials using API keys, run: atlas config init`)
3132
)
3233

3334
const (
@@ -53,9 +54,9 @@ func Check(err error) error {
5354
return err
5455
}
5556

56-
func CheckHTTPError(err error) error {
57+
func CheckHTTPErrors(err error) error {
5758
if strings.Contains(err.Error(), "401") && strings.Contains(err.Error(), "Unauthorized") {
58-
return errUnauthorized
59+
return ErrUnauthorized
5960
}
6061
return nil
6162
}

internal/cli/commonerrors/errors_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestCheck(t *testing.T) {
6868
}
6969
}
7070

71-
func TestCheckCommonErrors(t *testing.T) {
71+
func TestCheckHTTPErrors(t *testing.T) {
7272
dummyErr := errors.New("dummy error")
7373
testErr := errors.New(`Error: https://cloud.mongodb.com/api/atlas/v2/groups/670e34d35a4f587387db2102/clusters GET: HTTP 401 Unauthorized (Error code: "") Detail: You are not authorized for this resource. Reason: Unauthorized. Params: []`)
7474

@@ -80,7 +80,7 @@ func TestCheckCommonErrors(t *testing.T) {
8080
{
8181
name: "unauthorized error",
8282
err: testErr,
83-
want: errUnauthorized,
83+
want: ErrUnauthorized,
8484
},
8585
{
8686
name: "arbitrary error",
@@ -91,8 +91,8 @@ func TestCheckCommonErrors(t *testing.T) {
9191

9292
for _, tc := range testCases {
9393
t.Run(tc.name, func(t *testing.T) {
94-
if got := CheckHTTPError(tc.err); !errors.Is(got, tc.want) {
95-
t.Errorf("CheckHTTPError(%v) = %v, want %v", tc.err, got, tc.want)
94+
if got := CheckHTTPErrors(tc.err); !errors.Is(got, tc.want) {
95+
t.Errorf("CheckHTTPErrors(%v) = %v, want %v", tc.err, got, tc.want)
9696
}
9797
})
9898
}

internal/validate/validate.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"slices"
2525
"strings"
2626

27+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/commonerrors"
2728
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
2829
)
2930

@@ -95,8 +96,6 @@ func ObjectID(s string) error {
9596
return nil
9697
}
9798

98-
var ErrMissingCredentials = errors.New("this action requires authentication")
99-
10099
// Credentials validates public and private API keys have been set.
101100
func Credentials() error {
102101
if t, err := config.Token(); t != nil {
@@ -106,13 +105,7 @@ func Credentials() error {
106105
return nil
107106
}
108107

109-
return fmt.Errorf(
110-
`%w
111-
112-
To log in using your Atlas username and password, run: atlas auth login
113-
To set credentials using API keys, run: atlas config init`,
114-
ErrMissingCredentials,
115-
)
108+
return commonerrors.ErrUnauthorized
116109
}
117110

118111
var ErrAlreadyAuthenticatedAPIKeys = errors.New("already authenticated with an API key")

0 commit comments

Comments
 (0)