Exemple #1
0
// AddAgent simply adds an agent to the system
func AddAgent(agent *spec.Agent) error {

	key, err := getAgentKey(agent)
	if err != nil {
		return err
	}

	agent.PublicKey = key

	ks, err := keys.DecodePublicKeyString(key)
	if err != nil {
		return err
	}

	ip := strings.Split(agent.Address, ":")
	keyManager.PublicKeys[ip[0]] = ks

	return gDb.AddAgent(agent)
}
Exemple #2
0
// Init sets up the environement to run
func Init(c *config.Config) error {
	gDb = &sqlite.SQLite{}
	err := gDb.Init(c.DB)

	//err = db.Init()
	if err != nil {
		return err
	}

	keyManager = &keys.Manager{PublicKeys: make(map[string]*rsa.PublicKey)}
	key, err := keys.OpenPrivateKey(c.Host.PrivateKeyPath)
	if err != nil {
		return err
	}

	keyManager.PrivateKey = key

	agents, err := gDb.AgentList()
	if err != nil {
		return err
	}

	for _, a := range agents {
		key, err := keys.DecodePublicKeyString(a.PublicKey)
		if err != nil {
			fmt.Println("Error decoding key for agent: ", a)
		} else {
			ip := strings.Split(a.Address, ":")
			keyManager.PublicKeys[ip[0]] = key
		}

	}

	conf = c

	//init existing schedules
	if err = initCron(); err != nil {
		return err
	}

	return nil
}