async def upload_to_s3(context, s3_key, path): product = get_product_name(context.release_props["appName"].lower(), context.release_props["stage_platform"]) mime_type = mimetypes.guess_type(path)[0] if not mime_type: raise ScriptWorkerTaskException( "Unable to discover valid mime-type for path ({}), " "mimetypes.guess_type() returned {}".format(path, mime_type)) api_kwargs = { "Bucket": get_bucket_name(context, product), "Key": s3_key, "ContentType": mime_type } headers = { "Content-Type": mime_type, "Cache-Control": "public, max-age=%d" % CACHE_CONTROL_MAXAGE } creds = context.config["bucket_config"][context.bucket]["credentials"] s3 = boto3.client("s3", aws_access_key_id=creds["id"], aws_secret_access_key=creds["key"]) url = s3.generate_presigned_url("put_object", api_kwargs, ExpiresIn=1800, HttpMethod="PUT") log.info("upload_to_s3: %s -> s3://%s/%s", path, api_kwargs.get("Bucket"), s3_key) await retry_async(put, args=(context, url, headers, path), retry_exceptions=(Exception, ), kwargs={"session": context.session})
def enrich_balrog_manifest(context, locale): release_props = context.release_props url_replacements = [] if release_props["branch"] in RELEASE_BRANCHES: url_replacements.append(['http://archive.mozilla.org/pub', 'http://download.cdn.mozilla.net/pub']) enrich_dict = { "appName": get_product_name(release_props['appName'], release_props['stage_platform']), "appVersion": release_props["appVersion"], "branch": release_props["branch"], "buildid": release_props["buildid"], "extVersion": release_props["appVersion"], "hashType": release_props["hashType"], "locale": locale if not locale == 'multi' else 'en-US', "platform": NORMALIZED_BALROG_PLATFORMS.get(release_props["stage_platform"], release_props["stage_platform"]), "url_replacements": url_replacements } if is_promotion_action(context.action) or is_release_action(context.action): enrich_dict["tc_release"] = True enrich_dict["build_number"] = context.task['payload']['build_number'] enrich_dict["version"] = context.task['payload']['version'] else: enrich_dict["tc_nightly"] = True return enrich_dict
async def upload_to_s3(context, s3_key, path): product = get_product_name(context.release_props['appName'].lower(), context.release_props['stage_platform']) mime_type = mimetypes.guess_type(path)[0] if not mime_type: raise ScriptWorkerTaskException("Unable to discover valid mime-type for path ({}), " "mimetypes.guess_type() returned {}".format( path, mime_type )) api_kwargs = { 'Bucket': get_bucket_name(context, product), 'Key': s3_key, 'ContentType': mime_type, } headers = { 'Content-Type': mime_type, 'Cache-Control': 'public, max-age=%d' % CACHE_CONTROL_MAXAGE, } creds = context.config['bucket_config'][context.bucket]['credentials'] s3 = boto3.client('s3', aws_access_key_id=creds['id'], aws_secret_access_key=creds['key'],) url = s3.generate_presigned_url('put_object', api_kwargs, ExpiresIn=1800, HttpMethod='PUT') log.info("upload_to_s3: %s -> s3://%s/%s", path, api_kwargs.get('Bucket'), s3_key) await retry_async(put, args=(context, url, headers, path), retry_exceptions=(Exception, ), kwargs={'session': context.session})
def test_get_product_name(appName, tmpl_key, expected): assert get_product_name(appName, tmpl_key) == expected