warren/cmd/warrend/conf/deployments.go

77 lines
1.5 KiB
Go

package conf
import (
"errors"
"os"
)
type DeploymentMsg struct {
Name string
Path string
Reply chan error
}
// reverse look up map
var dirToNick map[string]string = make(map[string]string)
// Validate a deployment is ok to insert
// internal thread unsafe
func validateDeployment(d *DeploymentMsg) error {
// check if exists
if _, ok := conf.Deployments[d.Name]; ok {
return errors.New("Deployment with that name already exists")
}
if r, ok := dirToNick[d.Path]; ok {
return errors.New("Directory with that name already registered under nick '" + r + "'")
}
// check if dir exists
if _, err := os.Stat(d.Path); err != nil {
return err
}
return nil
}
// given a valid deployment, add it
// internal, thread unsafe
func addDeployment(d *DeploymentMsg) error {
if err := validateDeployment(d); err != nil {
d.Reply <- err
return err
}
conf.Deployments[d.Name] = d.Path
dirToNick[d.Path] = d.Name
saveConf()
d.Reply <- nil
return nil
}
// conf API interface to add a deployment, vets it
func AddDeployment(d *DeploymentMsg) error {
d.Reply = make(chan error)
// add to conf / save
addDeploymentChan <- *d
err := <-d.Reply
return err
// TODO: register with runner, like conf would
return nil
}
func RmDeployment(string arg) error {
reply = make(chan error)
rmDeploymentChan <-
// Assume nick, check if registered
deps := GetConf().Deployments
arg := args[0]
if _,ok := deps[arg]; !ok {
// not a registered nick, try as path
absPath := absPath(path, arg)
// if _,ok := conf.
}
}