conf.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Licensed to Cloudera, Inc. under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. Cloudera, Inc. licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from __future__ import absolute_import
  17. from boto.regioninfo import get_regions
  18. from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool
  19. AWS_ACCOUNTS = UnspecifiedConfigSection(
  20. 'aws_accounts',
  21. help='One entry for each AWS account',
  22. each=ConfigSection(
  23. help='Information about single AWS account',
  24. members=dict(
  25. ACCESS_KEY_ID=Config(
  26. key='access_key_id',
  27. type=str,
  28. private=True
  29. ),
  30. SECRET_ACCESS_KEY=Config(
  31. key='secret_access_key',
  32. type=str,
  33. private=True
  34. ),
  35. ALLOW_ENVIRONMENT_CREDENTIALS=Config(
  36. help='Allow to use environment sources of credentials (environment variables, EC2 profile).',
  37. key='allow_environment_credentials',
  38. default=True,
  39. type=coerce_bool
  40. ),
  41. REGION=Config(
  42. key='region',
  43. default='us-east-1',
  44. type=str
  45. )
  46. )
  47. )
  48. )
  49. def is_enabled():
  50. return 'default' in AWS_ACCOUNTS.keys() and AWS_ACCOUNTS['default'].get_raw()
  51. def is_default_configured():
  52. return is_enabled() and AWS_ACCOUNTS['default'].ACCESS_KEY_ID.get() is not None
  53. def config_validator(user):
  54. res = []
  55. if is_enabled():
  56. if not is_default_configured(): # Make a redundant call to is_enabled so that we only check default if it's non-empty
  57. res.append(('aws.aws_accounts', 'Default AWS account is not configured'))
  58. regions = get_regions('s3') # S3 is only supported service so far
  59. region_names = [r.name for r in regions]
  60. for name in AWS_ACCOUNTS.keys():
  61. region_name = AWS_ACCOUNTS[name].REGION.get()
  62. if region_name not in region_names:
  63. res.append(('aws.aws_accounts.%s.region' % name, 'Unknown region %s' % region_name))
  64. return res