-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'dbt-cloud audit-log get' command (#58)
* Add 'dbt-cloud audit-log get' command * Add unit test * Update README * Add integration test Co-authored-by: Simo Tumelius <[email protected]>
- Loading branch information
1 parent
dfa344d
commit 8e78454
Showing
10 changed files
with
278 additions
and
7 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
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 @@ | ||
from .get import DbtCloudAuditLogGetCommand |
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,40 @@ | ||
import requests | ||
from typing import Optional | ||
from pydantic import Field, PrivateAttr | ||
from dbt_cloud.command.command import DbtCloudAccountCommand | ||
|
||
|
||
class DbtCloudAuditLogGetCommand(DbtCloudAccountCommand): | ||
"""Retrieves audit logs for the dbt Cloud account.""" | ||
|
||
logged_at_start: Optional[str] = Field( | ||
description="Start date (YYYY-MM-DD) for the returned logs." | ||
) | ||
logged_at_end: Optional[str] = Field( | ||
description="End date (YYYY-MM-DD) for the returned logs." | ||
) | ||
offset: Optional[int] = Field( | ||
0, | ||
ge=0, | ||
description="Offset for the returned logs. Must be a positive integer.", | ||
) | ||
limit: Optional[int] = Field( | ||
100, | ||
ge=0, | ||
description="A limit on the number of logs to be returned. Must be a positive integer.", | ||
) | ||
_api_version: str = PrivateAttr("v3") | ||
|
||
@property | ||
def api_url(self) -> str: | ||
return f"{super().api_url}/audit-logs/" | ||
|
||
def execute(self) -> requests.Response: | ||
response = requests.get( | ||
url=self.api_url, | ||
headers=self.request_headers, | ||
params=self.get_payload( | ||
exclude=["api_token", "dbt_cloud_host", "account_id"] | ||
), | ||
) | ||
return response |
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
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,127 @@ | ||
{ | ||
"status": { | ||
"code": 200, | ||
"is_success": true, | ||
"user_message": "Success!", | ||
"developer_message": "" | ||
}, | ||
"data": [ | ||
{ | ||
"account_id": 123456, | ||
"service": "SERVICE_DBT_CLOUD", | ||
"source": "SOURCE_CLOUD_UI", | ||
"routing_key": "v1.events.auth.credentialsloginsucceeded", | ||
"actor_type": "ACTOR_USER", | ||
"actor_name": "REDACTED", | ||
"actor_id": 123454, | ||
"logged_at": "2022-05-05 06:51:10+00:00", | ||
"uuid": "8868c439-8928-4e8c-924b-77558d65db0b", | ||
"actor_ip": "REDACTED", | ||
"metadata": { | ||
"auth_credentials": { | ||
"user": { | ||
"id": "REDACTED", | ||
"email": "REDACTED" | ||
} | ||
} | ||
}, | ||
"internal": false, | ||
"id": 1809583, | ||
"state": 1, | ||
"created_at": "2022-05-05 06:51:12.454677+00:00", | ||
"updated_at": "2022-05-05 06:51:12.454677+00:00" | ||
}, | ||
{ | ||
"account_id": 123456, | ||
"service": "SERVICE_DBT_CLOUD", | ||
"source": "SOURCE_CLOUD_UI", | ||
"routing_key": "v1.events.auth.credentialsloginsucceeded", | ||
"actor_type": "ACTOR_USER", | ||
"actor_name": "REDACTED", | ||
"actor_id": 123454, | ||
"logged_at": "2022-05-05 05:42:26+00:00", | ||
"uuid": "029625d0-8dcf-4fa7-9567-26f8f4648122", | ||
"actor_ip": "REDACTED", | ||
"metadata": { | ||
"auth_credentials": { | ||
"user": { | ||
"id": "REDACTED", | ||
"email": "REDACTED" | ||
} | ||
} | ||
}, | ||
"internal": false, | ||
"id": 1809076, | ||
"state": 1, | ||
"created_at": "2022-05-05 05:42:30.635635+00:00", | ||
"updated_at": "2022-05-05 05:42:30.635635+00:00" | ||
}, | ||
{ | ||
"account_id": 123456, | ||
"service": "SERVICE_DBT_CLOUD", | ||
"source": "SOURCE_CLOUD_UI", | ||
"routing_key": "v1.events.auth.credentialsloginsucceeded", | ||
"actor_type": "ACTOR_USER", | ||
"actor_name": "REDACTED", | ||
"actor_id": 123454, | ||
"logged_at": "2022-05-04 16:13:33+00:00", | ||
"uuid": "ba0c717d-6ea7-4e10-b4ba-48e956163938", | ||
"actor_ip": "REDACTED", | ||
"metadata": { | ||
"auth_credentials": { | ||
"user": { | ||
"id": "REDACTED", | ||
"email": "REDACTED" | ||
} | ||
} | ||
}, | ||
"internal": false, | ||
"id": 1802985, | ||
"state": 1, | ||
"created_at": "2022-05-04 16:13:34.295300+00:00", | ||
"updated_at": "2022-05-04 16:13:34.295300+00:00" | ||
}, | ||
{ | ||
"account_id": 123456, | ||
"service": "SERVICE_DBT_CLOUD", | ||
"source": "SOURCE_CLOUD_UI", | ||
"routing_key": "v1.events.auth.credentialsloginsucceeded", | ||
"actor_type": "ACTOR_USER", | ||
"actor_name": "REDACTED", | ||
"actor_id": 123454, | ||
"logged_at": "2022-05-02 06:33:48+00:00", | ||
"uuid": "fe0dfd93-8654-4568-8c13-ecf61eaf9cdb", | ||
"actor_ip": "REDACTED", | ||
"metadata": { | ||
"auth_credentials": { | ||
"user": { | ||
"id": "REDACTED", | ||
"email": "REDACTED" | ||
} | ||
} | ||
}, | ||
"internal": false, | ||
"id": 1770400, | ||
"state": 1, | ||
"created_at": "2022-05-02 06:33:49.777343+00:00", | ||
"updated_at": "2022-05-02 06:33:49.777343+00:00" | ||
} | ||
], | ||
"extra": { | ||
"filters": { | ||
"account_id": 123456, | ||
"limit": 10, | ||
"offset": 0, | ||
"logged_at__range": [ | ||
"2022-05-01 00:00:00Z", | ||
"2022-05-07 00:00:00Z" | ||
], | ||
"internal": false | ||
}, | ||
"order_by": "-logged_at", | ||
"pagination": { | ||
"count": 4, | ||
"total_count": 4 | ||
} | ||
} | ||
} |