Beispiel #1
0
def _get_bakery_client(auth_info=None):
    """Return an httpbakery.Client."""
    interaction_methods = None
    if auth_info is not None:
        interaction_methods = [AgentInteractor(auth_info)]
    else:
        username, password = None, None
        credentials = os.environ.get('MAAS_CANDID_CREDENTIALS')
        if credentials:
            user_pass = credentials.split(':', 1)
            if len(user_pass) == 2:
                username, password = user_pass
        if username and password:

            def login_with_credentials(visit_url):
                """Login with Candid's builtin username/password form.

                This is only intended for use in automated testing.

                """
                resp = requests.get(visit_url)
                assert resp.status_code == 200
                requests.post(resp.url,
                              data={
                                  'username': username,
                                  'password': password
                              })

            interaction_methods = [
                httpbakery.WebBrowserInteractor(open=login_with_credentials)
            ]

    return httpbakery.Client(interaction_methods=interaction_methods)
Beispiel #2
0
def _get_bakery_client(auth_info=None):
    """Return an httpbakery.Client."""
    if auth_info is not None:
        interactor = AgentInteractor(auth_info)
    else:
        interactor = httpbakery.WebBrowserInteractor(
            open=_candid_login(os.environ.get("MAAS_CANDID_CREDENTIALS")))
    return httpbakery.Client(interaction_methods=[interactor])
Beispiel #3
0
 def __init__(self, url, auth_info):
     self._url = url.rstrip('/')
     self._auth_info = auth_info
     interaction_methods = None
     if auth_info is not None:
         # if auth info is specified, use the default interaction (most
         # likely the browser-based one)
         interaction_methods = [AgentInteractor(self._auth_info)]
     self._client = httpbakery.Client(
         interaction_methods=interaction_methods)
Beispiel #4
0
 def __init__(self):
     auth_info = self._get_auth_info()
     self._client = httpbakery.Client(
         interaction_methods=[AgentInteractor(auth_info)])
Beispiel #5
0
 def __init__(self, url, auth_info):
     self._url = url
     self._auth_info = auth_info
     self._client = httpbakery.Client(
         interaction_methods=[AgentInteractor(self._auth_info)])