Exemplo n.º 1
0
 def check_api_key(self, bot_handler: BotHandler) -> None:
     test_request_data = self.call_link_shorten_service('www.youtube.com/watch')  # type: Any
     try:
         if self.is_invalid_token_error(test_request_data):
             bot_handler.quit('Invalid key. Follow the instructions in doc.md for setting API key.')
     except KeyError:
         pass
Exemplo n.º 2
0
    def check_access_token(self, bot_handler: BotHandler) -> None:
        test_query_response = requests.get(
            f"https://api.trello.com/1/members/{self.user_name}/", params=self.auth_params
        )

        if test_query_response.text == "invalid key":
            bot_handler.quit("Invalid Credentials. Please see doc.md to find out how to get them.")
Exemplo n.º 3
0
    def check_api_key(self, bot_handler: BotHandler) -> None:
        url = "https://api.baremetrics.com/v1/account"
        test_query_response = requests.get(url, headers=self.auth_header)
        test_query_data = test_query_response.json()

        try:
            if test_query_data["error"] == "Unauthorized. Token not found (001)":
                bot_handler.quit("API Key not valid. Please see doc.md to find out how to get it.")
        except KeyError:
            pass
Exemplo n.º 4
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('beeminder')
     # Check for valid auth_token
     auth_token = self.config_info['auth_token']
     try:
         r = requests.get("https://www.beeminder.com/api/v1/users/me.json",
                          params={'auth_token': auth_token})
         if r.status_code == 401:
             bot_handler.quit('Invalid key!')
     except ConnectionError as e:
         logging.exception(str(e))
Exemplo n.º 5
0
 def check_api_key(self, bot_handler: BotHandler) -> None:
     api_params = dict(q="nyc", APPID=self.api_key)
     test_response = requests.get(api_url, params=api_params)
     try:
         test_response_data = test_response.json()
         if test_response_data["cod"] == 401:
             bot_handler.quit(
                 "API Key not valid. Please see doc.md to find out how to get it."
             )
     except KeyError:
         pass
Exemplo n.º 6
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("salesforce")
     try:
         self.sf = simple_salesforce.Salesforce(
             username=self.config_info["username"],
             password=self.config_info["password"],
             security_token=self.config_info["security_token"],
         )
     except simple_salesforce.exceptions.SalesforceAuthenticationFailed as err:
         bot_handler.quit(
             f"Failed to log in to Salesforce. {err.code} {err.message}")
Exemplo n.º 7
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("youtube")
     # Check if API key is valid. If it is not valid, don't run the bot.
     try:
         search_youtube("test", self.config_info["key"], self.config_info["video_region"])
     except HTTPError as e:
         if e.response.json()["error"]["errors"][0]["reason"] == "keyInvalid":
             bot_handler.quit(
                 "Invalid key." "Follow the instructions in doc.md for setting API key."
             )
         else:
             raise
     except ConnectionError:
         logging.warning("Bad connection")
Exemplo n.º 8
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('youtube')
     # Check if API key is valid. If it is not valid, don't run the bot.
     try:
         search_youtube('test', self.config_info['key'],
                        self.config_info['video_region'])
     except HTTPError as e:
         if (e.response.json()['error']['errors'][0]['reason'] ==
                 'keyInvalid'):
             bot_handler.quit(
                 'Invalid key.'
                 'Follow the instructions in doc.md for setting API key.')
         else:
             raise
     except ConnectionError:
         logging.warning('Bad connection')
Exemplo n.º 9
0
    def check_access_token(self, bot_handler: BotHandler) -> None:
        test_query_header = {
            'Authorization': 'Bearer ' + self.access_token,
            'Accept-Version': '1.15',
        }
        test_query_response = requests.get(
            'https://api.mention.net/api/accounts/me',
            headers=test_query_header)

        try:
            test_query_data = test_query_response.json()
            if test_query_data['error'] == 'invalid_grant' and \
               test_query_data['error_description'] == 'The access token provided is invalid.':
                bot_handler.quit(
                    'Access Token Invalid. Please see doc.md to find out how to get it.'
                )
        except KeyError:
            pass
Exemplo n.º 10
0
    def check_access_token(self, bot_handler: BotHandler) -> None:
        test_query_header = {
            "Authorization": "Bearer " + self.access_token,
            "Accept-Version": "1.15",
        }
        test_query_response = requests.get(
            "https://api.mention.net/api/accounts/me",
            headers=test_query_header)

        try:
            test_query_data = test_query_response.json()
            if (test_query_data["error"] == "invalid_grant"
                    and test_query_data["error_description"]
                    == "The access token provided is invalid."):
                bot_handler.quit(
                    "Access Token Invalid. Please see doc.md to find out how to get it."
                )
        except KeyError:
            pass
Exemplo n.º 11
0
    def initialize(self, bot_handler: BotHandler) -> None:
        global api_key, default_team
        self.config_info = bot_handler.get_config_info("idonethis")
        if "api_key" in self.config_info:
            api_key = self.config_info["api_key"]
        else:
            logging.error("An API key must be specified for this bot to run.")
            logging.error(
                "Have a look at the Setup section of my documenation for more information."
            )
            bot_handler.quit()

        if "default_team" in self.config_info:
            default_team = self.config_info["default_team"]
        else:
            logging.error(
                "Cannot find default team. Users will need to manually specify a team each time an entry is created."
            )

        try:
            api_noop()
        except AuthenticationException:
            logging.error(
                "Authentication exception with idonethis. Can you check that your API keys are correct? "
            )
            bot_handler.quit()
        except UnspecifiedProblemException:
            logging.error(
                "Problem connecting to idonethis. Please check connection")
            bot_handler.quit()
Exemplo n.º 12
0
    def initialize(self, bot_handler: BotHandler) -> None:
        try:
            self.config = bot_handler.get_config_info("monkeytestit")
        except NoBotConfigException:
            bot_handler.quit("Quitting because there's no config file "
                             "supplied. See doc.md for a guide on setting up "
                             "one. If you already know the drill, just create "
                             'a .conf file with "monkeytestit" as the '
                             "section header and api_key = <your key> for "
                             "the api key.")

        self.api_key = self.config.get("api_key")

        if not self.api_key:
            bot_handler.quit("Config file exists, but can't find api_key key "
                             "or value. Perhaps it is misconfigured. Check "
                             "doc.md for details on how to setup the config.")

        logging.info("Checking validity of API key. This will take a while.")

        if "wrong secret" in parse.execute("check https://website",
                                           self.api_key).lower():
            bot_handler.quit("API key exists, but it is not valid. Reconfigure"
                             " your api_key value and try again.")