Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_account(self, new_account, new_user, new_password):
- """
- Handles the create_account call for developers, used to request
- an account be created both on a Swift cluster and in the auth server
- database.
- This will make ReST requests to the Swift cluster's account servers
- to have an account created on its side. The resulting account hash
- along with the URL to use to access the account, the account name, the
- user name, and the password is recorded in the auth server's database.
- The url is constructed now and stored separately to support changing
- the configuration file's default_cluster_url for directing new accounts
- to a different Swift cluster while still supporting old accounts going
- to the Swift clusters they were created on.
- :param new_account: The name for the new account
- :param new_user: The name for the new user
- :param new_password: The password for the new account
- :returns: False if the create fails or the user exists, storage url if successful
- """
- begin = time()
- if not all((new_account, new_user, new_password)):
- return False
- account_hash = False
- with self.get_conn() as conn:
- row = conn.execute('''SELECT cfaccount FROM account WHERE
- account = ? AND user = ? AND password = ?''',
- (new_account, new_user, new_password)).fetchone()
- if row:
- account_hash = row[0]
- if not account_hash:
- account_hash = self.add_storage_account()
- else:
- account_hash = self.add_storage_account(self, account_hash)
- if not account_hash:
- self.logger.info(
- 'FAILED create_account(%s, %s, _,) [%.02f]' %
- (repr(new_account), repr(new_user), time() - begin))
- return False
- url = self.default_cluster_url.rstrip('/') + '/' + account_hash
- with self.get_conn() as conn:
- conn.execute('''INSERT OR REPLACE INTO account
- (account, url, cfaccount, user, password)
- VALUES (?, ?, ?, ?, ?)''',
- (new_account, url, account_hash, new_user, new_password))
- conn.commit()
- self.logger.info(
- 'SUCCESS create_account(%s, %s, _) = %s [%.02f]' %
- (repr(new_account), repr(new_user), repr(url), time() - begin))
- return url
Add Comment
Please, Sign In to add comment