autogits/bots-common/tokens.go
Adam Majer d0fb7ab761 .
2024-08-07 01:37:55 +02:00

51 lines
961 B
Go

package common
import (
"errors"
"fmt"
"os"
)
var giteaToken string
var obsUser, obsPassword string
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 GetGiteaToken() string {
return giteaToken
}
func RequireObsSecretToken() error {
obsUser = os.Getenv(ObsUserEnv)
obsPassword = os.Getenv(ObsPasswordEnv)
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)
}
return nil
}