示例#1
0
 async def _retrieve_from_db(
     cls,
     redis: redis_utils.RedisCache,
     api_access_key: str,
     api_secret_key: str,
     account_scope: typing.Optional[github_types.GitHubLogin],
 ) -> "ApplicationSaas":
     async with dashboard.AsyncDashboardSaasClient() as client:
         headers: typing.Dict[str, str]
         if account_scope is None:
             headers = {}
         else:
             headers = {"Mergify-Application-Account-Scope": account_scope}
         resp = await client.post(
             "/engine/applications",
             json={"token": f"{api_access_key}{api_secret_key}"},
             headers=headers,
         )
         data = typing.cast(ApplicationDashboardJSON, resp.json())
         return cls(
             redis,
             data["id"],
             data["name"],
             api_access_key,
             api_secret_key,
             account_scope=None
             if account_scope is None else ApplicationAccountScope(
                 {
                     "id": data["github_account"]["id"],
                     "login": data["github_account"]["login"],
                 }),
         )
示例#2
0
 async def _retrieve_from_db(cls, redis: utils.RedisCache,
                             owner_id: int) -> "UserTokensSaas":
     async with dashboard.AsyncDashboardSaasClient() as client:
         try:
             resp = await client.get(f"/engine/user_tokens/{owner_id}")
         except http.HTTPNotFound:
             return cls(redis, owner_id, [])
         else:
             tokens = resp.json()
             return cls(redis, owner_id, tokens["user_tokens"])
示例#3
0
 async def _retrieve_subscription_from_db(cls: typing.Type[SubscriptionT],
                                          redis: utils.RedisCache,
                                          owner_id: int) -> SubscriptionT:
     async with dashboard.AsyncDashboardSaasClient() as client:
         try:
             resp = await client.get(f"/engine/subscription/{owner_id}")
         except http.HTTPNotFound:
             raise exceptions.MergifyNotInstalled()
         else:
             sub = resp.json()
             return cls.from_dict(redis, owner_id, sub)