Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEFAULT_XML_ACCOUNT = '<?xml version="1.0" encoding="UTF-8"?> ' \
- '<account sysid="%(api_key)s" password="%(api_secret)s" max-binds="2" ' \
- ' max-mt-per-second="100" max-mo-per-second="2" smpp-enabled="false" ' \
- 'use-http="true" ' \
- ' http-mo-base-url="" http-dn-base-url="" http-post-username="" ' \
- 'http-post-password="" ' \
- ' http-post-method="get" encoding="latin9"> <mo-queue enabled="true" ' \
- 'mo-required="true" ' \
- ' delivery-receipts-required="true" queue-size="50" ' \
- 'discard-when-queue-full="false" /> ' \
- '<quota enabled="%(quota)s" pricing-group-id="" mo-quota-enabled="%(' \
- 'mo_quota)s" /> ' \
- '<banned banned="false" reason="" /> ' \
- '<routing group-id="" /> ' \
- '<dlr-format message-id-is-in-hex="false" /> ' \
- '<special-capabilities> ' \
- ' <internal can-specify-explicit-message-id="false" /> ' \
- ' <automatically-ack-mo-and-dlr enabled="false" /> ' \
- ' <custom-so-timeout value="0" /> ' \
- ' <custom-mo-window-size value="0" /> ' \
- ' <tlv can-specify-explicit-network-code="false" /> ' \
- ' <smpp-nack include-message-id="true" /> ' \
- ' <capabilities>%(capabilities)s</capabilities> ' \
- '</special-capabilities> ' \
- '<restrictions>%(restrictions)s</restrictions> ' \
- '<security sign-mo-and-dlr-http-requests="false" ' \
- ' require-signed-http-submissions="false" secret-key="" /> ' \
- '<capacity-thresholds>%(thresholds)s</capacity-thresholds>' \
- '<time-created>%(creation_date)s</time-created> ' \
- '<time-of-last-activity>%(creation_date)s</time-of-last-activity> ' \
- '<time-last-modified>%(creation_date)s</time-last-modified> ' \
- '</account>'
- def create_d_user(api_key,
- api_host=DEFAULT_API_HOST,
- fraud_score="GOOD",
- email_password=None,
- dry_run=False,
- verbose=True,
- registration_phone_country="US",
- registration_country="US",
- number=nexmo_random.random_number(),
- start_index=1,
- first_name=None,
- last_name=None,
- mail_domain=DEFAULT_MAIL_DOMAIN,
- credit=2,
- quota="true",
- mo_quota="true",
- capabilities='',
- restrictions='',
- thresholds='<threshold id="max-concurrent-calls" max="1000" />'):
- creation_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
- uid = uuid.uuid4()
- api_key = "{}{}{}".format(api_key, uid.hex[:8], nexmo_config.User.POSTFIX)
- print('Creating user %s' % api_key)
- api_secret = api_key
- email = '%s@%s' % (api_key, mail_domain)
- email_password = email_password if email_password is not None else "123456A"
- m = hashlib.md5()
- m.update(email_password)
- email_password_md5 = m.hexdigest()
- fn = first_name if first_name is not None else api_key
- ln = last_name if last_name is not None else DEFAULT_LASTNAME
- # Make provisioning call
- xml = DEFAULT_XML_ACCOUNT % locals()
- if verbose:
- print('HTTP request: %s' % (DEFAULT_PROV_URL % locals()))
- if not dry_run:
- prov = requests.get(DEFAULT_PROV_URL % locals())
- if 'OK' not in prov.text:
- print('Error calling provisioning API\nReq: %s\nResp: %s' %
- (DEFAULT_PROV_URL % locals(), str(prov.text)))
- return False
- # Make quota call
- if verbose:
- print('HTTP request: %s' % (DEFAULT_QUOTA_URL % locals()))
- if not dry_run:
- quota = requests.get(DEFAULT_QUOTA_URL % locals())
- quota_json = quota.json()
- if quota_json.get('result-code', -1) != 0:
- print('Error calling quota API\nReq: %s\nResp: %s' %
- (DEFAULT_QUOTA_URL % locals(), str(quota_json)))
- return False
- # Make mysql call
- mysql_conn = connector.connect(
- user=DEFAULT_MYSQL_USER,
- password=DEFAULT_MYSQL_PASSWORD,
- host=DEFAULT_MYSQL_HOST,
- database=DEFAULT_MYSQL_DATABASE)
- if verbose:
- print('Mysql query: %s' % (DEFAULT_MYSQL_QUERY % locals()))
- if not dry_run:
- cursor = mysql_conn.cursor()
- cursor.execute(DEFAULT_MYSQL_QUERY % locals())
- mysql_conn.commit()
- cursor.close()
- print json.dumps({"api_key": api_key,
- "api_secret": api_secret,
- "number": number,
- "fraud_score": fraud_score,
- "email": email,
- "email_password": email_password,
- "restrictions": restrictions,
- }, sort_keys=True, indent=4, separators=(',', ': '))
- return {"api_key": api_key,
- "api_secret": api_secret,
- "number": number,
- "fraud_score": fraud_score,
- "email": email,
- "email_password": email_password,
- "restrictions": restrictions,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement