Skip to content

Commit

Permalink
Merge pull request #178 from djmitche/fix-root-url
Browse files Browse the repository at this point in the history
Use `root_url()` to determine root URL for all TC clients
  • Loading branch information
djmitche authored May 5, 2021
2 parents f2ffe86 + 87f8ab6 commit a410e8d
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tcadmin/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ async def apply_changes(generated, current, grep):
resources=(r for r in current.resources if reg.search(r.id)),
)

updater = Updater()
updater = await Updater()
await updater.update(generated, current)
4 changes: 2 additions & 2 deletions tcadmin/current/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from ..resources import Client
from ..util.sessions import aiohttp_session
from ..util.taskcluster import optionsFromEnvironment
from ..util.taskcluster import tcClientOptions


async def fetch_clients(resources):
auth = Auth(optionsFromEnvironment(), session=aiohttp_session())
auth = Auth(await tcClientOptions(), session=aiohttp_session())
query = {}
while True:
res = await auth.listClients(query=query)
Expand Down
4 changes: 2 additions & 2 deletions tcadmin/current/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from ..resources import Hook
from ..util.sessions import aiohttp_session
from ..util.taskcluster import optionsFromEnvironment
from ..util.taskcluster import tcClientOptions


async def fetch_hooks(resources):
hooks = Hooks(optionsFromEnvironment(), session=aiohttp_session())
hooks = Hooks(await tcClientOptions(), session=aiohttp_session())
for hookGroupId in (await hooks.listHookGroups())["groups"]:
idPrefix = "Hook={}/".format(hookGroupId)
# if no hook with this hookGroupId is managed, skip it
Expand Down
4 changes: 2 additions & 2 deletions tcadmin/current/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from ..resources import Role
from ..util.sessions import aiohttp_session
from ..util.taskcluster import optionsFromEnvironment
from ..util.taskcluster import tcClientOptions


async def fetch_roles(resources):
auth = Auth(optionsFromEnvironment(), session=aiohttp_session())
auth = Auth(await tcClientOptions(), session=aiohttp_session())
for role in await auth.listRoles():
role = Role.from_api(role)
if resources.is_managed(role.id):
Expand Down
4 changes: 2 additions & 2 deletions tcadmin/current/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from ..options import with_options
from ..resources import Secret
from ..util.sessions import aiohttp_session
from ..util.taskcluster import optionsFromEnvironment
from ..util.taskcluster import tcClientOptions


@with_options("with_secrets")
async def fetch_secrets(resources, with_secrets):
api = Secrets(optionsFromEnvironment(), session=aiohttp_session())
api = Secrets(await tcClientOptions(), session=aiohttp_session())
query = {}
while True:
res = await api.list(query=query)
Expand Down
4 changes: 2 additions & 2 deletions tcadmin/current/worker_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from ..resources import WorkerPool
from ..util.sessions import aiohttp_session
from ..util.taskcluster import optionsFromEnvironment
from ..util.taskcluster import tcClientOptions


async def fetch_worker_pools(resources):
worker_manager = WorkerManager(optionsFromEnvironment(), session=aiohttp_session())
worker_manager = WorkerManager(await tcClientOptions(), session=aiohttp_session())
query = {}
while True:
res = await worker_manager.listWorkerPools(query=query)
Expand Down
9 changes: 9 additions & 0 deletions tcadmin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ def appconfig():
appconfig = AppConfig()
with AppConfig._as_current(appconfig):
yield appconfig


@pytest.fixture(scope="module")
def fake_root_url():
import tcadmin.util.root_url
fake_root_url = "https://tc-testing.example.com"
tcadmin.util.root_url._root_url = fake_root_url
yield fake_root_url
tcadmin.util.root_url._root_url = None
2 changes: 1 addition & 1 deletion tcadmin/tests/test_current_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tcadmin.current.clients import fetch_clients


pytestmark = pytest.mark.usefixtures("appconfig")
pytestmark = pytest.mark.usefixtures("appconfig", "fake_root_url")


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tcadmin/tests/test_current_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tcadmin.current.hooks import fetch_hooks


pytestmark = pytest.mark.usefixtures("appconfig")
pytestmark = pytest.mark.usefixtures("appconfig", "fake_root_url")


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tcadmin/tests/test_current_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tcadmin.current.roles import fetch_roles


pytestmark = pytest.mark.usefixtures("appconfig")
pytestmark = pytest.mark.usefixtures("appconfig", "fake_root_url")


@pytest.fixture
Expand Down
3 changes: 3 additions & 0 deletions tcadmin/tests/test_current_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from tcadmin.current.secrets import fetch_secrets


pytestmark = pytest.mark.usefixtures("fake_root_url")


@pytest.fixture
def Secrets(mocker):
"""
Expand Down
2 changes: 1 addition & 1 deletion tcadmin/tests/test_current_worker_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tcadmin.current.worker_pools import fetch_worker_pools


pytestmark = pytest.mark.usefixtures("appconfig")
pytestmark = pytest.mark.usefixtures("appconfig", "fake_root_url")


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tcadmin/tests/test_util_scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os

from tcadmin.util.scopes import Resolver, satisfies
from tcadmin.util.taskcluster import optionsFromEnvironment
from tcadmin.resources import Role, Resources


Expand Down Expand Up @@ -238,7 +237,8 @@ def auth():
pytest.fail(msg)
else:
pytest.skip(msg)
return taskcluster.Auth(optionsFromEnvironment())
return
return taskcluster.Auth({"rootUrl": os.environ["TASKCLUSTER_ROOT_URL"]})


@pytest.fixture(scope="module")
Expand Down
12 changes: 6 additions & 6 deletions tcadmin/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .appconfig import AppConfig
from .util.ansi import strip_ansi
from .util.sessions import aiohttp_session
from .util.taskcluster import optionsFromEnvironment
from .util.taskcluster import tcClientOptions
from .constants import (
ACTION_CREATE,
ACTION_UPDATE,
Expand All @@ -29,12 +29,12 @@ class Updater:
A simple one-instance class to encapsulate shared Taskcluster API clients.
"""

def __init__(self):
self.auth = Auth(optionsFromEnvironment(), session=aiohttp_session())
self.secrets = Secrets(optionsFromEnvironment(), session=aiohttp_session())
self.hooks = Hooks(optionsFromEnvironment(), session=aiohttp_session())
async def __init__(self):
self.auth = Auth(await tcClientOptions(), session=aiohttp_session())
self.secrets = Secrets(await tcClientOptions(), session=aiohttp_session())
self.hooks = Hooks(await tcClientOptions(), session=aiohttp_session())
self.worker_manager = WorkerManager(
optionsFromEnvironment(), session=aiohttp_session()
await tcClientOptions(), session=aiohttp_session()
)

async def create_role(self, role):
Expand Down
13 changes: 9 additions & 4 deletions tcadmin/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.

from taskcluster import optionsFromEnvironment as originalOptions
from taskcluster import optionsFromEnvironment
import os

from .root_url import root_url

def optionsFromEnvironment():
"""Build Taskcluster options, supporting proxy"""

async def tcClientOptions():
"""Build Taskcluster client options, supporting proxy and getting root_url
from the appconfig"""
if "TASKCLUSTER_PROXY_URL" in os.environ:
return {"rootUrl": os.environ["TASKCLUSTER_PROXY_URL"]}
else:
return originalOptions()
options = optionsFromEnvironment()
options["rootUrl"] = await root_url()
return options

0 comments on commit a410e8d

Please sign in to comment.