iam_client.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module provides a client for IAM.
  14. """
  15. import copy
  16. import json
  17. import logging
  18. from future.utils import iteritems
  19. from baidubce.auth import bce_v1_signer
  20. from baidubce.bce_base_client import BceBaseClient
  21. from baidubce.http import bce_http_client
  22. from baidubce.http import handler
  23. from baidubce.http import http_content_types
  24. from baidubce.http import http_headers
  25. from baidubce.http import http_methods
  26. from baidubce.services import iam
  27. from baidubce.utils import required
  28. _logger = logging.getLogger(__name__)
  29. class IamClient(BceBaseClient):
  30. """
  31. sdk client
  32. """
  33. def __init__(self, config=None):
  34. BceBaseClient.__init__(self, config)
  35. def _send_iam_request(self,
  36. http_method,
  37. path,
  38. body=None,
  39. headers=None,
  40. params=None,
  41. config=None,
  42. body_parser=None):
  43. config = self._merge_config(config)
  44. path = iam.URL_PREFIX + path
  45. if body_parser is None:
  46. body_parser = handler.parse_json
  47. return bce_http_client.send_request(
  48. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  49. http_method, path, body, headers, params)
  50. def _merge_config(self, config):
  51. if config is None:
  52. return self.config
  53. else:
  54. new_config = copy.copy(self.config)
  55. new_config.merge_non_none_values(config)
  56. return new_config
  57. # ######################################### #role management# #################################################### #
  58. def get_role(self, role_name):
  59. """
  60. :type role_name: bytes
  61. :return:
  62. **HttpResponse**
  63. """
  64. path = b"/role/" + role_name
  65. return self._send_iam_request(
  66. http_methods.GET,
  67. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  68. path=path
  69. )
  70. def create_role(self, create_role_request):
  71. """
  72. :type create_role_request: dict
  73. :return:
  74. **HttpResponse**
  75. """
  76. if create_role_request is None:
  77. body = None
  78. else:
  79. if not isinstance(create_role_request, dict):
  80. raise TypeError(b'create_role_request should be dict')
  81. else:
  82. body = json.dumps(create_role_request)
  83. path = b"/role"
  84. return self._send_iam_request(
  85. http_methods.POST,
  86. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  87. path=path,
  88. body=body
  89. )
  90. def update_role(self, role_name, update_role_request):
  91. """
  92. :type role_name: bytes
  93. :type update_role_request: dict
  94. :return:
  95. **HttpResponse**
  96. """
  97. if update_role_request is None:
  98. body = None
  99. else:
  100. if not isinstance(update_role_request, dict):
  101. raise TypeError(b'update_role_request should be dict')
  102. else:
  103. body = json.dumps(update_role_request)
  104. path = b"/role/" + role_name
  105. return self._send_iam_request(
  106. http_methods.PUT,
  107. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  108. path=path,
  109. body=body
  110. )
  111. def delete_role(self, role_name):
  112. """
  113. :type role_name: bytes
  114. :return:
  115. **HttpResponse**
  116. """
  117. path = b"/role/" + role_name
  118. return self._send_iam_request(
  119. http_methods.DELETE,
  120. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  121. path=path
  122. )
  123. def list_role(self):
  124. """
  125. :return:
  126. **HttpResponse**
  127. """
  128. path = b"/role"
  129. return self._send_iam_request(
  130. http_methods.GET,
  131. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  132. path=path
  133. )
  134. # ######################################### #policy management# ################################################## #
  135. def create_policy(self, create_policy_request):
  136. """
  137. :type create_policy_request: dict
  138. :return:
  139. **HttpResponse**
  140. """
  141. if create_policy_request is None:
  142. body = None
  143. else:
  144. if not isinstance(create_policy_request, dict):
  145. raise TypeError(b'create_policy_request should be dict')
  146. else:
  147. body = json.dumps(create_policy_request)
  148. path = b"/policy"
  149. return self._send_iam_request(
  150. http_methods.POST,
  151. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  152. path=path,
  153. body=body
  154. )
  155. def get_policy(self, policy_name, policy_type):
  156. """
  157. :type policy_name: bytes
  158. :type policy_type: bytes
  159. :return:
  160. **HttpResponse**
  161. """
  162. path = b"/policy/" + policy_name
  163. params = {b"policyType": policy_type}
  164. return self._send_iam_request(
  165. http_methods.GET,
  166. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  167. path=path,
  168. params=params
  169. )
  170. @required(policy_name=(bytes, str))
  171. def update_policy(self, policy_name, update_policy_request):
  172. """
  173. :type update_policy_request: dict
  174. :return:
  175. **HttpResponse**
  176. """
  177. policy_name_bytes = policy_name
  178. if isinstance(policy_name, str):
  179. policy_name_bytes = policy_name.encode('utf-8')
  180. if update_policy_request is None:
  181. body = None
  182. else:
  183. if not isinstance(update_policy_request, dict):
  184. raise TypeError(b'update_policy_request should be dict')
  185. else:
  186. body = json.dumps(update_policy_request)
  187. path = b"/policy/" + policy_name_bytes
  188. return self._send_iam_request(
  189. http_methods.POST,
  190. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  191. path=path,
  192. body=body
  193. )
  194. def delete_policy(self, policy_name):
  195. """
  196. :type policy_name: bytes
  197. :return:
  198. **HttpResponse**
  199. """
  200. path = b"/policy/" + policy_name
  201. return self._send_iam_request(
  202. http_methods.DELETE,
  203. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  204. path=path
  205. )
  206. def list_policy(self, policy_type=None, name_filter=None):
  207. """
  208. :type policy_type: bytes
  209. :type name_filter: bytes
  210. :param name_filter: bytes
  211. :return:
  212. **HttpResponse**
  213. """
  214. path = b"/policy"
  215. params = {b"policyType": policy_type, b"nameFilter": name_filter}
  216. return self._send_iam_request(
  217. http_methods.GET,
  218. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  219. path=path,
  220. params=params
  221. )
  222. def attach_policy_to_user(self, user_name, policy_name, policy_type=None):
  223. """
  224. :type user_name: bytes
  225. :type policy_name: bytes
  226. :type policy_type: bytes
  227. :param policy_type: None
  228. :return:
  229. **HttpResponse**
  230. """
  231. path = b"/user/" + user_name + b"/policy/" + policy_name
  232. params = {b"policyType": policy_type}
  233. return self._send_iam_request(
  234. http_methods.PUT,
  235. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  236. path=path,
  237. params=params
  238. )
  239. def detach_policy_from_user(self, user_name, policy_name, policy_type=None):
  240. """
  241. :type user_name: bytes
  242. :type policy_name: bytes
  243. :type policy_type: bytes
  244. :param policy_type: None
  245. :return:
  246. **HttpResponse**
  247. """
  248. path = b"/user/" + user_name + b"/policy/" + policy_name
  249. params = {b"policyType": policy_type}
  250. return self._send_iam_request(
  251. http_methods.DELETE,
  252. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  253. path=path,
  254. params=params
  255. )
  256. def list_policies_from_user(self, user_name):
  257. """
  258. :type user_name: bytes
  259. :return:
  260. **HttpResponse**
  261. """
  262. path = b"/user/" + user_name + b"/policy"
  263. return self._send_iam_request(
  264. http_methods.GET,
  265. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  266. path=path
  267. )
  268. def attach_policy_to_group(self, group_name, policy_name, policy_type=None):
  269. """
  270. :type group_name: bytes
  271. :type policy_name: bytes
  272. :type policy_type: bytes
  273. :param policy_type: None
  274. :return:
  275. **HttpResponse**
  276. """
  277. path = b"/group/" + group_name + b"/policy/" + policy_name
  278. params = {"policyType": policy_type}
  279. return self._send_iam_request(
  280. http_methods.PUT,
  281. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  282. path=path,
  283. params=params
  284. )
  285. def detach_policy_from_group(self, group_name, policy_name, policy_type=None):
  286. """
  287. :type group_name: bytes
  288. :type policy_name: bytes
  289. :type policy_type: bytes
  290. :param policy_type: None
  291. :return:
  292. **HttpResponse**
  293. """
  294. path = b"/group/" + group_name + b"/policy/" + policy_name
  295. params = {b"policyType": policy_type}
  296. return self._send_iam_request(
  297. http_methods.DELETE,
  298. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  299. path=path,
  300. params=params
  301. )
  302. def list_policies_from_group(self, group_name):
  303. """
  304. :type group_name: bytes
  305. :return:
  306. **HttpResponse**
  307. """
  308. path = b"/group/" + group_name + b"/policy"
  309. return self._send_iam_request(
  310. http_methods.GET,
  311. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  312. path=path
  313. )
  314. def attach_policy_to_role(self, role_name, policy_name, policy_type=None):
  315. """
  316. :type role_name: bytes
  317. :type policy_name: bytes
  318. :type policy_type: bytes
  319. :param policy_type: None
  320. :return:
  321. **HttpResponse**
  322. """
  323. path = b"/role/" + role_name + b"/policy/" + policy_name
  324. params = {b"policyType": policy_type}
  325. return self._send_iam_request(
  326. http_methods.PUT,
  327. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  328. path=path,
  329. params=params
  330. )
  331. def detach_policy_from_role(self, role_name, policy_name, policy_type=None):
  332. """
  333. :type role_name: bytes
  334. :type policy_name: bytes
  335. :type policy_type: bytes
  336. :param policy_type: None
  337. :return:
  338. **HttpResponse**
  339. """
  340. path = b"/role/" + role_name + b"/policy/" + policy_name
  341. params = {b"policyType": policy_type}
  342. return self._send_iam_request(
  343. http_methods.DELETE,
  344. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  345. path=path,
  346. params=params
  347. )
  348. def list_policies_from_role(self, role_name):
  349. """
  350. :type role_name: bytes
  351. :return:
  352. **HttpResponse**
  353. """
  354. path = b"/role/" + role_name + b"/policy"
  355. return self._send_iam_request(
  356. http_methods.GET,
  357. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  358. path=path
  359. )
  360. @required(policy_id=(bytes, str), grant_type=(bytes, str))
  361. def list_attached_entities_by_grant_type(self, policy_id, grant_type):
  362. """
  363. :type policy_id: bytes :type grant_type:
  364. : grant_type: UserPolicy, GroupPolicy
  365. :return:
  366. **HttpResponse**
  367. """
  368. policy_id_bytes = policy_id
  369. if isinstance(policy_id, str):
  370. policy_id_bytes = policy_id.encode('utf-8')
  371. grant_type_bytes = grant_type
  372. if isinstance(grant_type, str):
  373. grant_type_bytes = grant_type.encode('utf-8')
  374. path = b"/policy/" + policy_id_bytes + b"/grant/" + grant_type_bytes
  375. return self._send_iam_request(
  376. http_methods.GET,
  377. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  378. path=path
  379. )
  380. # ######################################### #user management# #################################################### #
  381. def create_user(self, create_user_request):
  382. """
  383. :type create_user_request: dict
  384. :return:
  385. **HttpResponse**
  386. """
  387. if create_user_request is None:
  388. body = None
  389. else:
  390. if not isinstance(create_user_request, dict):
  391. raise TypeError(b'create_user_request should be dict')
  392. else:
  393. body = json.dumps(create_user_request)
  394. path = b'/user'
  395. return self._send_iam_request(
  396. http_methods.POST,
  397. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  398. path=path,
  399. body=body
  400. )
  401. def get_user(self, user_name):
  402. """
  403. :type user_name: bytes
  404. :return:
  405. **HttpResponse**
  406. """
  407. path = b'/user/' + user_name
  408. return self._send_iam_request(
  409. http_methods.GET,
  410. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  411. path=path
  412. )
  413. def update_user(self, user_name, update_user_request):
  414. """
  415. :type user_name: bytes
  416. :type update_user_request: dict
  417. :return:
  418. **HttpResponse**
  419. """
  420. if update_user_request is None:
  421. body = None
  422. else:
  423. if not isinstance(update_user_request, dict):
  424. raise TypeError(b'update_user_request should be dict')
  425. else:
  426. body = json.dumps(update_user_request)
  427. path = b"/user/" + user_name
  428. return self._send_iam_request(
  429. http_methods.PUT,
  430. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  431. path=path,
  432. body=body
  433. )
  434. def delete_user(self, user_name):
  435. """
  436. :type user_name: bytes
  437. :return:
  438. **HttpResponse**
  439. """
  440. path = b"/user/" + user_name
  441. return self._send_iam_request(
  442. http_methods.DELETE,
  443. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  444. path=path
  445. )
  446. def list_user(self):
  447. """
  448. :return:
  449. **HttpResponse**
  450. """
  451. path = b"/user"
  452. return self._send_iam_request(
  453. http_methods.GET,
  454. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  455. path=path
  456. )
  457. def update_user_login_profile(self, user_name, update_user_login_profile_request):
  458. """
  459. :type user_name: bytes
  460. :type update_user_login_profile_request: dict
  461. :return:
  462. **HttpResponse**
  463. """
  464. if update_user_login_profile_request is None:
  465. body = None
  466. else:
  467. if not isinstance(update_user_login_profile_request, dict):
  468. raise TypeError(b'update_user_login_profile_request should be dict')
  469. else:
  470. body = json.dumps(update_user_login_profile_request)
  471. path = b"/user/" + user_name + b"/loginProfile"
  472. return self._send_iam_request(
  473. http_methods.PUT,
  474. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  475. path=path,
  476. body=body
  477. )
  478. def get_user_login_profile(self, user_name):
  479. """
  480. :type user_name: bytes
  481. :return:
  482. **HttpResponse**
  483. """
  484. path = b"/user/" + user_name + b"/loginProfile"
  485. return self._send_iam_request(
  486. http_methods.GET,
  487. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  488. path=path
  489. )
  490. def delete_user_login_profile(self, user_name):
  491. """
  492. :type user_name: bytes
  493. :return:
  494. **HttpResponse**
  495. """
  496. path = b"/user/" + user_name + b"/loginProfile"
  497. return self._send_iam_request(
  498. http_methods.DELETE,
  499. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  500. path=path
  501. )
  502. def create_user_accesskey(self, user_name):
  503. """
  504. :type user_name: bytes
  505. :return:
  506. **HttpResponse**
  507. """
  508. path = b"/user/" + user_name + b"/accesskey"
  509. return self._send_iam_request(
  510. http_methods.POST,
  511. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  512. path=path
  513. )
  514. def disable_user_accesskey(self, user_name, accesskey_id):
  515. """
  516. :type user_name: bytes
  517. :type accesskey_id: bytes
  518. :return:
  519. **HttpResponse**
  520. """
  521. path = b"/user/" + user_name + b"/accesskey/" + accesskey_id
  522. params = {"disable": ""}
  523. return self._send_iam_request(
  524. http_methods.PUT,
  525. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  526. path=path,
  527. params=params
  528. )
  529. def enable_user_accesskey(self, user_name, accesskey_id):
  530. """
  531. :type user_name: bytes
  532. :type accesskey_id: bytes
  533. :return:
  534. **HttpResponse**
  535. """
  536. path = b"/user/" + user_name + b"/accesskey/" + accesskey_id
  537. params = {"enable": ""}
  538. return self._send_iam_request(
  539. http_methods.PUT,
  540. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  541. path=path,
  542. params=params
  543. )
  544. def delete_user_accesskey(self, user_name, accesskey_id):
  545. """
  546. :type user_name: bytes
  547. :type accesskey_id: bytes
  548. :return:
  549. **HttpResponse**
  550. """
  551. path = b"/user/" + user_name + b"/accesskey/" + accesskey_id
  552. return self._send_iam_request(
  553. http_methods.DELETE,
  554. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  555. path=path
  556. )
  557. def list_user_accesskey(self, user_name):
  558. """
  559. :type user_name: bytes
  560. :return:
  561. **HttpResponse**
  562. """
  563. path = b"/user/" + user_name + b"/accesskey"
  564. return self._send_iam_request(
  565. http_methods.GET,
  566. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  567. path=path
  568. )
  569. @required(user_name=(bytes, str), mfa_type=(bytes, str))
  570. def unbind_user_mfa_device(self, user_name, mfa_type):
  571. """
  572. :type user_name: bytes :type mfa_type:
  573. :mfa_type: TOTP
  574. :return:
  575. none
  576. """
  577. user_name_bytes = user_name
  578. if isinstance(user_name, str):
  579. user_name_bytes = user_name.encode('utf-8')
  580. mfa_type_bytes = mfa_type
  581. if isinstance(mfa_type, str):
  582. mfa_type_bytes = mfa_type.encode('utf-8')
  583. path = b"/user/" + user_name_bytes + b"/mfaType/" + mfa_type_bytes
  584. return self._send_iam_request(
  585. http_methods.DELETE,
  586. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  587. path=path
  588. )
  589. # ######################################### #group management# ################################################### #
  590. def create_group(self, create_group_request):
  591. """
  592. :type create_group_request:dict
  593. :return:
  594. **HttpResponse**
  595. """
  596. if create_group_request is None:
  597. body = None
  598. else:
  599. if not isinstance(create_group_request, dict):
  600. raise TypeError(b'create_group_request should be dict')
  601. else:
  602. body = json.dumps(create_group_request)
  603. path = b"/group"
  604. return self._send_iam_request(
  605. http_methods.POST,
  606. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  607. path=path,
  608. body=body
  609. )
  610. def get_group(self, group_name):
  611. """
  612. :type group_name: bytes
  613. :return:
  614. **HttpResponse**
  615. """
  616. path = b"/group/" + group_name
  617. return self._send_iam_request(
  618. http_methods.GET,
  619. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  620. path=path
  621. )
  622. def update_group(self, group_name, update_group_request):
  623. """
  624. :type group_name: bytes
  625. :type update_group_request: dict
  626. :return:
  627. **HttpResponse**
  628. """
  629. if update_group_request is None:
  630. body = None
  631. else:
  632. if not isinstance(update_group_request, dict):
  633. raise TypeError(b'update_group_request should be dict')
  634. else:
  635. body = json.dumps(update_group_request)
  636. path = b"/group/" + group_name
  637. return self._send_iam_request(
  638. http_methods.PUT,
  639. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  640. path=path,
  641. body=body
  642. )
  643. def delete_group(self, group_name):
  644. """
  645. :type group_name: bytes
  646. :return:
  647. **HttpResponse**
  648. """
  649. path = b"/group/" + group_name
  650. return self._send_iam_request(
  651. http_methods.DELETE,
  652. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  653. path=path
  654. )
  655. def list_group(self):
  656. """
  657. :return:
  658. **HttpResponse**
  659. """
  660. path = b"/group"
  661. return self._send_iam_request(
  662. http_methods.GET,
  663. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  664. path=path
  665. )
  666. def add_user_to_group(self, group_name, user_name):
  667. """
  668. :type group_name: bytes
  669. :type user_name: bytes
  670. :return:
  671. **HttpResponse**
  672. """
  673. path = b"/group/" + group_name + b"/user/" + user_name
  674. return self._send_iam_request(
  675. http_methods.PUT,
  676. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  677. path=path
  678. )
  679. def remove_user_from_group(self, group_name, user_name):
  680. """
  681. :type group_name: bytes
  682. :type user_name: bytes
  683. :return:
  684. **HttpResponse**
  685. """
  686. path = b"/group/" + group_name + b"/user/" + user_name
  687. return self._send_iam_request(
  688. http_methods.DELETE,
  689. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  690. path=path
  691. )
  692. def list_user_group(self, user_name):
  693. """
  694. :type user_name: bytes
  695. :return:
  696. **HttpResponse**
  697. """
  698. path = b"/user/" + user_name + b"/group"
  699. return self._send_iam_request(
  700. http_methods.GET,
  701. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  702. path=path
  703. )
  704. def list_group_user(self, group_name):
  705. """
  706. :type group_name: bytes
  707. :return:
  708. **HttpResponse**
  709. """
  710. path = b"/group/" + group_name + b"/user"
  711. return self._send_iam_request(
  712. http_methods.GET,
  713. headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
  714. path=path
  715. )