From 348beec0674955dee4f1a7dd3301f68d18d2958a Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Thu, 15 Sep 2022 15:21:03 -0400 Subject: [PATCH 01/23] implementing email_addresses_add method --- comanage_api/_emailaddresses.py | 79 ++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/comanage_api/_emailaddresses.py b/comanage_api/_emailaddresses.py index 0e4788f..dbb2616 100644 --- a/comanage_api/_emailaddresses.py +++ b/comanage_api/_emailaddresses.py @@ -6,7 +6,6 @@ Methods ------- email_addresses_add() -> dict - ### NOT IMPLEMENTED ### Add a new EmailAddress. email_addresses_delete() -> bool ### NOT IMPLEMENTED ### @@ -25,23 +24,83 @@ import json -def email_addresses_add(self) -> dict: +def email_addresses_add(self, email_address: str, person_type: str, person_id: int) -> dict: """ - ### NOT IMPLEMENTED ### - Add a new EmailAddress. + Add a new EmailAddress :param self: + :param email_address: + :param person_type: + :param person_id: :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + { + "RequestType":"EmailAddresses", + "Version":"1.0", + "EmailAddresses": + [ + { + "Version":"1.0", + "Mail":"", + "Type":"", + "Description":"", + "Verified":true|false, + "Person": + { + "Type":("CO"|"Dept"|"Org"|"Organization"), + "Id":"" + } + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse EmailAddress added + 400 Bad Request EmailAddress Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more provided fields + 401 Unauthorized Authentication required + 403 No Person Specified Either a CO Person or an Org Identity + must be specified to attach the + Email Address to + 403 Person Does Not Exist The specified CO Department, CO Person, + or Org Identity does not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"EmailAddresses", + "Version":"1.0", + "EmailAddresses": + [ + { + "Version":"1.0", + "Mail":"", + "Type":"official", + "Description":"", + "Verified": False, + "Person": + { + "Type":"", + "Id":"" + } + } + ] + } + + post_body['EmailAddresses'][0]['Mail'] = email_address + post_body['EmailAddresses'][0]['Person']['Type'] = person_type + post_body['EmailAddresses'][0]['Person']['Id'] = person_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/email_addresses.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) - else: - resp.raise_for_status() + + resp.raise_for_status() def email_addresses_delete(self) -> bool: From efa88e2955fa42ef1ae8f7bae2818405d61594e3 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Thu, 15 Sep 2022 15:26:42 -0400 Subject: [PATCH 02/23] implementing email_addresses_add method --- comanage_api/_emailaddresses.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comanage_api/_emailaddresses.py b/comanage_api/_emailaddresses.py index dbb2616..87a8c52 100644 --- a/comanage_api/_emailaddresses.py +++ b/comanage_api/_emailaddresses.py @@ -26,7 +26,7 @@ def email_addresses_add(self, email_address: str, person_type: str, person_id: int) -> dict: """ - Add a new EmailAddress + Add a new EmailAddress. :param self: :param email_address: @@ -99,8 +99,8 @@ def email_addresses_add(self, email_address: str, person_type: str, person_id: i ) if resp.status_code == 201: return json.loads(resp.text) - - resp.raise_for_status() + else: + resp.raise_for_status() def email_addresses_delete(self) -> bool: From 9d7028849d9162dc33606269f3ed5e324ec446e4 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 13:52:19 -0400 Subject: [PATCH 03/23] updating README for implementation of email_addresses_add method --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 07b9446..b763354 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,6 @@ AFFILIATION_OPTIONS = ['affiliate', 'alum', 'employee', 'faculty', 'member', 'st ### [EmailAddress API](https://spaces.at.internet2.edu/display/COmanage/EmailAddress+API) (COmanage v3.3.0+) - `email_addresses_add() -> dict` - - `### NOT IMPLEMENTED ###` - Add a new EmailAddress. - `email_addresses_delete() -> bool` - `### NOT IMPLEMENTED ###` From 59de30b0ea490bd0466cac3878707a24528d4abb Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 14:12:04 -0400 Subject: [PATCH 04/23] implementing names_add method --- README.md | 3 +- comanage_api/__init__.py | 4 +- comanage_api/_names.py | 91 ++++++++++++++++++++++++++++++++++----- examples/names_example.py | 9 +++- 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 07b9446..a9f9e84 100644 --- a/README.md +++ b/README.md @@ -274,8 +274,7 @@ ENTITY_OPTIONS = ['codeptid', 'cogroupid', 'copersonid', 'organizationid', 'orgi ### [Name API](https://spaces.at.internet2.edu/display/COmanage/Name+API) (COmanage v3.3.0+) -- `names_add() -> dict` - - `### NOT IMPLEMENTED ###` +- `names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict` - Add a new Name. - `names_delete() -> bool` - `### NOT IMPLEMENTED ###` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..cc2c3a1 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -224,8 +224,8 @@ def identifiers_view_one(self, identifier_id: int): return identifiers_view_one(self, identifier_id=identifier_id) # Name API - def names_add(self): - return names_add(self) + def names_add(self, person_type: str, person_id: int, given_name: str, family_name: str): + return names_add(self, person_type=person_type, person_id=person_id, given_name=given_name, family_name=family_name) def names_delete(self): return names_delete(self) diff --git a/comanage_api/_names.py b/comanage_api/_names.py index 7c40d97..257db1c 100644 --- a/comanage_api/_names.py +++ b/comanage_api/_names.py @@ -5,8 +5,7 @@ Methods ------- -names_add() -> dict - ### NOT IMPLEMENTED ### +names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict Add a new Name. names_delete() -> bool ### NOT IMPLEMENTED ### @@ -25,18 +24,88 @@ import json -def names_add(self) -> dict: +def names_add(self, person_type: str, person_id: int, given_name: str, family_name: str) -> dict: """ - ### NOT IMPLEMENTED ### - Add a new Name. + Add a new Name. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + person_type: Type of person (i.e. "CO"|"Org") + person_id: COmanage ID for the person_type + given_name: First name for the person + family_name: Last name for the person + :request + { + "RequestType":"Names", + "Version":"1.0", + "Names": + [ + { + "Version":"1.0", + "Honorific":"", + "Given":"", + "Middle":"", + "Family":"", + "Suffix":"", + "Type":"", + "Language":"", + "PrimaryName":true|false, + "Person": + { + "Type":("CO"|"Org"), + "Id":"" + } + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse Name added + 400 Bad Request Name Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 No Person Specified Either a CO Person or an Org Identity + must be specified to attach the + Name to + 403 Person Does Not Exist The specified CO Person or + Org Identity does not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"Names", + "Version":"1.0", + "Names": + [ + { + "Version":"1.0", + "Honorific":"", + "Given":"", + "Middle":"", + "Family":"", + "Suffix":"", + "Type":"official", + "Language":"", + "PrimaryName": True, + "Person": + { + "Type":"", + "Id":"" + } + } + ] + } + + post_body['Names'][0]['Given'] = given_name + post_body['Names'][0]['Family'] = family_name + post_body['Names'][0]['Person']['Type'] = person_type + post_body['Names'][0]['Person']['Id'] = person_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/names.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/examples/names_example.py b/examples/names_example.py index d63cabf..bad4fc1 100644 --- a/examples/names_example.py +++ b/examples/names_example.py @@ -12,10 +12,15 @@ # must be set ahead of time and be valid within the CO CO_PERSON_ID = 163 -# names_add() -> dict +# names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict print('### names_add') try: - new_name = api.names_add() + new_name = api.names_add( + person_type='copersonid', + person_id=CO_PERSON_ID, + given_name="TestGiven", + family_name="TestFamily" + )) print(json.dumps(new_name, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') From 24caef50dc4253c9debb6ac316225b01688e3b03 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 14:22:09 -0400 Subject: [PATCH 05/23] implementing email_addresses_add method --- comanage_api/__init__.py | 4 ++-- comanage_api/_emailaddresses.py | 2 +- examples/email_addresses_example.py | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..052cfc6 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -183,8 +183,8 @@ def cous_view_one(self, cou_id: int): return cous_view_one(self, cou_id=cou_id) # EmailAddress API - def email_addresses_add(self): - return email_addresses_add(self) + def email_addresses_add(self, email_address: str, person_type: str, person_id: int): + return email_addresses_add(self, email_address=email_address, person_type=person_type, person_id=person_id) def email_addresses_delete(self): return email_addresses_delete(self) diff --git a/comanage_api/_emailaddresses.py b/comanage_api/_emailaddresses.py index 87a8c52..c2cf307 100644 --- a/comanage_api/_emailaddresses.py +++ b/comanage_api/_emailaddresses.py @@ -5,7 +5,7 @@ Methods ------- -email_addresses_add() -> dict +email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict Add a new EmailAddress. email_addresses_delete() -> bool ### NOT IMPLEMENTED ### diff --git a/examples/email_addresses_example.py b/examples/email_addresses_example.py index c200805..4a96537 100644 --- a/examples/email_addresses_example.py +++ b/examples/email_addresses_example.py @@ -12,10 +12,14 @@ # must be set ahead of time and be valid within the CO CO_PERSON_ID = 163 -# email_addresses_add() -> dict +# email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict print('### email_addresses_add') try: - new_email_address = api.email_addresses_add() + new_email_address = api.email_addresses_add( + email_address='test@domain.com', + person_type='copersonid', + person_id=CO_PERSON_ID + ) print(json.dumps(new_email_address, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') From f889830a347697d2d32124a1bec92ee773f12603 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 14:45:04 -0400 Subject: [PATCH 06/23] implementing copeople_add and copeople_delete methods --- README.md | 4 +- comanage_api/__init__.py | 4 +- comanage_api/_copeople.py | 102 +++++++++++++++++++++++++++++------ examples/copeople_example.py | 7 ++- 4 files changed, 93 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 07b9446..d08c25e 100644 --- a/README.md +++ b/README.md @@ -149,11 +149,9 @@ IDENTITY_OPTIONS = ['copersonid', 'orgidentityid'] ### [CoPerson API](https://spaces.at.internet2.edu/display/COmanage/CoPerson+API) (COmanage v3.3.0+) - `copeople_add() -> dict` - - `### NOT IMPLEMENTED ###` - Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. - Note that linking to an OrgIdentity and invitations are separate operations. -- `copeople_delete() -> bool` - - `### NOT IMPLEMENTED ###` +- `copeople_delete(coperson_id: int) -> bool` - Remove a CO Person. This method will also delete related data, such as `CoPersonRoles`, `EmailAddresses`, and `Identifiers`. - A person must be removed from any COs (CoPerson records must be deleted) diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..d72f5d3 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -115,8 +115,8 @@ def coorg_identity_links_view_one(self, coorg_identity_link_id: int): def copeople_add(self): return copeople_add(self) - def copeople_delete(self): - return copeople_delete(self) + def copeople_delete(self, coperson_id: int): + return copeople_delete(self, coperson_id=coperson_id) def copeople_edit(self): return copeople_edit(self) diff --git a/comanage_api/_copeople.py b/comanage_api/_copeople.py index fe6705b..6b333ff 100644 --- a/comanage_api/_copeople.py +++ b/comanage_api/_copeople.py @@ -6,11 +6,9 @@ Methods ------- copeople_add() -> dict - ### NOT IMPLEMENTED ### Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. Note that linking to an OrgIdentity and invitations are separate operations. -copeople_delete() -> bool - ### NOT IMPLEMENTED ### +copeople_delete(coperson_id: int) -> bool Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses, and Identifiers. A person must be removed from any COs (CoPerson records must be deleted) before the OrgIdentity record can be removed. @@ -41,17 +39,59 @@ def copeople_add(self) -> dict: """ - ### NOT IMPLEMENTED ### Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. Note that linking to an OrgIdentity and invitations are separate operations. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + :request + { + "RequestType":"CoPeople", + "Version":"1.0", + "CoPeople": + [ + { + "Version":"1.0", + "CoId":"", + "Timezone":"", + "DateOfBirth":"", + "Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"| + "Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"| + "PendingApproval"|"PendingConfirmation"| + "PendingVetting"|"Suspended") + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse CoPerson created + 400 Bad Request CoPerson Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 Co Does Not Exist The specified Co does not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"CoPeople", + "Version":"1.0", + "CoPeople": + [ + { + "Version":"1.0", + "CoId":"", + "Status":"Active" + } + ] + } + + post_body['CoPeople'][0]['CoId'] = self._CO_API_ORG_ID + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/co_people.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) @@ -59,19 +99,47 @@ def copeople_add(self) -> dict: resp.raise_for_status() -def copeople_delete(self) -> bool: +def copeople_delete(self, coperson_id: int) -> bool: """ - ### NOT IMPLEMENTED ### Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses, and Identifiers. A person must be removed from any COs (CoPerson records must be deleted) before the OrgIdentity record can be removed. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + :request + { + "RequestType":"CoPeople", + "Version":"1.0", + "CoPeople": + [ + { + "Version":"1.0", + "CoId":"", + "Timezone":"", + "DateOfBirth":"", + "Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"| + "Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"| + "PendingApproval"|"PendingConfirmation"| + "PendingVetting"|"Suspended") + } + ] + }: + + Response Format + HTTP Status Response Body Description + 200 Deleted OrgPerson deleted + 400 Invalid Fields id not provided + 401 Unauthorized Authentication required + 403 CoPersonRole Exists The Person has one or more Person + Role records and cannot be deleted + 403 CouPerson Exists in Unowned COU The Person has a role in one + or more COUs that the authenitcated + user does not control + 404 OrgIdentity Unknown id not found + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( + + url = self._CO_API_URL + '/co_people/' + str(coperson_id) + '.json' + resp = self._s.delete( url=url ) if resp.status_code == 200: diff --git a/examples/copeople_example.py b/examples/copeople_example.py index b0edcc7..f786910 100644 --- a/examples/copeople_example.py +++ b/examples/copeople_example.py @@ -21,8 +21,11 @@ # copeople_delete() -> bool print('### copeople_delete') try: - delete_copeople = api.copeople_delete() - print(json.dumps(delete_copeople, indent=4)) + per_co_copeople = api.copeople_view_per_co() + if per_co_copeople['CoPeople']: + coperson_id = int(per_co_copeople['CoPeople'][0]['Id']) + delete_copeople = api.copeople_delete(coperson_id=coperson_id) + print(delete_copeople) except HTTPError as err: print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) From adb331aa16c6e6d4e08ff02859ac17c110832ee7 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 16:27:35 -0400 Subject: [PATCH 07/23] implementing identifiers_add method --- README.md | 3 +- comanage_api/__init__.py | 4 +- comanage_api/_identifiers.py | 88 +++++++++++++++++++++++++++++---- examples/identifiers_example.py | 7 ++- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 07b9446..e226a31 100644 --- a/README.md +++ b/README.md @@ -247,8 +247,7 @@ EMAILADDRESS_OPTIONS = ['codeptid', 'copersonid', 'organizationid', 'orgidentity ### [Identifier API](https://spaces.at.internet2.edu/display/COmanage/Identifier+API) (COmanage v3.3.0+) -- `identifiers_add() -> dict` - - `### NOT IMPLEMENTED ###` +- `identifiers_add(identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict` - Add a new Identifier. - `identifiers_assign() -> bool` - `### NOT IMPLEMENTED ###` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..0f296f6 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -202,8 +202,8 @@ def email_addresses_view_one(self, email_address_id: int): return email_addresses_view_one(self, email_address_id=email_address_id) # Indentifier API - def identifiers_add(self): - return identifiers_add(self) + def identifiers_add(self, identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int): + return identifiers_add(self, identity_type=identity_type, identifier=identifier, login_flag=login_flag, person_type=person_type, person_id=person_id) def identifiers_assign(self): return identifiers_assign(self) diff --git a/comanage_api/_identifiers.py b/comanage_api/_identifiers.py index 9b15692..d3e454b 100644 --- a/comanage_api/_identifiers.py +++ b/comanage_api/_identifiers.py @@ -5,8 +5,7 @@ Methods ------- -identifiers_add() -> dict - ### NOT IMPLEMENTED ### +identifiers_add(identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict Add a new Identifier. identifiers_assign() -> bool ### NOT IMPLEMENTED ### @@ -28,18 +27,87 @@ import json -def identifiers_add(self) -> dict: +def identifiers_add(self, identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict: """ - ### NOT IMPLEMENTED ### Add a new Identifier. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + identity_type: Identifier keyword (i.e. eppn, sorid) + identifier: The actual identifier for the indentity_type + login_flag: Whether this identifier is used for logging in + person_type: Type of person (i.e. "CO"|"Dept"|"Group"|"Org"|"Organization") + person_id: COmanage ID for the person_type + :request + { + "RequestType":"Identifiers", + "Version":"1.0", + "Identifiers": + [ + { + "Version":"1.0", + "Type":"", + "Identifier":"", + "Login":true|false, + "Person": + { + "Type":("CO"|"Dept"|"Group"|"Org"|"Organization"), + "Id":"" + }, + "CoProvisioningTargetId":"", + "Status":"Active"|"Deleted" + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse Identifier added + 400 Bad Request Identifier Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 Identifier In Use An entry already exists with the + specified identifier + 403 No Person Specified A CO Department, a CO Person, or an + Org Identity must be specified to + attach + the Identifier to + 403 Person Does Not Exist The specified CO Department, + CO Person, or Org Identity + does not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"Identifiers", + "Version":"1.0", + "Identifiers": + [ + { + "Version":"1.0", + "Type":"", + "Identifier":"", + "Login":"", + "Person": + { + "Type":"", + "Id":"" + }, + "Status":"Active" + } + ] + } + + post_body['Identifiers'][0]['Type'] = identity_type + post_body['Identifiers'][0]['Identifier'] = identifier + post_body['Identifiers'][0]['Login'] = login_flag + post_body['Identifiers'][0]['Person']['Type'] = person_type + post_body['Identifiers'][0]['Person']['Id'] = person_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/identifiers.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/examples/identifiers_example.py b/examples/identifiers_example.py index 978521e..3bebd70 100644 --- a/examples/identifiers_example.py +++ b/examples/identifiers_example.py @@ -15,7 +15,12 @@ # identifiers_add() -> dict print('### identifiers_add') try: - new_identifier = api.identifiers_add() + new_identifier = api.identifiers_add( + identity_type='eppn', + identifier='test@domain.com', + login_flag=False, + person_type='CO', + person_id=CO_PERSON_ID) print(json.dumps(new_identifier, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') From b38fd0521eea5c8a148b09af5a00f75bd946c827 Mon Sep 17 00:00:00 2001 From: Brennan Jones Date: Mon, 19 Sep 2022 16:59:00 -0400 Subject: [PATCH 08/23] implementing org_identities_add method --- comanage_api/_orgidentities.py | 58 +++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/comanage_api/_orgidentities.py b/comanage_api/_orgidentities.py index 746efa5..c9e6a7e 100644 --- a/comanage_api/_orgidentities.py +++ b/comanage_api/_orgidentities.py @@ -6,7 +6,6 @@ Methods ------- org_identities_add() -> dict - ### NOT IMPLEMENTED ### Add a new Organizational Identity. A person must have an OrgIdentity before they can be added to a CO. org_identities_delete() -> bool ### NOT IMPLEMENTED ### @@ -32,16 +31,59 @@ def org_identities_add(self) -> dict: """ - ### NOT IMPLEMENTED ### Add a new Organizational Identity. A person must have an OrgIdentity before they can be added to a CO. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + :request + { + "RequestType":"OrgIdentities", + "Version":"1.0", + "OrgIdentities": + [ + { + "Version":"1.0", + "Affiliation":"", + "Title":"", + "O":"<O>", + "Ou":"<Ou>", + "CoId":"<CoId>", + "ValidFrom":"<ValidFrom>", + "ValidThrough":"<ValidThrough>", + "DateOfBirth":"<DateOfBirth>" + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse OrgIdentity added + 400 Bad Request OrgIdentity Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 CO Does Not Exist The specified CO does not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"OrgIdentities", + "Version":"1.0", + "OrgIdentities": + [ + { + "Version":"1.0", + "Affiliation":"member", + "CoId":"<CoId>" + } + ] + } + + post_body['OrgIdentities'][0]['CoId'] = self._CO_API_ORG_ID + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/org_identities.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) From e8cf7e4c695d902113087b5e1452efd7db8ec99d Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Mon, 19 Sep 2022 17:05:14 -0400 Subject: [PATCH 09/23] implementing org_identities_delete method --- README.md | 4 +-- comanage_api/__init__.py | 4 +-- comanage_api/_orgidentities.py | 49 ++++++++++++++++++++++-------- examples/org_identities_example.py | 6 ++-- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 07b9446..565a8ae 100644 --- a/README.md +++ b/README.md @@ -299,10 +299,8 @@ PERSON_OPTIONS = ['copersonid', 'orgidentityid'] ### <a name="orgidentity"></a>[OrgIdentity API](https://spaces.at.internet2.edu/display/COmanage/OrgIdentity+API) (COmanage v3.3.0+) - `org_identities_add() -> dict` - - `### NOT IMPLEMENTED ###` - Add a new Organizational Identity. A person must have an `OrgIdentity` before they can be added to a CO. -- `org_identities_delete() -> bool` - - `### NOT IMPLEMENTED ###` +- `org_identities_delete(org_identity_id: int) -> bool` - Remove an Organizational Identity. - The person must be removed from any COs (`CoPerson`) before the OrgIdentity record can be removed. - This method will also delete related data, such as `Addresses`, `EmailAddresses`, and `TelephoneNumbers`. diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..14b43ad 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -246,8 +246,8 @@ def names_view_one(self, name_id: int): def org_identities_add(self): return org_identities_add(self) - def org_identities_delete(self): - return org_identities_delete(self) + def org_identities_delete(self, org_identity_id: int): + return org_identities_delete(self, org_identity_id=org_identity_id) def org_identities_edit(self): return org_identities_edit(self) diff --git a/comanage_api/_orgidentities.py b/comanage_api/_orgidentities.py index c9e6a7e..9dbf1d7 100644 --- a/comanage_api/_orgidentities.py +++ b/comanage_api/_orgidentities.py @@ -7,8 +7,7 @@ ------- org_identities_add() -> dict Add a new Organizational Identity. A person must have an OrgIdentity before they can be added to a CO. -org_identities_delete() -> bool - ### NOT IMPLEMENTED ### +org_identities_delete(org_identity_id: int) -> bool Remove an Organizational Identity. The person must be removed from any COs (CoPerson) before the OrgIdentity record can be removed. This method will also delete related data, such as Addresses, EmailAddresses, and TelephoneNumbers. @@ -91,19 +90,45 @@ def org_identities_add(self) -> dict: resp.raise_for_status() -def org_identities_delete(self) -> bool: +def org_identities_delete(self, org_identity_id: int) -> bool: """ - ### NOT IMPLEMENTED ### - Remove an Organizational Identity. - The person must be removed from any COs (CoPerson) before the OrgIdentity record can be removed. - This method will also delete related data, such as Addresses, EmailAddresses, and TelephoneNumbers. + Remove an Organizational Identity. The person must be removed from any COs (CoPerson) + before the OrgIdentity record can be removed. This method will also delete related data, + such as Addresses, EmailAddresses, and TelephoneNumbers. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + :request + { + "RequestType":"OrgIdentities", + "Version":"1.0", + "OrgIdentities": + [ + { + "Version":"1.0", + "Affiliation":"<Affiliation>", + "Title":"<Title>", + "O":"<O>", + "Ou":"<Ou>", + "CoId":"<CoId>", + "ValidFrom":"<ValidFrom>", + "ValidThrough":"<ValidThrough>", + "DateOfBirth":"<DateOfBirth>" + } + ] + } + + Response Format + HTTP Status Response Body Description + 200 Deleted OrgIdentity deleted + 400 Invalid Fields id not provided + 401 Unauthorized Authentication required + 403 CoPerson Exists ErrorResponse id must not be attached to any + CoPerson. (Delete the CoPerson first.) + 404 OrgIdentity Unknown id not found + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( + + url = self._CO_API_URL + '/org_identities/' + str(org_identity_id) + '.json' + resp = self._s.delete( url=url ) if resp.status_code == 200: diff --git a/examples/org_identities_example.py b/examples/org_identities_example.py index 110c36d..016e82e 100644 --- a/examples/org_identities_example.py +++ b/examples/org_identities_example.py @@ -21,10 +21,12 @@ print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) -# org_identities_delete() -> bool +# org_identities_delete(org_identity_id: int) -> bool print('### org_identities_delete') try: - delete_org_identity = api.org_identities_delete() + per_co_org_identities = api.org_identities_view_per_co() + org_identity_id = int(per_co_org_identities['OrgIdentities'][0]['Id']) + delete_org_identity = api.org_identities_delete(org_identity_id) print(json.dumps(delete_org_identity, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') From 77f05fc9ae2a55cb57078ea0761ad56c9c5f082c Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 20 Sep 2022 13:52:51 -0400 Subject: [PATCH 10/23] implementing coorg_identity_links_add method --- README.md | 3 +- comanage_api/__init__.py | 4 +- comanage_api/_coorgidentitylinks.py | 63 ++++++++++++++++++++---- examples/coorg_identity_links_example.py | 12 +++-- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 07b9446..9729ae1 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,7 @@ Return types based on implementation status of wrapped API endpoints ### <a name="coorgidentitylink"></a>[CoOrgIdentityLink API](https://spaces.at.internet2.edu/display/COmanage/CoOrgIdentityLink+API) (COmanage v4.0.0+) -- `coorg_identity_links_add() -> dict` - - `### NOT IMPLEMENTED ###` +- `coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict` - Add a new CO Org Identity Link. - A person must have an Org Identity and a CO Person record before they can be linked. - Note that invitations are a separate operation. diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..d7b9af1 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -93,8 +93,8 @@ def __init__(self, co_api_url: str, co_api_user: str, co_api_pass: str, co_api_o self._s.auth = (self._CO_API_USER, self._CO_API_PASS) # CoOrgIdentityLink API - def coorg_identity_links_add(self): - return coorg_identity_links_add(self) + def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int): + return coorg_identity_links_add(self, coperson_id=coperson_id, org_identity_id=org_identity_id) def coorg_identity_links_delete(self): return coorg_identity_links_delete(self) diff --git a/comanage_api/_coorgidentitylinks.py b/comanage_api/_coorgidentitylinks.py index 80d7b7a..dea5d1e 100644 --- a/comanage_api/_coorgidentitylinks.py +++ b/comanage_api/_coorgidentitylinks.py @@ -5,7 +5,7 @@ Methods ------- -coorg_identity_links_add() -> dict +coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. @@ -27,20 +27,65 @@ import json -def coorg_identity_links_add(self) -> dict: +def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int) -> dict: """ - ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + coapi: COmanage API object + coperson_id: COmanage ID of CoPerson to link + orgidentity_id: COmanage ID of OrgIdentity to link + :request + { + "RequestType":"CoOrgIdentityLinks", + "Version":"1.0", + "CoOrgIdentityLinks": + [ + { + "Version":"1.0", + "CoPersonId":"<CoPersonId>", + "OrgIdentityId":"<OrgIdentityId>" + } + ] + }: + + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse CoOrgIdentityLink created + 400 Bad Request CoOrgIdentityLink Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 COPerson Does Not Exist The specified CO Person does not exist + 403 OrgIdentity Already Linked The specified Org Identity is already + a member of this CO + 403 OrgIdentity Does Not Exist The specified Org Identity does + not exist + 500 Other Error Unknown error """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url + post_body = { + "RequestType":"CoOrgIdentityLinks", + "Version":"1.0", + "CoOrgIdentityLinks": + [ + { + "Version":"1.0", + "CoPersonId":"<CoPersonId>", + "OrgIdentityId":"<OrgIdentityId>" + } + ] + } + + post_body['CoOrgIdentityLinks'][0]['CoPersonId'] = coperson_id + post_body['CoOrgIdentityLinks'][0]['OrgIdentityId'] = org_identity_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/co_org_identity_links.json' + resp = self._s.post( + url=url, + data=post_body ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/examples/coorg_identity_links_example.py b/examples/coorg_identity_links_example.py index 52ff2bb..0244e4f 100644 --- a/examples/coorg_identity_links_example.py +++ b/examples/coorg_identity_links_example.py @@ -16,11 +16,17 @@ # coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ # coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one -# coorg_identity_links_add() -> dict +# coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict print('### coorg_identity_links_add') try: - new_coorg_identity_link = api.coorg_identity_links_add() - print(json.dumps(new_coorg_identity_link, indent=4)) + per_co_copeople = api.copeople_view_per_co() + if per_co_copeople['CoPeople']: + coperson_id = int(per_co_copeople['CoPeople'][0]['Id']) + new_coorg_identity_link = api.coorg_identity_links_add( + coperson_id=coperson_id, + org_identity_id=IDENTITY_ID + ) + print(json.dumps(new_coorg_identity_link, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) From 546d0a6af6406346e47934f8984506d8ff406717 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 20 Sep 2022 14:21:19 -0400 Subject: [PATCH 11/23] updating README for email_addresses_add method --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b763354..7b96b7a 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ AFFILIATION_OPTIONS = ['affiliate', 'alum', 'employee', 'faculty', 'member', 'st ### <a name="emailaddress"></a>[EmailAddress API](https://spaces.at.internet2.edu/display/COmanage/EmailAddress+API) (COmanage v3.3.0+) -- `email_addresses_add() -> dict` +- `email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict` - Add a new EmailAddress. - `email_addresses_delete() -> bool` - `### NOT IMPLEMENTED ###` From b138a6ce84b3101f155e3b69f3eba78cd80c9f3b Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 20 Sep 2022 14:25:04 -0400 Subject: [PATCH 12/23] fixing syntax for identifiers_add example method --- examples/identifiers_example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/identifiers_example.py b/examples/identifiers_example.py index 3bebd70..236d0cb 100644 --- a/examples/identifiers_example.py +++ b/examples/identifiers_example.py @@ -20,7 +20,8 @@ identifier='test@domain.com', login_flag=False, person_type='CO', - person_id=CO_PERSON_ID) + person_id=CO_PERSON_ID + ) print(json.dumps(new_identifier, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') From faec32b4d5c1f2765946fe38e3e3118db2a58d12 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 20 Sep 2022 14:29:09 -0400 Subject: [PATCH 13/23] implementing names_add method --- README.md | 2 +- comanage_api/__init__.py | 4 ++-- comanage_api/_names.py | 12 ++++++------ examples/names_example.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a9f9e84..003b39a 100644 --- a/README.md +++ b/README.md @@ -274,7 +274,7 @@ ENTITY_OPTIONS = ['codeptid', 'cogroupid', 'copersonid', 'organizationid', 'orgi ### <a name="name"></a>[Name API](https://spaces.at.internet2.edu/display/COmanage/Name+API) (COmanage v3.3.0+) -- `names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict` +- `names_add(person_type: str, person_id: int, given: str, family: str) -> dict` - Add a new Name. - `names_delete() -> bool` - `### NOT IMPLEMENTED ###` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index cc2c3a1..b143fcb 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -224,8 +224,8 @@ def identifiers_view_one(self, identifier_id: int): return identifiers_view_one(self, identifier_id=identifier_id) # Name API - def names_add(self, person_type: str, person_id: int, given_name: str, family_name: str): - return names_add(self, person_type=person_type, person_id=person_id, given_name=given_name, family_name=family_name) + def names_add(self, person_type: str, person_id: int, given: str, family: str): + return names_add(self, person_type=person_type, person_id=person_id, given=given, family=family) def names_delete(self): return names_delete(self) diff --git a/comanage_api/_names.py b/comanage_api/_names.py index 257db1c..3919199 100644 --- a/comanage_api/_names.py +++ b/comanage_api/_names.py @@ -5,7 +5,7 @@ Methods ------- -names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict +names_add(person_type: str, person_id: int, given: str, family: str) -> dict Add a new Name. names_delete() -> bool ### NOT IMPLEMENTED ### @@ -24,14 +24,14 @@ import json -def names_add(self, person_type: str, person_id: int, given_name: str, family_name: str) -> dict: +def names_add(self, person_type: str, person_id: int, given: str, family: str) -> dict: """ Add a new Name. person_type: Type of person (i.e. "CO"|"Org") person_id: COmanage ID for the person_type - given_name: First name for the person - family_name: Last name for the person + given: First name for the person + family: Last name for the person :request { "RequestType":"Names", @@ -96,8 +96,8 @@ def names_add(self, person_type: str, person_id: int, given_name: str, family_na ] } - post_body['Names'][0]['Given'] = given_name - post_body['Names'][0]['Family'] = family_name + post_body['Names'][0]['Given'] = given + post_body['Names'][0]['Family'] = family post_body['Names'][0]['Person']['Type'] = person_type post_body['Names'][0]['Person']['Id'] = person_id diff --git a/examples/names_example.py b/examples/names_example.py index bad4fc1..96a28c8 100644 --- a/examples/names_example.py +++ b/examples/names_example.py @@ -12,14 +12,14 @@ # must be set ahead of time and be valid within the CO CO_PERSON_ID = 163 -# names_add(person_type: str, person_id: int, given_name: str, family_name: str) -> dict +# names_add(person_type: str, person_id: int, given: str, family: str) -> dict print('### names_add') try: new_name = api.names_add( person_type='copersonid', person_id=CO_PERSON_ID, - given_name="TestGiven", - family_name="TestFamily" + given="TestGiven", + family="TestFamily" )) print(json.dumps(new_name, indent=4)) except HTTPError as err: From cfbff48f171994ff0981fda04ea871e261a8a2be Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 20 Sep 2022 14:37:04 -0400 Subject: [PATCH 14/23] implementing coorg_identity_links_add method --- comanage_api/_coorgidentitylinks.py | 1 - examples/coorg_identity_links_example.py | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/comanage_api/_coorgidentitylinks.py b/comanage_api/_coorgidentitylinks.py index dea5d1e..a093184 100644 --- a/comanage_api/_coorgidentitylinks.py +++ b/comanage_api/_coorgidentitylinks.py @@ -6,7 +6,6 @@ Methods ------- coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict - ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. diff --git a/examples/coorg_identity_links_example.py b/examples/coorg_identity_links_example.py index 0244e4f..04425ad 100644 --- a/examples/coorg_identity_links_example.py +++ b/examples/coorg_identity_links_example.py @@ -12,6 +12,7 @@ # must be set ahead of time and be valid within the CO IDENTITY_TYPE = 'orgidentityid' IDENTITY_ID = 190 +CO_PERSON_ID = 163 # coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ # coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one @@ -19,14 +20,11 @@ # coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict print('### coorg_identity_links_add') try: - per_co_copeople = api.copeople_view_per_co() - if per_co_copeople['CoPeople']: - coperson_id = int(per_co_copeople['CoPeople'][0]['Id']) - new_coorg_identity_link = api.coorg_identity_links_add( - coperson_id=coperson_id, - org_identity_id=IDENTITY_ID - ) - print(json.dumps(new_coorg_identity_link, indent=4)) + new_coorg_identity_link = api.coorg_identity_links_add( + coperson_id=CO_PERSON_ID, + org_identity_id=IDENTITY_ID + ) + print(json.dumps(new_coorg_identity_link, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) From 611f7e1a0e75ff43b3d363b65e283a18cdd960b1 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Wed, 21 Sep 2022 12:33:54 -0400 Subject: [PATCH 15/23] changing indentifier_id to identifier for org_identities_view_per_identifier to account for non int identifiers such as eppn --- README.md | 2 +- comanage_api/__init__.py | 6 +++--- comanage_api/_orgidentities.py | 6 +++--- examples/org_identities_example.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 98dfec9..fe75484 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ PERSON_OPTIONS = ['copersonid', 'orgidentityid'] - Retrieve all existing Organizational Identities. - `org_identities_view_per_co(person_type: str, person_id: int) -> dict` - Retrieve all existing Organizational Identities for the specified CO. -- `org_identities_view_per_identifier(identifier_id: int) -> dict` +- `org_identities_view_per_identifier(identifier: str) -> dict` - Retrieve all existing Organizational Identities attached to the specified identifier. - Note the specified identifier must be attached to an Org Identity, not a CO Person. - `org_identities_view_one(org_identity_id: int) -> dict` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 9472f1b..b24eb42 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -19,7 +19,7 @@ ssh_keys_view_one # fabric-comanage-api version -__VERSION__ = "0.1.5" +__VERSION__ = "0.1.6" class ComanageApi(object): @@ -258,8 +258,8 @@ def org_identities_view_all(self): def org_identities_view_per_co(self): return org_identities_view_per_co(self) - def org_identities_view_per_identifier(self, identifier_id: int): - return org_identities_view_per_identifier(self, identifier_id=identifier_id) + def org_identities_view_per_identifier(self, identifier: str): + return org_identities_view_per_identifier(self, identifier=identifier) def org_identities_view_one(self, org_identity_id: int): return org_identities_view_one(self, org_identity_id=org_identity_id) diff --git a/comanage_api/_orgidentities.py b/comanage_api/_orgidentities.py index 9dbf1d7..2a9714e 100644 --- a/comanage_api/_orgidentities.py +++ b/comanage_api/_orgidentities.py @@ -18,7 +18,7 @@ Retrieve all existing Organizational Identities. org_identities_view_per_co(person_type: str, person_id: int) -> dict Retrieve all existing Organizational Identities for the specified CO. -org_identities_view_per_identifier(identifier_id: int) -> dict +org_identities_view_per_identifier(identifier: str) -> dict Retrieve all existing Organizational Identities attached to the specified identifier. Note the specified identifier must be attached to an Org Identity, not a CO Person. org_identities_view_one(org_identity_id: int) -> dict @@ -249,7 +249,7 @@ def org_identities_view_per_co(self) -> dict: resp.raise_for_status() -def org_identities_view_per_identifier(self, identifier_id: int) -> dict: +def org_identities_view_per_identifier(self, identifier: str) -> dict: """ Retrieve all existing Organizational Identities attached to the specified identifier. Note the specified identifier must be attached to an Org Identity, not a CO Person. @@ -288,7 +288,7 @@ def org_identities_view_per_identifier(self, identifier_id: int) -> dict: 500 Other Error Unknown error """ url = self._CO_API_URL + '/org_identities.json' - params = {'coid': self._CO_API_ORG_ID, 'search.identifier': int(identifier_id)} + params = {'coid': self._CO_API_ORG_ID, 'search.identifier': identifier} resp = self._s.get( url=url, params=params diff --git a/examples/org_identities_example.py b/examples/org_identities_example.py index 016e82e..5f4f222 100644 --- a/examples/org_identities_example.py +++ b/examples/org_identities_example.py @@ -59,11 +59,11 @@ print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) -# org_identities_view_per_identitifer(identifier_id: int) -> dict: +# org_identities_view_per_identitifer(identifier: str) -> dict: print('### org_identities_view_per_identifier') try: per_identifier_org_identities = api.org_identities_view_per_identifier( - identifier_id=ORG_IDENDIFIER_ID + identifier=str(ORG_IDENDIFIER_ID) ) print(json.dumps(per_identifier_org_identities, indent=4)) except (TypeError, HTTPError) as err: From d27cfba3c351cd3bcc7deeee6bb3df3dba1ea85d Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 27 Sep 2022 14:32:58 -0400 Subject: [PATCH 16/23] adding cogroup api with cogroup_view_per_co method implemented --- comanage_api/_cogroup.py | 243 ++++++++++++++++++++++++++++++++++++ examples/cogroup_example.py | 103 +++++++++++++++ 2 files changed, 346 insertions(+) create mode 100644 comanage_api/_cogroup.py create mode 100644 examples/cogroup_example.py diff --git a/comanage_api/_cogroup.py b/comanage_api/_cogroup.py new file mode 100644 index 0000000..7b944d3 --- /dev/null +++ b/comanage_api/_cogroup.py @@ -0,0 +1,243 @@ +# comanage_api/_cogroup.py + +""" +CoGroup API - https://spaces.at.internet2.edu/display/COmanage/CoGroup+API + +Methods +------- +cogroup_add() -> dict + ### NOT IMPLEMENTED ### + Add a new CoGroup. +cogroup_delete() -> bool + ### NOT IMPLEMENTED ### + Remove a CoGroup. +cogroup_edit() -> bool + ### NOT IMPLEMENTED ### + Edit an existing CoGroup. +cogroup_reconcile_all() -> bool + ### NOT IMPLEMENTED ### + Reconcile all membership groups. +cogroup_reconcile_one() -> bool + ### NOT IMPLEMENTED ### + Reconcile memberships for a CoGroup. +cogroup_view_all() -> dict + ### NOT IMPLEMENTED ### + Retrieve all existing CoGroups. +cogroup_view_per_co() -> dict + Retrieve CoGroups attached to a CO. +cogroup_view_per_coperson() -> dict + ### NOT IMPLEMENTED ### + Retrieve Groups attached to a CO Person. +cogroup_view_per_identifier() -> dict + ### NOT IMPLEMENTED ### + Retrieve all existing CO Groups attached to the specified identifier. +cogroup_view_one() -> dict + ### NOT IMPLEMENTED ### + Retrieve an existing CoGroup. +""" + +import json + +def cogroup_add(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Add a new CoGroup. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return json.loads(resp.text) + else: + resp.raise_for_status() + +def cogroup_delete(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Remove a CoGroup. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + +def cogroup_edit(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Edit an existing CoGroup. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + +def cogroup_reconcile_all(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Reconcile all membership groups. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + +def cogroup_reconcile_one(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Reconcile memberships for a CoGroup. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + +def cogroup_view_all(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve all existing CoGroups. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return json.loads(resp.text) + else: + resp.raise_for_status() + +def cogroup_view_per_co(self) -> dict: + """ + Retrieve CoGroups attached to a CO. + + :param self: + :request + { + "RequestType":"CoGroups", + "Version":"1.0", + "CoGroups": + [ + { + "Version":"1.0", + "CoId":"<CoID>", + "Name":"<Name>", + "Description":"<Description>", + "Open":true|false, + "Status":("Active"|"Suspended"), + "CouId":"<CouID>" + } + ] + }: + + Response Format + HTTP Status Response Body Description + 200 OK CoGroup Response CoGroup returned + 401 Unauthorized Authentication required + 404 CO Unknown id not found + 500 Other Error Unknown error + """ + + url = self._CO_API_URL + '/co_groups.json' + params = {'coid': self._CO_API_ORG_ID} + resp = self._s.get( + url=url, + params=params + ) + if resp.status_code == 200: + return json.loads(resp.text) + + resp.raise_for_status() + +def cogroup_view_per_coperson(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve Groups attached to a CO Person. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return json.loads(resp.text) + else: + resp.raise_for_status() + +def cogroup_view_per_identifier(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve all existing CO Groups attached to the specified identifier. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return json.loads(resp.text) + else: + resp.raise_for_status() + +def cogroup_view_one(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve an existing CoGroup. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return json.loads(resp.text) + else: + resp.raise_for_status() diff --git a/examples/cogroup_example.py b/examples/cogroup_example.py new file mode 100644 index 0000000..212c78a --- /dev/null +++ b/examples/cogroup_example.py @@ -0,0 +1,103 @@ +# examples/cogroup_example.py +# CoGroup API examples + +import os +import sys + +sys.path.append( + os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) +) +from examples import * + +# cogroup_add, cogroup_delete, cogroup_edit, cogroup_reconcile_all, cogroup_reconcile_one, cogroup_view_all, \ +# cogroup_view_per_co, cogroup_view_per_coperson, cogroup_view_per_identifier, cogroup_view_one + +# cogroup_add() -> dict +print('### cogroup_add') +try: + new_cogroup = api.cogroup_add() + print(json.dumps(new_cogroup, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_delete() -> bool +print('### cogroup_delete') +try: + delete_cogroup = api.cogroup_delete() + print(json.dumps(delete_cogroup, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_edit() -> bool +print('### cogroup_edit') +try: + edit_cogroup = api.cogroup_edit() + print(json.dumps(edit_cogroup, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_reconcile_all() -> bool +print('### cogroup_reconcile_all') +try: + reconcile_all_cogroup = api.cogroup_reconcile_all() + print(json.dumps(reconcile_all_cogroup, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_reconcile_one() -> bool +print('### cogroup_reconcile_one') +try: + reconcile_one_cogroup = api.cogroup_reconcile_one() + print(json.dumps(reconcile_one_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_view_all() -> dict +print('### cogroup_view_all') +try: + all_cogroup = api.cogroup_view_all() + print(json.dumps(all_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_view_per_co() -> dict +print('### cogroup_view_per_co') +try: + per_co_cogroup = api.cogroup_view_per_co() + print(json.dumps(per_co_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_view_per_coperson() -> dict +print('### cogroup_view_per_coperson') +try: + per_coperson_cogroup = api.cogroup_view_per_coperson() + print(json.dumps(per_coperson_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_view_per_identifier() -> dict +print('### cogroup_view_per_identifier') +try: + per_identfier_cogroup = api.cogroup_view_per_identifier() + print(json.dumps(per_identfier_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroup_view_one() -> dict +print('### cogroup_view_one') +try: + one_cogroup = api.cogroup_view_one() + print(json.dumps(one_cogroup, indent=4)) +except (TypeError, HTTPError) as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) From e32e9bb799856efd014276e605ef2b72ead0f7f7 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 27 Sep 2022 14:33:25 -0400 Subject: [PATCH 17/23] adding cogroup api with cogroup_view_per_co method implemented --- README.md | 32 ++++++++++++++++++++++++++++++++ comanage_api/__init__.py | 33 +++++++++++++++++++++++++++++++++ examples/README.md | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/README.md b/README.md index 07b9446..026ab67 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,38 @@ Return types based on implementation status of wrapped API endpoints - `-> dict`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) - `-> bool`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) +### <a name="cogroup"></a>[CoGroup API](https://spaces.at.internet2.edu/display/COmanage/CoGroup+API) (COmanage v4.0.0+) + +- `cogroup_add() -> dict` + - `### NOT IMPLEMENTED ###` + - Add a new CoGroup. +- `cogroup_delete() -> bool` + - `### NOT IMPLEMENTED ###` + - Remove a CoGroup. +- `cogroup_edit() -> bool` + - `### NOT IMPLEMENTED ###` + - Edit an existing CoGroup. +- `cogroup_reconcile_all() -> bool` + - `### NOT IMPLEMENTED ###` + Reconcile all membership groups. +- `cogroup_reconcile_one() -> bool` + - `### NOT IMPLEMENTED ###` + - Reconcile memberships for a CoGroup. +- `cogroup_view_all() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve all existing CoGroups. +- `cogroup_view_per_co() -> dict` + - Retrieve CoGroups attached to a CO. +- `cogroup_view_per_coperson() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve Groups attached to a CO Person. +- `cogroup_view_per_identifier() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve all existing CO Groups attached to the specified identifier. +- `cogroup_view_one() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve an existing CoGroup. + ### <a name="coorgidentitylink"></a>[CoOrgIdentityLink API](https://spaces.at.internet2.edu/display/COmanage/CoOrgIdentityLink+API) (COmanage v4.0.0+) - `coorg_identity_links_add() -> dict` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..f6af7d3 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -1,6 +1,8 @@ import requests_mock from requests import Session +from ._cogroup import cogroup_add, cogroup_delete, cogroup_edit, cogroup_reconcile_all, cogroup_reconcile_one, \ + cogroup_view_all, cogroup_view_per_co, cogroup_view_per_coperson, cogroup_view_per_identifier, cogroup_view_one from ._coorgidentitylinks import coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one from ._copeople import copeople_add, copeople_delete, copeople_edit, copeople_find, copeople_match, \ @@ -92,6 +94,37 @@ def __init__(self, co_api_url: str, co_api_user: str, co_api_pass: str, co_api_o self._s.headers = {'Content-Type': 'application/json'} self._s.auth = (self._CO_API_USER, self._CO_API_PASS) + # CoGroup API + def cogroup_add(self): + return cogroup_add(self) + + def cogroup_delete(self): + return cogroup_delete(self) + + def cogroup_edit(self): + return cogroup_edit(self) + + def cogroup_reconcile_all(self): + return cogroup_reconcile_all(self) + + def cogroup_reconcile_one(self): + return cogroup_reconcile_one(self) + + def cogroup_view_all(self): + return cogroup_view_all(self) + + def cogroup_view_per_co(self): + return cogroup_view_per_co(self) + + def cogroup_view_per_coperson(self): + return cogroup_view_per_coperson(self) + + def cogroup_view_per_identifier(self): + return cogroup_view_per_identifier(self) + + def cogroup_view_one(self): + return cogroup_view_one(self) + # CoOrgIdentityLink API def coorg_identity_links_add(self): return coorg_identity_links_add(self) diff --git a/examples/README.md b/examples/README.md index 39c6d61..c749b90 100644 --- a/examples/README.md +++ b/examples/README.md @@ -61,6 +61,45 @@ api = ComanageApi( ) ``` +## <a name="cogroup"></a>CoGroup API + +Example: `co_group_example.py` + +```console +$ python examples/coorg_group_example.py +### cogroup_add +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_delete +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_edit +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_reconcile_all +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_reconcile_one +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_view_all +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_view_per_co +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_view_per_coperson +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_view_per_identifier +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroup_view_one +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local + +``` + ## <a name="coorgidentitylink"></a>CoOrgIdentityLink API Example: `co_org_identity_links_example.py` From 1c7eddba253a62786ca206278a383b715c371fcc Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 27 Sep 2022 14:37:27 -0400 Subject: [PATCH 18/23] adding CoGroup to README table of contents --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 026ab67..334a5de 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Available at PyPi: [https://pypi.org/project/fabric-comanage-api/](https://pypi. - [TL;DR](#tldr) - [API endpoints](#endpoints) + - [CoGroup](#cogroup) - [CoOrgIdentityLink](#coorgidentitylinks) - [CoPerson](#coperson) - [CoPersonRole](#copersonrole) @@ -133,7 +134,7 @@ Return types based on implementation status of wrapped API endpoints - Edit an existing CoGroup. - `cogroup_reconcile_all() -> bool` - `### NOT IMPLEMENTED ###` - Reconcile all membership groups. + - Reconcile all membership groups. - `cogroup_reconcile_one() -> bool` - `### NOT IMPLEMENTED ###` - Reconcile memberships for a CoGroup. From c06135a1bcbe5bf073b2e95353bbffe9267a61af Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Tue, 27 Sep 2022 14:39:16 -0400 Subject: [PATCH 19/23] adding CoGroup to examples README table of contents --- examples/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/README.md b/examples/README.md index c749b90..c3a9532 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,6 +7,7 @@ Examples demonstrating basic usage for each wrapped endpoint. Some of the values ## Table of Contents - [Configuration](#config) `__init__.py` used by all examples +- [CoGroup API](#cogroup) example output - [CoOrgIdentityLink API](#coorgidentitylink) example output - [CoPerson API](#coperson) example output - [CoPersonRole API](#copersonrole) example output From 8ce4735e0207cc292cdad4d95233e7d04ed91e5e Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Mon, 3 Oct 2022 14:11:01 -0400 Subject: [PATCH 20/23] adding cogroupmember api --- README.md | 19 +++ comanage_api/__init__.py | 21 +++ comanage_api/_cogroupmember.py | 222 ++++++++++++++++++++++++++++++ examples/README.md | 28 ++++ examples/cogroupmember_example.py | 75 ++++++++++ 5 files changed, 365 insertions(+) create mode 100644 comanage_api/_cogroupmember.py create mode 100644 examples/cogroupmember_example.py diff --git a/README.md b/README.md index 07b9446..c4ac0ff 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Available at PyPi: [https://pypi.org/project/fabric-comanage-api/](https://pypi. - [TL;DR](#tldr) - [API endpoints](#endpoints) + - [CoGroupMember](#cogroupmember) - [CoOrgIdentityLink](#coorgidentitylinks) - [CoPerson](#coperson) - [CoPersonRole](#copersonrole) @@ -120,6 +121,24 @@ Return types based on implementation status of wrapped API endpoints - `-> dict`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) - `-> bool`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) +### <a name="cogroupmember"></a>[CoGroupMember API](https://spaces.at.internet2.edu/display/COmanage/CoGroupMember+API) (COmanage v4.0.0+) +- `cogroupmember_add(group_id: int, person_id: int) -> dict` + - Add a new CoGroupMember (ie: a member of a CO group). +- `cogroupmember_delete() -> bool` + - `### NOT IMPLEMENTED ###` + - Remove a CoGroupMember. +- `cogroupmember_edit() -> bool` + - `### NOT IMPLEMENTED ###` + - Edit an existing CoGroupMember. +- `cogroupmember_view_all() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve all existing CoGroupMembers. +- `cogroupmember_view_per_group(group_id: int) -> dict` + - Retrieve CoGroupMembers attached to a CoGroup. +- `cogroupmember_view_one() -> dict` + - `### NOT IMPLEMENTED ###` + - Retrieve an existing CoGroupMember. + ### <a name="coorgidentitylink"></a>[CoOrgIdentityLink API](https://spaces.at.internet2.edu/display/COmanage/CoOrgIdentityLink+API) (COmanage v4.0.0+) - `coorg_identity_links_add() -> dict` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 39118f1..bcc1318 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -1,6 +1,8 @@ import requests_mock from requests import Session +from ._cogroupmember import cogroupmember_add, cogroupmember_delete, cogroupmember_edit, \ + cogroupmember_view_all, cogroupmember_view_per_group, cogroupmember_view_one from ._coorgidentitylinks import coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one from ._copeople import copeople_add, copeople_delete, copeople_edit, copeople_find, copeople_match, \ @@ -92,6 +94,25 @@ def __init__(self, co_api_url: str, co_api_user: str, co_api_pass: str, co_api_o self._s.headers = {'Content-Type': 'application/json'} self._s.auth = (self._CO_API_USER, self._CO_API_PASS) + # CoGroupMember API + def cogroupmember_add(self, group_id: int, person_id: int): + return cogroupmember_add(self, group_id=group_id, person_id=person_id) + + def cogroupmember_delete(self): + return cogroupmember_delete(self) + + def cogroupmember_edit(self): + return cogroupmember_edit(self) + + def cogroupmember_view_all(self): + return cogroupmember_view_all(self) + + def cogroupmember_view_per_group(self, group_id: int): + return cogroupmember_view_per_group(self, group_id=group_id) + + def cogroupmember_view_one(self): + return cogroupmember_view_one(self) + # CoOrgIdentityLink API def coorg_identity_links_add(self): return coorg_identity_links_add(self) diff --git a/comanage_api/_cogroupmember.py b/comanage_api/_cogroupmember.py new file mode 100644 index 0000000..afd2c49 --- /dev/null +++ b/comanage_api/_cogroupmember.py @@ -0,0 +1,222 @@ +# comanage_api/_cogroupmember.py + +""" +CoGroupMember API - https://spaces.at.internet2.edu/display/COmanage/CoGroupMember+API + +Methods +------- +cogroupmember_add(group_id: int, person_id: int) -> dict + Add a new CoGroupMember (ie: a member of a CO group). +cogroupmember_delete() -> bool + ### NOT IMPLEMENTED ### + Remove a CoGroupMember. +cogroupmember_edit() -> bool + ### NOT IMPLEMENTED ### + Edit an existing CoGroupMember. +cogroupmember_view_all() -> dict + ### NOT IMPLEMENTED ### + Retrieve all existing CoGroupMembers. +cogroupmember_view_per_group(group_id: int) -> dict + Retrieve CoGroupMembers attached to a CoGroup. +cogroupmember_view_one() -> dict + ### NOT IMPLEMENTED ### + Retrieve an existing CoGroupMember. +""" + +import json + + +def cogroupmember_add(self, group_id: int, person_id: int) -> dict: + """ + Add a new CoGroupMember (ie: a member of a CO group). + group_id: COmanage COGroup Id + person_id: COmanage COPerson Id + :request + { + "RequestType":"CoGroupMembers", + "Version":"1.0", + "CoGroupMembers": + [ + { + "Version":"1.0", + "CoGroupId":"<CoGroupId>", + "Person": + { + "Type":"CO", + "Id":"<ID>" + }, + "Member":true|false, + "Owner":true|false, + "ValidFrom":"<ValidFrom>", + "ValidThrough":"<ValidThrough>" + } + ] + }: + Response Format + HTTP Status Response Body Description + 201 Added NewObjectResponse CoGroupMember added + 400 Bad Request CoGroupMember Request not + provided in POST body + 400 Invalid Fields ErrorResponse An error in one or more + provided fields + 401 Unauthorized Authentication required + 403 CoGroup Does Not Exist The specified CoGroup does not exist + 403 CoPerson Does Not Exist The specified CoPerson does not exist + 403 CoPerson Already Member The specified CoPerson is already a + member of the specified CoGroup + 500 Other Error Unknown error + """ + + post_body = { + "RequestType":"CoGroupMembers", + "Version":"1.0", + "CoGroupMembers": + [ + { + "Version":"1.0", + "CoGroupId":"<CoGroupId>", + "Person": + { + "Type":"CO", + "Id":"<ID>" + }, + "Member":True, + "Owner":False + } + ] + } + + post_body['CoGroupMembers'][0]['CoGroupId'] = group_id + post_body['CoGroupMembers'][0]['Person']['Id'] = person_id + + post_body = json.dumps(post_body) + url = self._CO_API_URL + '/co_group_members.json' + resp = self._s.post( + url=url, + data=post_body + ) + if resp.status_code == 201: + return json.loads(resp.text) + else: + resp.raise_for_status() + + +def cogroupmember_delete(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Remove a CoGroupMember. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + + +def cogroupmember_edit(self) -> bool: + """ + ### NOT IMPLEMENTED ### + Edit an existing CoGroupMember. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + + +def cogroupmember_view_all(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve all existing CoGroupMembers. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + + +def cogroupmember_view_per_group(self, group_id: int) -> dict: + """ + Retrieve CoGroupMembers attached to a CoGroup. + group_id: COmanage COGroup Id + :request + { + "RequestType":"CoGroupMembers", + "Version":"1.0", + "CoGroupMembers": + [ + { + "Version":"1.0", + "CoGroupId":"<CoGroupId>", + "Person": + { + "Type":"CO", + "Id":"<ID>" + }, + "Member":true|false, + "Owner":true|false, + "ValidFrom":"<ValidFrom>", + "ValidThrough":"<ValidThrough>" + } + ] + }: + Response Format + HTTP Status Response Body Description + 200 OK CoGroupMemberResponse CoGroupMember returned + 401 Unauthorized Authentication required + 403 CoGroup Unknown id not found + 500 Other Error Unknown error + """ + + url = self._CO_API_URL + '/co_group_members.json' + params = {'cogroupid': group_id} + resp = self._s.get( + url=url, + params=params + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() + + +def cogroupmember_view_one(self) -> dict: + """ + ### NOT IMPLEMENTED ### + Retrieve an existing CoGroupMember. + + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: + """ + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url + ) + if resp.status_code == 200: + return True + else: + resp.raise_for_status() diff --git a/examples/README.md b/examples/README.md index 39c6d61..e8f9aec 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,6 +7,7 @@ Examples demonstrating basic usage for each wrapped endpoint. Some of the values ## Table of Contents - [Configuration](#config) `__init__.py` used by all examples +- [CoGroupMember API](#cogroupmember) example output - [CoOrgIdentityLink API](#coorgidentitylink) example output - [CoPerson API](#coperson) example output - [CoPersonRole API](#copersonrole) example output @@ -61,6 +62,33 @@ api = ComanageApi( ) ``` +## <a name="cogroupmember"></a>CoGroupMember API + +Example: `cogroupmember_example.py` + +```console +$ python examples/cogroupmember_example.py +### cogroupmember_add +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroupmember_delete +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroupmember_edit +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroupmember_view_all +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroupmember_view_per_group +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local +### cogroupmember_view_one +[ERROR] Exception caught +--> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local + +``` + ## <a name="coorgidentitylink"></a>CoOrgIdentityLink API Example: `co_org_identity_links_example.py` diff --git a/examples/cogroupmember_example.py b/examples/cogroupmember_example.py new file mode 100644 index 0000000..ee5230f --- /dev/null +++ b/examples/cogroupmember_example.py @@ -0,0 +1,75 @@ +# examples/cogroupmember_example.py +# CoGroupMember API examples + +import os +import sys + +sys.path.append( + os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) +) +from examples import * + +# cogroupmember_add, cogroupmember_delete, cogroupmember_edit, cogroupmember_view_all, cogroupmember_view_per_group, cogroupmember_view_one + +# must be set ahead of time and be valid within the CO +CO_PERSON_ID = 163 +CO_GROUP_ID = 2 + +# cogroupmember_add(group_id: int, person_id: int) -> dict +print('### cogroupmember_add') +try: + new_cogroupmember = api.cogroupmember_add( + group_id=CO_GROUP_ID, + person_id=CO_PERSON_ID + ) + print(json.dumps(new_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroupmember_delete() -> bool +print('### cogroupmember_delete') +try: + delete_cogroupmember = api.cogroupmember_delete() + print(json.dumps(delete_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroupmember_edit() -> bool +print('### cogroupmember_edit') +try: + edit_cogroupmember = api.cogroupmember_edit() + print(json.dumps(edit_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroupmember_view_all() -> dict +print('### cogroupmember_view_all') +try: + view_all_cogroupmember = api.cogroupmember_view_all() + print(json.dumps(view_all_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroupmember_view_per_group(group_id: int) -> dict +print('### cogroupmember_view_per_group') +try: + view_per_group_cogroupmember = api.cogroupmember_view_per_group( + group_id=CO_GROUP_ID + ) + print(json.dumps(view_per_group_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) + +# cogroupmember_view_one() -> dict +print('### cogroupmember_view_one') +try: + view_one_cogroupmember = api.cogroupmember_view_one() + print(json.dumps(view_one_cogroupmember, indent=4)) +except HTTPError as err: + print('[ERROR] Exception caught') + print('--> ', type(err).__name__, '-', err) From ac6b8bba5dba9ef2ac0dd05d8daf0b66817e6920 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Mon, 3 Oct 2022 14:12:20 -0400 Subject: [PATCH 21/23] fixing cogroup_example in examples README --- examples/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/README.md b/examples/README.md index c3a9532..8d0bd81 100644 --- a/examples/README.md +++ b/examples/README.md @@ -64,10 +64,10 @@ api = ComanageApi( ## <a name="cogroup"></a>CoGroup API -Example: `co_group_example.py` +Example: `cogroup_example.py` ```console -$ python examples/coorg_group_example.py +$ python examples/cogroup_example.py ### cogroup_add [ERROR] Exception caught --> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local From a36e1513e801b228fef41663f22513271c4dfdb3 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Mon, 3 Oct 2022 15:55:45 -0400 Subject: [PATCH 22/23] Revert "Merge branch 'main' into groupmembers" This reverts commit b9fbe5c84be2735be1ced93a6de34c6f195c2770, reversing changes made to 8ce4735e0207cc292cdad4d95233e7d04ed91e5e. --- README.md | 57 ++---- comanage_api/__init__.py | 63 ++---- comanage_api/_cogroup.py | 243 ----------------------- comanage_api/_coorgidentitylinks.py | 64 +----- comanage_api/_copeople.py | 102 ++-------- comanage_api/_emailaddresses.py | 75 +------ comanage_api/_identifiers.py | 88 +------- comanage_api/_names.py | 91 +-------- comanage_api/_orgidentities.py | 113 +++-------- examples/README.md | 42 ---- examples/cogroup_example.py | 103 ---------- examples/coorg_identity_links_example.py | 8 +- examples/copeople_example.py | 7 +- examples/email_addresses_example.py | 8 +- examples/identifiers_example.py | 8 +- examples/names_example.py | 9 +- examples/org_identities_example.py | 10 +- 17 files changed, 122 insertions(+), 969 deletions(-) delete mode 100644 comanage_api/_cogroup.py delete mode 100644 examples/cogroup_example.py diff --git a/README.md b/README.md index 0593a9b..c4ac0ff 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Available at PyPi: [https://pypi.org/project/fabric-comanage-api/](https://pypi. - [TL;DR](#tldr) - [API endpoints](#endpoints) - - [CoGroup](#cogroup) - [CoGroupMember](#cogroupmember) - [CoOrgIdentityLink](#coorgidentitylinks) - [CoPerson](#coperson) @@ -122,41 +121,7 @@ Return types based on implementation status of wrapped API endpoints - `-> dict`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) - `-> bool`: raise exception (`HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local`) - -### <a name="cogroup"></a>[CoGroup API](https://spaces.at.internet2.edu/display/COmanage/CoGroup+API) (COmanage v4.0.0+) - -- `cogroup_add() -> dict` - - `### NOT IMPLEMENTED ###` - - Add a new CoGroup. -- `cogroup_delete() -> bool` - - `### NOT IMPLEMENTED ###` - - Remove a CoGroup. -- `cogroup_edit() -> bool` - - `### NOT IMPLEMENTED ###` - - Edit an existing CoGroup. -- `cogroup_reconcile_all() -> bool` - - `### NOT IMPLEMENTED ###` - - Reconcile all membership groups. -- `cogroup_reconcile_one() -> bool` - - `### NOT IMPLEMENTED ###` - - Reconcile memberships for a CoGroup. -- `cogroup_view_all() -> dict` - - `### NOT IMPLEMENTED ###` - - Retrieve all existing CoGroups. -- `cogroup_view_per_co() -> dict` - - Retrieve CoGroups attached to a CO. -- `cogroup_view_per_coperson() -> dict` - - `### NOT IMPLEMENTED ###` - - Retrieve Groups attached to a CO Person. -- `cogroup_view_per_identifier() -> dict` - - `### NOT IMPLEMENTED ###` - - Retrieve all existing CO Groups attached to the specified identifier. -- `cogroup_view_one() -> dict` - - `### NOT IMPLEMENTED ###` - - Retrieve an existing CoGroup. - ### <a name="cogroupmember"></a>[CoGroupMember API](https://spaces.at.internet2.edu/display/COmanage/CoGroupMember+API) (COmanage v4.0.0+) - - `cogroupmember_add(group_id: int, person_id: int) -> dict` - Add a new CoGroupMember (ie: a member of a CO group). - `cogroupmember_delete() -> bool` @@ -176,7 +141,8 @@ Return types based on implementation status of wrapped API endpoints ### <a name="coorgidentitylink"></a>[CoOrgIdentityLink API](https://spaces.at.internet2.edu/display/COmanage/CoOrgIdentityLink+API) (COmanage v4.0.0+) -- `coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict` +- `coorg_identity_links_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new CO Org Identity Link. - A person must have an Org Identity and a CO Person record before they can be linked. - Note that invitations are a separate operation. @@ -202,9 +168,11 @@ IDENTITY_OPTIONS = ['copersonid', 'orgidentityid'] ### <a name="coperson"></a>[CoPerson API](https://spaces.at.internet2.edu/display/COmanage/CoPerson+API) (COmanage v3.3.0+) - `copeople_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. - Note that linking to an OrgIdentity and invitations are separate operations. -- `copeople_delete(coperson_id: int) -> bool` +- `copeople_delete() -> bool` + - `### NOT IMPLEMENTED ###` - Remove a CO Person. This method will also delete related data, such as `CoPersonRoles`, `EmailAddresses`, and `Identifiers`. - A person must be removed from any COs (CoPerson records must be deleted) @@ -274,7 +242,8 @@ AFFILIATION_OPTIONS = ['affiliate', 'alum', 'employee', 'faculty', 'member', 'st ### <a name="emailaddress"></a>[EmailAddress API](https://spaces.at.internet2.edu/display/COmanage/EmailAddress+API) (COmanage v3.3.0+) -- `email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict` +- `email_addresses_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new EmailAddress. - `email_addresses_delete() -> bool` - `### NOT IMPLEMENTED ###` @@ -297,7 +266,8 @@ EMAILADDRESS_OPTIONS = ['codeptid', 'copersonid', 'organizationid', 'orgidentity ### <a name="identifier"></a>[Identifier API](https://spaces.at.internet2.edu/display/COmanage/Identifier+API) (COmanage v3.3.0+) -- `identifiers_add(identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict` +- `identifiers_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new Identifier. - `identifiers_assign() -> bool` - `### NOT IMPLEMENTED ###` @@ -323,7 +293,8 @@ ENTITY_OPTIONS = ['codeptid', 'cogroupid', 'copersonid', 'organizationid', 'orgi ### <a name="name"></a>[Name API](https://spaces.at.internet2.edu/display/COmanage/Name+API) (COmanage v3.3.0+) -- `names_add(person_type: str, person_id: int, given: str, family: str) -> dict` +- `names_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new Name. - `names_delete() -> bool` - `### NOT IMPLEMENTED ###` @@ -347,8 +318,10 @@ PERSON_OPTIONS = ['copersonid', 'orgidentityid'] ### <a name="orgidentity"></a>[OrgIdentity API](https://spaces.at.internet2.edu/display/COmanage/OrgIdentity+API) (COmanage v3.3.0+) - `org_identities_add() -> dict` + - `### NOT IMPLEMENTED ###` - Add a new Organizational Identity. A person must have an `OrgIdentity` before they can be added to a CO. -- `org_identities_delete(org_identity_id: int) -> bool` +- `org_identities_delete() -> bool` + - `### NOT IMPLEMENTED ###` - Remove an Organizational Identity. - The person must be removed from any COs (`CoPerson`) before the OrgIdentity record can be removed. - This method will also delete related data, such as `Addresses`, `EmailAddresses`, and `TelephoneNumbers`. @@ -359,7 +332,7 @@ PERSON_OPTIONS = ['copersonid', 'orgidentityid'] - Retrieve all existing Organizational Identities. - `org_identities_view_per_co(person_type: str, person_id: int) -> dict` - Retrieve all existing Organizational Identities for the specified CO. -- `org_identities_view_per_identifier(identifier: str) -> dict` +- `org_identities_view_per_identifier(identifier_id: int) -> dict` - Retrieve all existing Organizational Identities attached to the specified identifier. - Note the specified identifier must be attached to an Org Identity, not a CO Person. - `org_identities_view_one(org_identity_id: int) -> dict` diff --git a/comanage_api/__init__.py b/comanage_api/__init__.py index 07f266d..bcc1318 100644 --- a/comanage_api/__init__.py +++ b/comanage_api/__init__.py @@ -1,8 +1,6 @@ import requests_mock from requests import Session -from ._cogroup import cogroup_add, cogroup_delete, cogroup_edit, cogroup_reconcile_all, cogroup_reconcile_one, \ - cogroup_view_all, cogroup_view_per_co, cogroup_view_per_coperson, cogroup_view_per_identifier, cogroup_view_one from ._cogroupmember import cogroupmember_add, cogroupmember_delete, cogroupmember_edit, \ cogroupmember_view_all, cogroupmember_view_per_group, cogroupmember_view_one from ._coorgidentitylinks import coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ @@ -23,7 +21,7 @@ ssh_keys_view_one # fabric-comanage-api version -__VERSION__ = "0.1.6" +__VERSION__ = "0.1.5" class ComanageApi(object): @@ -96,37 +94,6 @@ def __init__(self, co_api_url: str, co_api_user: str, co_api_pass: str, co_api_o self._s.headers = {'Content-Type': 'application/json'} self._s.auth = (self._CO_API_USER, self._CO_API_PASS) - # CoGroup API - def cogroup_add(self): - return cogroup_add(self) - - def cogroup_delete(self): - return cogroup_delete(self) - - def cogroup_edit(self): - return cogroup_edit(self) - - def cogroup_reconcile_all(self): - return cogroup_reconcile_all(self) - - def cogroup_reconcile_one(self): - return cogroup_reconcile_one(self) - - def cogroup_view_all(self): - return cogroup_view_all(self) - - def cogroup_view_per_co(self): - return cogroup_view_per_co(self) - - def cogroup_view_per_coperson(self): - return cogroup_view_per_coperson(self) - - def cogroup_view_per_identifier(self): - return cogroup_view_per_identifier(self) - - def cogroup_view_one(self): - return cogroup_view_one(self) - # CoGroupMember API def cogroupmember_add(self, group_id: int, person_id: int): return cogroupmember_add(self, group_id=group_id, person_id=person_id) @@ -147,8 +114,8 @@ def cogroupmember_view_one(self): return cogroupmember_view_one(self) # CoOrgIdentityLink API - def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int): - return coorg_identity_links_add(self, coperson_id=coperson_id, org_identity_id=org_identity_id) + def coorg_identity_links_add(self): + return coorg_identity_links_add(self) def coorg_identity_links_delete(self): return coorg_identity_links_delete(self) @@ -169,8 +136,8 @@ def coorg_identity_links_view_one(self, coorg_identity_link_id: int): def copeople_add(self): return copeople_add(self) - def copeople_delete(self, coperson_id: int): - return copeople_delete(self, coperson_id=coperson_id) + def copeople_delete(self): + return copeople_delete(self) def copeople_edit(self): return copeople_edit(self) @@ -237,8 +204,8 @@ def cous_view_one(self, cou_id: int): return cous_view_one(self, cou_id=cou_id) # EmailAddress API - def email_addresses_add(self, email_address: str, person_type: str, person_id: int): - return email_addresses_add(self, email_address=email_address, person_type=person_type, person_id=person_id) + def email_addresses_add(self): + return email_addresses_add(self) def email_addresses_delete(self): return email_addresses_delete(self) @@ -256,8 +223,8 @@ def email_addresses_view_one(self, email_address_id: int): return email_addresses_view_one(self, email_address_id=email_address_id) # Indentifier API - def identifiers_add(self, identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int): - return identifiers_add(self, identity_type=identity_type, identifier=identifier, login_flag=login_flag, person_type=person_type, person_id=person_id) + def identifiers_add(self): + return identifiers_add(self) def identifiers_assign(self): return identifiers_assign(self) @@ -278,8 +245,8 @@ def identifiers_view_one(self, identifier_id: int): return identifiers_view_one(self, identifier_id=identifier_id) # Name API - def names_add(self, person_type: str, person_id: int, given: str, family: str): - return names_add(self, person_type=person_type, person_id=person_id, given=given, family=family) + def names_add(self): + return names_add(self) def names_delete(self): return names_delete(self) @@ -300,8 +267,8 @@ def names_view_one(self, name_id: int): def org_identities_add(self): return org_identities_add(self) - def org_identities_delete(self, org_identity_id: int): - return org_identities_delete(self, org_identity_id=org_identity_id) + def org_identities_delete(self): + return org_identities_delete(self) def org_identities_edit(self): return org_identities_edit(self) @@ -312,8 +279,8 @@ def org_identities_view_all(self): def org_identities_view_per_co(self): return org_identities_view_per_co(self) - def org_identities_view_per_identifier(self, identifier: str): - return org_identities_view_per_identifier(self, identifier=identifier) + def org_identities_view_per_identifier(self, identifier_id: int): + return org_identities_view_per_identifier(self, identifier_id=identifier_id) def org_identities_view_one(self, org_identity_id: int): return org_identities_view_one(self, org_identity_id=org_identity_id) diff --git a/comanage_api/_cogroup.py b/comanage_api/_cogroup.py deleted file mode 100644 index 7b944d3..0000000 --- a/comanage_api/_cogroup.py +++ /dev/null @@ -1,243 +0,0 @@ -# comanage_api/_cogroup.py - -""" -CoGroup API - https://spaces.at.internet2.edu/display/COmanage/CoGroup+API - -Methods -------- -cogroup_add() -> dict - ### NOT IMPLEMENTED ### - Add a new CoGroup. -cogroup_delete() -> bool - ### NOT IMPLEMENTED ### - Remove a CoGroup. -cogroup_edit() -> bool - ### NOT IMPLEMENTED ### - Edit an existing CoGroup. -cogroup_reconcile_all() -> bool - ### NOT IMPLEMENTED ### - Reconcile all membership groups. -cogroup_reconcile_one() -> bool - ### NOT IMPLEMENTED ### - Reconcile memberships for a CoGroup. -cogroup_view_all() -> dict - ### NOT IMPLEMENTED ### - Retrieve all existing CoGroups. -cogroup_view_per_co() -> dict - Retrieve CoGroups attached to a CO. -cogroup_view_per_coperson() -> dict - ### NOT IMPLEMENTED ### - Retrieve Groups attached to a CO Person. -cogroup_view_per_identifier() -> dict - ### NOT IMPLEMENTED ### - Retrieve all existing CO Groups attached to the specified identifier. -cogroup_view_one() -> dict - ### NOT IMPLEMENTED ### - Retrieve an existing CoGroup. -""" - -import json - -def cogroup_add(self) -> dict: - """ - ### NOT IMPLEMENTED ### - Add a new CoGroup. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return json.loads(resp.text) - else: - resp.raise_for_status() - -def cogroup_delete(self) -> bool: - """ - ### NOT IMPLEMENTED ### - Remove a CoGroup. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return True - else: - resp.raise_for_status() - -def cogroup_edit(self) -> bool: - """ - ### NOT IMPLEMENTED ### - Edit an existing CoGroup. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return True - else: - resp.raise_for_status() - -def cogroup_reconcile_all(self) -> bool: - """ - ### NOT IMPLEMENTED ### - Reconcile all membership groups. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return True - else: - resp.raise_for_status() - -def cogroup_reconcile_one(self) -> bool: - """ - ### NOT IMPLEMENTED ### - Reconcile memberships for a CoGroup. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return True - else: - resp.raise_for_status() - -def cogroup_view_all(self) -> dict: - """ - ### NOT IMPLEMENTED ### - Retrieve all existing CoGroups. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return json.loads(resp.text) - else: - resp.raise_for_status() - -def cogroup_view_per_co(self) -> dict: - """ - Retrieve CoGroups attached to a CO. - - :param self: - :request - { - "RequestType":"CoGroups", - "Version":"1.0", - "CoGroups": - [ - { - "Version":"1.0", - "CoId":"<CoID>", - "Name":"<Name>", - "Description":"<Description>", - "Open":true|false, - "Status":("Active"|"Suspended"), - "CouId":"<CouID>" - } - ] - }: - - Response Format - HTTP Status Response Body Description - 200 OK CoGroup Response CoGroup returned - 401 Unauthorized Authentication required - 404 CO Unknown id not found - 500 Other Error Unknown error - """ - - url = self._CO_API_URL + '/co_groups.json' - params = {'coid': self._CO_API_ORG_ID} - resp = self._s.get( - url=url, - params=params - ) - if resp.status_code == 200: - return json.loads(resp.text) - - resp.raise_for_status() - -def cogroup_view_per_coperson(self) -> dict: - """ - ### NOT IMPLEMENTED ### - Retrieve Groups attached to a CO Person. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return json.loads(resp.text) - else: - resp.raise_for_status() - -def cogroup_view_per_identifier(self) -> dict: - """ - ### NOT IMPLEMENTED ### - Retrieve all existing CO Groups attached to the specified identifier. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return json.loads(resp.text) - else: - resp.raise_for_status() - -def cogroup_view_one(self) -> dict: - """ - ### NOT IMPLEMENTED ### - Retrieve an existing CoGroup. - - :param self: - :return - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: - """ - url = self._MOCK_501_URL - resp = self._mock_session.get( - url=url - ) - if resp.status_code == 200: - return json.loads(resp.text) - else: - resp.raise_for_status() diff --git a/comanage_api/_coorgidentitylinks.py b/comanage_api/_coorgidentitylinks.py index a093184..80d7b7a 100644 --- a/comanage_api/_coorgidentitylinks.py +++ b/comanage_api/_coorgidentitylinks.py @@ -5,7 +5,8 @@ Methods ------- -coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict +coorg_identity_links_add() -> dict + ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. @@ -26,65 +27,20 @@ import json -def coorg_identity_links_add(self, coperson_id: int, org_identity_id: int) -> dict: +def coorg_identity_links_add(self) -> dict: """ + ### NOT IMPLEMENTED ### Add a new CO Org Identity Link. A person must have an Org Identity and a CO Person record before they can be linked. Note that invitations are a separate operation. - coapi: COmanage API object - coperson_id: COmanage ID of CoPerson to link - orgidentity_id: COmanage ID of OrgIdentity to link - :request - { - "RequestType":"CoOrgIdentityLinks", - "Version":"1.0", - "CoOrgIdentityLinks": - [ - { - "Version":"1.0", - "CoPersonId":"<CoPersonId>", - "OrgIdentityId":"<OrgIdentityId>" - } - ] - }: - - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse CoOrgIdentityLink created - 400 Bad Request CoOrgIdentityLink Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more - provided fields - 401 Unauthorized Authentication required - 403 COPerson Does Not Exist The specified CO Person does not exist - 403 OrgIdentity Already Linked The specified Org Identity is already - a member of this CO - 403 OrgIdentity Does Not Exist The specified Org Identity does - not exist - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"CoOrgIdentityLinks", - "Version":"1.0", - "CoOrgIdentityLinks": - [ - { - "Version":"1.0", - "CoPersonId":"<CoPersonId>", - "OrgIdentityId":"<OrgIdentityId>" - } - ] - } - - post_body['CoOrgIdentityLinks'][0]['CoPersonId'] = coperson_id - post_body['CoOrgIdentityLinks'][0]['OrgIdentityId'] = org_identity_id - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/co_org_identity_links.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/comanage_api/_copeople.py b/comanage_api/_copeople.py index 6b333ff..fe6705b 100644 --- a/comanage_api/_copeople.py +++ b/comanage_api/_copeople.py @@ -6,9 +6,11 @@ Methods ------- copeople_add() -> dict + ### NOT IMPLEMENTED ### Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. Note that linking to an OrgIdentity and invitations are separate operations. -copeople_delete(coperson_id: int) -> bool +copeople_delete() -> bool + ### NOT IMPLEMENTED ### Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses, and Identifiers. A person must be removed from any COs (CoPerson records must be deleted) before the OrgIdentity record can be removed. @@ -39,59 +41,17 @@ def copeople_add(self) -> dict: """ + ### NOT IMPLEMENTED ### Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO. Note that linking to an OrgIdentity and invitations are separate operations. - :request - { - "RequestType":"CoPeople", - "Version":"1.0", - "CoPeople": - [ - { - "Version":"1.0", - "CoId":"<CoId>", - "Timezone":"<Timezone>", - "DateOfBirth":"<DateOfBirth>", - "Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"| - "Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"| - "PendingApproval"|"PendingConfirmation"| - "PendingVetting"|"Suspended") - } - ] - }: - - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse CoPerson created - 400 Bad Request CoPerson Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more - provided fields - 401 Unauthorized Authentication required - 403 Co Does Not Exist The specified Co does not exist - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"CoPeople", - "Version":"1.0", - "CoPeople": - [ - { - "Version":"1.0", - "CoId":"<CoId>", - "Status":"Active" - } - ] - } - - post_body['CoPeople'][0]['CoId'] = self._CO_API_ORG_ID - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/co_people.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) @@ -99,47 +59,19 @@ def copeople_add(self) -> dict: resp.raise_for_status() -def copeople_delete(self, coperson_id: int) -> bool: +def copeople_delete(self) -> bool: """ + ### NOT IMPLEMENTED ### Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses, and Identifiers. A person must be removed from any COs (CoPerson records must be deleted) before the OrgIdentity record can be removed. - :request - { - "RequestType":"CoPeople", - "Version":"1.0", - "CoPeople": - [ - { - "Version":"1.0", - "CoId":"<CoId>", - "Timezone":"<Timezone>", - "DateOfBirth":"<DateOfBirth>", - "Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"| - "Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"| - "PendingApproval"|"PendingConfirmation"| - "PendingVetting"|"Suspended") - } - ] - }: - - Response Format - HTTP Status Response Body Description - 200 Deleted OrgPerson deleted - 400 Invalid Fields id not provided - 401 Unauthorized Authentication required - 403 CoPersonRole Exists The Person has one or more Person - Role records and cannot be deleted - 403 CouPerson Exists in Unowned COU The Person has a role in one - or more COUs that the authenitcated - user does not control - 404 OrgIdentity Unknown id not found - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - - url = self._CO_API_URL + '/co_people/' + str(coperson_id) + '.json' - resp = self._s.delete( + url = self._MOCK_501_URL + resp = self._mock_session.get( url=url ) if resp.status_code == 200: diff --git a/comanage_api/_emailaddresses.py b/comanage_api/_emailaddresses.py index c2cf307..0e4788f 100644 --- a/comanage_api/_emailaddresses.py +++ b/comanage_api/_emailaddresses.py @@ -5,7 +5,8 @@ Methods ------- -email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict +email_addresses_add() -> dict + ### NOT IMPLEMENTED ### Add a new EmailAddress. email_addresses_delete() -> bool ### NOT IMPLEMENTED ### @@ -24,78 +25,18 @@ import json -def email_addresses_add(self, email_address: str, person_type: str, person_id: int) -> dict: +def email_addresses_add(self) -> dict: """ + ### NOT IMPLEMENTED ### Add a new EmailAddress. :param self: - :param email_address: - :param person_type: - :param person_id: :return - { - "RequestType":"EmailAddresses", - "Version":"1.0", - "EmailAddresses": - [ - { - "Version":"1.0", - "Mail":"<Mail>", - "Type":"<Type>", - "Description":"<Description>", - "Verified":true|false, - "Person": - { - "Type":("CO"|"Dept"|"Org"|"Organization"), - "Id":"<ID>" - } - } - ] - }: - - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse EmailAddress added - 400 Bad Request EmailAddress Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more provided fields - 401 Unauthorized Authentication required - 403 No Person Specified Either a CO Person or an Org Identity - must be specified to attach the - Email Address to - 403 Person Does Not Exist The specified CO Department, CO Person, - or Org Identity does not exist - 500 Other Error Unknown error + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"EmailAddresses", - "Version":"1.0", - "EmailAddresses": - [ - { - "Version":"1.0", - "Mail":"<Mail>", - "Type":"official", - "Description":"", - "Verified": False, - "Person": - { - "Type":"<Type>", - "Id":"<ID>" - } - } - ] - } - - post_body['EmailAddresses'][0]['Mail'] = email_address - post_body['EmailAddresses'][0]['Person']['Type'] = person_type - post_body['EmailAddresses'][0]['Person']['Id'] = person_id - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/email_addresses.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/comanage_api/_identifiers.py b/comanage_api/_identifiers.py index d3e454b..9b15692 100644 --- a/comanage_api/_identifiers.py +++ b/comanage_api/_identifiers.py @@ -5,7 +5,8 @@ Methods ------- -identifiers_add(identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict +identifiers_add() -> dict + ### NOT IMPLEMENTED ### Add a new Identifier. identifiers_assign() -> bool ### NOT IMPLEMENTED ### @@ -27,87 +28,18 @@ import json -def identifiers_add(self, identity_type: str, identifier: str, login_flag: bool, person_type: str, person_id: int) -> dict: +def identifiers_add(self) -> dict: """ + ### NOT IMPLEMENTED ### Add a new Identifier. - identity_type: Identifier keyword (i.e. eppn, sorid) - identifier: The actual identifier for the indentity_type - login_flag: Whether this identifier is used for logging in - person_type: Type of person (i.e. "CO"|"Dept"|"Group"|"Org"|"Organization") - person_id: COmanage ID for the person_type - :request - { - "RequestType":"Identifiers", - "Version":"1.0", - "Identifiers": - [ - { - "Version":"1.0", - "Type":"<Type>", - "Identifier":"<Identifier>", - "Login":true|false, - "Person": - { - "Type":("CO"|"Dept"|"Group"|"Org"|"Organization"), - "Id":"<ID>" - }, - "CoProvisioningTargetId":"<CoProvisioningTargetId>", - "Status":"Active"|"Deleted" - } - ] - }: - - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse Identifier added - 400 Bad Request Identifier Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more - provided fields - 401 Unauthorized Authentication required - 403 Identifier In Use An entry already exists with the - specified identifier - 403 No Person Specified A CO Department, a CO Person, or an - Org Identity must be specified to - attach - the Identifier to - 403 Person Does Not Exist The specified CO Department, - CO Person, or Org Identity - does not exist - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"Identifiers", - "Version":"1.0", - "Identifiers": - [ - { - "Version":"1.0", - "Type":"<Type>", - "Identifier":"<Identifier>", - "Login":"<Login>", - "Person": - { - "Type":"<Type>", - "Id":"<ID>" - }, - "Status":"Active" - } - ] - } - - post_body['Identifiers'][0]['Type'] = identity_type - post_body['Identifiers'][0]['Identifier'] = identifier - post_body['Identifiers'][0]['Login'] = login_flag - post_body['Identifiers'][0]['Person']['Type'] = person_type - post_body['Identifiers'][0]['Person']['Id'] = person_id - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/identifiers.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/comanage_api/_names.py b/comanage_api/_names.py index 3919199..7c40d97 100644 --- a/comanage_api/_names.py +++ b/comanage_api/_names.py @@ -5,7 +5,8 @@ Methods ------- -names_add(person_type: str, person_id: int, given: str, family: str) -> dict +names_add() -> dict + ### NOT IMPLEMENTED ### Add a new Name. names_delete() -> bool ### NOT IMPLEMENTED ### @@ -24,88 +25,18 @@ import json -def names_add(self, person_type: str, person_id: int, given: str, family: str) -> dict: +def names_add(self) -> dict: """ - Add a new Name. - - person_type: Type of person (i.e. "CO"|"Org") - person_id: COmanage ID for the person_type - given: First name for the person - family: Last name for the person - :request - { - "RequestType":"Names", - "Version":"1.0", - "Names": - [ - { - "Version":"1.0", - "Honorific":"<Honorific>", - "Given":"<Given>", - "Middle":"<Middle>", - "Family":"<Family>", - "Suffix":"<Suffix>", - "Type":"<Type>", - "Language":"<Language>", - "PrimaryName":true|false, - "Person": - { - "Type":("CO"|"Org"), - "Id":"<ID>" - } - } - ] - }: + ### NOT IMPLEMENTED ### + Add a new Name. - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse Name added - 400 Bad Request Name Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more - provided fields - 401 Unauthorized Authentication required - 403 No Person Specified Either a CO Person or an Org Identity - must be specified to attach the - Name to - 403 Person Does Not Exist The specified CO Person or - Org Identity does not exist - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"Names", - "Version":"1.0", - "Names": - [ - { - "Version":"1.0", - "Honorific":"", - "Given":"<Given>", - "Middle":"", - "Family":"<Family>", - "Suffix":"", - "Type":"official", - "Language":"", - "PrimaryName": True, - "Person": - { - "Type":"<Type>", - "Id":"<ID>" - } - } - ] - } - - post_body['Names'][0]['Given'] = given - post_body['Names'][0]['Family'] = family - post_body['Names'][0]['Person']['Type'] = person_type - post_body['Names'][0]['Person']['Id'] = person_id - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/names.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) diff --git a/comanage_api/_orgidentities.py b/comanage_api/_orgidentities.py index 2a9714e..746efa5 100644 --- a/comanage_api/_orgidentities.py +++ b/comanage_api/_orgidentities.py @@ -6,8 +6,10 @@ Methods ------- org_identities_add() -> dict + ### NOT IMPLEMENTED ### Add a new Organizational Identity. A person must have an OrgIdentity before they can be added to a CO. -org_identities_delete(org_identity_id: int) -> bool +org_identities_delete() -> bool + ### NOT IMPLEMENTED ### Remove an Organizational Identity. The person must be removed from any COs (CoPerson) before the OrgIdentity record can be removed. This method will also delete related data, such as Addresses, EmailAddresses, and TelephoneNumbers. @@ -18,7 +20,7 @@ Retrieve all existing Organizational Identities. org_identities_view_per_co(person_type: str, person_id: int) -> dict Retrieve all existing Organizational Identities for the specified CO. -org_identities_view_per_identifier(identifier: str) -> dict +org_identities_view_per_identifier(identifier_id: int) -> dict Retrieve all existing Organizational Identities attached to the specified identifier. Note the specified identifier must be attached to an Org Identity, not a CO Person. org_identities_view_one(org_identity_id: int) -> dict @@ -30,59 +32,16 @@ def org_identities_add(self) -> dict: """ + ### NOT IMPLEMENTED ### Add a new Organizational Identity. A person must have an OrgIdentity before they can be added to a CO. - :request - { - "RequestType":"OrgIdentities", - "Version":"1.0", - "OrgIdentities": - [ - { - "Version":"1.0", - "Affiliation":"<Affiliation>", - "Title":"<Title>", - "O":"<O>", - "Ou":"<Ou>", - "CoId":"<CoId>", - "ValidFrom":"<ValidFrom>", - "ValidThrough":"<ValidThrough>", - "DateOfBirth":"<DateOfBirth>" - } - ] - }: - - Response Format - HTTP Status Response Body Description - 201 Added NewObjectResponse OrgIdentity added - 400 Bad Request OrgIdentity Request not - provided in POST body - 400 Invalid Fields ErrorResponse An error in one or more - provided fields - 401 Unauthorized Authentication required - 403 CO Does Not Exist The specified CO does not exist - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - post_body = { - "RequestType":"OrgIdentities", - "Version":"1.0", - "OrgIdentities": - [ - { - "Version":"1.0", - "Affiliation":"member", - "CoId":"<CoId>" - } - ] - } - - post_body['OrgIdentities'][0]['CoId'] = self._CO_API_ORG_ID - - post_body = json.dumps(post_body) - url = self._CO_API_URL + '/org_identities.json' - resp = self._s.post( - url=url, - data=post_body + url = self._MOCK_501_URL + resp = self._mock_session.get( + url=url ) if resp.status_code == 201: return json.loads(resp.text) @@ -90,45 +49,19 @@ def org_identities_add(self) -> dict: resp.raise_for_status() -def org_identities_delete(self, org_identity_id: int) -> bool: +def org_identities_delete(self) -> bool: """ - Remove an Organizational Identity. The person must be removed from any COs (CoPerson) - before the OrgIdentity record can be removed. This method will also delete related data, - such as Addresses, EmailAddresses, and TelephoneNumbers. - - :request - { - "RequestType":"OrgIdentities", - "Version":"1.0", - "OrgIdentities": - [ - { - "Version":"1.0", - "Affiliation":"<Affiliation>", - "Title":"<Title>", - "O":"<O>", - "Ou":"<Ou>", - "CoId":"<CoId>", - "ValidFrom":"<ValidFrom>", - "ValidThrough":"<ValidThrough>", - "DateOfBirth":"<DateOfBirth>" - } - ] - } + ### NOT IMPLEMENTED ### + Remove an Organizational Identity. + The person must be removed from any COs (CoPerson) before the OrgIdentity record can be removed. + This method will also delete related data, such as Addresses, EmailAddresses, and TelephoneNumbers. - Response Format - HTTP Status Response Body Description - 200 Deleted OrgIdentity deleted - 400 Invalid Fields id not provided - 401 Unauthorized Authentication required - 403 CoPerson Exists ErrorResponse id must not be attached to any - CoPerson. (Delete the CoPerson first.) - 404 OrgIdentity Unknown id not found - 500 Other Error Unknown error + :param self: + :return + 501 Server Error: Not Implemented for url: mock://not_implemented_501.local: """ - - url = self._CO_API_URL + '/org_identities/' + str(org_identity_id) + '.json' - resp = self._s.delete( + url = self._MOCK_501_URL + resp = self._mock_session.get( url=url ) if resp.status_code == 200: @@ -249,7 +182,7 @@ def org_identities_view_per_co(self) -> dict: resp.raise_for_status() -def org_identities_view_per_identifier(self, identifier: str) -> dict: +def org_identities_view_per_identifier(self, identifier_id: int) -> dict: """ Retrieve all existing Organizational Identities attached to the specified identifier. Note the specified identifier must be attached to an Org Identity, not a CO Person. @@ -288,7 +221,7 @@ def org_identities_view_per_identifier(self, identifier: str) -> dict: 500 Other Error Unknown error """ url = self._CO_API_URL + '/org_identities.json' - params = {'coid': self._CO_API_ORG_ID, 'search.identifier': identifier} + params = {'coid': self._CO_API_ORG_ID, 'search.identifier': int(identifier_id)} resp = self._s.get( url=url, params=params diff --git a/examples/README.md b/examples/README.md index 8eb7126..e8f9aec 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,7 +7,6 @@ Examples demonstrating basic usage for each wrapped endpoint. Some of the values ## Table of Contents - [Configuration](#config) `__init__.py` used by all examples -- [CoGroup API](#cogroup) example output - [CoGroupMember API](#cogroupmember) example output - [CoOrgIdentityLink API](#coorgidentitylink) example output - [CoPerson API](#coperson) example output @@ -63,46 +62,6 @@ api = ComanageApi( ) ``` -## <a name="cogroup"></a>CoGroup API - -Example: `cogroup_example.py` - -```console -$ python examples/cogroup_example.py -### cogroup_add -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_delete -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_edit -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_reconcile_all -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_reconcile_one -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_view_all -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_view_per_co -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_view_per_coperson -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_view_per_identifier -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local -### cogroup_view_one -[ERROR] Exception caught ---> HTTPError - 501 Server Error: Not Implemented for url: mock://not_implemented_501.local - -``` - - ## <a name="cogroupmember"></a>CoGroupMember API Example: `cogroupmember_example.py` @@ -130,7 +89,6 @@ $ python examples/cogroupmember_example.py ``` - ## <a name="coorgidentitylink"></a>CoOrgIdentityLink API Example: `co_org_identity_links_example.py` diff --git a/examples/cogroup_example.py b/examples/cogroup_example.py deleted file mode 100644 index 212c78a..0000000 --- a/examples/cogroup_example.py +++ /dev/null @@ -1,103 +0,0 @@ -# examples/cogroup_example.py -# CoGroup API examples - -import os -import sys - -sys.path.append( - os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) -) -from examples import * - -# cogroup_add, cogroup_delete, cogroup_edit, cogroup_reconcile_all, cogroup_reconcile_one, cogroup_view_all, \ -# cogroup_view_per_co, cogroup_view_per_coperson, cogroup_view_per_identifier, cogroup_view_one - -# cogroup_add() -> dict -print('### cogroup_add') -try: - new_cogroup = api.cogroup_add() - print(json.dumps(new_cogroup, indent=4)) -except HTTPError as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_delete() -> bool -print('### cogroup_delete') -try: - delete_cogroup = api.cogroup_delete() - print(json.dumps(delete_cogroup, indent=4)) -except HTTPError as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_edit() -> bool -print('### cogroup_edit') -try: - edit_cogroup = api.cogroup_edit() - print(json.dumps(edit_cogroup, indent=4)) -except HTTPError as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_reconcile_all() -> bool -print('### cogroup_reconcile_all') -try: - reconcile_all_cogroup = api.cogroup_reconcile_all() - print(json.dumps(reconcile_all_cogroup, indent=4)) -except HTTPError as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_reconcile_one() -> bool -print('### cogroup_reconcile_one') -try: - reconcile_one_cogroup = api.cogroup_reconcile_one() - print(json.dumps(reconcile_one_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_view_all() -> dict -print('### cogroup_view_all') -try: - all_cogroup = api.cogroup_view_all() - print(json.dumps(all_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_view_per_co() -> dict -print('### cogroup_view_per_co') -try: - per_co_cogroup = api.cogroup_view_per_co() - print(json.dumps(per_co_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_view_per_coperson() -> dict -print('### cogroup_view_per_coperson') -try: - per_coperson_cogroup = api.cogroup_view_per_coperson() - print(json.dumps(per_coperson_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_view_per_identifier() -> dict -print('### cogroup_view_per_identifier') -try: - per_identfier_cogroup = api.cogroup_view_per_identifier() - print(json.dumps(per_identfier_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) - -# cogroup_view_one() -> dict -print('### cogroup_view_one') -try: - one_cogroup = api.cogroup_view_one() - print(json.dumps(one_cogroup, indent=4)) -except (TypeError, HTTPError) as err: - print('[ERROR] Exception caught') - print('--> ', type(err).__name__, '-', err) diff --git a/examples/coorg_identity_links_example.py b/examples/coorg_identity_links_example.py index 04425ad..52ff2bb 100644 --- a/examples/coorg_identity_links_example.py +++ b/examples/coorg_identity_links_example.py @@ -12,18 +12,14 @@ # must be set ahead of time and be valid within the CO IDENTITY_TYPE = 'orgidentityid' IDENTITY_ID = 190 -CO_PERSON_ID = 163 # coorg_identity_links_add, coorg_identity_links_delete, coorg_identity_links_edit, \ # coorg_identity_links_view_all, coorg_identity_links_view_by_identity, coorg_identity_links_view_one -# coorg_identity_links_add(coperson_id: int, org_identity_id: int) -> dict +# coorg_identity_links_add() -> dict print('### coorg_identity_links_add') try: - new_coorg_identity_link = api.coorg_identity_links_add( - coperson_id=CO_PERSON_ID, - org_identity_id=IDENTITY_ID - ) + new_coorg_identity_link = api.coorg_identity_links_add() print(json.dumps(new_coorg_identity_link, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') diff --git a/examples/copeople_example.py b/examples/copeople_example.py index f786910..b0edcc7 100644 --- a/examples/copeople_example.py +++ b/examples/copeople_example.py @@ -21,11 +21,8 @@ # copeople_delete() -> bool print('### copeople_delete') try: - per_co_copeople = api.copeople_view_per_co() - if per_co_copeople['CoPeople']: - coperson_id = int(per_co_copeople['CoPeople'][0]['Id']) - delete_copeople = api.copeople_delete(coperson_id=coperson_id) - print(delete_copeople) + delete_copeople = api.copeople_delete() + print(json.dumps(delete_copeople, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) diff --git a/examples/email_addresses_example.py b/examples/email_addresses_example.py index 4a96537..c200805 100644 --- a/examples/email_addresses_example.py +++ b/examples/email_addresses_example.py @@ -12,14 +12,10 @@ # must be set ahead of time and be valid within the CO CO_PERSON_ID = 163 -# email_addresses_add(email_address: str, person_type: str, person_id: int) -> dict +# email_addresses_add() -> dict print('### email_addresses_add') try: - new_email_address = api.email_addresses_add( - email_address='test@domain.com', - person_type='copersonid', - person_id=CO_PERSON_ID - ) + new_email_address = api.email_addresses_add() print(json.dumps(new_email_address, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') diff --git a/examples/identifiers_example.py b/examples/identifiers_example.py index 236d0cb..978521e 100644 --- a/examples/identifiers_example.py +++ b/examples/identifiers_example.py @@ -15,13 +15,7 @@ # identifiers_add() -> dict print('### identifiers_add') try: - new_identifier = api.identifiers_add( - identity_type='eppn', - identifier='test@domain.com', - login_flag=False, - person_type='CO', - person_id=CO_PERSON_ID - ) + new_identifier = api.identifiers_add() print(json.dumps(new_identifier, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') diff --git a/examples/names_example.py b/examples/names_example.py index 96a28c8..d63cabf 100644 --- a/examples/names_example.py +++ b/examples/names_example.py @@ -12,15 +12,10 @@ # must be set ahead of time and be valid within the CO CO_PERSON_ID = 163 -# names_add(person_type: str, person_id: int, given: str, family: str) -> dict +# names_add() -> dict print('### names_add') try: - new_name = api.names_add( - person_type='copersonid', - person_id=CO_PERSON_ID, - given="TestGiven", - family="TestFamily" - )) + new_name = api.names_add() print(json.dumps(new_name, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') diff --git a/examples/org_identities_example.py b/examples/org_identities_example.py index 5f4f222..110c36d 100644 --- a/examples/org_identities_example.py +++ b/examples/org_identities_example.py @@ -21,12 +21,10 @@ print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) -# org_identities_delete(org_identity_id: int) -> bool +# org_identities_delete() -> bool print('### org_identities_delete') try: - per_co_org_identities = api.org_identities_view_per_co() - org_identity_id = int(per_co_org_identities['OrgIdentities'][0]['Id']) - delete_org_identity = api.org_identities_delete(org_identity_id) + delete_org_identity = api.org_identities_delete() print(json.dumps(delete_org_identity, indent=4)) except HTTPError as err: print('[ERROR] Exception caught') @@ -59,11 +57,11 @@ print('[ERROR] Exception caught') print('--> ', type(err).__name__, '-', err) -# org_identities_view_per_identitifer(identifier: str) -> dict: +# org_identities_view_per_identitifer(identifier_id: int) -> dict: print('### org_identities_view_per_identifier') try: per_identifier_org_identities = api.org_identities_view_per_identifier( - identifier=str(ORG_IDENDIFIER_ID) + identifier_id=ORG_IDENDIFIER_ID ) print(json.dumps(per_identifier_org_identities, indent=4)) except (TypeError, HTTPError) as err: From f6757d97a1768fc160f5af1d75be4725a7461113 Mon Sep 17 00:00:00 2001 From: Brennan Jones <brennan.jones@ufl.edu> Date: Mon, 3 Oct 2022 16:05:11 -0400 Subject: [PATCH 23/23] fixing up return statements in cogroupmember.py --- comanage_api/_cogroupmember.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comanage_api/_cogroupmember.py b/comanage_api/_cogroupmember.py index afd2c49..0abdb78 100644 --- a/comanage_api/_cogroupmember.py +++ b/comanage_api/_cogroupmember.py @@ -153,7 +153,7 @@ def cogroupmember_view_all(self) -> dict: url=url ) if resp.status_code == 200: - return True + return json.loads(resp.text) else: resp.raise_for_status() @@ -198,7 +198,7 @@ def cogroupmember_view_per_group(self, group_id: int) -> dict: params=params ) if resp.status_code == 200: - return True + return json.loads(resp.text) else: resp.raise_for_status() @@ -217,6 +217,6 @@ def cogroupmember_view_one(self) -> dict: url=url ) if resp.status_code == 200: - return True + return json.loads(resp.text) else: resp.raise_for_status()