2024-07-08 17:14:26 +02:00
|
|
|
package common
|
|
|
|
|
2024-09-10 18:24:41 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Autogits.
|
|
|
|
*
|
|
|
|
* Copyright © 2024 SUSE LLC
|
|
|
|
*
|
|
|
|
* Autogits is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-07-08 17:14:26 +02:00
|
|
|
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
|
|
|
|
}
|