Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

EVEREST-526: Add support for authentication #193

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 1 addition & 4 deletions commands/delete/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package delete //nolint:predeclared

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -41,13 +39,12 @@ func NewClusterCmd(l *zap.SugaredLogger) *cobra.Command {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
everestClConnector, err := everestClient.NewEverestFromURL(cmd.Context(), c.Everest.Endpoint)
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
op, err := delete.NewCluster(*c, everestClConnector, l)
if err != nil {
l.Error(err)
Expand Down
6 changes: 1 addition & 5 deletions commands/delete/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package delete //nolint:predeclared

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -42,15 +40,13 @@ func NewMySQLCmd(l *zap.SugaredLogger) *cobra.Command {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
everestClConnector, err := everestClient.NewEverestFromURL(cmd.Context(), c.Everest.Endpoint)
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
command := delete.NewMySQL(*c, everestClConnector, l)

if err := command.Run(cmd.Context()); err != nil {
output.PrintError(err, l)
os.Exit(1)
Expand Down
5 changes: 1 addition & 4 deletions commands/list/database_engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package list

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -43,13 +41,12 @@ func NewDatabaseEnginesCmd(l *zap.SugaredLogger) *cobra.Command {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
everestClConnector, err := everestClient.NewEverestFromURL(cmd.Context(), c.Everest.Endpoint)
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
command := list.NewDatabaseEngines(*c, everestClConnector, l)
dbEngines, err := command.Run(cmd.Context())
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions commands/list/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package list

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -43,13 +41,12 @@ func NewVersionsCmd(l *zap.SugaredLogger) *cobra.Command {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
everestClConnector, err := everestClient.NewEverestFromURL(cmd.Context(), c.Everest.Endpoint)
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
command := list.NewVersions(*c, everestClConnector, l)
res, err := command.Run(cmd.Context())
if err != nil {
Expand Down
79 changes: 79 additions & 0 deletions commands/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"

everestClient "github.com/percona/percona-everest-cli/pkg/everest/client"
"github.com/percona/percona-everest-cli/pkg/login"
"github.com/percona/percona-everest-cli/pkg/output"
)

// newLoginCmd returns a new login command.
func newLoginCmd(l *zap.SugaredLogger) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Run: func(cmd *cobra.Command, args []string) {
initLoginViperFlags(cmd)

c, err := parseLoginConfig()
if err != nil {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
command := login.NewLogin(*c, everestClConnector, l)
if err := command.Run(cmd.Context()); err != nil {
output.PrintError(err, l)
os.Exit(1)
}
},
}

initLoginFlags(cmd)

return cmd
}

func initLoginFlags(cmd *cobra.Command) {
cmd.Flags().String("everest.endpoint", "http://127.0.0.1:8080", "Everest endpoint URL")
cmd.Flags().String("personal-access-token", "", "Personal access token (PAT) to be used for login")
cmd.MarkFlagRequired("personal-access-token") //nolint:errcheck,gosec
}

func initLoginViperFlags(cmd *cobra.Command) {
viper.BindPFlag("everest.endpoint", cmd.Flags().Lookup("everest.endpoint")) //nolint:errcheck,gosec
viper.BindPFlag("personal-access-token", cmd.Flags().Lookup("personal-access-token")) //nolint:errcheck,gosec
}

func parseLoginConfig() (*login.LoginConfig, error) {
c := &login.LoginConfig{}
err := viper.Unmarshal(c)
return c, err
}
5 changes: 1 addition & 4 deletions commands/provision/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package provision

import (
"fmt"
"os"

"github.com/percona/percona-everest-backend/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
Expand All @@ -42,13 +40,12 @@ func NewMySQLCmd(l *zap.SugaredLogger) *cobra.Command {
os.Exit(1)
}

everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint))
everestClConnector, err := everestClient.NewEverestFromURL(cmd.Context(), c.Everest.Endpoint)
if err != nil {
l.Error(err)
os.Exit(1)
}

everestClConnector := everestClient.NewEverest(everestCl)
command := provision.NewMySQL(*c, everestClConnector, l)

if err := command.Run(cmd.Context()); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func NewRootCmd(l *zap.SugaredLogger) *cobra.Command {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose mode")
rootCmd.PersistentFlags().Bool("json", false, "Set output type to JSON")

rootCmd.AddCommand(newLoginCmd(l))

rootCmd.AddCommand(newInstallCmd(l))
// rootCmd.AddCommand(newProvisionCmd(l))
// rootCmd.AddCommand(newListCmd(l))
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/zitadel/oidc/v2 v2.11.0
go.uber.org/zap v1.26.0
golang.org/x/oauth2 v0.12.0
golang.org/x/sync v0.4.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
Expand Down Expand Up @@ -53,6 +55,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/h2non/filetype v1.1.1 // indirect
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -72,6 +75,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/onsi/gomega v1.27.10 // indirect
Expand All @@ -95,9 +99,9 @@ require (
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand All @@ -108,6 +112,7 @@ require (
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230816210353-14e408962443 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down Expand Up @@ -669,6 +671,8 @@ github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/muhlemmer/gu v0.3.1 h1:7EAqmFrW7n3hETvuAdmFmn4hS8W+z3LgKtrnow+YzNM=
github.com/muhlemmer/gu v0.3.1/go.mod h1:YHtHR+gxM+bKEIIs7Hmi9sPT3ZDUvTN/i88wQpZkrdM=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
Expand Down Expand Up @@ -903,6 +907,8 @@ github.com/yvasiyarov/gorelic v0.0.7 h1:4DTF1WOM2ZZS/xMOkTFBOcb6XiHu/PKn3rVo6dbe
github.com/yvasiyarov/gorelic v0.0.7/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA=
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20160601141957-9c099fbc30e9 h1:AsFN8kXcCVkUFHyuzp1FtYbzp1nCO/H6+1uPSGEyPzM=
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20160601141957-9c099fbc30e9/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg=
github.com/zitadel/oidc/v2 v2.11.0 h1:Am4/yQr4iiM5bznRgF3FOp+wLdKx2gzSU73uyI9vvBE=
github.com/zitadel/oidc/v2 v2.11.0/go.mod h1:enFSVBQI6aE0TEB1ntjXs9r6O6DEosxX4uhEBLBVD8o=
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down Expand Up @@ -968,6 +974,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1408,6 +1416,8 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
Expand Down
Loading
Loading