Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Zarytovsky <[email protected]>
  • Loading branch information
asviel committed Mar 7, 2024
1 parent 86e8b7a commit b5e56e4
Show file tree
Hide file tree
Showing 8 changed files with 962 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# vim
*.swp

# IDE
.project
.settings
.idea/
.vscode
venv/
out/

# macOS Finder files
*.DS_Store
._*

# Dev environment
bin/

d8
build/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Deckhouse Client

Deckhouse Client (d8) is a command-line client for Deckhouse.
25 changes: 25 additions & 0 deletions cmd/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"math/rand"
"time"

cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
kubecmd "k8s.io/kubectl/pkg/cmd"
)

func init() {
rand.Seed(time.Now().UnixNano())

kubectlCmd := kubecmd.NewDefaultKubectlCommand()
kubectlCmd.Use = "k"
kubectlCmd.Aliases = []string{"kubectl"}

logs.InitLogs()
defer logs.FlushLogs()
kubectlCmd.SetGlobalNormalizationFunc(cliflag.WordSepNormalizeFunc)
logs.AddFlags(kubectlCmd.PersistentFlags())

rootCmd.AddCommand(kubectlCmd)
}
134 changes: 134 additions & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package cmd

import (
"os"

kubelogincmd "github.com/int128/kubelogin/pkg/cmd"
writer2 "github.com/int128/kubelogin/pkg/credentialplugin/writer"
"github.com/int128/kubelogin/pkg/infrastructure/browser"
"github.com/int128/kubelogin/pkg/infrastructure/clock"
"github.com/int128/kubelogin/pkg/infrastructure/logger"
"github.com/int128/kubelogin/pkg/infrastructure/mutex"
"github.com/int128/kubelogin/pkg/infrastructure/reader"
"github.com/int128/kubelogin/pkg/oidc/client"
"github.com/int128/kubelogin/pkg/tlsclientconfig/loader"
"github.com/int128/kubelogin/pkg/tokencache/repository"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"github.com/int128/kubelogin/pkg/usecases/authentication/authcode"
"github.com/int128/kubelogin/pkg/usecases/authentication/devicecode"
"github.com/int128/kubelogin/pkg/usecases/authentication/ropc"
"github.com/int128/kubelogin/pkg/usecases/credentialplugin"
"github.com/int128/kubelogin/pkg/usecases/standalone"

"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)

func getKubeloginCmd() *kubelogincmd.Cmd {
clockReal := &clock.Real{}
loggerInterface := logger.New()
browserBrowser := &browser.Browser{}

factory := &client.Factory{
Loader: loader.Loader{},
Clock: clockReal,
Logger: loggerInterface,
}
authcodeBrowser := &authcode.Browser{
Browser: browserBrowser,
Logger: loggerInterface,
}
readerReader := &reader.Reader{
Stdin: os.Stdin,
}
keyboard := &authcode.Keyboard{
Reader: readerReader,
Logger: loggerInterface,
}
ropcROPC := &ropc.ROPC{
Reader: readerReader,
Logger: loggerInterface,
}
deviceCode := &devicecode.DeviceCode{
Browser: browserBrowser,
Logger: loggerInterface,
}
authenticationAuthentication := &authentication.Authentication{
ClientFactory: factory,
Logger: loggerInterface,
Clock: clockReal,
AuthCodeBrowser: authcodeBrowser,
AuthCodeKeyboard: keyboard,
ROPC: ropcROPC,
DeviceCode: deviceCode,
}

root := &kubelogincmd.Root{
Standalone: &standalone.Standalone{},
Logger: loggerInterface,
}
getToken := &credentialplugin.GetToken{
Authentication: authenticationAuthentication,
TokenCacheRepository: &repository.Repository{},
Writer: &writer2.Writer{
Stdout: os.Stdout,
},
Mutex: &mutex.Mutex{
Logger: loggerInterface,
},
Logger: loggerInterface,
}
cmdGetToken := &kubelogincmd.GetToken{
GetToken: getToken,
Logger: loggerInterface,
}
cmdCmd := &kubelogincmd.Cmd{
Root: root,
GetToken: cmdGetToken,
Setup: &kubelogincmd.Setup{},
Logger: loggerInterface,
}

return cmdCmd
}

var (
loginLong = templates.LongDesc(`
Log in to the Deckhouse Kubernetes Platform.
UNDER DEVELOPMENT. THE ONLY COMMAND AVAILABLE: get-token
First-time users of the client should run this command to connect to a server,
establish an authenticated session, and save connection to the configuration file. The
default configuration will be saved to your home directory under
".kube/config".
The information required to login -- like username and password, a session token, or
the server details -- can be provided through flags. If not provided, the command will
prompt for user input as needed. It is also possible to login through a web browser by
providing the respective flag.`)

loginExample = templates.Examples(`
# Log in to the external OIDC issuer
d8 login get-token --oidc-issuer-url=https://dex.example.com --oidc-client-id=kubeconfig-generator --oidc-client-secret=YOUR_SECRET`)
)

func init() {
klCmd := getKubeloginCmd()

loginCmd := &cobra.Command{
Use: "login",
Short: "Log in to the Deckhouse Kubernetes Platform",
Long: loginLong,
Example: loginExample,
SilenceErrors: true,
SilenceUsage: true,
}

klCmd.Logger.AddFlags(loginCmd.PersistentFlags())

getTokenCmd := klCmd.GetToken.New()
loginCmd.AddCommand(getTokenCmd)

rootCmd.AddCommand(loginCmd)
}
19 changes: 19 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "d8",
Short: "d8 controls the Deckhouse Kubernetes Platform",
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
108 changes: 108 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module github.com/deckhouse/deckhouse-cli

go 1.22.0

require (
github.com/int128/kubelogin v1.28.0
github.com/spf13/cobra v1.8.0
k8s.io/component-base v0.28.2
k8s.io/kubectl v0.28.2
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/alexflint/go-filemutex v1.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/coreos/go-oidc/v3 v3.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/daviddengcn/go-colortext v1.0.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/int128/listener v1.1.0 // indirect
github.com/int128/oauth2cli v1.14.0 // indirect
github.com/int128/oauth2dev v1.0.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lithammer/dedent v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.2 // indirect
k8s.io/apimachinery v0.28.2 // indirect
k8s.io/cli-runtime v0.28.2 // indirect
k8s.io/client-go v0.28.2 // indirect
k8s.io/component-helpers v0.28.2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/metrics v0.28.2 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kustomize/v5 v5.0.4-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit b5e56e4

Please sign in to comment.