You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

6 years ago
  1. #!/usr/bin/env python
  2. ## -*- encoding: utf-8 -*-
  3. import ovh
  4. import yaml
  5. import sys
  6. import os.path
  7. # Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
  8. # to get your credentials
  9. def main(argv):
  10. if len(argv) == 1:
  11. sys.stderr.write("Error: provide a YAML compose file as first argument.\n")
  12. exit(1)
  13. if not os.path.exists(argv[1]):
  14. sys.stderr.write("Error: file '%s' not found.\n" % argv[0])
  15. sys.stderr.write("Error: provide a YAML compose file as first argument.\n")
  16. exit(1)
  17. try:
  18. with open(sys.argv[1], 'r') as stream:
  19. yml = yaml.load(stream)
  20. except Exception:
  21. sys.stderr.write("Error: provide a YAML compose file as first argument.\n")
  22. exit(1)
  23. ovh_cfg = yml["letsencrypt"]["options"]["env"]["ovh"]
  24. client = ovh.Client(
  25. endpoint=ovh_cfg["entrypoint"],
  26. application_key=ovh_cfg["application"]["key"],
  27. application_secret=ovh_cfg["application"]["secret"],
  28. consumer_key=ovh_cfg["consumer_key"],
  29. )
  30. # Print nice welcome message
  31. print "Welcome", client.get('/me')['firstname']
  32. domains = client.get('/domain/zone')
  33. print "Domains:"
  34. for domain in domains:
  35. print " - %s" % domain
  36. if __name__ == "__main__":
  37. main(sys.argv)