Skip to content

Commit

Permalink
chore: delete unused OAuth support for direct Kubernetes communication (
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Nov 6, 2024
1 parent fd4b475 commit 8b26e37
Show file tree
Hide file tree
Showing 15 changed files with 2 additions and 312 deletions.
10 changes: 0 additions & 10 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import (
"github.com/kubeshop/testkube/cmd/api-server/commons"
"github.com/kubeshop/testkube/cmd/api-server/services"
"github.com/kubeshop/testkube/internal/app/api/debug"
"github.com/kubeshop/testkube/internal/app/api/oauth"
cloudartifacts "github.com/kubeshop/testkube/pkg/cloud/data/artifact"
cloudtestworkflow "github.com/kubeshop/testkube/pkg/cloud/data/testworkflow"
"github.com/kubeshop/testkube/pkg/event/kind/cdevent"
"github.com/kubeshop/testkube/pkg/event/kind/k8sevent"
"github.com/kubeshop/testkube/pkg/event/kind/webhook"
ws "github.com/kubeshop/testkube/pkg/event/kind/websocket"
"github.com/kubeshop/testkube/pkg/executor/output"
oauth2 "github.com/kubeshop/testkube/pkg/oauth"
"github.com/kubeshop/testkube/pkg/secretmanager"
"github.com/kubeshop/testkube/pkg/server"
"github.com/kubeshop/testkube/pkg/tcl/checktcl"
Expand Down Expand Up @@ -276,14 +274,6 @@ func main() {
httpServer := server.NewServer(server.Config{Port: cfg.APIServerPort})
httpServer.Routes.Use(cors.New())

// Handle OAuth TODO: deprecated?
httpServer.Routes.Use(oauth.CreateOAuthHandler(oauth.OauthParams{
ClientID: cfg.TestkubeOAuthClientID,
ClientSecret: cfg.TestkubeOAuthClientSecret,
Provider: oauth2.ProviderType(cfg.TestkubeOAuthProvider),
Scopes: cfg.TestkubeOAuthScopes,
}))

if deprecatedSystem != nil && deprecatedSystem.API != nil {
deprecatedSystem.API.Init(httpServer)
}
Expand Down
31 changes: 2 additions & 29 deletions cmd/kubectl-testkube/commands/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package common

import (
"context"
"errors"
"fmt"
"os"
"runtime"
"strconv"

"github.com/spf13/cobra"
"golang.org/x/oauth2"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/api/v1/client"
Expand All @@ -23,10 +20,6 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {
clientType := cmd.Flag("client").Value.String()
namespace := cmd.Flag("namespace").Value.String()
apiURI := cmd.Flag("api-uri").Value.String()
oauthEnabled, err := strconv.ParseBool(cmd.Flag("oauth-enabled").Value.String())
if err != nil {
return nil, "", fmt.Errorf("parsing flag value %w", err)
}

insecure, err := strconv.ParseBool(cmd.Flag("insecure").Value.String())
if err != nil {
Expand Down Expand Up @@ -71,30 +64,10 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {
options.APIServerName = cfg.APIServerName
options.APIServerPort = cfg.APIServerPort

switch cfg.ContextType {
case config.ContextTypeKubeconfig:
if oauthEnabled {
options.Provider = cfg.OAuth2Data.Provider
options.ClientID = cfg.OAuth2Data.ClientID
options.ClientSecret = cfg.OAuth2Data.ClientSecret
options.Scopes = cfg.OAuth2Data.Scopes
options.Token = cfg.OAuth2Data.Token

if os.Getenv("TESTKUBE_OAUTH_ACCESS_TOKEN") != "" {
options.Token = &oauth2.Token{
AccessToken: os.Getenv("TESTKUBE_OAUTH_ACCESS_TOKEN"),
}
}

if options.Token == nil {
return nil, "", errors.New("oauth token is empty, please configure your oauth settings first")
}
}
case config.ContextTypeCloud:

if cfg.ContextType == config.ContextTypeCloud {
token := cfg.CloudContext.ApiKey

if cfg.CloudContext.ApiKey != "" && cfg.CloudContext.RefreshToken != "" && cfg.OAuth2Data.Enabled {
if cfg.CloudContext.ApiKey != "" && cfg.CloudContext.RefreshToken != "" {
var refreshToken string
authURI := fmt.Sprintf("%s/idp", cfg.CloudContext.ApiUri)
token, refreshToken, err = cloudlogin.CheckAndRefreshToken(context.Background(), authURI, cfg.CloudContext.ApiKey, cfg.CloudContext.RefreshToken)
Expand Down
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
commands "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/config"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/oauth"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand All @@ -30,7 +29,6 @@ func NewConfigCmd() *cobra.Command {
cmd.AddCommand(commands.NewConfigureNamespaceCmd())
cmd.AddCommand(commands.NewConfigureAPIURICmd())
cmd.AddCommand(commands.NewConfigureHeadersCmd())
cmd.AddCommand(oauth.NewConfigureOAuthCmd())
cmd.AddCommand(commands.NewConfigureAPIServerNameCmd())
cmd.AddCommand(commands.NewConfigureAPIServerPortCmd())

Expand Down
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"github.com/spf13/cobra"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/oauth"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/telemetry"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand All @@ -20,7 +19,6 @@ func NewDisableCmd() *cobra.Command {
}

cmd.AddCommand(telemetry.NewDisableTelemetryCmd())
cmd.AddCommand(oauth.NewDisableOAuthCmd())

return cmd
}
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"github.com/spf13/cobra"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/oauth"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/telemetry"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand All @@ -20,7 +19,6 @@ func NewEnableCmd() *cobra.Command {
}

cmd.AddCommand(telemetry.NewEnableTelemetryCmd())
cmd.AddCommand(oauth.NewEnableOAuthCmd())

return cmd
}
78 changes: 0 additions & 78 deletions cmd/kubectl-testkube/commands/oauth/config.go

This file was deleted.

35 changes: 0 additions & 35 deletions cmd/kubectl-testkube/commands/oauth/disable.go

This file was deleted.

34 changes: 0 additions & 34 deletions cmd/kubectl-testkube/commands/oauth/enable.go

This file was deleted.

31 changes: 0 additions & 31 deletions cmd/kubectl-testkube/commands/oauth/status.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/kubectl-testkube/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func Execute() {
RootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "", defaultNamespace, "Kubernetes namespace, default value read from config if set")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false, "show additional debug messages")
RootCmd.PersistentFlags().StringVarP(&apiURI, "api-uri", "a", apiURI, "api uri, default value read from config if set")
RootCmd.PersistentFlags().BoolVarP(&oauthEnabled, "oauth-enabled", "", cfg.OAuth2Data.Enabled, "enable oauth")
RootCmd.PersistentFlags().BoolVarP(&insecure, "insecure", "", false, "insecure connection for direct client")
RootCmd.PersistentFlags().StringToStringVarP(&headers, "header", "", cfg.Headers, "headers for direct client key value pair: --header name=value")

Expand Down
7 changes: 0 additions & 7 deletions cmd/kubectl-testkube/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/oauth"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/telemetry"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/ui"
Expand Down Expand Up @@ -39,17 +38,11 @@ func NewStatusCmd() *cobra.Command {
ui.PrintDisabled("Telemetry on API", "disabled")
}

if cfg.OAuth2Data.Enabled {
ui.PrintEnabled("OAuth", "enabled")
} else {
ui.PrintDisabled("Oauth", "disabled")
}
ui.NL()
},
}

cmd.AddCommand(telemetry.NewStatusTelemetryCmd())
cmd.AddCommand(oauth.NewStatusOAuthCmd())

return cmd
}
27 changes: 0 additions & 27 deletions cmd/kubectl-testkube/config/data.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package config

import (
"golang.org/x/oauth2"

"github.com/kubeshop/testkube/pkg/oauth"
)

type ContextType string

const (
Expand Down Expand Up @@ -43,7 +37,6 @@ type Data struct {
APIServerPort int `json:"apiServerPort,omitempty"`
DashboardName string `json:"dashboardName,omitempty"`
DashboardPort int `json:"dashboardPort,omitempty"`
OAuth2Data OAuth2Data `json:"oauth2Data"`

ContextType ContextType `json:"contextType,omitempty"`
CloudContext CloudContext `json:"cloudContext,omitempty"`
Expand All @@ -65,23 +58,3 @@ func (c *Data) SetNamespace(ns string) {
func (c *Data) SetInitialized() {
c.Initialized = true
}

// OAuth2Data contains oauth credentials
type OAuth2Data struct {
Enabled bool `json:"enabled,omitempty"`
Token *oauth2.Token `json:"token,omitempty"`
ClientID string `json:"clientID,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
Provider oauth.ProviderType `json:"providerType,omitempty"`
Scopes []string `json:"scopes"`
}

// EnableOAuth is oauth enable method
func (c *Data) EnableOAuth() {
c.OAuth2Data.Enabled = true
}

// DisableOauth is oauth disable method
func (c *Data) DisableOauth() {
c.OAuth2Data.Enabled = false
}
Loading

0 comments on commit 8b26e37

Please sign in to comment.