autogits/bots-common/tokens.go

47 lines
909 B
Go
Raw Normal View History

2024-07-08 17:14:26 +02:00
package common
import (
"errors"
"fmt"
"os"
)
2024-07-22 17:09:45 +02:00
var giteaToken string
var obsUser, obsPassword string
2024-07-08 17:14:26 +02:00
func RequireGiteaSecretToken() error {
giteaToken = os.Getenv(GiteaTokenEnv)
if len(giteaToken) < 10 {
return errors.New(GiteaTokenEnv + " not provided")
}
err := os.Setenv(GiteaTokenEnv, "")
if err != nil {
return fmt.Errorf("%s: %v", "Cannot reset "+GiteaTokenEnv, err)
}
return nil
}
func RequireObsSecretToken() error {
2024-07-26 16:53:09 +02:00
obsUser = os.Getenv(ObsUserEnv)
obsPassword = os.Getenv(ObsPasswordEnv)
2024-07-22 17:09:45 +02:00
if len(obsPassword) < 10 || len(obsUser) < 2 {
return fmt.Errorf("Missing OBS authentication: %s %s", ObsUserEnv, ObsPasswordEnv)
}
err := os.Setenv(ObsUserEnv, "")
if err != nil {
return fmt.Errorf("Cannot reset %s: %v", ObsUserEnv, err)
}
err = os.Setenv(ObsPasswordEnv, "")
if err != nil {
return fmt.Errorf("Cannot reset %s: %v", ObsPasswordEnv, err)
}
2024-07-08 17:14:26 +02:00
return nil
}