envoid/internal/types/project.go
Sagi Dayan 05db3e503f
Some checks failed
ci/ci / Check for spelling errors (pull_request) Successful in 22s
ci/ci / GonalgCI lint (pull_request) Failing after 1m6s
ci/ci / Make sure build does not fail (pull_request) Has been skipped
ci/ci / notify-fail (pull_request) Successful in 14s
Added lint to the CI. formatted all code accordingly
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
2024-12-16 21:17:44 +02:00

66 lines
1.3 KiB
Go

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 `default:"[]" json:"envorinments"`
}
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
}