2020-01-30 22:37:59 -07:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2020-05-30 19:02:49 -07:00
|
|
|
"context"
|
|
|
|
|
|
|
|
steveauth "github.com/rancher/steve/pkg/auth"
|
2020-01-30 22:37:59 -07:00
|
|
|
authcli "github.com/rancher/steve/pkg/auth/cli"
|
|
|
|
"github.com/rancher/steve/pkg/server"
|
2021-02-18 10:36:27 -07:00
|
|
|
"github.com/rancher/steve/pkg/ui"
|
2024-06-05 00:22:48 +05:30
|
|
|
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
|
|
|
|
"github.com/rancher/wrangler/v3/pkg/ratelimit"
|
2020-01-30 22:37:59 -07:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
KubeConfig string
|
2021-02-18 10:36:27 -07:00
|
|
|
Context string
|
2020-01-30 22:37:59 -07:00
|
|
|
HTTPSListenPort int
|
|
|
|
HTTPListenPort int
|
2021-02-18 10:36:27 -07:00
|
|
|
UIPath string
|
2020-01-30 22:37:59 -07:00
|
|
|
|
|
|
|
WebhookConfig authcli.WebhookConfig
|
|
|
|
}
|
|
|
|
|
2020-05-30 19:02:49 -07:00
|
|
|
func (c *Config) MustServer(ctx context.Context) *server.Server {
|
2024-06-05 16:17:12 +02:00
|
|
|
cc, err := c.ToServer(ctx, false)
|
2020-01-30 22:37:59 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cc
|
|
|
|
}
|
|
|
|
|
2024-06-05 16:17:12 +02:00
|
|
|
func (c *Config) ToServer(ctx context.Context, sqlCache bool) (*server.Server, error) {
|
2020-05-30 19:02:49 -07:00
|
|
|
var (
|
2020-07-24 01:42:00 -07:00
|
|
|
auth steveauth.Middleware
|
2020-05-30 19:02:49 -07:00
|
|
|
)
|
|
|
|
|
2021-02-18 10:36:27 -07:00
|
|
|
restConfig, err := kubeconfig.GetNonInteractiveClientConfigWithContext(c.KubeConfig, c.Context).ClientConfig()
|
2020-01-30 22:37:59 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-21 22:18:58 -07:00
|
|
|
restConfig.RateLimiter = ratelimit.None
|
2020-01-30 22:37:59 -07:00
|
|
|
|
2021-02-18 10:36:27 -07:00
|
|
|
if c.WebhookConfig.WebhookAuthentication {
|
2020-05-30 19:02:49 -07:00
|
|
|
auth, err = c.WebhookConfig.WebhookMiddleware()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-30 22:37:59 -07:00
|
|
|
}
|
|
|
|
|
2020-07-24 01:42:00 -07:00
|
|
|
return server.New(ctx, restConfig, &server.Options{
|
2020-01-30 22:37:59 -07:00
|
|
|
AuthMiddleware: auth,
|
2021-02-18 10:36:27 -07:00
|
|
|
Next: ui.New(c.UIPath),
|
2024-06-05 16:17:12 +02:00
|
|
|
SQLCache: sqlCache,
|
2020-07-24 01:42:00 -07:00
|
|
|
})
|
2020-01-30 22:37:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func Flags(config *Config) []cli.Flag {
|
|
|
|
flags := []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "kubeconfig",
|
|
|
|
EnvVar: "KUBECONFIG",
|
|
|
|
Destination: &config.KubeConfig,
|
|
|
|
},
|
2021-02-18 10:36:27 -07:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "context",
|
|
|
|
EnvVar: "CONTEXT",
|
|
|
|
Destination: &config.Context,
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "ui-path",
|
|
|
|
Destination: &config.UIPath,
|
|
|
|
},
|
2020-01-30 22:37:59 -07:00
|
|
|
cli.IntFlag{
|
|
|
|
Name: "https-listen-port",
|
2020-05-30 19:02:49 -07:00
|
|
|
Value: 9443,
|
2020-01-30 22:37:59 -07:00
|
|
|
Destination: &config.HTTPSListenPort,
|
|
|
|
},
|
|
|
|
cli.IntFlag{
|
|
|
|
Name: "http-listen-port",
|
2020-05-30 19:02:49 -07:00
|
|
|
Value: 9080,
|
2020-01-30 22:37:59 -07:00
|
|
|
Destination: &config.HTTPListenPort,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return append(flags, authcli.Flags(&config.WebhookConfig)...)
|
|
|
|
}
|