This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVEREST-593: Support for password reset (#221)
- Generate password during installation
- Loading branch information
Michal Kralik
authored
Nov 28, 2023
1 parent
f86629d
commit a9add28
Showing
10 changed files
with
294 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// percona-everest-cli | ||
// Copyright (C) 2023 Percona LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package commands ... | ||
package commands | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
|
||
"github.com/percona/percona-everest-cli/commands/password" | ||
) | ||
|
||
func newPasswordCmd(l *zap.SugaredLogger) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "password", | ||
} | ||
|
||
cmd.AddCommand(password.NewResetCmd(l)) | ||
|
||
return cmd | ||
} |
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,78 @@ | ||
// percona-everest-cli | ||
// Copyright (C) 2023 Percona LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package password holds commands for password command. | ||
package password | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"go.uber.org/zap" | ||
|
||
"github.com/percona/percona-everest-cli/pkg/output" | ||
"github.com/percona/percona-everest-cli/pkg/password" | ||
) | ||
|
||
// NewResetCmd returns a new versions command. | ||
func NewResetCmd(l *zap.SugaredLogger) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "reset", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
initResetViperFlags(cmd) | ||
|
||
c, err := parseResetConfig() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
command, err := password.NewReset(*c, l) | ||
if err != nil { | ||
output.PrintError(err, l) | ||
os.Exit(1) | ||
} | ||
|
||
res, err := command.Run(cmd.Context()) | ||
if err != nil { | ||
output.PrintError(err, l) | ||
os.Exit(1) | ||
} | ||
|
||
output.PrintOutput(cmd, l, res) | ||
}, | ||
} | ||
|
||
initResetFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func initResetFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringP("kubeconfig", "k", "~/.kube/config", "Path to a kubeconfig") | ||
cmd.Flags().String("namespace", "percona-everest", "Namespace where Percona Everest is deployed") | ||
} | ||
|
||
func initResetViperFlags(cmd *cobra.Command) { | ||
viper.BindEnv("kubeconfig") //nolint:errcheck,gosec | ||
viper.BindPFlag("kubeconfig", cmd.Flags().Lookup("kubeconfig")) //nolint:errcheck,gosec | ||
viper.BindPFlag("namespace", cmd.Flags().Lookup("namespace")) //nolint:errcheck,gosec | ||
} | ||
|
||
func parseResetConfig() (*password.ResetConfig, error) { | ||
c := &password.ResetConfig{} | ||
err := viper.Unmarshal(c) | ||
return c, err | ||
} |
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
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
Oops, something went wrong.