Skip to content

Commit f1f3d91

Browse files
authored
feat(IAM Identity): add filter parameter for search api (#288)
Signed-off-by: Somanath Chavan <somanath.chavan@ibm.com>
1 parent 30ec152 commit f1f3d91

File tree

4 files changed

+124
-16
lines changed

4 files changed

+124
-16
lines changed

examples/test_iam_identity_v1_examples.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,11 @@ def test_update_preference_on_scope_account(self):
17941794
# begin-update_preference_on_scope_account
17951795

17961796
preference = iam_identity_service.update_preference_on_scope_account(
1797-
iam_id=iam_id_for_preferences, service=service, preference_id=preference_id1, value_string=value_string
1797+
iam_id=iam_id_for_preferences,
1798+
account_id=account_id,
1799+
service=service,
1800+
preference_id=preference_id1,
1801+
value_string=value_string,
17981802
).get_result()
17991803
print(json.dumps(preference, indent=2))
18001804

@@ -1813,7 +1817,7 @@ def test_get_preferences_on_scope_account(self):
18131817
# begin-get_preferences_on_scope_account
18141818

18151819
preference = iam_identity_service.get_preferences_on_scope_account(
1816-
iam_id=iam_id_for_preferences, service=service, preference_id=preference_id1
1820+
iam_id=iam_id_for_preferences, account_id=account_id, service=service, preference_id=preference_id1
18171821
).get_result()
18181822
print(json.dumps(preference, indent=2))
18191823

@@ -1832,7 +1836,7 @@ def test_get_all_preferences_on_scope_account(self):
18321836
# begin-get_all_preferences_on_scope_account
18331837

18341838
preference = iam_identity_service.get_all_preferences_on_scope_account(
1835-
iam_id=iam_id_for_preferences
1839+
iam_id=iam_id_for_preferences, account_id=account_id
18361840
).get_result()
18371841
print(json.dumps(preference, indent=2))
18381842

@@ -1850,7 +1854,7 @@ def test_delete_preferences_on_scope_account(self):
18501854
# begin-delete_preferences_on_scope_account
18511855

18521856
response = iam_identity_service.delete_preferences_on_scope_account(
1853-
iam_id=iam_id_for_preferences, service=service, preference_id=preference_id1
1857+
iam_id=iam_id_for_preferences, account_id=account_id, service=service, preference_id=preference_id1
18541858
)
18551859

18561860
# end-delete_preferences_on_scope_account

ibm_platform_services/iam_identity_v1.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# IBM OpenAPI SDK Code Generator Version: 3.98.0-8be2046a-20241205-162752
17+
# IBM OpenAPI SDK Code Generator Version: 3.103.0-e8b84313-20250402-201816
1818

1919
"""
2020
The IAM Identity Service API allows for the management of Account Settings and Identities
@@ -89,6 +89,7 @@ def list_api_keys(
8989
sort: Optional[str] = None,
9090
order: Optional[str] = None,
9191
include_history: Optional[bool] = None,
92+
filter: Optional[str] = None,
9293
**kwargs,
9394
) -> DetailedResponse:
9495
"""
@@ -120,6 +121,9 @@ def list_api_keys(
120121
desc. Default: asc.
121122
:param bool include_history: (optional) Defines if the entity history is
122123
included in the response.
124+
:param str filter: (optional) An optional filter query parameter used to
125+
refine the results of the search operation. For more information see
126+
[Filtering list results](#filter-list-results) section.
123127
:param dict headers: A `dict` containing the request headers
124128
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
125129
:rtype: DetailedResponse with `dict` result representing a `ApiKeyList` object
@@ -143,6 +147,7 @@ def list_api_keys(
143147
'sort': sort,
144148
'order': order,
145149
'include_history': include_history,
150+
'filter': filter,
146151
}
147152

148153
if 'headers' in kwargs:
@@ -691,6 +696,7 @@ def list_service_ids(
691696
sort: Optional[str] = None,
692697
order: Optional[str] = None,
693698
include_history: Optional[bool] = None,
699+
filter: Optional[str] = None,
694700
**kwargs,
695701
) -> DetailedResponse:
696702
"""
@@ -715,6 +721,9 @@ def list_service_ids(
715721
desc. Default: asc.
716722
:param bool include_history: (optional) Defines if the entity history is
717723
included in the response.
724+
:param str filter: (optional) An optional filter query parameter used to
725+
refine the results of the search operation. For more information see
726+
[Filtering list results](#filter-list-results) section.
718727
:param dict headers: A `dict` containing the request headers
719728
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
720729
:rtype: DetailedResponse with `dict` result representing a `ServiceIdList` object
@@ -736,6 +745,7 @@ def list_service_ids(
736745
'sort': sort,
737746
'order': order,
738747
'include_history': include_history,
748+
'filter': filter,
739749
}
740750

741751
if 'headers' in kwargs:
@@ -1187,6 +1197,7 @@ def list_profiles(
11871197
order: Optional[str] = None,
11881198
include_history: Optional[bool] = None,
11891199
pagetoken: Optional[str] = None,
1200+
filter: Optional[str] = None,
11901201
**kwargs,
11911202
) -> DetailedResponse:
11921203
"""
@@ -1208,6 +1219,9 @@ def list_profiles(
12081219
included in the response.
12091220
:param str pagetoken: (optional) Optional Prev or Next page token returned
12101221
from a previous query execution. Default is start with first page.
1222+
:param str filter: (optional) An optional filter query parameter used to
1223+
refine the results of the search operation. For more information see
1224+
[Filtering list results](#filter-list-results) section.
12111225
:param dict headers: A `dict` containing the request headers
12121226
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
12131227
:rtype: DetailedResponse with `dict` result representing a `TrustedProfilesList` object
@@ -1231,6 +1245,7 @@ def list_profiles(
12311245
'order': order,
12321246
'include_history': include_history,
12331247
'pagetoken': pagetoken,
1248+
'filter': filter,
12341249
}
12351250

12361251
if 'headers' in kwargs:
@@ -2090,7 +2105,10 @@ def set_profile_identity(
20902105
"""
20912106
Add a specific identity that can assume the trusted profile.
20922107

2093-
Add a specific identity that can assume the trusted profile.
2108+
Add a specific identity that can assume the trusted profile. This API will update
2109+
the trusted profile itself, thus calling it repeatedly for the same profile can
2110+
lead to conflicts responded with HTTP code 409. Make sure to call this API only
2111+
once in a few seconds for the same trusted profile.
20942112

20952113
:param str profile_id: ID of the trusted profile.
20962114
:param str identity_type: Type of the identity.
@@ -2219,7 +2237,7 @@ def delete_profile_identity(
22192237
**kwargs,
22202238
) -> DetailedResponse:
22212239
"""
2222-
Delete the identity that can assume the trusted profile.
2240+
Delete the identity that can assume the trusted profile. This API will update the trusted profile itself, thus calling it repeatedly for the same profile can lead to conflicts responded with HTTP code 409. Make sure to call this API only once in a few seconds for the same trusted profile.
22232241

22242242
Delete the identity that can assume the trusted profile.
22252243

@@ -3825,7 +3843,7 @@ def delete_preferences_on_scope_account(
38253843
:param str preference_id: Identifier of preference to be deleted.
38263844
:param dict headers: A `dict` containing the request headers
38273845
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
3828-
:rtype: DetailedResponse
3846+
:rtype: DetailedResponse with `dict` result representing a `ExceptionResponse` object
38293847
"""
38303848

38313849
if not account_id:
@@ -3847,6 +3865,7 @@ def delete_preferences_on_scope_account(
38473865
if 'headers' in kwargs:
38483866
headers.update(kwargs.get('headers'))
38493867
del kwargs['headers']
3868+
headers['Accept'] = 'application/json'
38503869

38513870
path_param_keys = ['account_id', 'iam_id', 'service', 'preference_id']
38523871
path_param_values = self.encode_path_vars(account_id, iam_id, service, preference_id)

test/integration/test_iam_identity_v1.py

+84-8
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,35 @@ def test_list_api_keys(self):
428428
# make sure we retrieved the two apikeys that we created previously.
429429
assert len(apikeys) == 2
430430

431+
@needscredentials
432+
def test_list_api_keys_with_filter(self):
433+
apikeys = []
434+
435+
# Retrieve one apikey at a time to test the pagination.
436+
pagetoken = None
437+
pagetoken_present = True
438+
filter = "name co \"Python\""
439+
while pagetoken_present:
440+
list_api_keys_response = self.iam_identity_service.list_api_keys(
441+
account_id=self.account_id, iam_id=self.iam_id, pagesize=1, pagetoken=pagetoken, filter=filter
442+
)
443+
assert list_api_keys_response.get_status_code() == 200
444+
api_key_list = list_api_keys_response.get_result()
445+
assert api_key_list is not None
446+
print('\nlist_api_keys() response: ', json.dumps(api_key_list, indent=2))
447+
448+
if len(api_key_list['apikeys']) > 0:
449+
for apikey in api_key_list['apikeys']:
450+
if apikey['name'] == self.apikey_name:
451+
apikeys.append(apikey)
452+
453+
# fetch pagetoken value
454+
pagetoken = self.get_page_token(api_key_list.get('next'))
455+
pagetoken_present = pagetoken is not None
456+
457+
# make sure we retrieved the two apikeys that we created previously.
458+
assert len(apikeys) == 2
459+
431460
@needscredentials
432461
def test_update_api_key(self):
433462
assert apikey_id1 is not None
@@ -570,6 +599,20 @@ def test_list_service_ids(self):
570599
assert service_id_list is not None
571600
assert len(service_id_list['serviceids']) == 1
572601

602+
@needscredentials
603+
def test_list_service_ids_with_filter(self):
604+
filter = "name co \"Python\""
605+
list_service_ids_response = self.iam_identity_service.list_service_ids(
606+
account_id=self.account_id, name=self.serviceid_name, pagesize=100, filter=filter
607+
)
608+
609+
assert list_service_ids_response.get_status_code() == 200
610+
service_id_list = list_service_ids_response.get_result()
611+
print('\nlist_service_ids() response: ', json.dumps(service_id_list, indent=2))
612+
613+
assert service_id_list is not None
614+
assert len(service_id_list['serviceids']) == 1
615+
573616
@needscredentials
574617
def test_update_service_id(self):
575618
assert serviceid_id1 is not None
@@ -704,6 +747,32 @@ def test_list_profiles(self):
704747

705748
assert len(profiles) == 2
706749

750+
@needscredentials
751+
def test_list_profiles_with_filter(self):
752+
profiles = []
753+
754+
pagetoken = None
755+
pagetoken_present = True
756+
filter = "name co \"Python\""
757+
while pagetoken_present:
758+
list_profiles_response = self.iam_identity_service.list_profiles(
759+
account_id=self.account_id, pagesize=1, pagetoken=pagetoken, include_history=False, filter=filter
760+
)
761+
assert list_profiles_response.get_status_code() == 200
762+
profile_list = list_profiles_response.get_result()
763+
assert profile_list is not None
764+
print('\nlist_profiles() response: ', json.dumps(profile_list, indent=2))
765+
766+
if len(profile_list['profiles']) > 0:
767+
for profile in profile_list['profiles']:
768+
if profile['name'] == self.profile_name1 or profile['name'] == self.profile_name2:
769+
profiles.append(profile)
770+
771+
pagetoken = self.get_page_token(profile_list.get('next'))
772+
pagetoken_present = pagetoken is not None
773+
774+
assert len(profiles) == 2
775+
707776
@needscredentials
708777
def test_update_profile(self):
709778
assert profile_id1 is not None
@@ -1844,11 +1913,12 @@ def test_update_api_key(self):
18441913

18451914
@needscredentials
18461915
def test_update_preference_on_scope_account(self):
1847-
assert iam_id_for_preferences is not None
1916+
assert self.iam_id_for_preferences is not None
18481917
assert self.preference_id1 is not None
18491918

18501919
preference = self.iam_identity_service.update_preference_on_scope_account(
1851-
iam_id=iam_id_for_preferences,
1920+
iam_id=self.iam_id_for_preferences,
1921+
account_id=self.account_id,
18521922
service=self.service,
18531923
preference_id=self.preference_id1,
18541924
value_string=self.value_string,
@@ -1858,29 +1928,35 @@ def test_update_preference_on_scope_account(self):
18581928

18591929
@needscredentials
18601930
def test_get_preferences_on_scope_account(self):
1861-
assert iam_id_for_preferences is not None
1931+
assert self.iam_id_for_preferences is not None
18621932
assert self.preference_id1 is not None
18631933
preference = self.iam_identity_service.get_preferences_on_scope_account(
1864-
iam_id=iam_id_for_preferences, service=self.service, preference_id=self.preference_id1
1934+
iam_id=self.iam_id_for_preferences,
1935+
account_id=self.account_id,
1936+
service=self.service,
1937+
preference_id=self.preference_id1,
18651938
).get_result()
18661939
print('\nget_preference_on_scope_account() response: ', json.dumps(preference, indent=2))
18671940
preference is not None
18681941

18691942
@needscredentials
18701943
def test_get_all_preferences_on_scope_account(self):
1871-
assert iam_id_for_preferences is not None
1944+
assert self.iam_id_for_preferences is not None
18721945
assert self.preference_id1 is not None
18731946
preference = self.iam_identity_service.get_all_preferences_on_scope_account(
1874-
iam_id=iam_id_for_preferences
1947+
account_id=self.account_id, iam_id=self.iam_id_for_preferences
18751948
).get_result()
18761949
print('\nget_all_preference_on_scope_account() response: ', json.dumps(preference, indent=2))
18771950
preference is not None
18781951

18791952
@needscredentials
18801953
def test_delete_preferences_on_scope_account(self):
1881-
assert iam_id_for_preferences is not None
1954+
assert self.iam_id_for_preferences is not None
18821955
assert self.preference_id1 is not None
18831956
preference = self.iam_identity_service.delete_preferences_on_scope_account(
1884-
iam_id=iam_id_for_preferences, service=self.service, preference_id=self.preference_id1
1957+
iam_id=self.iam_id_for_preferences,
1958+
account_id=self.account_id,
1959+
service=self.service,
1960+
preference_id=self.preference_id1,
18851961
)
18861962
assert preference.get_status_code() == 204

test/unit/test_iam_identity_v1.py

+9
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def test_list_api_keys_all_params(self):
120120
sort = 'testString'
121121
order = 'asc'
122122
include_history = False
123+
filter = 'testString'
123124

124125
# Invoke method
125126
response = _service.list_api_keys(
@@ -132,6 +133,7 @@ def test_list_api_keys_all_params(self):
132133
sort=sort,
133134
order=order,
134135
include_history=include_history,
136+
filter=filter,
135137
headers={},
136138
)
137139

@@ -150,6 +152,7 @@ def test_list_api_keys_all_params(self):
150152
assert 'sort={}'.format(sort) in query_string
151153
assert 'order={}'.format(order) in query_string
152154
assert 'include_history={}'.format('true' if include_history else 'false') in query_string
155+
assert 'filter={}'.format(filter) in query_string
153156

154157
def test_list_api_keys_all_params_with_retries(self):
155158
# Enable retries and run test_list_api_keys_all_params.
@@ -1128,6 +1131,7 @@ def test_list_service_ids_all_params(self):
11281131
sort = 'testString'
11291132
order = 'asc'
11301133
include_history = False
1134+
filter = 'testString'
11311135

11321136
# Invoke method
11331137
response = _service.list_service_ids(
@@ -1138,6 +1142,7 @@ def test_list_service_ids_all_params(self):
11381142
sort=sort,
11391143
order=order,
11401144
include_history=include_history,
1145+
filter=filter,
11411146
headers={},
11421147
)
11431148

@@ -1154,6 +1159,7 @@ def test_list_service_ids_all_params(self):
11541159
assert 'sort={}'.format(sort) in query_string
11551160
assert 'order={}'.format(order) in query_string
11561161
assert 'include_history={}'.format('true' if include_history else 'false') in query_string
1162+
assert 'filter={}'.format(filter) in query_string
11571163

11581164
def test_list_service_ids_all_params_with_retries(self):
11591165
# Enable retries and run test_list_service_ids_all_params.
@@ -1987,6 +1993,7 @@ def test_list_profiles_all_params(self):
19871993
order = 'asc'
19881994
include_history = False
19891995
pagetoken = 'testString'
1996+
filter = 'testString'
19901997

19911998
# Invoke method
19921999
response = _service.list_profiles(
@@ -1997,6 +2004,7 @@ def test_list_profiles_all_params(self):
19972004
order=order,
19982005
include_history=include_history,
19992006
pagetoken=pagetoken,
2007+
filter=filter,
20002008
headers={},
20012009
)
20022010

@@ -2013,6 +2021,7 @@ def test_list_profiles_all_params(self):
20132021
assert 'order={}'.format(order) in query_string
20142022
assert 'include_history={}'.format('true' if include_history else 'false') in query_string
20152023
assert 'pagetoken={}'.format(pagetoken) in query_string
2024+
assert 'filter={}'.format(filter) in query_string
20162025

20172026
def test_list_profiles_all_params_with_retries(self):
20182027
# Enable retries and run test_list_profiles_all_params.

0 commit comments

Comments
 (0)