Example #1
0
func showUserInfo(uid string) {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	user := md.AdminGetUserInfoByID(uid)
	if user == nil {
		fmt.Println("User Not Found")
		return
	}

	fmt.Println("User info:")
	fmt.Println("ID:", uid)
	fmt.Println("Enabled:", user.Enabled)
	fmt.Println("Registered TS:", user.RegTs)
	fmt.Println("Registered IP:", user.RegIP)
	fmt.Println("Activity Logs:")

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, '\t', 0)
	fmt.Fprintln(w, "Timestamp\tType\tDescripton")
	fmt.Fprintln(w, "---------\t----\t----------")

	for _, lines := range user.GetAllActivity() {
		for _, line := range lines {
			fmt.Fprintf(
				w,
				"%d\t%s\t%s\n",
				line.Ts,
				line.LogType,
				line.Desc)
		}
	}
	w.Flush()
}
Example #2
0
func listGroups(userID string) {
	md := shardinfo.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		"")

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, '\t', 0)
	fmt.Fprintln(w, "User ID\tSecret\tGroupID\tMax Score\tTotal Shards\tMax Elements\tMax req sec\tMax Insert Req Sec\tShard owners")
	fmt.Fprintln(w, "-------\t------\t-------\t---------\t------------\t------------\t-----------\t------------------\t------------")

	groups := md.GetAllGroups()
	for _, groups := range groups {
		for _, group := range groups {
			shardOwners := ""
			for _, shard := range group.Shards {
				shardOwners += fmt.Sprintf("%s %d\t", shard.Addr, shard.LastTs)
			}

			fmt.Fprintf(
				w,
				"%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\n",
				group.UserID,
				group.Secret,
				group.GroupID,
				group.MaxScore,
				group.NumShards,
				group.MaxElements,
				group.MaxReqSec,
				group.MaxInsertReqSec,
				shardOwners)
		}
	}
	w.Flush()
}
Example #3
0
func listUsers() {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, '\t', 0)
	fmt.Fprintln(w, "Uid\tEnabled\tRegTs\tRegIP\tLogLines")
	fmt.Fprintln(w, "---\t-------\t-----\t-----\t--------")

	for uid, user := range md.GetRegisteredUsers() {
		lines := 0
		for _, v := range user.GetAllActivity() {
			lines += len(v)
		}
		fmt.Fprintf(
			w,
			"%s\t%s\t%d\t%s\t%d\n",
			uid,
			user.Enabled,
			user.RegTs,
			user.RegIP,
			lines)
	}
	w.Flush()
}
Example #4
0
func addUser(cmdUsersAddUID string, cmdUsersAddKey string) {
	md := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	if _, err := md.RegisterUser(cmdUsersAddUID, cmdUsersAddKey, "127.0.0.1"); err != nil {
		fmt.Println("Problem trying to register the user:"******"User registered")
	}
}
Example #5
0
func listInstances() {
	md := instances.InitAndKeepAlive(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		false)

	fmt.Println(CLRG + "Instances" + CLRN)
	fmt.Println(CLRG + "---------" + CLRN)
	for _, instance := range md.GetInstances() {
		fmt.Println(instance)
	}
}
Example #6
0
func enableUser(uid string) {
	fmt.Println("The user with user ID:", uid, "will be enabled")
	if askForConfirmation() {
		md := users.GetModel(
			cfg.GetStr("aws", "prefix"),
			cfg.GetStr("aws", "region"))

		user := md.AdminGetUserInfoByID(uid)
		if user != nil {
			user.EnableUser()
			fmt.Println("User Enabled")
		} else {
			fmt.Println("User not found")
		}
	}
}
Example #7
0
func delGroup(groupID string) {
	fmt.Println("The next group will be deleted:")
	md := shardinfo.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		"")

	group := md.GetGroupByID(groupID)
	if group == nil {
		fmt.Println("Group not found with ID:", groupID)
		return
	}

	if askForConfirmation() {
		md.RemoveGroup(groupID)
		fmt.Println("Group removed")
	}
}
Example #8
0
func addGroup(userID, groupID string, numShards int, maxElements, maxReqSec, maxInsertReqSec uint64, maxScore uint8) {
	md := shardinfo.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		"")

	fmt.Println(CLRG + "The next group will be added:" + CLRN)
	fmt.Println("User ID:", userID)
	fmt.Println("Group ID:", groupID)
	fmt.Println("Num Shards:", numShards)
	fmt.Println("Max elements:", maxElements)
	fmt.Println("Max requests by sec / shard:", maxReqSec)
	fmt.Println("Max Insert requests by sec / shard:", maxInsertReqSec)
	fmt.Println("Max score:", maxScore)

	if askForConfirmation() {
		_, key, err := md.AddUpdateGroup("Custom", userID, groupID, numShards, maxElements, maxReqSec, maxInsertReqSec, maxScore)
		if err != nil {
			fmt.Println("Problem adding a new group, Error:", err)
		} else {
			fmt.Println("Group added, key:", key)
		}
	}
}
Example #9
0
func TestPlaceOrder(t *testing.T) {
	cfg.Init("v", "dev")

	api, err := InitOandaApi(
		cfg.GetStr("oanda", "endpoint"),
		cfg.GetStr("oanda", "token"),
		int(cfg.GetInt("oanda", "account-id")),
		strings.Split(cfg.GetStr("oanda", "currencies"), ","),
		cfg.GetStr("oanda", "exanges-log"),
	)

	if err != nil {
		t.Error("Problem connecting with oanda, Error:", err)
	}

	curr := api.GetBaseCurrency()
	if curr != "EUR" {
		t.Error("The configured value on the test account was EUR, but:", curr, "was returned")
	}

	currs := api.GetCurrencies()
	log.Debug(currs)

	order, err := api.Buy("USD", 1, 1.3, true, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Sell("USD", 1, 1.0, true, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Buy("USD", 1, 1.3, false, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Sell("USD", 1, 1.0, false, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}
}
Example #10
0
File: pit.go Project: postfix/pit
func main() {
	if len(os.Args) > 1 {
		cfg.Init("pit", os.Args[1])

		log.SetLogger(
			log.Levels[cfg.GetStr("logger", "level")],
			cfg.GetStr("logger", "log_file"),
			cfg.GetInt("logger", "max_log_size_mb"),
		)
	} else {
		cfg.Init("pit", "dev")
	}
	runtime.GOMAXPROCS(runtime.NumCPU())

	usersModel := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	accountsManager := accountsmanager.Init(
		cfg.GetStr("rec-api", "base-url"),
		cfg.GetStr("mail", "addr"),
		cfg.GetStr("mail", "server"),
		cfg.GetInt("mail", "port"),
		usersModel)

	shardsManager := shardsmanager.Init(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		cfg.GetStr("aws", "s3-backups-path"),
		int(cfg.GetInt("rec-api", "port")),
		usersModel,
		cfg.GetStr("mail", "addr"))

	api.Init(
		shardsManager,
		accountsManager,
		cfg.GetStr("rec-api", "static"),
		int(cfg.GetInt("rec-api", "port")),
		int(cfg.GetInt("rec-api", "ssl-port")),
		cfg.GetStr("rec-api", "ssl-cert"),
		cfg.GetStr("rec-api", "ssl-key"))

	log.Info("System started...")
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
	// Block until a signal is received.
	<-c

	log.Info("Stopping all the services")
	shardsManager.Stop()
}