diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2020-05-26 16:58:38 -0300 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2020-05-28 10:10:40 -0300 |
commit | 72b3e5ff5d68d9f70257f9556068cc1e5de23e1c (patch) | |
tree | 07b5e4d26eda13d11eef2b17bc94d659a2652651 /cloud_mdir_sync/gmail.py | |
parent | 88c8cdb534716a163c28ec13e12c2877cef19e1f (diff) | |
download | cloud_mdir_sync-72b3e5ff5d68d9f70257f9556068cc1e5de23e1c.tar.gz cloud_mdir_sync-72b3e5ff5d68d9f70257f9556068cc1e5de23e1c.tar.bz2 cloud_mdir_sync-72b3e5ff5d68d9f70257f9556068cc1e5de23e1c.zip |
Remove cfg.domains
Directly connect the 'account' API objects to their mailbox users through
the config language instead of trying to fix it up after the fact with
a dictionary.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'cloud_mdir_sync/gmail.py')
-rw-r--r-- | cloud_mdir_sync/gmail.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/cloud_mdir_sync/gmail.py b/cloud_mdir_sync/gmail.py index 8b03e66..b22291f 100644 --- a/cloud_mdir_sync/gmail.py +++ b/cloud_mdir_sync/gmail.py @@ -118,17 +118,20 @@ class GmailAPI(object): authenticator = None headers: Optional[Dict[str, str]] = None - def __init__(self, cfg: config.Config, domain_id: str, user: str): - self.domain_id = domain_id + def __init__(self, cfg: config.Config, user: str): + self.domain_id = f"gmail-{user}" self.cfg = cfg self.user = user + async def go(self): + cfg = self.cfg + connector = aiohttp.connector.TCPConnector(limit=20, limit_per_host=5) self.session = aiohttp.ClientSession(connector=connector, raise_for_status=False) self.redirect_url = cfg.web_app.url + "oauth2/gmail" - self.api_token = cfg.msgdb.get_authenticator(domain_id) + self.api_token = cfg.msgdb.get_authenticator(self.domain_id) self.oauth = requests_oauthlib.OAuth2Session( client_id=self.client_id, client=NativePublicApplicationClient(self.client_id), @@ -350,23 +353,15 @@ class GMailMailbox(mailbox.Mailbox): history_delta = None delete_action = "archive" # or delete - def __init__(self, cfg: config.Config, label: str, user: str): + def __init__(self, cfg: config.Config, label: str, gmail: GmailAPI): super().__init__(cfg) self.label_name = label - self.user = user + self.gmail = gmail self.gmail_messages = {} async def setup_mbox(self): """Setup access to the authenticated API domain for this endpoint""" - cfg = self.cfg - did = f"gmail-{self.user}" - self.name = f"{self.user}:{self.label_name}" - gmail = cfg.domains.get(did) - if gmail is None: - self.gmail = GmailAPI(cfg, did, self.user) - cfg.domains[did] = self.gmail - else: - self.gmail = gmail + self.name = f"{self.gmail.user}:{self.label_name}" # Verify the label exists jmsg = await self.gmail.get_json("v1", f"/users/me/labels") |