-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1325 from alenkacz/av/rpk-logout
rpk cloud logout
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 Vectorized, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package cloud | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
"github.com/vectorizedio/redpanda/src/go/rpk/pkg/vcloud/config" | ||
) | ||
|
||
func NewLogoutCommand(fs afero.Fs) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "logout", | ||
Short: "Logout from vectorized cloud", | ||
Long: `If there's a token stored locally after you've logged in, it will be wiped out.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configRW := config.NewVCloudConfigReaderWriter(fs) | ||
// write an empty string to the config | ||
err := configRW.WriteToken("") | ||
if err != nil { | ||
log.Info("Error while logging out:") | ||
return err | ||
} | ||
log.Info("Logged out!") | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 Vectorized, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package cloud_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/require" | ||
"github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/cloud" | ||
"github.com/vectorizedio/redpanda/src/go/rpk/pkg/vcloud/config" | ||
) | ||
|
||
func TestLogout(t *testing.T) { | ||
fs := afero.NewMemMapFs() | ||
configRW := config.NewVCloudConfigReaderWriter(fs) | ||
err := configRW.WriteToken("xxx") | ||
require.NoError(t, err) | ||
|
||
cmd := cloud.NewLogoutCommand(fs) | ||
err = cmd.Execute() | ||
require.NoError(t, err) | ||
|
||
token, err := configRW.ReadToken() | ||
require.NoError(t, err) | ||
if token != "" { | ||
t.Fatalf("Expecting empty token after logout called, got %s", token) | ||
} | ||
} |