func (cmd *Command) deleteHostAction(c *cli.Context) { if err := cmd.client.DeleteHost(engine.HostKey{Name: c.String("name")}); err != nil { cmd.printError(err) return } cmd.printOk("host deleted") }
func (cmd *Command) deleteBackendAction(c *cli.Context) { if err := cmd.client.DeleteBackend(engine.BackendKey{Id: c.String("id")}); err != nil { cmd.printError(err) } else { cmd.printOk("backend deleted") } }
func (cmd *Command) printHostAction(c *cli.Context) { host, err := cmd.client.GetHost(engine.HostKey{Name: c.String("name")}) if err != nil { cmd.printError(err) return } cmd.printHost(host) }
func (cmd *Command) printListenerAction(c *cli.Context) { l, err := cmd.client.GetListener(engine.ListenerKey{Id: c.String("id")}) if err != nil { cmd.printError(err) return } cmd.printListener(l) }
func (cmd *Command) printServersAction(c *cli.Context) { srvs, err := cmd.client.GetServers(engine.BackendKey{Id: c.String("backend")}) if err != nil { cmd.printError(err) return } cmd.printServers(srvs) }
func (cmd *Command) deleteFrontendAction(c *cli.Context) { err := cmd.client.DeleteFrontend(engine.FrontendKey{Id: c.String("id")}) if err != nil { cmd.printError(err) return } cmd.printOk("frontend deleted") }
func (cmd *Command) printServerAction(c *cli.Context) { s, err := cmd.client.GetServer(engine.ServerKey{Id: c.String("id"), BackendKey: engine.BackendKey{Id: c.String("backend")}}) if err != nil { cmd.printError(err) return } cmd.printServer(s) }
func (cmd *Command) deleteServerAction(c *cli.Context) { sk := engine.ServerKey{BackendKey: engine.BackendKey{Id: c.String("backend")}, Id: c.String("id")} if err := cmd.client.DeleteServer(sk); err != nil { cmd.printError(err) return } cmd.printOk("Server %v deleted", sk.Id) }
// FromCli constructs a middleware instance from the command line parameters. func FromCli(c *cli.Context) (plugin.Middleware, error) { return FromOther( RateLimit{ PeriodSeconds: int64(c.Int("period")), Requests: int64(c.Int("requests")), Burst: int64(c.Int("burst")), Variable: c.String("var"), RateVar: c.String("rateVar")}) }
func initBundle(c *cli.Context) { b, err := NewBundler(c.StringSlice("middleware")) if err != nil { log.Errorf("Failed to bundle middlewares: %s", err) return } if err := b.bundle(); err != nil { log.Errorf("Failed to bundle middlewares: %s", err) } else { log.Infof("SUCCESS: bundle vulcand and vctl completed") } }
func (cmd *Command) updateLogSeverityAction(c *cli.Context) { sev, err := log.SeverityFromString(c.String("severity")) if err != nil { cmd.printError(err) return } if err := cmd.client.UpdateLogSeverity(sev); err != nil { cmd.printError(err) return } cmd.printOk("log severity updated") }
func (cmd *Command) upsertBackendAction(c *cli.Context) { settings, err := getBackendSettings(c) if err != nil { cmd.printError(err) return } b, err := engine.NewHTTPBackend(c.String("id"), settings) if err != nil { cmd.printError(err) return } cmd.printResult("%s upserted", b, cmd.client.UpsertBackend(*b)) }
func (cmd *Command) printBackendAction(c *cli.Context) { bk := engine.BackendKey{Id: c.String("id")} b, err := cmd.client.GetBackend(bk) if err != nil { cmd.printError(err) return } srvs, err := cmd.client.GetServers(bk) if err != nil { cmd.printError(err) return } cmd.printBackend(b, srvs) }
func (cmd *Command) printFrontendAction(c *cli.Context) { fk := engine.FrontendKey{Id: c.String("id")} frontend, err := cmd.client.GetFrontend(fk) if err != nil { cmd.printError(err) return } ms, err := cmd.client.GetMiddlewares(fk) if err != nil { cmd.printError(err) return } cmd.printFrontend(frontend, ms) }
func (cmd *Command) upsertServerAction(c *cli.Context) { s, err := engine.NewServer(c.String("id"), c.String("url")) if err != nil { cmd.printError(err) return } if err := cmd.client.UpsertServer(engine.BackendKey{Id: c.String("backend")}, *s, c.Duration("ttl")); err != nil { cmd.printError(err) return } cmd.printOk("server upserted") }
func getBackendSettings(c *cli.Context) (engine.HTTPBackendSettings, error) { s := engine.HTTPBackendSettings{} s.Timeouts.Read = c.Duration("readTimeout").String() s.Timeouts.Dial = c.Duration("dialTimeout").String() s.Timeouts.TLSHandshake = c.Duration("handshakeTimeout").String() s.KeepAlive.Period = c.Duration("keepAlivePeriod").String() s.KeepAlive.MaxIdleConnsPerHost = c.Int("maxIdleConns") tlsSettings, err := getTLSSettings(c) if err != nil { return s, err } s.TLS = tlsSettings return s, nil }
func (cmd *Command) upsertFrontendAction(c *cli.Context) { settings, err := getFrontendSettings(c) if err != nil { cmd.printError(err) return } f, err := engine.NewHTTPFrontend(route.NewMux(), c.String("id"), c.String("b"), c.String("route"), settings) if err != nil { cmd.printError(err) return } if err := cmd.client.UpsertFrontend(*f, c.Duration("ttl")); err != nil { cmd.printError(err) return } cmd.printOk("frontend upserted") }
func getStream(c *cli.Context) (io.Writer, io.Closer, error) { if c.String("file") != "" { file, err := os.OpenFile(c.String("file"), os.O_WRONLY|os.O_CREATE, 0600) if err != nil { return nil, nil, fmt.Errorf("failed to open file %s, error: %s", c.String("file"), err) } return file, file, nil } return os.Stdout, nil, nil }
func (cmd *Command) upsertListenerAction(c *cli.Context) { var settings *engine.HTTPSListenerSettings if c.String("proto") == engine.HTTPS { s, err := getTLSSettings(c) if err != nil { cmd.printError(err) return } settings = &engine.HTTPSListenerSettings{TLS: *s} } listener, err := engine.NewListener(c.String("id"), c.String("proto"), c.String("net"), c.String("addr"), c.String("scope"), settings) if err != nil { cmd.printError(err) return } if err := cmd.client.UpsertListener(*listener); err != nil { cmd.printError(err) return } cmd.printOk("listener upserted") }
func (cmd *Command) sealKeyPairAction(c *cli.Context) { // Read the key and get a box box, err := readBox(c.String("sealKey")) if err != nil { cmd.printError(err) return } // Read keyPairificate stream, closer, err := getStream(c) if err != nil { cmd.printError(err) return } if closer != nil { defer closer.Close() } keyPair, err := readKeyPair(c.String("cert"), c.String("privateKey")) if err != nil { cmd.printError(fmt.Errorf("failed to read key pair: %s", err)) return } bytes, err := secret.SealKeyPairToJSON(box, keyPair) if err != nil { cmd.printError(fmt.Errorf("failed to seal key pair: %s", err)) return } _, err = stream.Write(bytes) if err != nil { cmd.printError(fmt.Errorf("failed writing to output stream, error %s", err)) return } }
func (cmd *Command) deleteListenerAction(c *cli.Context) { if err := cmd.client.DeleteListener(engine.ListenerKey{Id: c.String("id")}); err != nil { cmd.printError(err) } cmd.printOk("listener deleted") }
// Constructs the middleware from the command line func FromCli(c *cli.Context) (plugin.Middleware, error) { return NewConnLimit(int64(c.Int("connections")), c.String("var")) }
func getTLSSettings(c *cli.Context) (*engine.TLSSettings, error) { s := &engine.TLSSettings{ InsecureSkipVerify: c.Bool("tlsSkipVerify"), PreferServerCipherSuites: c.Bool("tlsPreferServerCS"), SessionTicketsDisabled: c.Bool("tlsSessionTicketsOff"), MinVersion: c.String("tlsMinV"), MaxVersion: c.String("tlsMaxV"), CipherSuites: c.StringSlice("tlsCS"), } s.SessionCache.Type = c.String("tlsSessionCache") if s.SessionCache.Type == engine.LRUCacheType { s.SessionCache.Settings = &engine.LRUSessionCacheSettings{ Capacity: c.Int("tlsSessionCacheCapacity"), } } if _, err := engine.NewTLSConfig(s); err != nil { return nil, err } return s, nil }
func FromCli(c *cli.Context) (plugin.Middleware, error) { return NewRewrite(c.String("regexp"), c.String("replacement"), c.Bool("rewriteBody"), c.Bool("redirect")) }
// FromCli constructs the middleware from the command line arguments func FromCli(c *cli.Context) (plugin.Middleware, error) { return NewSpec(c.String("condition"), c.String("fallback"), c.String("onTripped"), c.String("onStandby"), c.Duration("fallbackDuration"), c.Duration("recoveryDuration"), c.Duration("checkPeriod")) }
func (cmd *Command) topAction(c *cli.Context) { cmd.overviewAction(c.String("backend"), c.Int("refresh"), c.Int("limit")) }
func getFrontendSettings(c *cli.Context) (engine.HTTPFrontendSettings, error) { s := engine.HTTPFrontendSettings{} s.Limits.MaxMemBodyBytes = int64(c.Int("maxMemBodyKB") * 1024) s.Limits.MaxBodyBytes = int64(c.Int("maxBodyKB") * 1024) s.FailoverPredicate = c.String("failoverPredicate") s.Hostname = c.String("forwardHost") s.TrustForwardHeader = c.Bool("trustForwardHeader") s.PassHostHeader = c.Bool("passHostHeader") return s, nil }
func (cmd *Command) upsertHostAction(c *cli.Context) { host, err := engine.NewHost(c.String("name"), engine.HostSettings{}) if err != nil { cmd.printError(err) return } if c.String("cert") != "" || c.String("privateKey") != "" { keyPair, err := readKeyPair(c.String("cert"), c.String("privateKey")) if err != nil { cmd.printError(fmt.Errorf("failed to read key pair: %s", err)) return } host.Settings.KeyPair = keyPair } host.Settings.OCSP = engine.OCSPSettings{ Enabled: c.Bool("ocsp"), SkipSignatureCheck: c.Bool("ocspSkipCheck"), Period: c.Duration("ocspPeriod").String(), Responders: c.StringSlice("ocspResponder"), } if err := cmd.client.UpsertHost(*host); err != nil { cmd.printError(err) return } cmd.printOk("host added") }
// FromCli creates a Trace plugin object from command line func FromCli(c *cli.Context) (plugin.Middleware, error) { return New(c.String("addr"), c.StringSlice("reqHeader"), c.StringSlice("respHeader")) }