Example #1
0
func main() {
	var opts ShieldAgentOpts
	opts.Log = "Info"
	if err := goptions.Parse(&opts); err != nil {
		fmt.Printf("%s\n", err)
		goptions.PrintHelp()
		return
	}
	if opts.Help {
		goptions.PrintHelp()
		os.Exit(0)
	}
	if opts.Version {
		if Version == "" {
			fmt.Printf("shield-agent (development)%s\n", Version)
		} else {
			fmt.Printf("shield-agent v%s\n", Version)
		}
		os.Exit(0)
	}
	if opts.ConfigFile == "" {
		fmt.Fprintf(os.Stderr, "You must specify a configuration file via `--config`\n")
		os.Exit(1)
	}

	log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log})
	log.Infof("starting agent")

	ag := agent.NewAgent()
	if err := ag.ReadConfig(opts.ConfigFile); err != nil {
		log.Errorf("configuration failed: %s", err)
		return
	}
	ag.Run()
}
Example #2
0
func main() {
	supervisor.Version = Version
	var opts ShielddOpts
	opts.Log = "Info"
	if err := goptions.Parse(&opts); err != nil {
		fmt.Printf("%s\n", err)
		goptions.PrintHelp()
		return
	}

	if opts.Help {
		goptions.PrintHelp()
		os.Exit(0)
	}
	if opts.Version {
		if Version == "" {
			fmt.Printf("shieldd (development)\n")
		} else {
			fmt.Printf("shieldd v%s\n", Version)
		}
		os.Exit(0)
	}

	if opts.ConfigFile == "" {
		fmt.Fprintf(os.Stderr, "No config specified. Please try again using the -c/--config argument\n")
		os.Exit(1)
	}

	log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log})
	log.Infof("starting shield daemon")

	s := supervisor.NewSupervisor()
	if err := s.ReadConfig(opts.ConfigFile); err != nil {
		log.Errorf("Failed to load config: %s", err)
		return
	}

	s.SpawnAPI()
	s.SpawnWorkers()

	if err := s.Run(); err != nil {
		log.Errorf("shield daemon failed: %s", err)
	}
	log.Infof("stopping daemon")
}
Example #3
0
func main() {
	var opts ShieldAgentOpts
	opts.Log = "Info"
	if err := goptions.Parse(&opts); err != nil {
		fmt.Printf("%s\n", err)
		goptions.PrintHelp()
		return
	}

	log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log})
	log.Infof("starting agent")

	ag := agent.NewAgent()
	if err := ag.ReadConfig(opts.ConfigFile); err != nil {
		log.Errorf("configuration failed: %s", err)
		return
	}
	ag.Run()
}
Example #4
0
	"github.com/starkandwayne/goutils/log"
	"io/ioutil"
	"net/http"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/starkandwayne/shield/supervisor"
)

var _ = Describe("OAuthenticator", func() {
	var oa OAuthenticator
	var req *http.Request
	BeforeEach(func() {
		log.SetupLogging(log.LogConfig{Type: "file", File: "/dev/null", Level: "error"})
		data, err := ioutil.ReadFile("test/etc/jwt/valid.pem")
		if err != nil {
			panic(err)
		}
		sk, err := jwt.ParseRSAPrivateKeyFromPEM(data)
		if err != nil {
			panic(err)
		}
		oa = OAuthenticator{
			Cfg: OAuthConfig{
				Key:           "mykey",
				Secret:        "mysecret",
				JWTPrivateKey: sk,
				JWTPublicKey:  &sk.PublicKey,
				Client:        http.DefaultClient,
				 "sundays at 3:15am")`,

		`INSERT INTO schedules (uuid, name, summary, timespec) VALUES
				("` + DAILY + `",
				 "Daily Backups",
				 "Use for daily (11-something-at-night) bosh-blobs",
				 "daily at 11:24pm")`,

		`INSERT INTO jobs (uuid, store_uuid, target_uuid, schedule_uuid, retention_uuid)
				VALUES ("abc-def", "` + NIL + `", "` + NIL + `", "` + WEEKLY + `", "` + NIL + `")`,
	}

	var data *db.DB

	BeforeEach(func() {
		log.SetupLogging(log.LogConfig{Type: "file", Level: "EMERG", File: "/dev/null"})
		var err error
		data, err = Database(databaseEntries...)
		Ω(err).ShouldNot(HaveOccurred())
		resyncChan = make(chan int, 1)
	})

	JustBeforeEach(func() {
		API = ScheduleAPI{
			Data:       data,
			ResyncChan: resyncChan,
		}

	})

	AfterEach(func() {