Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
soql_check_upload = "select Status, Errors, MetadataPackageVersionId from PackageUploadRequest where Id = '{}'".format(upload['id'])
upload = self.tooling.query(soql_check_upload)
if upload['totalSize'] != 1:
message = 'Failed to get info for upload with id {}'.format(upload_id)
self.logger.error(message)
raise SalesforceException(message)
upload = upload['records'][0]
while upload['Status'] == 'IN_PROGRESS' or upload['Status'] == 'QUEUED':
time.sleep(3)
upload = self.tooling.query(soql_check_upload)
if upload['totalSize'] != 1:
message = 'Failed to get info for upload with id {}'.format(upload_id)
self.logger.error(message)
raise SalesforceException(message)
upload = upload['records'][0]
if upload['Status'] == 'ERROR':
self.logger.error('Package upload failed with the following errors')
for error in upload['Errors']['errors']:
self.logger.error(' {}'.format(error['message']))
if error['message'] == 'ApexTestFailure':
e = ApexTestException
else:
e = SalesforceException
raise e('Package upload failed')
else:
time.sleep(5)
version_id = upload['MetadataPackageVersionId']
version_res = self.tooling.query("select MajorVersion, MinorVersion, PatchVersion, BuildNumber, ReleaseState from MetadataPackageVersion where Id = '{}'".format(version_id))
if version_res['totalSize'] != 1:
def _poll_action(self):
elapsed = datetime.now() - self.time_start
if elapsed.total_seconds() > self.options["timeout"]:
raise SalesforceException(
"Community creation not finished after {timeout} seconds".format(
**self.options
)
)
community_list = self.sf.restful("connect/communities")["communities"]
communities = {c["name"]: c for c in community_list}
if self.options["name"] in communities:
self.poll_complete = True
self.logger.info(
"Community {} created".format(communities[self.options["name"]]["id"])
)
time.sleep(3)
upload = self.tooling.query(soql_check_upload)
if upload['totalSize'] != 1:
message = 'Failed to get info for upload with id {}'.format(upload_id)
self.logger.error(message)
raise SalesforceException(message)
upload = upload['records'][0]
if upload['Status'] == 'ERROR':
self.logger.error('Package upload failed with the following errors')
for error in upload['Errors']['errors']:
self.logger.error(' {}'.format(error['message']))
if error['message'] == 'ApexTestFailure':
e = ApexTestException
else:
e = SalesforceException
raise e('Package upload failed')
else:
time.sleep(5)
version_id = upload['MetadataPackageVersionId']
version_res = self.tooling.query("select MajorVersion, MinorVersion, PatchVersion, BuildNumber, ReleaseState from MetadataPackageVersion where Id = '{}'".format(version_id))
if version_res['totalSize'] != 1:
message = 'Version {} not found'.format(version_id)
self.logger.error(message)
raise SalesforceException(message)
version = version_res['records'][0]
version_parts = [
str(version['MajorVersion']),
str(version['MinorVersion']),
]
if version['PatchVersion']:
def _run_task(self):
package_res = self.tooling.query("select Id from MetadataPackage where NamespacePrefix='{}'".format(self.options['namespace']))
if package_res['totalSize'] != 1:
message = 'No package found with namespace {}'.format(self.options['namespace'])
self.logger.error(message)
raise SalesforceException(message)
package_id = package_res['records'][0]['Id']
production = self.options.get('production', False) in [True, 'True', 'true']
package_info = {
'VersionName': self.options['name'],
'IsReleaseVersion': production,
'MetadataPackageId': package_id,
}
if 'description' in self.options:
package_info['Description'] = self.options['description']
if 'password' in self.options:
package_info['Password'] = self.options['password']
if 'post_install_url' in self.options:
package_info['PostInstallUrl'] = self.options['post_install_url']
def _get_one_record(self, query, message):
result = self.tooling.query(query)
if result["totalSize"] != 1:
self.logger.error(message)
raise SalesforceException(message)
return result["records"][0]
def _run_task(self):
package_res = self.tooling.query("select Id from MetadataPackage where NamespacePrefix='{}'".format(self.options['namespace']))
if package_res['totalSize'] != 1:
message = 'No package found with namespace {}'.format(self.options['namespace'])
self.logger.error(message)
raise SalesforceException(message)
package_id = package_res['records'][0]['Id']
production = self.options.get('production', False) in [True, 'True', 'true']
package_info = {
'VersionName': self.options['name'],
'IsReleaseVersion': production,
'MetadataPackageId': package_id,
}
if 'description' in self.options:
package_info['Description'] = self.options['description']
if 'password' in self.options:
package_info['Password'] = self.options['password']
if 'post_install_url' in self.options:
package_info['PostInstallUrl'] = self.options['post_install_url']