示例#1
0
文件: run.go 项目: 5Sigma/Conduit
func runProxy() {
	proxy := goproxy.NewProxyHttpServer()
	proxyAddress := viper.GetString("master.Address")
	err := http.ListenAndServe(proxyAddress, proxy)
	if err != nil {
		log.Fatal(err.Error())
	}
}
示例#2
0
	"conduit/log"
	"github.com/spf13/cobra"
	"postmaster/mailbox"
)

// acessListCmd represents the acessList command
var accessListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all administrative access keys",
	Long: `Display a list of all administrative access keys that have been
generated using 'conduit server access'. The server must be stopped when
running this command.`,
	Run: func(cmd *cobra.Command, args []string) {
		mailbox.OpenDB()
		keys, err := mailbox.AdminKeys()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not list keys")
		}
		log.Alert("Access keys:")
		for _, k := range keys {
			log.Info(k.Name)
		}
		mailbox.CloseDB()
	},
}

func init() {
	accessCmd.AddCommand(accessListCmd)
}
示例#3
0
文件: info.go 项目: 5Sigma/Conduit
	"github.com/pivotal-golang/bytefmt"
	"github.com/spf13/cobra"
)

// statsCmd represents the stats command
var infoCmd = &cobra.Command{
	Use:     "info",
	Short:   "Retrieve system statistics from the server",
	Aliases: []string{"stats"},
	Long: `Gathers system statistics such as connected clients, and pending
message count from the remote server.`,
	Run: func(cmd *cobra.Command, args []string) {
		client, err := ClientFromConfig()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not configure client")
		}
		stats, err := client.Stats()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not retrieve statistics")
		}
		log.Alert("\nSystem Statistics\n")
		log.Stats("Host", client.Host)
		log.Stats("Version", stats.Version)
		if cmd.Flag("verbose").Value.String() == "true" {
			log.Stats("Total messages", stats.MessageCount)
		}
		log.Stats("Pending messages", stats.PendingMessages)
		log.Stats("Connected clients",
			fmt.Sprintf("%d / %d", stats.ConnectedClients, stats.TotalMailboxes))
示例#4
0
package cmd

import (
	"conduit/log"
	"github.com/spf13/cobra"
	"postmaster/mailbox"
)

// registerCmd represents the register command
var serverRegisterCmd = &cobra.Command{
	Use:   "register [name]",
	Short: "Register a new mailbox",
	Long:  `This registers a new mailbox for the local server.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("No mailbox name specified")
		}
		mailbox.OpenDB()
		mb, err := mailbox.Create(args[0])
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not create mailbox")
		}
		key := &mailbox.AccessKey{MailboxId: mb.Id}
		err = key.Create()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not create mailbox access token")
		}
		log.Infof("Mailbox created: %s", mb.Id)
		log.Infof("Access key created: %s", key.Secret)
示例#5
0
package cmd

import (
	"conduit/log"
	"github.com/spf13/cobra"
)

// deregisterCmd represents the deregister command
var deregisterCmd = &cobra.Command{
	Use:   "deregister",
	Short: "Deregister a mailbox",
	Long:  `Remove a mailbox, its access tokens, and messages.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("No mailbox identifier specified.")
		}
		client, err := ClientFromConfig()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not configure client")
		}
		_, err = client.DeregisterMailbox(args[0])
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not remove mailbox.")
		}
		log.Infof("Mailbox deregistered: %s", args[0])
	},
}
示例#6
0
local Conduit server. This key gives full access to the Conduit API and should
be used for administrative purposes in a Conduit client or by an external system
that can manage the Conduit service.

For audit purposes the access key can be given a name. If no name is specified a
randomly generated identifier will be used.`,
	Run: func(cmd *cobra.Command, args []string) {
		mailbox.OpenDB()
		key := mailbox.AccessKey{FullAccess: true}
		if len(args) > 0 {
			key.Name = args[0]
		}
		err := key.Create()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not create access key.")
		}
		log.Info("Access key created: ")
		log.Info("  Access key name: " + key.Name)
		log.Info("  Access key: " + key.Secret)
	},
}

func init() {
	serverCmd.AddCommand(accessCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// accessCmd.PersistentFlags().String("foo", "", "A help for foo")
示例#7
0
文件: deploy.go 项目: 5Sigma/Conduit
	Use:     "deploy [file] [client]",
	Aliases: []string{"send"},
	Short:   "Send a script to be executed",
	Long: `Send a script to be executed by a client. The file can either be a
