config.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package secretserver
  14. import (
  15. "fmt"
  16. "os"
  17. )
  18. type config struct {
  19. username string
  20. password string
  21. serverURL string
  22. }
  23. func loadConfigFromEnv() (*config, error) {
  24. var cfg config
  25. var err error
  26. // Required settings
  27. cfg.username, err = getEnv("SECRETSERVER_USERNAME")
  28. if err != nil {
  29. return nil, err
  30. }
  31. cfg.password, err = getEnv("SECRETSERVER_PASSWORD")
  32. if err != nil {
  33. return nil, err
  34. }
  35. cfg.serverURL, err = getEnv("SECRETSERVER_URL")
  36. if err != nil {
  37. return nil, err
  38. }
  39. return &cfg, nil
  40. }
  41. func getEnv(name string) (string, error) {
  42. value, ok := os.LookupEnv(name)
  43. if !ok {
  44. return "", fmt.Errorf("environment variable %q is not set", name)
  45. }
  46. return value, nil
  47. }