package types import ( "encoding/base64" "fmt" "os" "git.dayanhub.com/sagi/envoid/internal/errors" ) type Project struct { Path string `json:"path"` Name string `json:"name"` Password string `json:"password"` Environments []*Environment `json:"envorinments" default:"[]"` } func (p *Project) GetEnv(name string) (*Environment, error) { var e *Environment for _, env := range p.Environments { if env.Name == name { passByte, err := base64.RawStdEncoding.DecodeString(p.Password) if err != nil { fmt.Printf("[ERROR] Failed to decode project password @ %s. %e\n", p.Path, err) os.Exit(1) } e = &Environment{ Name: env.Name, Password: string(passByte), } } } if e == nil { return nil, errors.NewEnvironmentNotFoundError(p.Path, name) } return e, nil } func (p *Project) NewEnv(name string) error { e := &Environment{ Name: name, } p.Environments = append(p.Environments, e) return nil } func (p *Project) RemoveEnv(name string) { environments := []*Environment{} for _, env := range p.Environments { if env.Name != name { environments = append(environments, env) } } p.Environments = environments } func (p *Project) IsEmpty() bool { return len(p.Environments) == 0 }