javascript file or a zip file containing a javascript file and other arbitrary
files.`,
	Run: func(cmd *cobra.Command, args []string) {
		client := client.Client{
			Host:          viper.GetString("host"),
			Mailbox:       viper.GetString("mailbox"),
			AccessKey:     viper.GetString("access_key"),
			AccessKeyName: viper.GetString("access_key_name"),
			ShowRequests:  viper.GetBool("show_requests"),
		}
		if len(args) == 0 {
			log.Fatal("No script specified.")
		}
		filename := args[0]
		mailboxes := args[1:]
		pattern := cmd.Flag("pattern").Value.String()
		if pattern == "" && len(mailboxes) == 0 {
			log.Fatal("Must provide either a list of mailboxes, a pattern, or both.")
		}
		data, err := ioutil.ReadFile(filename)
		if err != nil {
			log.Fatal(err.Error())
		}
		eng := engine.New()
		err = eng.Validate(string(data))
		if err != nil {
			log.Error(err.Error())
示例#8
0
文件: agent.go 项目: 5Sigma/Conduit
agents:
	myAgentName: 10.0.100.15:2222

To run as an agent an address and port must be specified in the config file.
This is the interface and port to listen on. It should match the configuration
on the handler. For example:

agent_host: 10.0.100.15:2222

Agents must also have the same access_key as their handler in the config file.`,
	Run: func(cmd *cobra.Command, args []string) {
		agent.Address = viper.GetString("agent_host")
		agent.AccessKey = viper.GetString("access_key")
		if agent.Address == "" {
			cmd.Help()
			log.Fatal("\nThe 'agent_host' field in the config file is not present.")
		}
		log.Info("Starting agent on " + agent.Address)
		agent.Start()
	},
}

func init() {
	RootCmd.AddCommand(agentCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// agentCmd.PersistentFlags().String("foo", "", "A help for foo")
示例#9
0
文件: service.go 项目: 5Sigma/Conduit
				time.Sleep(100 * time.Millisecond)
				changes <- c.CurrentStatus
			case svc.Stop, svc.Shutdown:
				break loop
			default:
			}
		}
	}
	changes <- svc.Status{State: svc.StopPending}
	return
}

// serviceCmd represents the service command
var serviceCmd = &cobra.Command{
	Use:   "service",
	Short: "Run Conduit as a Windows service.",
	Long: `Use this command line flag to run Conduit as a Windows service. The
service in Windows should be setup to run 'conduit service'.`,
	Run: func(cmd *cobra.Command, args []string) {
		run := svc.Run
		err := run("Conduit Client", &conduitService{})
		if err != nil {
			log.Fatal(err.Error())
		}
	},
}

func init() {
	RootCmd.AddCommand(serviceCmd)
}
示例#10
0
import (
	"conduit/log"
	"github.com/spf13/cobra"
	"postmaster/mailbox"
)

// purgeCmd represents the purge command
var purgeCmd = &cobra.Command{
	Use:   "purge [mailbox]",
	Short: "Purge all messages for a mailbox.",
	Long: `Delete all messages for the local server for a given mailbox. This
purges local data from the server's database. To purge a remote server use
conduit purge instead.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("No mailbox specified.")
		}
		mailbox.OpenDB()
		mailboxId := args[0]
		mb, err := mailbox.Find(mailboxId)
		if err != nil {
			log.Fatal("Could not lookup mailbox.")
			log.Debug(err.Error())
		}
		if mb == nil {
			log.Fatal("Could not find the mailbox specified")
		}
		c, err := mb.Purge()
		if err != nil {
			log.Fatal("Could not purge mailbox")
			log.Debug(err.Error())
示例#11
0
	"conduit/log"
	"github.com/spf13/cobra"
	"strconv"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "List past deployments",
	Long: `Lists past deployments, by default it will list the last 10 deployments
made by your access key.`,
	Run: func(cmd *cobra.Command, args []string) {
		client, err := ClientFromConfig()
		if err != nil {
			log.Debug(err.Error())
			log.Fatal("Could not configure client")
		}
		limitToken := (cmd.Flag("all").Value.String() == "false")
		count, _ := strconv.ParseInt(cmd.Flag("count").Value.String(), 10, 64)
		resp, err := client.ListDeploys(cmd.Flag("name").Value.String(),
			limitToken, int(count))
		if err != nil {
			log.Debug(err.Error())
			log.Error("Could not list deploys")
			return
		}
		if len(resp.Deployments) == 0 {
			log.Warn("There are no open deployments")
		}
		for _, dep := range resp.Deployments {
			log.Alertf("%s:", dep.Name)