def generate_access_token(self, from_refresh_token: bool):
        """Generate the Token and Refresh token.

        Args:
            from_refresh_token (bool): To generate Access Token from refresh token or not

        Raises:
            ValueError: When response status code is not [200,201]
        """
        try:
            __method_name = inspect.currentframe().f_code.co_name
            url = self.base_url + consts.OAUTH2_ENDPOINT
            auth = HTTPBasicAuth(self.client_id, self.client_secret)
            data = None
            if from_refresh_token:
                data = {
                    "grant_type": "refresh_token",
                    "refresh_token": self.refresh_token,
                }
                self.applogger.debug(
                    "{}(method={}) : {} : Generating access token using refresh token.".format(
                        consts.LOGS_STARTS_WITH, __method_name, self.function_name
                    )
                )
            else:
                data = {"grant_type": "client_credentials"}
                self.applogger.debug(
                    "{}(method={}) : {} : Generating access token.".format(
                        consts.LOGS_STARTS_WITH, __method_name, self.function_name
                    )
                )
            response = requests.post(url, auth=auth, data=data, timeout=consts.API_TIMEOUT)

            if response.status_code in [200, 201]:
                token_data = response.json()
                self.add_token_expiration_to_checkpoint_file(token_data, from_refresh_token)
                self.update_checkpoint_of_disabling_function(make_count_zero=True)
                self.applogger.debug(
                    "{}(method={}) : {} : New access token generated successfully ".format(
                        consts.LOGS_STARTS_WITH, __method_name, self.function_name
                    )
                )
            elif response.status_code in [400, 401, 403, 404]:
                self.update_checkpoint_of_disabling_function()
                self.applogger.error(
                    "{}(method={}) : {} : status code={}, reason={}".format(
                        consts.LOGS_STARTS_WITH,
                        __method_name,
                        self.function_name,
                        response.status_code,
                        response.text
                    )
                )
                raise Exception
            else:
                self.applogger.error(
                    "{}(method={}) : {} : Unknown status code: {} ".format(
                        consts.LOGS_STARTS_WITH,
                        __method_name,
                        self.function_name,
                        response.status_code,
                    )
                )
                raise Exception

        except requests.exceptions.RequestException as err:
            self.applogger.error(
                "{}(method={}) : {} : Error occurred while generating a Access Token : {} ".format(
                    consts.LOGS_STARTS_WITH, __method_name, self.function_name, err
                )
            )
            raise Exception(f"Error occurred while generating a Access Token : {err}")
        except Exception as err:
            self.applogger.error(
                "{}(method={}) : {} : Error occurred while generating a Access Token : {} ".format(
                    consts.LOGS_STARTS_WITH, __method_name, self.function_name, err
                )
            )
            raise Exception(err)
Generate the Token and Refresh token.

        Args:
            from_refresh_token (bool): To generate Access Token from refresh token or not

        Raises:
            ValueError: When response status code is not [200,201]
        
Solutions/Vectra XDR/Data Connectors/VectraDataConnector/SharedCode/collector.py