1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-18 00:08:17 +00:00
Files
steve/pkg/server/cli/clicontext.go
Silvio Moioli 7a84620e8b SQLite backed cache (#223)
This uses SQLite-backed informers provided by Lasso with https://github.com/rancher/lasso/pull/65 to implement Steve API (/v1/) functionality.

This new functionality is available behind a feature flag to be specified at Steve startup

See https://confluence.suse.com/pages/viewpage.action?pageId=1359086083 

Co-authored-by: Ricardo Weir <ricardo.weir@suse.com>
Co-authored-by: Michael Bolot <michael.bolot@suse.com>
Co-authored-by: Silvio Moioli <silvio@moioli.net>
Signed-off-by: Silvio Moioli <silvio@moioli.net>
2024-06-05 16:17:12 +02:00

88 lines
1.9 KiB
Go

package cli
import (
"context"
steveauth "github.com/rancher/steve/pkg/auth"
authcli "github.com/rancher/steve/pkg/auth/cli"
"github.com/rancher/steve/pkg/server"
"github.com/rancher/steve/pkg/ui"
"github.com/rancher/wrangler/v2/pkg/kubeconfig"
"github.com/rancher/wrangler/v2/pkg/ratelimit"
"github.com/urfave/cli"
)
type Config struct {
KubeConfig string
Context string
HTTPSListenPort int
HTTPListenPort int
UIPath string
WebhookConfig authcli.WebhookConfig
}
func (c *Config) MustServer(ctx context.Context) *server.Server {
cc, err := c.ToServer(ctx, false)
if err != nil {
panic(err)
}
return cc
}
func (c *Config) ToServer(ctx context.Context, sqlCache bool) (*server.Server, error) {
var (
auth steveauth.Middleware
)
restConfig, err := kubeconfig.GetNonInteractiveClientConfigWithContext(c.KubeConfig, c.Context).ClientConfig()
if err != nil {
return nil, err
}
restConfig.RateLimiter = ratelimit.None
if c.WebhookConfig.WebhookAuthentication {
auth, err = c.WebhookConfig.WebhookMiddleware()
if err != nil {
return nil, err
}
}
return server.New(ctx, restConfig, &server.Options{
AuthMiddleware: auth,
Next: ui.New(c.UIPath),
SQLCache: sqlCache,
})
}
func Flags(config *Config) []cli.Flag {
flags := []cli.Flag{
cli.StringFlag{
Name: "kubeconfig",
EnvVar: "KUBECONFIG",
Destination: &config.KubeConfig,
},
cli.StringFlag{
Name: "context",
EnvVar: "CONTEXT",
Destination: &config.Context,
},
cli.StringFlag{
Name: "ui-path",
Destination: &config.UIPath,
},
cli.IntFlag{
Name: "https-listen-port",
Value: 9443,
Destination: &config.HTTPSListenPort,
},
cli.IntFlag{
Name: "http-listen-port",
Value: 9080,
Destination: &config.HTTPListenPort,
},
}
return append(flags, authcli.Flags(&config.WebhookConfig)...)
}