config.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  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 delinea
  14. import (
  15. "fmt"
  16. "os"
  17. )
  18. type config struct {
  19. tld string
  20. urlTemplate string
  21. tenant string
  22. clientID string
  23. clientSecret string
  24. }
  25. func loadConfigFromEnv() (*config, error) {
  26. var cfg config
  27. var err error
  28. // Optional settings
  29. cfg.tld, _ = getEnv("DELINEA_TLD")
  30. cfg.urlTemplate, _ = getEnv("DELINEA_URL_TEMPLATE")
  31. // Required settings
  32. cfg.tenant, err = getEnv("DELINEA_TENANT")
  33. if err != nil {
  34. return nil, err
  35. }
  36. cfg.clientID, err = getEnv("DELINEA_CLIENT_ID")
  37. if err != nil {
  38. return nil, err
  39. }
  40. cfg.clientSecret, err = getEnv("DELINEA_CLIENT_SECRET")
  41. if err != nil {
  42. return nil, err
  43. }
  44. return &cfg, nil
  45. }
  46. func getEnv(name string) (string, error) {
  47. value, ok := os.LookupEnv(name)
  48. if !ok {
  49. return "", fmt.Errorf("environment variable %q is not set", name)
  50. }
  51. return value, nil
  52. }