migrate 977 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/python3
  2. import json
  3. import os
  4. import sys
  5. def migrate(values):
  6. storageKey = 'npmStorage'
  7. storages = ['data', 'certs']
  8. for storage in storages:
  9. check_val = values.get(storageKey, {}).get(storage, {})
  10. if not isinstance(check_val, dict) or not check_val or check_val.get('type', 'hostPath') == 'hostPath':
  11. continue
  12. values[storageKey][storage] = {key: value for key, value in check_val.items() if key != 'hostPath'}
  13. # If there is no npmID, add it defaults to
  14. # 1000 to account for existing installations
  15. if values.get('npmID', None) is None:
  16. values.update({
  17. 'npmID': {
  18. 'user': 1000,
  19. 'group': 1000
  20. }
  21. })
  22. return values
  23. if __name__ == '__main__':
  24. if len(sys.argv) != 2:
  25. exit(1)
  26. if os.path.exists(sys.argv[1]):
  27. with open(sys.argv[1], 'r') as f:
  28. print(json.dumps(migrate(json.loads(f.read()))))