-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
Build succeeded (check pipeline). |
Codecov Report
❗ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
82ce8d3
to
8f7546a
Compare
Build succeeded (check pipeline). |
gooddata-sdk/tests/catalog/fixtures/permissions/manage_organization_permissions.yaml
Show resolved
Hide resolved
8f7546a
to
00aa6db
Compare
Build succeeded (check pipeline). |
00aa6db
to
e498de2
Compare
Build succeeded (check pipeline). |
e498de2
to
f7e6b3a
Compare
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], |
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.
This is not correct typing. Note that mypy
does not work in tests, so it is undetected. Please use List[CatalogDeclarativeOrganizationPermission]
.
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.
I missed this one, thank you
""" | ||
|
||
catalog_list = [] | ||
for permission in self._layout_api.get_organization_permissions(): |
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.
Please store the result from self._layout_api.get_organization_permissions()
first and then use it.
e.g.:
for permission in organization_permissions:
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.
updated as recommended
None | ||
""" | ||
permissions = [permission.to_api() for permission in organization_permission_assignments] | ||
print(permissions) |
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.
Please delete this print.
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.
forgot to remove, thanks
Returns: | ||
None | ||
""" | ||
permissions = [permission.to_api() for permission in organization_permission_assignments] |
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.
This seems to be unused.
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.
right, now to be used as input param for the following line:
self._actions_api.manage_organization_permissions(permissions, _check_return_type=False,)
|
||
|
||
@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", | ||
} |
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.
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.
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.
updated as discussed. Thank you
Build succeeded (check pipeline). |
30981ca
to
f9e5ae4
Compare
Build succeeded (check pipeline). |
Sonar scan resultMore 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'. |
Build succeeded (gate pipeline).
|
No description provided.