Skip to content
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

NAS-5360 Enforcing api-token permission python sdk update #398

Merged
1 commit merged into from
Oct 30, 2023

Conversation

JKlucka
Copy link
Contributor

@JKlucka JKlucka commented Oct 30, 2023

No description provided.

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2023

Codecov Report

Merging #398 (00aa6db) into master (c3772ac) will increase coverage by 0.15%.
Report is 30 commits behind head on master.
The diff coverage is n/a.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
+ Coverage   91.19%   91.34%   +0.15%     
==========================================
  Files          90       91       +1     
  Lines        6005     6091      +86     
==========================================
+ Hits         5476     5564      +88     
+ Misses        529      527       -2     
Files Coverage Δ
gooddata-sdk/gooddata_sdk/__init__.py 100.00% <ø> (ø)
...mission/declarative_model/dashboard_permissions.py 89.36% <ø> (-0.12%) ⬇️
.../declarative_model/manage_dashboard_permissions.py 100.00% <ø> (+5.26%) ⬆️
...catalog/permission/declarative_model/permission.py 98.57% <ø> (-1.43%) ⬇️
...ata-sdk/gooddata_sdk/catalog/permission/service.py 100.00% <ø> (ø)
gooddata-sdk/gooddata_sdk/catalog/rule.py 100.00% <ø> (ø)
gooddata-sdk/gooddata_sdk/catalog/setting.py 90.90% <ø> (+0.43%) ⬆️
...model/workspace/analytics_model/analytics_model.py 97.86% <ø> (-0.47%) ⬇️
.../entity_model/content_objects/workspace_setting.py 93.54% <ø> (+1.24%) ⬆️
...catalog/workspace/entity_model/user_data_filter.py 74.80% <ø> (ø)
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@@ -54,6 +56,12 @@ def _assert_default_permissions(catalog_declarative_permissions: CatalogDeclarat
assert set(permission.name for permission in catalog_declarative_permissions.permissions) == {"ANALYZE", "VIEW"}


def _assert_organization_permissions_id(
catalog_organization_permissions: [CatalogDeclarativeOrganizationPermission],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct typing. Note that mypy does not work in tests, so it is undetected. Please use List[CatalogDeclarativeOrganizationPermission].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this one, thank you

"""

catalog_list = []
for permission in self._layout_api.get_organization_permissions():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please store the result from self._layout_api.get_organization_permissions() first and then use it.

e.g.:
for permission in organization_permissions:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as recommended

None
"""
permissions = [permission.to_api() for permission in organization_permission_assignments]
print(permissions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete this print.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to remove, thanks

Returns:
None
"""
permissions = [permission.to_api() for permission in organization_permission_assignments]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, now to be used as input param for the following line:
self._actions_api.manage_organization_permissions(permissions, _check_return_type=False,)

Comment on lines 175 to 224


@gd_vcr.use_cassette(str(_fixtures_dir / "put_declarative_organization_permissions.yaml"))
def test_put_and_get_declarative_organization_permissions(test_config):
expected_json_path = _current_dir / "expected" / "declarative_organization_permissions.json"
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
catalog_declarative_permissions_initial = sdk.catalog_permission.get_declarative_organization_permissions()

assert len(catalog_declarative_permissions_initial) == 1
_assert_organization_permissions_id(catalog_declarative_permissions_initial)
assert set(org_permission.name for org_permission in catalog_declarative_permissions_initial) == {"MANAGE"}

with open(expected_json_path, "r", encoding="utf-8") as f:
data = json.load(f)

declarative_organization_permissions = []
for permission in data:
declarative_organization_permissions.append(CatalogDeclarativeOrganizationPermission.from_api(permission))

sdk.catalog_permission.put_declarative_organization_permissions(declarative_organization_permissions)

catalog_declarative_permissions_after_put = sdk.catalog_permission.get_declarative_organization_permissions()
assert len(catalog_declarative_permissions_after_put) == 2
_assert_organization_permissions_id(catalog_declarative_permissions_after_put)
assert set(org_permission.name for org_permission in catalog_declarative_permissions_after_put) == {
"MANAGE",
"SELF_CREATE_TOKEN",
}


@gd_vcr.use_cassette(str(_fixtures_dir / "manage_organization_permissions.yaml"))
def test_manage_organization_permissions(test_config):
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])

# assign permissions to adminGroup
sdk.catalog_permission.manage_organization_permissions(
[
CatalogOrganizationPermissionAssignment(
assignee_identifier=CatalogAssigneeIdentifier(id="adminGroup", type="userGroup"),
permissions=["MANAGE", "SELF_CREATE_TOKEN"],
)
],
)

catalog_declarative_permissions_initial = sdk.catalog_permission.get_declarative_organization_permissions()
assert len(catalog_declarative_permissions_initial) == 2
assert set(org_permission.name for org_permission in catalog_declarative_permissions_initial) == {
"MANAGE",
"SELF_CREATE_TOKEN",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still determining the tests. There is no AfterAll or AfterEach mechanism as is, for example, known in Java. Therefore, if you put something, then it stays put. There should be a try-finally block where the change is reverted in the final block back to the original state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as discussed. Thank you

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@ghost
Copy link

ghost commented Oct 30, 2023

Build succeeded (check pipeline).

@hkad98 hkad98 added the merge label Oct 30, 2023
@yenkins
Copy link

yenkins commented Oct 30, 2023

Sonar scan result

More detail, see in https://sonarqube-gate.intgdc.com/dashboard?id=gooddata-python-sdk-gate-PR398

To scan for vulnerabilities in dependencies and run unit tests (to get coverage report in sonar) please comment your PR with 'extended check sonar'.

@ghost ghost removed the merge label Oct 30, 2023
@ghost ghost merged commit d705310 into gooddata:master Oct 30, 2023
6 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants