-
Notifications
You must be signed in to change notification settings - Fork 71
iam integrations #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iam integrations #279
Changes from all commits
36c911b
602ce16
c6cdbea
0fb8e21
2e51c92
c0e680e
0fa0e3a
87c1697
a7904b9
1b76fc1
daf0756
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from labelbox.utils import snake_case | ||
| from labelbox.orm.db_object import DbObject | ||
| from labelbox.orm.model import Field | ||
|
|
||
|
|
||
| @dataclass | ||
| class AwsIamIntegrationSettings: | ||
| role_arn: str | ||
|
|
||
|
|
||
| @dataclass | ||
| class GcpIamIntegrationSettings: | ||
| service_account_email_id: str | ||
| read_bucket: str | ||
|
|
||
|
|
||
| class IAMIntegration(DbObject): | ||
| """ Represents an IAM integration for delegated access | ||
|
|
||
| Attributes: | ||
| name (str) | ||
| updated_at (datetime) | ||
| created_at (datetime) | ||
| provider (str) | ||
| valid (bool) | ||
| last_valid_at (datetime) | ||
| is_org_default (boolean) | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, client, data): | ||
| settings = data.pop('settings', None) | ||
| if settings is not None: | ||
| type_name = settings.pop('__typename') | ||
| settings = {snake_case(k): v for k, v in settings.items()} | ||
| if type_name == "GcpIamIntegrationSettings": | ||
| self.settings = GcpIamIntegrationSettings(**settings) | ||
| elif type_name == "AwsIamIntegrationSettings": | ||
| self.settings = AwsIamIntegrationSettings(**settings) | ||
| else: | ||
| self.settings = None | ||
| else: | ||
| self.settings = None | ||
| super().__init__(client, data) | ||
|
|
||
| _DEFAULT = "DEFAULT" | ||
|
|
||
| name = Field.String("name") | ||
| created_at = Field.DateTime("created_at") | ||
| updated_at = Field.DateTime("updated_at") | ||
| provider = Field.String("provider") | ||
| valid = Field.Boolean("valid") | ||
| last_valid_at = Field.DateTime("last_valid_at") | ||
| is_org_default = Field.Boolean("is_org_default") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like we're missing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ugh - I know. The union thing is a nightmare. But users might want to know which bucket they have access to. I'll try to figure something out. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import requests | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.skip("Can only be tested in specific organizations.") | ||
| def test_default_integration(client): | ||
| # This tests assumes the following: | ||
| # 1. gcp delegated access is configured to work with utkarsh-da-test-bucket | ||
| # 2. the integration name is gcp test | ||
| # 3. This integration is the default | ||
| ds = client.create_dataset(name="new_ds") | ||
| dr = ds.create_data_row( | ||
| row_data= | ||
| "gs://utkarsh-da-test-bucket/mathew-schwartz-8rj4sz9YLCI-unsplash.jpg") | ||
| assert requests.get(dr.row_data).status_code == 200 | ||
| assert ds.iam_integration().name == "GCP Test" | ||
| ds.delete() | ||
|
|
||
|
|
||
| @pytest.mark.skip("Can only be tested in specific organizations.") | ||
| def test_non_default_integration(client): | ||
| # This tests assumes the following: | ||
| # 1. aws delegated access is configured to work with lbox-test-bucket | ||
| # 2. an integration called aws is available to the org | ||
| integrations = client.get_organization().get_iam_integrations() | ||
| integration = [inte for inte in integrations if 'aws' in inte.name][0] | ||
| assert integration.valid | ||
| ds = client.create_dataset(iam_integration=integration, name="new_ds") | ||
| assert ds.iam_integration().name == "aws" | ||
| dr = ds.create_data_row( | ||
| row_data= | ||
| "https://lbox-test-bucket.s3.us-east-1.amazonaws.com/2021_09_08_0hz_Kleki.png" | ||
| ) | ||
| assert requests.get(dr.row_data).status_code == 200 | ||
| ds.delete() | ||
|
|
||
|
|
||
| def test_no_integration(client, image_url): | ||
| ds = client.create_dataset(iam_integration=None, name="new_ds") | ||
| assert ds.iam_integration() is None | ||
| dr = ds.create_data_row(row_data=image_url) | ||
| assert requests.get(dr.row_data).status_code == 200 | ||
| ds.delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: can we add optional SignerId to createDatasetInput? This way we wouldn't have to do this rollback, it would all be handled by the backend