Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Remove basic auth support (#52)
Browse files Browse the repository at this point in the history
* Remove basic auth support

* Update hash

* Version bump
  • Loading branch information
Rail Aliiev committed Apr 4, 2019
1 parent e3851d4 commit f2ca15e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 107 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Scriptworker Specfic:

Balrog Specific:
- `BALROG_API_ROOT`
- `BALROG_USERNAME`
- `BALROG_PASSWORD`

### task.json

Expand Down
2 changes: 1 addition & 1 deletion balrogscript/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.0.0"
__version__ = "5.0.0"
42 changes: 17 additions & 25 deletions balrogscript/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@


# create_locale_submitter {{{1
def create_locale_submitter(e, extra_suffix, balrog_auth, auth0_secrets, config):
auth = balrog_auth

def create_locale_submitter(e, extra_suffix, auth0_secrets, config):
if "tc_release" in e:
log.info("Taskcluster Release style Balrog submission")

submitter = ReleaseSubmitterV9(
api_root=config['api_root'], auth=auth, auth0_secrets=auth0_secrets,
api_root=config['api_root'], auth0_secrets=auth0_secrets,
dummy=config['dummy'],
suffix=e.get('blob_suffix', '') + extra_suffix,
)
Expand All @@ -59,7 +57,7 @@ def create_locale_submitter(e, extra_suffix, balrog_auth, auth0_secrets, config)
elif "tc_nightly" in e:
log.info("Taskcluster Nightly style Balrog submission")

submitter = NightlySubmitterV4(api_root=config['api_root'], auth=auth,
submitter = NightlySubmitterV4(api_root=config['api_root'],
auth0_secrets=auth0_secrets,
dummy=config['dummy'],
url_replacements=e.get('url_replacements', []))
Expand All @@ -83,7 +81,7 @@ def create_locale_submitter(e, extra_suffix, balrog_auth, auth0_secrets, config)


# submit_locale {{{1
def submit_locale(task, config, balrog_auth, auth0_secrets):
def submit_locale(task, config, auth0_secrets):
"""Submit a release blob to balrog."""
upstream_artifacts = get_upstream_artifacts(task)

Expand All @@ -95,7 +93,7 @@ def submit_locale(task, config, balrog_auth, auth0_secrets):
for e in manifest:
for suffix in suffixes:
# Get release metadata from manifest
submitter, release = create_locale_submitter(e, suffix, balrog_auth, auth0_secrets, config)
submitter, release = create_locale_submitter(e, suffix, auth0_secrets, config)
# Connect to balrog and submit the metadata
retry(lambda: submitter.run(**release))

Expand All @@ -105,11 +103,10 @@ def create_scheduler(**kwargs):
return ReleaseScheduler(**kwargs)


def schedule(task, config, balrog_auth, auth0_secrets):
def schedule(task, config, auth0_secrets):
"""Schedule a release to ship on balrog channel(s)"""
auth = balrog_auth
scheduler = create_scheduler(
api_root=config['api_root'], auth=auth,
api_root=config['api_root'],
auth0_secrets=auth0_secrets,
dummy=config['dummy'],
suffix=task['payload'].get('blob_suffix', ''),
Expand Down Expand Up @@ -137,9 +134,8 @@ def create_pusher(**kwargs):
return ReleasePusher(**kwargs)


def submit_toplevel(task, config, balrog_auth, auth0_secrets):
def submit_toplevel(task, config, auth0_secrets):
"""Push a top-level release blob to balrog."""
auth = balrog_auth
partials = {}
if task['payload'].get('partial_versions'):
for v in task['payload']['partial_versions'].split(','):
Expand All @@ -151,7 +147,7 @@ def submit_toplevel(task, config, balrog_auth, auth0_secrets):

for suffix in suffixes:
creator = create_creator(
api_root=config['api_root'], auth=auth,
api_root=config['api_root'],
auth0_secrets=auth0_secrets,
dummy=config['dummy'],
suffix=task['payload'].get('blob_suffix', '') + suffix,
Expand All @@ -175,7 +171,7 @@ def submit_toplevel(task, config, balrog_auth, auth0_secrets):
))

pusher = create_pusher(
api_root=config['api_root'], auth=auth,
api_root=config['api_root'],
auth0_secrets=auth0_secrets,
dummy=config['dummy'],
suffix=task['payload'].get('blob_suffix', ''),
Expand Down Expand Up @@ -210,27 +206,23 @@ def update_config(config, server='default'):
config = deepcopy(config)

config['api_root'] = config['server_config'][server]['api_root']
basic_auth = (
config['server_config'][server]['balrog_username'],
config['server_config'][server]['balrog_password'],
)
auth0_secrets = dict(
domain=config['server_config'][server]['auth0_domain'],
client_id=config['server_config'][server]['auth0_client_id'],
client_secret=config['server_config'][server]['auth0_client_secret'],
audience=config['server_config'][server]['auth0_audience'],
)
del(config['server_config'])
return (basic_auth, auth0_secrets), config
return auth0_secrets, config


# load_config {{{1
def load_config(path=None):
try:
with open(path) as fh:
config = json.load(fh)
except (ValueError, OSError, IOError) as e:
print >> sys.stderr, "Can't read config file {}!\n{}".format(path, e)
except (ValueError, OSError, IOError):
log.fatal("Can't read config file %s", path)
sys.exit(5)
return config

Expand Down Expand Up @@ -265,14 +257,14 @@ def main(config_path=None):
validate_task_schema(config, task, action)

server = get_task_server(task, config)
(balrog_auth, auth0_secrets), config = update_config(config, server)
auth0_secrets, config = update_config(config, server)

if action == 'submit-toplevel':
submit_toplevel(task, config, balrog_auth, auth0_secrets)
submit_toplevel(task, config, auth0_secrets)
elif action == 'schedule':
schedule(task, config, balrog_auth, auth0_secrets)
schedule(task, config, auth0_secrets)
else:
submit_locale(task, config, balrog_auth, auth0_secrets)
submit_locale(task, config, auth0_secrets)


__name__ == '__main__' and main()
29 changes: 12 additions & 17 deletions balrogscript/submitter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ def _getFileUrls(self, productName, version, buildNumber, updateChannels,
class ReleaseCreatorV9(ReleaseCreatorFileUrlsMixin):
schemaVersion = 9

def __init__(self, api_root, auth, auth0_secrets=None, dummy=False, suffix="",
def __init__(self, api_root, auth0_secrets=None, dummy=False, suffix="",
from_suffix="",
complete_mar_filename_pattern=None,
complete_mar_bouncer_product_pattern=None):
self.api_root = api_root
self.auth = auth
self.auth0_secrets = auth0_secrets
self.suffix = suffix
self.from_suffix = from_suffix
Expand Down Expand Up @@ -176,7 +175,7 @@ def run(self, appVersion, productName, version, buildNumber,
updateLine, **updateKwargs)
name = get_release_blob_name(productName, version, buildNumber,
self.suffix)
api = Release(name=name, auth=self.auth, auth0_secrets=self.auth0_secrets, api_root=self.api_root)
api = Release(name=name, auth0_secrets=self.auth0_secrets, api_root=self.api_root)
try:
current_data, data_version = api.get_data()
except HTTPError as e:
Expand All @@ -197,9 +196,8 @@ def run(self, appVersion, productName, version, buildNumber,
class NightlySubmitterBase(object):
build_type = 'nightly'

def __init__(self, api_root, auth, auth0_secrets=None, dummy=False, url_replacements=None):
def __init__(self, api_root, auth0_secrets=None, dummy=False, url_replacements=None):
self.api_root = api_root
self.auth = auth
self.auth0_secrets = auth0_secrets
self.dummy = dummy
self.url_replacements = url_replacements
Expand Down Expand Up @@ -244,7 +242,7 @@ def run(self, platform, buildID, productName, branch, appVersion, locale,
name = get_nightly_blob_name(productName, branch, build_type, buildID,
self.dummy)
api = SingleLocale(name=name, build_target=build_target, locale=locale,
auth=self.auth, auth0_secrets=self.auth0_secrets, api_root=self.api_root)
auth0_secrets=self.auth0_secrets, api_root=self.api_root)

# wrap operations into "atomic" functions that can be retried
def update_dated():
Expand Down Expand Up @@ -273,7 +271,7 @@ def update_dated():
retry(update_dated, sleeptime=2, max_sleeptime=2, attempts=10)

latest = SingleLocale(
api_root=self.api_root, auth=self.auth,
api_root=self.api_root,
auth0_secrets=self.auth0_secrets,
name=get_nightly_blob_name(productName, branch, build_type,
'latest', self.dummy),
Expand Down Expand Up @@ -372,9 +370,8 @@ def _get_update_data(self, productName, version, build_number,


class ReleaseSubmitterV9(MultipleUpdatesReleaseMixin):
def __init__(self, api_root, auth, auth0_secrets=None, dummy=False, suffix="", from_suffix=""):
def __init__(self, api_root, auth0_secrets=None, dummy=False, suffix="", from_suffix=""):
self.api_root = api_root
self.auth = auth
self.auth0_secrets = auth0_secrets
self.suffix = suffix
if dummy:
Expand All @@ -400,7 +397,7 @@ def run(self, platform, productName, appVersion, version, build_number, locale,
**updateKwargs))

api = SingleLocale(name=name, build_target=build_target, locale=locale,
auth=self.auth, auth0_secrets=self.auth0_secrets,
auth0_secrets=self.auth0_secrets,
api_root=self.api_root)
current_data, data_version = api.get_data()
api.update_build(
Expand All @@ -411,9 +408,8 @@ def run(self, platform, productName, appVersion, version, build_number, locale,


class ReleasePusher(object):
def __init__(self, api_root, auth, auth0_secrets=None, dummy=False, suffix=""):
def __init__(self, api_root, auth0_secrets=None, dummy=False, suffix=""):
self.api_root = api_root
self.auth = auth
self.auth0_secrets = auth0_secrets
self.suffix = suffix
if dummy:
Expand All @@ -426,14 +422,13 @@ def run(self, productName, version, build_number, rule_ids, backgroundRate=None)
data = {"mapping": name}
if backgroundRate:
data["backgroundRate"] = backgroundRate
Rule(api_root=self.api_root, auth=self.auth,
Rule(api_root=self.api_root,
auth0_secrets=self.auth0_secrets, rule_id=rule_id).update_rule(**data)


class ReleaseScheduler(object):
def __init__(self, api_root, auth, auth0_secrets=None, dummy=False, suffix=""):
def __init__(self, api_root, auth0_secrets=None, dummy=False, suffix=""):
self.api_root = api_root
self.auth = auth
self.auth0_secrets = auth0_secrets
self.suffix = suffix
if dummy:
Expand All @@ -452,7 +447,7 @@ def run(self, productName, version, build_number, rule_ids, when=None, backgroun

for rule_id in rule_ids:
data, data_version = Rule(
api_root=self.api_root, auth=self.auth, auth0_secrets=self.auth0_secrets,
api_root=self.api_root, auth0_secrets=self.auth0_secrets,
rule_id=rule_id).get_data()
# If the _currently_ shipped release is at a background rate of
# 100%, it's safe to set it as the fallback mapping. (Everyone
Expand All @@ -475,5 +470,5 @@ def run(self, productName, version, build_number, rule_ids, when=None, backgroun
data["backgroundRate"] = backgroundRate

ScheduledRuleChange(
api_root=self.api_root, auth=self.auth, auth0_secrets=self.auth0_secrets,
api_root=self.api_root, auth0_secrets=self.auth0_secrets,
rule_id=rule_id).add_scheduled_rule_change(**data)
6 changes: 0 additions & 6 deletions balrogscript/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def config():
"server_config": {
"nightly": {
"api_root": "BALROG_API_ROOT",
"balrog_username": "BALROG_USERNAME",
"balrog_password": "BALROG_PASSWORD",
"auth0_domain": "AUTH0_DOMAIN",
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
Expand All @@ -57,8 +55,6 @@ def config():
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
"auth0_audience": "AUTH0_AUDIENCE",
"balrog_username": "BALROG_USERNAME",
"balrog_password": "BALROG_PASSWORD",
"allowed_channels": ["release", "release-localtest", "release-cdntest"]
},
"dep": {
Expand All @@ -67,8 +63,6 @@ def config():
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
"auth0_audience": "AUTH0_AUDIENCE",
"balrog_username": "BALROG_USERNAME",
"balrog_password": "BALROG_PASSWORD",
"allowed_channels": ["nightly", "release", "beta", "etc"]
},

Expand Down
12 changes: 3 additions & 9 deletions balrogscript/test/data/hardcoded_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"auth0_domain": "AUTH0_DOMAIN",
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
"auth0_audience": "AUTH0_AUDIENCE",
"balrog_password": "BALROG_PASSWORD",
"balrog_username": "BALROG_USERNAME"
"auth0_audience": "AUTH0_AUDIENCE"
},
"nightly": {
"allowed_channels": [
Expand All @@ -27,9 +25,7 @@
"auth0_domain": "AUTH0_DOMAIN",
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
"auth0_audience": "AUTH0_AUDIENCE",
"balrog_password": "BALROG_PASSWORD",
"balrog_username": "BALROG_USERNAME"
"auth0_audience": "AUTH0_AUDIENCE"
},
"release": {
"allowed_channels": [
Expand All @@ -41,9 +37,7 @@
"auth0_domain": "AUTH0_DOMAIN",
"auth0_client_id": "AUTH0_CLIENT_ID",
"auth0_client_secret": "AUTH0_CLIENT_SECRET",
"auth0_audience": "AUTH0_AUDIENCE",
"balrog_password": "BALROG_PASSWORD",
"balrog_username": "BALROG_USERNAME"
"auth0_audience": "AUTH0_AUDIENCE"
}
},
"verbose": true,
Expand Down

0 comments on commit f2ca15e

Please sign in to comment.