Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_version(self):
"""Version returned."""
runner = CliRunner()
expected_output = "greynoise {}".format(__version__)
result = runner.invoke(subcommand.version)
assert result.exit_code == 0
assert result.output.startswith(expected_output)
:param endpoint: Endpoint to send the request to.
:type endpoint: str
:param params: Request parameters.
:type param: dict
:param json: Request's JSON payload.
:type json: dict
:returns: Response's JSON payload
:rtype: dict
:raises RequestFailure: when HTTP status code is not 2xx
"""
if params is None:
params = {}
headers = {
"User-Agent": "GreyNoise/{}".format(__version__),
"key": self.api_key,
}
url = "/".join([self.BASE_URL, self.API_VERSION, endpoint])
LOGGER.msg(
"Sending API request...", url=url, params=params, json=json, level="debug"
)
response = self.session.get(
url, headers=headers, timeout=self.timeout, params=params, json=json
)
if "application/json" in response.headers.get("Content-Type", ""):
body = response.json()
else:
body = response.text
if response.status_code == 429:
def version():
"""Get version and OS information for your GreyNoise commandline installation."""
click.echo(
"greynoise {}\n"
" Python {}\n"
" {}\n".format(__version__, platform.python_version(), platform.platform())
)
:type endpoint: str
:param params: Request parameters
:type param: dict
:param json: Request's JSON payload
:type json: dict
:param method: Request method name
:type method: str
:returns: Response's JSON payload
:rtype: dict
:raises RequestFailure: when HTTP status code is not 2xx
"""
if params is None:
params = {}
headers = {
"User-Agent": "GreyNoise/{}".format(__version__),
"key": self.api_key,
}
url = "/".join([self.api_server, self.API_VERSION, endpoint])
LOGGER.debug(
"Sending API request...", url=url, method=method, params=params, json=json
)
request_method = getattr(self.session, method)
response = request_method(
url, headers=headers, timeout=self.timeout, params=params, json=json
)
content_type = response.headers.get("Content-Type", "")
if "application/json" in content_type:
body = response.json()
else:
body = response.text