Exemplo n.º 1
0
func trustLevelForToken(token string) (string, error) {
	c, _ := lib.GetContext()

	// FIXME cache the lookup map
	var m = map[string]([]string){
		"admin":     c.Cfg.Tokens.Admin,
		"trusted":   c.Cfg.Tokens.Trusted,
		"untrusted": c.Cfg.Tokens.Untrusted,
	}

	var lookup = map[string]string{}

	for policy, tokens := range m {
		for _, t := range tokens {
			lookup[t] = policy
		}
	}

	if p, ok := lookup[token]; ok {
		return p, nil
	} else {
		return "", errors.New("unknown token")
	}

	return "", errors.New("unknown token")
}
Exemplo n.º 2
0
func Connect() (session *gocql.Session, err error) {
	c, _ := lib.GetContext()
	log.Printf("Connecting to Cassandra: Hosts %s using Keyspace %s", strings.Join(c.Cfg.Cassandra.Hosts, ","), c.Cfg.Cassandra.Keyspace)

	cluster := gocql.NewCluster(c.Cfg.Cassandra.Hosts...)
	cluster.Keyspace = c.Cfg.Cassandra.Keyspace
	session, err = cluster.CreateSession()

	return
}
Exemplo n.º 3
0
func trustLevelForEvent(event string) string {
	c, _ := lib.GetContext()

	// dedicated setting available?
	if dedicated, ok := c.Cfg.Beacons[event]; ok {
		return dedicated.Policy
	}

	// retrun the default
	return c.Cfg.Policy.Beacons
}
Exemplo n.º 4
0
func ExecWriteQuery(stmt string, args ...interface{}) error {
	c, _ := lib.GetContext()
	return c.Session.Query(stmt, args...).Exec()
}
Exemplo n.º 5
0
func main() {

	log.Println("-> pxm 0.0")

	var configFilename string
	flag.StringVar(&configFilename, "config", "/etc/pxm.ini", "relative or absolute path to a pxm config file")

	cmd := flag.String("cmd", "blank", "internal commands to be execute before start: drop,create,migrate,flush")

	flag.Parse()

	if err := lib.LoadConfig(configFilename, &lib.Cfg); err != nil {
		log.Fatal("Failed to load/parse config", err)
	}

	var err error
	if lib.Session, err = storage.Connect(); err != nil {
		log.Fatal(err)
	}
	context, _ := lib.GetContext()
	defer context.Close()

	for _, c := range strings.Split(*cmd, ",") {
		switch c {
		case "drop":
			storage.Drop()
		case "migrate":
			storage.Migrate()
		case "flush":
			storage.Flush()
		default:
			log.Printf("unsupported command: %s", c)
		}
	}

	started := 0
	var stoppers []chan bool
	sigs := make(chan os.Signal)
	done := make(chan bool, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	for _, m := range flag.Args() {
		switch m {
		case "dummy":
			log.Println("* Starting endless dummy")
			c := make(chan bool)
			go lib.X(c, done)
			stoppers = append(stoppers, c)
			started = started + 1
		case "mxpsink":
			ms := roles.MxpSinkFactory(context)
			c := make(chan bool)
			go ms.Start(c, done)
			stoppers = append(stoppers, c)
			started = started + 1
		case "mxpstream":
			log.Println("* mxp stream to be implemented")
		case "debug":
			log.Println("* debug mode to be implemented")
		default:
			log.Println("* unknown mode", m)
		}

	}

	fmt.Println("Waiting until the sun goes down...")

	_ = <-sigs

	for i := range stoppers {
		stoppers[i] <- true
	}

	for c := 0; c < started; c++ {
		<-done
	}

	os.Exit(0)
}