2020-01-31 05:37:59 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2020-05-31 02:02:49 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
steveauth "github.com/rancher/steve/pkg/auth"
|
2020-01-31 05:37:59 +00:00
|
|
|
authcli "github.com/rancher/steve/pkg/auth/cli"
|
|
|
|
"github.com/rancher/steve/pkg/server"
|
|
|
|
"github.com/rancher/wrangler/pkg/kubeconfig"
|
2020-02-22 05:18:58 +00:00
|
|
|
"github.com/rancher/wrangler/pkg/ratelimit"
|
2020-01-31 05:37:59 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
KubeConfig string
|
|
|
|
HTTPSListenPort int
|
|
|
|
HTTPListenPort int
|
2020-02-22 05:18:58 +00:00
|
|
|
DashboardURL string
|
2020-05-31 02:02:49 +00:00
|
|
|
Authentication bool
|
2020-01-31 05:37:59 +00:00
|
|
|
|
|
|
|
WebhookConfig authcli.WebhookConfig
|
|
|
|
}
|
|
|
|
|
2020-05-31 02:02:49 +00:00
|
|
|
func (c *Config) MustServer(ctx context.Context) *server.Server {
|
|
|
|
cc, err := c.ToServer(ctx)
|
2020-01-31 05:37:59 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cc
|
|
|
|
}
|
|
|
|
|
2020-05-31 02:02:49 +00:00
|
|
|
func (c *Config) ToServer(ctx context.Context) (*server.Server, error) {
|
|
|
|
var (
|
|
|
|
auth steveauth.Middleware
|
|
|
|
startHooks []server.StartHook
|
|
|
|
)
|
|
|
|
|
2020-01-31 05:37:59 +00:00
|
|
|
restConfig, err := kubeconfig.GetNonInteractiveClientConfig(c.KubeConfig).ClientConfig()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-22 05:18:58 +00:00
|
|
|
restConfig.RateLimiter = ratelimit.None
|
2020-01-31 05:37:59 +00:00
|
|
|
|
2020-05-31 02:02:49 +00:00
|
|
|
if c.Authentication {
|
|
|
|
auth, err = c.WebhookConfig.WebhookMiddleware()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-31 05:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &server.Server{
|
2020-07-19 20:56:34 +00:00
|
|
|
RESTConfig: restConfig,
|
2020-01-31 05:37:59 +00:00
|
|
|
AuthMiddleware: auth,
|
2020-02-22 05:18:58 +00:00
|
|
|
DashboardURL: func() string {
|
|
|
|
return c.DashboardURL
|
|
|
|
},
|
2020-05-31 02:02:49 +00:00
|
|
|
StartHooks: startHooks,
|
2020-01-31 05:37:59 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Flags(config *Config) []cli.Flag {
|
|
|
|
flags := []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "kubeconfig",
|
|
|
|
EnvVar: "KUBECONFIG",
|
|
|
|
Destination: &config.KubeConfig,
|
|
|
|
},
|
|
|
|
cli.IntFlag{
|
|
|
|
Name: "https-listen-port",
|
2020-05-31 02:02:49 +00:00
|
|
|
Value: 9443,
|
2020-01-31 05:37:59 +00:00
|
|
|
Destination: &config.HTTPSListenPort,
|
|
|
|
},
|
|
|
|
cli.IntFlag{
|
|
|
|
Name: "http-listen-port",
|
2020-05-31 02:02:49 +00:00
|
|
|
Value: 9080,
|
2020-01-31 05:37:59 +00:00
|
|
|
Destination: &config.HTTPListenPort,
|
|
|
|
},
|
2020-02-22 05:18:58 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "dashboard-url",
|
|
|
|
Value: "https://releases.rancher.com/dashboard/latest/index.html",
|
|
|
|
Destination: &config.DashboardURL,
|
|
|
|
},
|
2020-05-31 02:02:49 +00:00
|
|
|
cli.BoolTFlag{
|
|
|
|
Name: "authentication",
|
|
|
|
Destination: &config.Authentication,
|
|
|
|
},
|
2020-01-31 05:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return append(flags, authcli.Flags(&config.WebhookConfig)...)
|
|
|
|
}
|