envoid/internal/types/project.go
Sagi Dayan 29e31c5b21
All checks were successful
CI / check for spelling errors (pull_request) Successful in 21s
CI / code quality (lint/tests) (pull_request) Successful in 2m6s
CI / make sure build does not fail (pull_request) Successful in 2m22s
CI / notify-fail (pull_request) Has been skipped
CI / check for spelling errors (push) Successful in 21s
CI / code quality (lint/tests) (push) Successful in 2m4s
CI / make sure build does not fail (push) Successful in 2m24s
CI / notify-fail (push) Has been skipped
Added lint to the CI. formatted all code accordingly
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
2024-12-17 13:10:42 +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
}