This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Merge Generic DB framework changes for OpenLdap to Kubernetes branch #526
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a10a374
EOS-22623: add openldap interface skeleton to generic db framework
dc073c7
EOS-22623: add generic db example for OpenLdap
c9c4eb3
EOS-22623: add object mapping to 'get' method for OpenLdap
7655593
EOS-22626: implement filtering for OpenLdap queries
68ebf38
EOS-22626: implement Update and Delete for OpenLdap
31cb0ad
EOS-22626: update the OpenLdap sample with filtering, update and dele…
893eac4
EOS-22626: handle TODOs for OpenLdap integration in generic db framework
2a1796e
EOS-22626: fix codacy errors in OpenLdap sample application
125fca2
EOS-22632: implement 'count' mehtod for OpenLdap
6f7180d
EOS-22632: remove manual extraction of result and description from LD…
d4e7150
EOS-23899: update object when storing if it exists in OpenLdap
cc1dcd9
Merge branch 'kubernetes' of github.com:Seagate/cortx-utils into kube…
udayan-y21 141c619
Licence modifications
udayan-y21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions
44
py-utils/src/utils/data/db/examples/openldap/cortxuser_model.py
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,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# CORTX-Py-Utils: CORTX Python common library. | ||
# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, | ||
# please email [email protected] or [email protected]. | ||
|
||
|
||
from datetime import datetime, timezone | ||
from schematics.types import (StringType, DateTimeType, BooleanType) | ||
|
||
from cortx.utils.data.access import BaseModel | ||
|
||
|
||
class CortxUser(BaseModel): | ||
_id = "user_id" | ||
|
||
user_id = StringType() | ||
user_type = StringType() | ||
user_role = StringType() | ||
password_hash = StringType() | ||
email = StringType() | ||
alert_notification = BooleanType() | ||
updated_time = DateTimeType() | ||
created_time = DateTimeType() | ||
|
||
def update(self, new_values: dict): | ||
if 'password' in new_values: | ||
self.password_hash = 'dummyhash' | ||
new_values.pop('password') | ||
for key in new_values: | ||
setattr(self, key, new_values[key]) | ||
|
||
self.updated_time = datetime.now(timezone.utc) |
173 changes: 173 additions & 0 deletions
173
py-utils/src/utils/data/db/examples/openldap/openldap_storage.py
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,173 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# CORTX-Py-Utils: CORTX Python common library. | ||
# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates | ||
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. 2020 -> 2021 |
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, | ||
# please email [email protected] or [email protected]. | ||
|
||
import asyncio | ||
from datetime import datetime | ||
import os | ||
import pathlib | ||
import sys | ||
|
||
|
||
def print_items(items): | ||
for item in items: | ||
print(item.to_primitive()) | ||
|
||
|
||
async def example(): | ||
conf = GeneralConfig({ | ||
"databases": { | ||
"openldap": { | ||
"import_path": "OpenLdap", | ||
"config": { | ||
"hosts": ["127.0.0.1"], | ||
"port": 389, | ||
"login": "cn=sgiamadmin,dc=seagate,dc=com", | ||
"password": "+_14zxKRJG=0ru" | ||
} | ||
} | ||
}, | ||
"models": [ | ||
{ | ||
"import_path": "cortx.utils.data.db.examples.openldap.cortxuser_model.CortxUser", | ||
"database": "openldap", | ||
"config": { | ||
"openldap": { | ||
"collection": "ou=accounts,dc=csm,dc=seagate,dc=com" | ||
} | ||
} | ||
}] | ||
}) | ||
|
||
SAMPLE_USER = { | ||
"user_id": "eos22623demo", | ||
'user_type': 'csm', | ||
'email': '[email protected]', | ||
'password_hash': 'demopasswd', | ||
'user_role': 'manage', | ||
'created_time': datetime.now(), | ||
'updated_time': datetime.now(), | ||
'alert_notification': True | ||
} | ||
|
||
SAMPLE_USER2 = { | ||
"user_id": "test1", | ||
'user_type': 'csm', | ||
'email': '[email protected]', | ||
'password_hash': '987dfsg231sdg234GG', | ||
'user_role': 'manage', | ||
'created_time': datetime.strptime("20210801045500Z", '%Y%m%d%H%M%SZ'), | ||
'updated_time': datetime.now(), | ||
'alert_notification': True | ||
} | ||
|
||
SAMPLE_USER3 = { | ||
"user_id": "test2", | ||
'user_type': 'csm', | ||
'email': '[email protected]', | ||
'password_hash': '12358ZHGJDhhasdfG', | ||
'user_role': 'manage', | ||
'created_time': datetime.strptime("20200103125530Z", '%Y%m%d%H%M%SZ'), | ||
'updated_time': datetime.now(), | ||
'alert_notification': True | ||
} | ||
|
||
SAMPLE_USER4 = { | ||
"user_id": "s3sampleuser", | ||
'user_type': 's3', | ||
'email': '[email protected]', | ||
'password_hash': 'asghuoanmnxcbg', | ||
'user_role': 'monitor', | ||
'created_time': datetime.strptime("20210803120030Z", '%Y%m%d%H%M%SZ'), | ||
'updated_time': datetime.now(), | ||
'alert_notification': False | ||
} | ||
|
||
sample_users = [SAMPLE_USER, SAMPLE_USER2, SAMPLE_USER3, SAMPLE_USER4] | ||
|
||
db = DataBaseProvider(conf) | ||
|
||
items = await db(CortxUser).get(Query()) | ||
print('Users collection') | ||
print_items(items) | ||
print(20 * '-') | ||
|
||
for user in sample_users: | ||
user_obj = CortxUser(user) | ||
await db(CortxUser).store(user_obj) | ||
|
||
print('Collection status after addition') | ||
updated_items = await db(CortxUser).get(Query()) | ||
print_items(updated_items) | ||
print(20 * '-') | ||
|
||
print('Query search') | ||
filter_obj = And( | ||
Or( | ||
Compare(CortxUser.user_role, '=', 'manage'), | ||
Compare(CortxUser.user_role, "=", "admin")), | ||
Compare(CortxUser.user_type, '=', 'csm') | ||
) | ||
query = Query().filter_by(filter_obj).order_by(CortxUser.user_id, SortOrder.DESC) | ||
queried_items = await db(CortxUser).get(query) | ||
print_items(queried_items) | ||
print(20 * '-') | ||
|
||
print('Query generalized') | ||
filter_obj = And( | ||
Compare(CortxUser.created_time, '>=', datetime.strptime('20210827000005Z', '%Y%m%d%H%M%SZ')), | ||
Compare(CortxUser.alert_notification, '=', True) | ||
) | ||
query = Query().filter_by(filter_obj) | ||
queried_items = await db(CortxUser).get(query) | ||
print_items(queried_items) | ||
print(20 * '-') | ||
|
||
filter_obj = Compare(CortxUser.user_type, '=', 's3') | ||
to_update = { | ||
'user_role': 'admin' | ||
} | ||
num = await db(CortxUser).update(filter_obj, to_update) | ||
items = await db(CortxUser).get(Query()) | ||
print(f'Updated - {num}') | ||
print_items(items) | ||
print(20 * '-') | ||
|
||
filter_obj = Or( | ||
Compare(CortxUser.user_type, '=', 's3'), | ||
Compare(CortxUser.user_id, 'like', 'est')) | ||
cnt = await db(CortxUser).count(filter_obj) | ||
print(f'Counted - {cnt}') | ||
print(20 * '-') | ||
|
||
num = await db(CortxUser).delete(None) | ||
items = await db(CortxUser).get(Query()) | ||
print(f'Deleted - {num}') | ||
print_items(items) | ||
print(20 * '-') | ||
|
||
|
||
if __name__ == "__main__": | ||
py_utils_rel_path = os.path.join(os.path.dirname(pathlib.Path(__file__)), '../../../../../..') | ||
sys.path.insert(1, py_utils_rel_path) | ||
|
||
from cortx.utils.data.access import Query, And, Or, Compare, SortOrder | ||
from cortx.utils.data.db.db_provider import (DataBaseProvider, GeneralConfig) | ||
from cortx.utils.data.db.examples.openldap.cortxuser_model import CortxUser | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(example()) | ||
loop.close() |
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,18 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# CORTX-Py-Utils: CORTX Python common library. | ||
# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates | ||
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. 2020 -> 2021 |
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# For any questions about this software or licensing, | ||
# please email [email protected] or [email protected]. | ||
|
||
from cortx.utils.data.db.openldap.storage import OpenLdap |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
correct the copyright year at all applicable places/files
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.
Modifications done.
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.
2020 -> 2021