Skip to content

Commit

Permalink
feat: added permission check for onboarding (#42)
Browse files Browse the repository at this point in the history
* feat: added permission check

* fix: as per comments
  • Loading branch information
AdiGajbhiye authored Oct 2, 2024
1 parent c06eeea commit 250290a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/datapilot/clients/altimate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get(self, endpoint, params=None, timeout=None):
return response.json()

except HTTPError as http_err:
self.logger.error(f"{http_err.response.json()} - Status code: {response.status_code}")
self.logger.debug(f"HTTP Error: {http_err.response.json()} - Status code: {response.status_code}")
except ConnectionError as conn_err:
self.logger.error(f"Connection error occurred: {conn_err}")
except Timeout as timeout_err:
Expand Down Expand Up @@ -83,6 +83,10 @@ def get_signed_url(self, params=None):
def validate_credentials(self):
endpoint = "/dbt/v3/validate-credentials"
return self.get(endpoint)

def validate_upload_to_integration(self):
endpoint = "/dbt/v1/validate-permissions"
return self.get(endpoint)

def start_dbt_ingestion(self, params=None):
endpoint = "/dbt/v1/start_dbt_ingestion"
Expand Down
8 changes: 8 additions & 0 deletions src/datapilot/clients/altimate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def validate_credentials(
return api_client.validate_credentials()


def validate_permissions(
token,
backend_url,
tenant,
) -> Response:
api_client = APIClient(api_token=token, base_url=backend_url, tenant=tenant)
return api_client.validate_upload_to_integration()

def onboard_file(api_token, tenant, dbt_core_integration_id, dbt_core_integration_environment, file_type, file_path, backend_url) -> Dict:
api_client = APIClient(api_token, base_url=backend_url, tenant=tenant)

Expand Down
5 changes: 5 additions & 0 deletions src/datapilot/core/platforms/dbt/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datapilot.clients.altimate.utils import onboard_file
from datapilot.clients.altimate.utils import start_dbt_ingestion
from datapilot.clients.altimate.utils import validate_credentials
from datapilot.clients.altimate.utils import validate_permissions
from datapilot.config.config import load_config
from datapilot.core.platforms.dbt.constants import MODEL
from datapilot.core.platforms.dbt.constants import PROJECT
Expand Down Expand Up @@ -110,6 +111,10 @@ def onboard(
if not validate_credentials(token, backend_url, instance_name):
click.echo("Error: Invalid credentials.")
return

if not validate_permissions(token, backend_url, instance_name):
click.echo("Error: You don't have permission to perform this action.")
return

# This will throw error if manifest file is incorrect
try:
Expand Down

0 comments on commit 250290a

Please sign in to comment.