autogits/bots-common/tokens.go

66 lines
1.3 KiB
Go
Raw Normal View History

2024-07-08 17:14:26 +02:00
package common
import (
"errors"
"fmt"
"os"
)
2024-08-28 00:45:47 +02:00
const (
RabbitUserEnv = "AMQP_USERNAME"
RabbitPasswordEnv = "AMQP_PASSWORD"
)
2024-07-22 17:09:45 +02:00
var giteaToken string
var obsUser, obsPassword string
2024-08-28 00:45:47 +02:00
var rabbitUser, rabbitPassword 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
}
2024-08-07 01:37:55 +02:00
func GetGiteaToken() string {
return giteaToken
}
2024-07-08 17:14:26 +02:00
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
}
2024-08-28 00:45:47 +02:00
func RequireRabbitSecrets() error {
rabbitUser = os.Getenv(RabbitUserEnv)
rabbitPassword = os.Getenv(RabbitPasswordEnv)
if len(rabbitUser) == 0 || len(rabbitPassword) == 0 {
return fmt.Errorf("Missing RabbitMQ env variables: %s, %s", RabbitUserEnv, RabbitPasswordEnv)
}
return nil
}