Esempio n. 1
0
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")
}
Esempio n. 2
0
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")
	}
}
Esempio n. 3
0
func (cmd *Command) locationUpdateOptionsAction(c *cli.Context) {
	options, err := getOptions(c)
	if err != nil {
		cmd.printError(err)
		return
	}
	cmd.printStatus(cmd.client.UpdateLocationOptions(c.String("host"), c.String("id"), options))
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
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)
}
Esempio n. 6
0
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)
}
Esempio n. 7
0
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)
}
Esempio n. 8
0
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")
}
Esempio n. 9
0
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)
}
Esempio n. 10
0
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")

	return s, nil
}
Esempio n. 11
0
func (cmd *Command) upstreamDrainConnections(c *cli.Context) {
	connections, err := cmd.client.DrainUpstreamConnections(c.String("id"), c.String("timeout"))
	if err != nil {
		cmd.printError(err)
		return
	}
	if connections == 0 {
		cmd.printOk("Connections: %d", connections)
	} else {
		cmd.printInfo("Connections: %d", connections)
	}
}
Esempio n. 12
0
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")
	}
}
Esempio n. 13
0
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")
}
Esempio n. 14
0
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))
}
Esempio n. 15
0
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)
}
Esempio n. 16
0
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)
}
Esempio n. 17
0
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")
}
Esempio n. 18
0
func (cmd *Command) addLocationAction(c *cli.Context) {
	options, err := getOptions(c)
	if err != nil {
		cmd.printError(err)
		return
	}
	cmd.printStatus(cmd.client.AddLocationWithOptions(c.String("host"), c.String("id"), c.String("path"), c.String("up"), options))
}
Esempio n. 19
0
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
}
Esempio n. 20
0
func (cmd *Command) upsertFrontendAction(c *cli.Context) {
	settings, err := getFrontendSettings(c)
	if err != nil {
		cmd.printError(err)
		return
	}
	f, err := engine.NewHTTPFrontend(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")
}
Esempio n. 21
0
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
}
Esempio n. 22
0
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")
}
Esempio n. 23
0
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
	}
}
Esempio n. 24
0
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")
}
Esempio n. 25
0
func getOptions(c *cli.Context) (backend.LocationOptions, error) {
	o := backend.LocationOptions{}

	o.Timeouts.Read = c.Duration("readTimeout").String()
	o.Timeouts.Dial = c.Duration("dialTimeout").String()
	o.Timeouts.TlsHandshake = c.Duration("handshakeTimeout").String()

	o.KeepAlive.Period = c.Duration("keepAlivePeriod").String()
	o.KeepAlive.MaxIdleConnsPerHost = c.Int("maxIdleConns")

	o.Limits.MaxMemBodyBytes = int64(c.Int("maxMemBodyKB") * 1024)
	o.Limits.MaxBodyBytes = int64(c.Int("maxBodyKB") * 1024)

	o.FailoverPredicate = c.String("failoverPredicate")
	o.Hostname = c.String("forwardHost")
	o.TrustForwardHeader = c.Bool("trustForwardHeader")

	return o, nil
}
Esempio n. 26
0
func FromCli(c *cli.Context) (plugin.Middleware, error) {
	return NewRewrite(c.String("regexp"), c.String("replacement"), c.Bool("rewriteBody"), c.Bool("redirect"))
}
Esempio n. 27
0
// FromCli constructs the middleware from the command line
func FromCli(c *cli.Context) (plugin.Middleware, error) {
	return New(c.String("credentials"))
}
Esempio n. 28
0
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")
}
Esempio n. 29
0
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
}
Esempio n. 30
0
func (cmd *Command) deleteLocationAction(c *cli.Context) {
	cmd.printStatus(cmd.client.DeleteLocation(c.String("host"), c.String("id")))
}