Пример #1
0
 def _check_with_catalog(logger: AirbyteLogger, streams: List,
                         config: json):
     repositories = config["repository"].split(" ")
     for repository in repositories:
         org = repository.split("/")[0]
         # requests for checking streams permissions
         # first is for checking if user has access to Collaborators API
         # if user is not one of the collaborators, request will return 403 error
         # third is for checking access and permission to Teams API
         # Teams API is only available to authenticated members of the team's organization,
         # in another case it will return 404 error
         # if user doesn't have permission, it will return 401 error
         check_streams = {
             "collaborators":
             f"https://api.github.com/repos/{repository}/collaborators",
             "teams":
             f"https://api.github.com/orgs/{org}/teams?sort=created_at&direction=desc",
         }
         for stream in streams:
             if stream in check_streams:
                 response = requests.get(check_streams[stream],
                                         auth=(config["access_token"], ""))
                 if response.status_code != requests.codes.ok:
                     logger.log_by_prefix(f"{repository} {response.text}",
                                          "ERROR")
                     sys.exit(1)
Пример #2
0
 def _check_internal(self, logger: AirbyteLogger, streams: List,
                     config: json):
     # checking if REPORT syncing will be called for manager account
     # https://developers.google.com/adwords/api/docs/common-errors#ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH
     try:
         customer_ids = config["customer_ids"].split(",")
         oauth2_client = oauth2.GoogleRefreshTokenClient(
             config["oauth_client_id"], config["oauth_client_secret"],
             config["refresh_token"])
         for customer_id in customer_ids:
             sdk_client = adwords.AdWordsClient(
                 config["developer_token"],
                 oauth2_client,
                 user_agent=config["user_agent"],
                 client_customer_id=customer_id)
             selector = {
                 "fields": [
                     "Name", "CanManageClients", "CustomerId",
                     "TestAccount", "DateTimeZone", "CurrencyCode"
                 ],
                 "predicates": [{
                     "field": "CustomerId",
                     "operator": "IN",
                     "values": [
                         customer_id,
                     ],
                 }],
             }
             accounts = self._get_accounts(logger, sdk_client, selector)
             if accounts:
                 account = accounts[0]
                 is_manager = account.canManageClients
                 for stream in streams:
                     if stream.endswith("REPORT") and is_manager:
                         logger.log_by_prefix(
                             f"Unable to sync {stream} with the manager account {customer_id}",
                             "ERROR")
                         sys.exit(1)
             else:
                 err = f"No accounts associated with customer id {customer_id}"
                 logger.log_by_prefix(
                     f"Unable to sync with the provided credentials. Error: {err}",
                     "ERROR")
                 sys.exit(1)
     except Exception as err:
         logger.log_by_prefix(f"Unable to sync. Error: {err}", "ERROR")
         sys.exit(1)