55 lines
1000 B
Go
55 lines
1000 B
Go
|
package conf
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
type DeploymentMsg struct {
|
||
|
Name string
|
||
|
Path string
|
||
|
Reply chan error
|
||
|
}
|
||
|
|
||
|
// 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")
|
||
|
}
|
||
|
|
||
|
// 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
|
||
|
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
|
||
|
}
|