ca.go 868 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package acme
  2. /*
  3. CA.go
  4. This script load CA defination from embedded ca.json
  5. */
  6. import (
  7. _ "embed"
  8. "encoding/json"
  9. "errors"
  10. "log"
  11. )
  12. // CA Defination, load from embeded json when startup
  13. type CaDef struct {
  14. Production map[string]string
  15. Test map[string]string
  16. }
  17. //go:embed ca.json
  18. var caJson []byte
  19. var caDef CaDef = CaDef{}
  20. func init() {
  21. runtimeCaDef := CaDef{}
  22. err := json.Unmarshal(caJson, &runtimeCaDef)
  23. if err != nil {
  24. log.Println("[ERR] Unable to unmarshal CA def from embedded file. You sure your ca.json is valid?")
  25. return
  26. }
  27. caDef = runtimeCaDef
  28. }
  29. // Get the CA ACME server endpoint and error if not found
  30. func loadCAApiServerFromName(caName string) (string, error) {
  31. val, ok := caDef.Production[caName]
  32. if !ok {
  33. return "", errors.New("This CA is not supported")
  34. }
  35. return val, nil
  36. }