-
Notifications
You must be signed in to change notification settings - Fork 19
EVEREST-1819 [CLI] Get rid of spf13/viper lib for parsing CLI params #1015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
847b6aa
EVEREST-1819 [CLI] Get rid of spf13/viper lib for parsing CLI params
maxkondr 2e13d4f
Merge branch 'main' into EVEREST-1819-main-remove-viper
maxkondr a81d8f8
Merge branch 'main' into EVEREST-1819-main-remove-viper
maxkondr ada34f0
EVEREST-1819 Fix formatting
maxkondr afad32f
Merge branch 'main' into EVEREST-1819-main-remove-viper
maxkondr ac83768
EVEREST-1819 Update dev helm chart
maxkondr 410de0b
Merge branch 'main' into EVEREST-1819-main-remove-viper
github-actions[bot] cc33632
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot b64c222
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot 4b636bf
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot d49b33c
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot 0970594
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot db433d7
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot bb01d9e
Merge branch 'main' into EVEREST-1819-main-remove-viper
maxkondr f6b7ca1
Merge branch 'main' into EVEREST-1819-main-remove-viper
percona-robot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,61 +1,68 @@ | ||
// everest | ||
// 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 accounts holds commands for accounts command. | ||
package accounts | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"go.uber.org/zap" | ||
|
||
"github.com/percona/everest/pkg/common" | ||
"github.com/percona/everest/pkg/kubernetes" | ||
accountscli "github.com/percona/everest/pkg/accounts/cli" | ||
"github.com/percona/everest/pkg/cli" | ||
"github.com/percona/everest/pkg/logger" | ||
) | ||
|
||
// NewInitialAdminPasswdCommand returns a new initial-admin-passwd command. | ||
func NewInitialAdminPasswdCommand(l *zap.SugaredLogger) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "initial-admin-password", | ||
var ( | ||
accountsInitAdminPasswdCmd = &cobra.Command{ | ||
Use: "initial-admin-password [flags]", | ||
Args: cobra.NoArgs, | ||
Example: "everestctl accounts initial-admin-password", | ||
Long: "Get the initial admin password for Everest", | ||
Short: "Get the initial admin password for Everest", | ||
Run: func(cmd *cobra.Command, args []string) { //nolint:revive | ||
viper.BindEnv("kubeconfig") //nolint:errcheck,gosec | ||
viper.BindPFlag("kubeconfig", cmd.Flags().Lookup("kubeconfig")) //nolint:errcheck,gosec | ||
kubeconfigPath := viper.GetString("kubeconfig") | ||
|
||
k, err := kubernetes.New(kubeconfigPath, l) | ||
if err != nil { | ||
var u *url.Error | ||
l.Error("Could not connect to Kubernetes. " + | ||
"Make sure Kubernetes is running and is accessible from this computer/server.") | ||
if !errors.As(err, &u) { | ||
l.Error(err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
ctx := context.Background() | ||
secure, err := k.Accounts().IsSecure(ctx, common.EverestAdminUser) | ||
if err != nil { | ||
l.Error(err) | ||
os.Exit(1) | ||
} | ||
if secure { | ||
l.Error("Cannot retrieve admin password after it has been updated.") | ||
os.Exit(1) | ||
} | ||
admin, err := k.Accounts().Get(ctx, common.EverestAdminUser) | ||
if err != nil { | ||
l.Error(err) | ||
os.Exit(1) | ||
} | ||
fmt.Fprint(os.Stdout, admin.PasswordHash+"\n") | ||
}, | ||
PreRun: accountsInitAdminPasswdPreRun, | ||
Run: accountsInitAdminPasswdRun, | ||
} | ||
accountsInitAdminPasswdCfg = &accountscli.Config{} | ||
) | ||
|
||
func accountsInitAdminPasswdPreRun(cmd *cobra.Command, _ []string) { //nolint:revive | ||
// Copy global flags to config | ||
accountsInitAdminPasswdCfg.Pretty = !(cmd.Flag(cli.FlagVerbose).Changed || cmd.Flag(cli.FlagJSON).Changed) | ||
accountsInitAdminPasswdCfg.KubeconfigPath = cmd.Flag(cli.FlagKubeconfig).Value.String() | ||
} | ||
|
||
func accountsInitAdminPasswdRun(cmd *cobra.Command, _ []string) { //nolint:revive | ||
cliA, err := accountscli.NewAccounts(*accountsInitAdminPasswdCfg, logger.GetLogger()) | ||
if err != nil { | ||
logger.GetLogger().Error(err) | ||
os.Exit(1) | ||
} | ||
return cmd | ||
|
||
passwordHash, err := cliA.GetInitAdminPassword(cmd.Context()) | ||
if err != nil { | ||
logger.GetLogger().Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
_, _ = fmt.Fprint(os.Stdout, passwordHash+"\n") | ||
} | ||
|
||
// GetInitAdminPasswordCmd returns the command to get the initial admin password. | ||
func GetInitAdminPasswordCmd() *cobra.Command { | ||
return accountsInitAdminPasswdCmd | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.