Guest User

Untitled

a guest
Jun 1st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. def create_account(self, new_account, new_user, new_password):
  2. """
  3. Handles the create_account call for developers, used to request
  4. an account be created both on a Swift cluster and in the auth server
  5. database.
  6.  
  7. This will make ReST requests to the Swift cluster's account servers
  8. to have an account created on its side. The resulting account hash
  9. along with the URL to use to access the account, the account name, the
  10. user name, and the password is recorded in the auth server's database.
  11. The url is constructed now and stored separately to support changing
  12. the configuration file's default_cluster_url for directing new accounts
  13. to a different Swift cluster while still supporting old accounts going
  14. to the Swift clusters they were created on.
  15.  
  16. :param new_account: The name for the new account
  17. :param new_user: The name for the new user
  18. :param new_password: The password for the new account
  19.  
  20. :returns: False if the create fails or the user exists, storage url if successful
  21. """
  22. begin = time()
  23. if not all((new_account, new_user, new_password)):
  24. return False
  25.  
  26. account_hash = False
  27. with self.get_conn() as conn:
  28. row = conn.execute('''SELECT cfaccount FROM account WHERE
  29. account = ? AND user = ? AND password = ?''',
  30. (new_account, new_user, new_password)).fetchone()
  31. if row:
  32. account_hash = row[0]
  33.  
  34. if not account_hash:
  35. account_hash = self.add_storage_account()
  36. else:
  37. account_hash = self.add_storage_account(self, account_hash)
  38.  
  39. if not account_hash:
  40. self.logger.info(
  41. 'FAILED create_account(%s, %s, _,) [%.02f]' %
  42. (repr(new_account), repr(new_user), time() - begin))
  43. return False
  44. url = self.default_cluster_url.rstrip('/') + '/' + account_hash
  45. with self.get_conn() as conn:
  46. conn.execute('''INSERT OR REPLACE INTO account
  47. (account, url, cfaccount, user, password)
  48. VALUES (?, ?, ?, ?, ?)''',
  49. (new_account, url, account_hash, new_user, new_password))
  50. conn.commit()
  51. self.logger.info(
  52. 'SUCCESS create_account(%s, %s, _) = %s [%.02f]' %
  53. (repr(new_account), repr(new_user), repr(url), time() - begin))
  54. return url
Add Comment
Please, Sign In to add comment