-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(status_cmd): add the api-status command
- Loading branch information
Showing
7 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/python3 | ||
|
||
import click | ||
from pygitguardian import GGClient | ||
from pygitguardian.models import HealthCheckResponse | ||
|
||
from ggshield.output.text.message import format_healthcheck_status | ||
|
||
from .utils import json_output_option_decorator, retrieve_client | ||
|
||
|
||
@click.command() | ||
@click.pass_context | ||
def status(ctx: click.Context, json_output: bool) -> int: | ||
"""Command to show api status.""" | ||
client: GGClient = retrieve_client(ctx) | ||
response: HealthCheckResponse = client.health_check() | ||
|
||
if not isinstance(response, HealthCheckResponse): | ||
raise click.ClickException("Unexpected health check response") | ||
|
||
click.echo( | ||
response.to_json() | ||
if json_output | ||
else ( | ||
f"status: {format_healthcheck_status(response)}\n" | ||
f"app-version: {response.app_version or 'Unknown'}\n" | ||
"secrets-engine-version-version: " | ||
f"{response.secrets_engine_version or 'Unknown'}\n" | ||
) | ||
) | ||
|
||
return 0 | ||
|
||
|
||
status = json_output_option_decorator(status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- "*/*" | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- pygitguardian/1.1.0 (Linux;py3.8.3) | ||
method: GET | ||
uri: https://api.gitguardian.com/v1/health | ||
response: | ||
body: | ||
string: '{"detail":"Valid API key."}' | ||
headers: | ||
Allow: | ||
- OPTIONS, GET | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "27" | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Fri, 19 Jun 2020 13:32:39 GMT | ||
Server: | ||
- nginx | ||
Vary: | ||
- Cookie | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
X-App-Version: | ||
- 1.26.0-rc.4 | ||
X-Secrets-Engine-Version: | ||
- 2.43.0 | ||
status: | ||
code: 200 | ||
message: OK | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- "*/*" | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- pygitguardian/1.1.0 (Linux;py3.8.3) | ||
method: GET | ||
uri: https://api.gitguardian.com/v1/health | ||
response: | ||
body: | ||
string: '{"detail":"Valid API key."}' | ||
headers: | ||
Allow: | ||
- OPTIONS, GET | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "27" | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Fri, 19 Jun 2020 14:58:35 GMT | ||
Server: | ||
- nginx | ||
Vary: | ||
- Cookie | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
X-App-Version: | ||
- 1.26.0-rc.4 | ||
X-Secrets-Engine-Version: | ||
- 2.43.0 | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- "*/*" | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- pygitguardian/1.1.0 (Linux;py3.8.3) | ||
method: GET | ||
uri: https://api.gitguardian.com/v1/health | ||
response: | ||
body: | ||
string: '{"error":"Configuration error."}' | ||
headers: | ||
Allow: | ||
- OPTIONS, GET | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "27" | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Fri, 19 Jun 2020 13:32:39 GMT | ||
Server: | ||
- nginx | ||
Vary: | ||
- Cookie | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
X-App-Version: | ||
- 1.26.0-rc.4 | ||
X-Secrets-Engine-Version: | ||
- 2.43.0 | ||
status: | ||
code: 400 | ||
message: OK | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- "*/*" | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- pygitguardian/1.1.0 (Linux;py3.8.3) | ||
method: GET | ||
uri: https://api.gitguardian.com/v1/health | ||
response: | ||
body: | ||
string: '{"detail":"Valid API key."}' | ||
headers: | ||
Allow: | ||
- OPTIONS, GET | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "27" | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Fri, 19 Jun 2020 14:58:35 GMT | ||
Server: | ||
- nginx | ||
Vary: | ||
- Cookie | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
X-App-Version: | ||
- 1.26.0-rc.4 | ||
X-Secrets-Engine-Version: | ||
- 2.43.0 | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters