Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

PMM-4743 Allow to pass password individually. #71

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion commands/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ func (e errFromNginx) GoString() string {
}

// SetupClients configures local and PMM Server API clients.
func SetupClients(ctx context.Context, serverURL string) {
func SetupClients(ctx context.Context, serverURL, serverUsername, serverPassword string, serverInsecureTLS bool) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golangci-lint] reported by reviewdog 🐶
Function 'SetupClients' is too long (93 > 60) (funlen)

agentlocal.SetTransport(ctx, GlobalFlags.Debug || GlobalFlags.Trace)

// set server URL
if serverURL == "" {
status, err := agentlocal.GetStatus(agentlocal.DoNotRequestNetworkInfo)
if err != nil {
Expand Down Expand Up @@ -189,6 +190,29 @@ func SetupClients(ctx context.Context, serverURL string) {
}
}

// override username, password, insecure-tls if given
if serverUsername != "" || serverPassword != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golangci-lint] reported by reviewdog 🐶
if serverUsername != "" || serverPassword != "" is deeply nested (complexity: 5) (nestif)

var newUsername, newPassword string
if GlobalFlags.ServerURL.User != nil {
newUsername = GlobalFlags.ServerURL.User.Username()
newPassword, _ = GlobalFlags.ServerURL.User.Password()
}
if serverUsername != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golangci-lint] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)

newUsername = serverUsername
}
if serverPassword != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golangci-lint] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)

newPassword = serverPassword
}
if newPassword != "" {
GlobalFlags.ServerURL.User = url.UserPassword(newUsername, newPassword)
} else {
GlobalFlags.ServerURL.User = url.User(newUsername)
}
}
if serverInsecureTLS {
GlobalFlags.ServerInsecureTLS = true
}

// use JSON APIs over HTTP/1.1
transport := httptransport.New(GlobalFlags.ServerURL.Host, GlobalFlags.ServerURL.Path, []string{GlobalFlags.ServerURL.Scheme})
if u := GlobalFlags.ServerURL.User; u != nil {
Expand Down
7 changes: 6 additions & 1 deletion commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type configCommand struct {
Region string
Az string

Force bool
Force bool
DontStorePassword bool
}

func (cmd *configCommand) args() (res []string, switchedToTLS bool) {
Expand Down Expand Up @@ -98,6 +99,9 @@ func (cmd *configCommand) args() (res []string, switchedToTLS bool) {
if cmd.Force {
res = append(res, "--force")
}
if cmd.DontStorePassword {
res = append(res, "--dont-store-password")
}
res = append(res, cmd.NodeAddress, cmd.NodeType, cmd.NodeName)
return //nolint:nakedret
}
Expand Down Expand Up @@ -148,4 +152,5 @@ func init() {
ConfigC.Flag("az", "Node availability zone").StringVar(&Config.Az)

ConfigC.Flag("force", "Remove Node with that name with all dependent Services and Agents if one exist").BoolVar(&Config.Force)
ConfigC.Flag("dont-store-password", "Do not store password in configuration file").BoolVar(&Config.DontStorePassword)
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func main() {
kingpin.CommandLine.UsageTemplate(commands.UsageTemplate)

serverURLF := kingpin.Flag("server-url", "PMM Server URL in `https://username:password@pmm-server-host/` format").String()
kingpin.Flag("server-insecure-tls", "Skip PMM Server TLS certificate validation").BoolVar(&commands.GlobalFlags.ServerInsecureTLS)
serverUsernameF := kingpin.Flag("server-username", "Username to connect to PMM Server").String()
serverPasswordF := kingpin.Flag("server-password", "Password to connect to PMM Server").String()
serverInsecureTLS := kingpin.Flag("server-insecure-tls", "Skip PMM Server TLS certificate validation").Bool()
kingpin.Flag("debug", "Enable debug logging").BoolVar(&commands.GlobalFlags.Debug)
kingpin.Flag("trace", "Enable trace logging (implies debug)").BoolVar(&commands.GlobalFlags.Trace)
jsonF := kingpin.Flag("json", "Enable JSON output").Bool()
Expand Down Expand Up @@ -73,7 +75,7 @@ func main() {
cancel()
}()

commands.SetupClients(ctx, *serverURLF)
commands.SetupClients(ctx, *serverURLF, *serverUsernameF, *serverPasswordF, *serverInsecureTLS)

allCommands := map[string]commands.Command{
management.RegisterC.FullCommand(): management.Register,
Expand Down