How to use _get_auth method in tempest

Best Python code snippet using tempest_python

grafana4.py

Source:grafana4.py Github

copy

Full Screen

...38 headers = {"Content-type": "application/json"}39 if profile.get("grafana_token", False):40 headers["Authorization"] = "Bearer {0}".format(profile["grafana_token"])41 return headers42def _get_auth(profile):43 if profile.get("grafana_token", False):44 return None45 return requests.auth.HTTPBasicAuth(46 profile["grafana_user"], profile["grafana_password"]47 )48def get_users(profile="grafana"):49 """50 List all users.51 profile52 Configuration profile used to connect to the Grafana instance.53 Default is 'grafana'.54 CLI Example:55 .. code-block:: bash56 salt '*' grafana4.get_users57 """58 if isinstance(profile, string_types):59 profile = __salt__["config.option"](profile)60 response = requests.get(61 "{0}/api/users".format(profile["grafana_url"]),62 auth=_get_auth(profile),63 headers=_get_headers(profile),64 timeout=profile.get("grafana_timeout", 3),65 )66 if response.status_code >= 400:67 response.raise_for_status()68 return response.json()69def get_user(login, profile="grafana"):70 """71 Show a single user.72 login73 Login of the user.74 profile75 Configuration profile used to connect to the Grafana instance.76 Default is 'grafana'.77 CLI Example:78 .. code-block:: bash79 salt '*' grafana4.get_user <login>80 """81 data = get_users(profile)82 for user in data:83 if user["login"] == login:84 return user85 return None86def get_user_data(userid, profile="grafana"):87 """88 Get user data.89 userid90 Id of the user.91 profile92 Configuration profile used to connect to the Grafana instance.93 Default is 'grafana'.94 CLI Example:95 .. code-block:: bash96 salt '*' grafana4.get_user_data <user_id>97 """98 if isinstance(profile, string_types):99 profile = __salt__["config.option"](profile)100 response = requests.get(101 "{0}/api/users/{1}".format(profile["grafana_url"], userid),102 auth=_get_auth(profile),103 headers=_get_headers(profile),104 timeout=profile.get("grafana_timeout", 3),105 )106 if response.status_code >= 400:107 response.raise_for_status()108 return response.json()109def create_user(profile="grafana", **kwargs):110 """111 Create a new user.112 login113 Login of the new user.114 password115 Password of the new user.116 email117 Email of the new user.118 name119 Optional - Full name of the new user.120 profile121 Configuration profile used to connect to the Grafana instance.122 Default is 'grafana'.123 CLI Example:124 .. code-block:: bash125 salt '*' grafana4.create_user login=<login> password=<password> email=<email>126 """127 if isinstance(profile, string_types):128 profile = __salt__["config.option"](profile)129 response = requests.post(130 "{0}/api/admin/users".format(profile["grafana_url"]),131 json=kwargs,132 auth=_get_auth(profile),133 headers=_get_headers(profile),134 timeout=profile.get("grafana_timeout", 3),135 )136 if response.status_code >= 400:137 response.raise_for_status()138 return response.json()139def update_user(userid, profile="grafana", **kwargs):140 """141 Update an existing user.142 userid143 Id of the user.144 login145 Optional - Login of the user.146 email147 Optional - Email of the user.148 name149 Optional - Full name of the user.150 profile151 Configuration profile used to connect to the Grafana instance.152 Default is 'grafana'.153 CLI Example:154 .. code-block:: bash155 salt '*' grafana4.update_user <user_id> login=<login> email=<email>156 """157 if isinstance(profile, string_types):158 profile = __salt__["config.option"](profile)159 response = requests.put(160 "{0}/api/users/{1}".format(profile["grafana_url"], userid),161 json=kwargs,162 auth=_get_auth(profile),163 headers=_get_headers(profile),164 timeout=profile.get("grafana_timeout", 3),165 )166 if response.status_code >= 400:167 response.raise_for_status()168 return response.json()169def update_user_password(userid, profile="grafana", **kwargs):170 """171 Update a user password.172 userid173 Id of the user.174 password175 New password of the user.176 profile177 Configuration profile used to connect to the Grafana instance.178 Default is 'grafana'.179 CLI Example:180 .. code-block:: bash181 salt '*' grafana4.update_user_password <user_id> password=<password>182 """183 if isinstance(profile, string_types):184 profile = __salt__["config.option"](profile)185 response = requests.put(186 "{0}/api/admin/users/{1}/password".format(profile["grafana_url"], userid),187 json=kwargs,188 auth=_get_auth(profile),189 headers=_get_headers(profile),190 timeout=profile.get("grafana_timeout", 3),191 )192 if response.status_code >= 400:193 response.raise_for_status()194 return response.json()195def update_user_permissions(userid, profile="grafana", **kwargs):196 """197 Update a user password.198 userid199 Id of the user.200 isGrafanaAdmin201 Whether user is a Grafana admin.202 profile203 Configuration profile used to connect to the Grafana instance.204 Default is 'grafana'.205 CLI Example:206 .. code-block:: bash207 salt '*' grafana4.update_user_permissions <user_id> isGrafanaAdmin=<true|false>208 """209 if isinstance(profile, string_types):210 profile = __salt__["config.option"](profile)211 response = requests.put(212 "{0}/api/admin/users/{1}/permissions".format(profile["grafana_url"], userid),213 json=kwargs,214 auth=_get_auth(profile),215 headers=_get_headers(profile),216 timeout=profile.get("grafana_timeout", 3),217 )218 if response.status_code >= 400:219 response.raise_for_status()220 return response.json()221def delete_user(userid, profile="grafana"):222 """223 Delete a user.224 userid225 Id of the user.226 profile227 Configuration profile used to connect to the Grafana instance.228 Default is 'grafana'.229 CLI Example:230 .. code-block:: bash231 salt '*' grafana4.delete_user <user_id>232 """233 if isinstance(profile, string_types):234 profile = __salt__["config.option"](profile)235 response = requests.delete(236 "{0}/api/admin/users/{1}".format(profile["grafana_url"], userid),237 auth=_get_auth(profile),238 headers=_get_headers(profile),239 timeout=profile.get("grafana_timeout", 3),240 )241 if response.status_code >= 400:242 response.raise_for_status()243 return response.json()244def get_user_orgs(userid, profile="grafana"):245 """246 Get the list of organisations a user belong to.247 userid248 Id of the user.249 profile250 Configuration profile used to connect to the Grafana instance.251 Default is 'grafana'.252 CLI Example:253 .. code-block:: bash254 salt '*' grafana4.get_user_orgs <user_id>255 """256 if isinstance(profile, string_types):257 profile = __salt__["config.option"](profile)258 response = requests.get(259 "{0}/api/users/{1}/orgs".format(profile["grafana_url"], userid),260 auth=_get_auth(profile),261 headers=_get_headers(profile),262 timeout=profile.get("grafana_timeout", 3),263 )264 if response.status_code >= 400:265 response.raise_for_status()266 return response.json()267def delete_user_org(userid, orgid, profile="grafana"):268 """269 Remove a user from an organization.270 userid271 Id of the user.272 orgid273 Id of the organization.274 profile275 Configuration profile used to connect to the Grafana instance.276 Default is 'grafana'.277 CLI Example:278 .. code-block:: bash279 salt '*' grafana4.delete_user_org <user_id> <org_id>280 """281 if isinstance(profile, string_types):282 profile = __salt__["config.option"](profile)283 response = requests.delete(284 "{0}/api/orgs/{1}/users/{2}".format(profile["grafana_url"], orgid, userid),285 auth=_get_auth(profile),286 headers=_get_headers(profile),287 timeout=profile.get("grafana_timeout", 3),288 )289 if response.status_code >= 400:290 response.raise_for_status()291 return response.json()292def get_orgs(profile="grafana"):293 """294 List all organizations.295 profile296 Configuration profile used to connect to the Grafana instance.297 Default is 'grafana'.298 CLI Example:299 .. code-block:: bash300 salt '*' grafana4.get_orgs301 """302 if isinstance(profile, string_types):303 profile = __salt__["config.option"](profile)304 response = requests.get(305 "{0}/api/orgs".format(profile["grafana_url"]),306 auth=_get_auth(profile),307 headers=_get_headers(profile),308 timeout=profile.get("grafana_timeout", 3),309 )310 if response.status_code >= 400:311 response.raise_for_status()312 return response.json()313def get_org(name, profile="grafana"):314 """315 Show a single organization.316 name317 Name of the organization.318 profile319 Configuration profile used to connect to the Grafana instance.320 Default is 'grafana'.321 CLI Example:322 .. code-block:: bash323 salt '*' grafana4.get_org <name>324 """325 if isinstance(profile, string_types):326 profile = __salt__["config.option"](profile)327 response = requests.get(328 "{0}/api/orgs/name/{1}".format(profile["grafana_url"], name),329 auth=_get_auth(profile),330 headers=_get_headers(profile),331 timeout=profile.get("grafana_timeout", 3),332 )333 if response.status_code >= 400:334 response.raise_for_status()335 return response.json()336def switch_org(orgname, profile="grafana"):337 """338 Switch the current organization.339 name340 Name of the organization to switch to.341 profile342 Configuration profile used to connect to the Grafana instance.343 Default is 'grafana'.344 CLI Example:345 .. code-block:: bash346 salt '*' grafana4.switch_org <name>347 """348 if isinstance(profile, string_types):349 profile = __salt__["config.option"](profile)350 org = get_org(orgname, profile)351 response = requests.post(352 "{0}/api/user/using/{1}".format(profile["grafana_url"], org["id"]),353 auth=_get_auth(profile),354 headers=_get_headers(profile),355 timeout=profile.get("grafana_timeout", 3),356 )357 if response.status_code >= 400:358 response.raise_for_status()359 return org360def get_org_users(orgname=None, profile="grafana"):361 """362 Get the list of users that belong to the organization.363 orgname364 Name of the organization.365 profile366 Configuration profile used to connect to the Grafana instance.367 Default is 'grafana'.368 CLI Example:369 .. code-block:: bash370 salt '*' grafana4.get_org_users <orgname>371 """372 if isinstance(profile, string_types):373 profile = __salt__["config.option"](profile)374 if orgname:375 switch_org(orgname, profile)376 response = requests.get(377 "{0}/api/org/users".format(profile["grafana_url"]),378 auth=_get_auth(profile),379 headers=_get_headers(profile),380 timeout=profile.get("grafana_timeout", 3),381 )382 if response.status_code >= 400:383 response.raise_for_status()384 return response.json()385def create_org_user(orgname=None, profile="grafana", **kwargs):386 """387 Add user to the organization.388 loginOrEmail389 Login or email of the user.390 role391 Role of the user for this organization. Should be one of:392 - Admin393 - Editor394 - Read Only Editor395 - Viewer396 orgname397 Name of the organization in which users are added.398 profile399 Configuration profile used to connect to the Grafana instance.400 Default is 'grafana'.401 CLI Example:402 .. code-block:: bash403 salt '*' grafana4.create_org_user <orgname> loginOrEmail=<loginOrEmail> role=<role>404 """405 if isinstance(profile, string_types):406 profile = __salt__["config.option"](profile)407 if orgname:408 switch_org(orgname, profile)409 response = requests.post(410 "{0}/api/org/users".format(profile["grafana_url"]),411 json=kwargs,412 auth=_get_auth(profile),413 headers=_get_headers(profile),414 timeout=profile.get("grafana_timeout", 3),415 )416 if response.status_code >= 400:417 response.raise_for_status()418 return response.json()419def update_org_user(userid, orgname=None, profile="grafana", **kwargs):420 """421 Update user role in the organization.422 userid423 Id of the user.424 loginOrEmail425 Login or email of the user.426 role427 Role of the user for this organization. Should be one of:428 - Admin429 - Editor430 - Read Only Editor431 - Viewer432 orgname433 Name of the organization in which users are updated.434 profile435 Configuration profile used to connect to the Grafana instance.436 Default is 'grafana'.437 CLI Example:438 .. code-block:: bash439 salt '*' grafana4.update_org_user <user_id> <orgname> loginOrEmail=<loginOrEmail> role=<role>440 """441 if isinstance(profile, string_types):442 profile = __salt__["config.option"](profile)443 if orgname:444 switch_org(orgname, profile)445 response = requests.patch(446 "{0}/api/org/users/{1}".format(profile["grafana_url"], userid),447 json=kwargs,448 auth=_get_auth(profile),449 headers=_get_headers(profile),450 timeout=profile.get("grafana_timeout", 3),451 )452 if response.status_code >= 400:453 response.raise_for_status()454 return response.json()455def delete_org_user(userid, orgname=None, profile="grafana"):456 """457 Remove user from the organization.458 userid459 Id of the user.460 orgname461 Name of the organization in which users are updated.462 profile463 Configuration profile used to connect to the Grafana instance.464 Default is 'grafana'.465 CLI Example:466 .. code-block:: bash467 salt '*' grafana4.delete_org_user <user_id> <orgname>468 """469 if isinstance(profile, string_types):470 profile = __salt__["config.option"](profile)471 if orgname:472 switch_org(orgname, profile)473 response = requests.delete(474 "{0}/api/org/users/{1}".format(profile["grafana_url"], userid),475 auth=_get_auth(profile),476 headers=_get_headers(profile),477 timeout=profile.get("grafana_timeout", 3),478 )479 if response.status_code >= 400:480 response.raise_for_status()481 return response.json()482def get_org_address(orgname=None, profile="grafana"):483 """484 Get the organization address.485 orgname486 Name of the organization in which users are updated.487 profile488 Configuration profile used to connect to the Grafana instance.489 Default is 'grafana'.490 CLI Example:491 .. code-block:: bash492 salt '*' grafana4.get_org_address <orgname>493 """494 if isinstance(profile, string_types):495 profile = __salt__["config.option"](profile)496 if orgname:497 switch_org(orgname, profile)498 response = requests.get(499 "{0}/api/org/address".format(profile["grafana_url"]),500 auth=_get_auth(profile),501 headers=_get_headers(profile),502 timeout=profile.get("grafana_timeout", 3),503 )504 if response.status_code >= 400:505 response.raise_for_status()506 return response.json()507def update_org_address(orgname=None, profile="grafana", **kwargs):508 """509 Update the organization address.510 orgname511 Name of the organization in which users are updated.512 address1513 Optional - address1 of the org.514 address2515 Optional - address2 of the org.516 city517 Optional - city of the org.518 zip_code519 Optional - zip_code of the org.520 state521 Optional - state of the org.522 country523 Optional - country of the org.524 profile525 Configuration profile used to connect to the Grafana instance.526 Default is 'grafana'.527 CLI Example:528 .. code-block:: bash529 salt '*' grafana4.update_org_address <orgname> country=<country>530 """531 if isinstance(profile, string_types):532 profile = __salt__["config.option"](profile)533 if orgname:534 switch_org(orgname, profile)535 response = requests.put(536 "{0}/api/org/address".format(profile["grafana_url"]),537 json=kwargs,538 auth=_get_auth(profile),539 headers=_get_headers(profile),540 timeout=profile.get("grafana_timeout", 3),541 )542 if response.status_code >= 400:543 response.raise_for_status()544 return response.json()545def get_org_prefs(orgname=None, profile="grafana"):546 """547 Get the organization preferences.548 orgname549 Name of the organization in which users are updated.550 profile551 Configuration profile used to connect to the Grafana instance.552 Default is 'grafana'.553 CLI Example:554 .. code-block:: bash555 salt '*' grafana4.get_org_prefs <orgname>556 """557 if isinstance(profile, string_types):558 profile = __salt__["config.option"](profile)559 if orgname:560 switch_org(orgname, profile)561 response = requests.get(562 "{0}/api/org/preferences".format(profile["grafana_url"]),563 auth=_get_auth(profile),564 headers=_get_headers(profile),565 timeout=profile.get("grafana_timeout", 3),566 )567 if response.status_code >= 400:568 response.raise_for_status()569 return response.json()570def update_org_prefs(orgname=None, profile="grafana", **kwargs):571 """572 Update the organization preferences.573 orgname574 Name of the organization in which users are updated.575 theme576 Selected theme for the org.577 homeDashboardId578 Home dashboard for the org.579 timezone580 Timezone for the org (one of: "browser", "utc", or "").581 profile582 Configuration profile used to connect to the Grafana instance.583 Default is 'grafana'.584 CLI Example:585 .. code-block:: bash586 salt '*' grafana4.update_org_prefs <orgname> theme=<theme> timezone=<timezone>587 """588 if isinstance(profile, string_types):589 profile = __salt__["config.option"](profile)590 if orgname:591 switch_org(orgname, profile)592 response = requests.put(593 "{0}/api/org/preferences".format(profile["grafana_url"]),594 json=kwargs,595 auth=_get_auth(profile),596 headers=_get_headers(profile),597 timeout=profile.get("grafana_timeout", 3),598 )599 if response.status_code >= 400:600 response.raise_for_status()601 return response.json()602def create_org(profile="grafana", **kwargs):603 """604 Create a new organization.605 name606 Name of the organization.607 profile608 Configuration profile used to connect to the Grafana instance.609 Default is 'grafana'.610 CLI Example:611 .. code-block:: bash612 salt '*' grafana4.create_org <name>613 """614 if isinstance(profile, string_types):615 profile = __salt__["config.option"](profile)616 response = requests.post(617 "{0}/api/orgs".format(profile["grafana_url"]),618 json=kwargs,619 auth=_get_auth(profile),620 headers=_get_headers(profile),621 timeout=profile.get("grafana_timeout", 3),622 )623 if response.status_code >= 400:624 response.raise_for_status()625 return response.json()626def update_org(orgid, profile="grafana", **kwargs):627 """628 Update an existing organization.629 orgid630 Id of the organization.631 name632 New name of the organization.633 profile634 Configuration profile used to connect to the Grafana instance.635 Default is 'grafana'.636 CLI Example:637 .. code-block:: bash638 salt '*' grafana4.update_org <org_id> name=<name>639 """640 if isinstance(profile, string_types):641 profile = __salt__["config.option"](profile)642 response = requests.put(643 "{0}/api/orgs/{1}".format(profile["grafana_url"], orgid),644 json=kwargs,645 auth=_get_auth(profile),646 headers=_get_headers(profile),647 timeout=profile.get("grafana_timeout", 3),648 )649 if response.status_code >= 400:650 response.raise_for_status()651 return response.json()652def delete_org(orgid, profile="grafana"):653 """654 Delete an organization.655 orgid656 Id of the organization.657 profile658 Configuration profile used to connect to the Grafana instance.659 Default is 'grafana'.660 CLI Example:661 .. code-block:: bash662 salt '*' grafana4.delete_org <org_id>663 """664 if isinstance(profile, string_types):665 profile = __salt__["config.option"](profile)666 response = requests.delete(667 "{0}/api/orgs/{1}".format(profile["grafana_url"], orgid),668 auth=_get_auth(profile),669 headers=_get_headers(profile),670 timeout=profile.get("grafana_timeout", 3),671 )672 if response.status_code >= 400:673 response.raise_for_status()674 return response.json()675def get_datasources(orgname=None, profile="grafana"):676 """677 List all datasources in an organisation.678 orgname679 Name of the organization.680 profile681 Configuration profile used to connect to the Grafana instance.682 Default is 'grafana'.683 CLI Example:684 .. code-block:: bash685 salt '*' grafana4.get_datasources <orgname>686 """687 if isinstance(profile, string_types):688 profile = __salt__["config.option"](profile)689 if orgname:690 switch_org(orgname, profile)691 response = requests.get(692 "{0}/api/datasources".format(profile["grafana_url"]),693 auth=_get_auth(profile),694 headers=_get_headers(profile),695 timeout=profile.get("grafana_timeout", 3),696 )697 if response.status_code >= 400:698 response.raise_for_status()699 return response.json()700def get_datasource(name, orgname=None, profile="grafana"):701 """702 Show a single datasource in an organisation.703 name704 Name of the datasource.705 orgname706 Name of the organization.707 profile708 Configuration profile used to connect to the Grafana instance.709 Default is 'grafana'.710 CLI Example:711 .. code-block:: bash712 salt '*' grafana4.get_datasource <name> <orgname>713 """714 data = get_datasources(orgname=orgname, profile=profile)715 for datasource in data:716 if datasource["name"] == name:717 return datasource718 return None719def create_datasource(orgname=None, profile="grafana", **kwargs):720 """721 Create a new datasource in an organisation.722 name723 Name of the data source.724 type725 Type of the datasource ('graphite', 'influxdb' etc.).726 access727 Use proxy or direct.728 url729 The URL to the data source API.730 user731 Optional - user to authenticate with the data source.732 password733 Optional - password to authenticate with the data source.734 database735 Optional - database to use with the data source.736 basicAuth737 Optional - set to True to use HTTP basic auth to authenticate with the738 data source.739 basicAuthUser740 Optional - HTTP basic auth username.741 basicAuthPassword742 Optional - HTTP basic auth password.743 jsonData744 Optional - additional json data to post (eg. "timeInterval").745 isDefault746 Optional - set data source as default.747 withCredentials748 Optional - Whether credentials such as cookies or auth headers should749 be sent with cross-site requests.750 typeLogoUrl751 Optional - Logo to use for this datasource.752 orgname753 Name of the organization in which the data source should be created.754 profile755 Configuration profile used to connect to the Grafana instance.756 Default is 'grafana'.757 CLI Example:758 .. code-block:: bash759 salt '*' grafana4.create_datasource760 """761 if isinstance(profile, string_types):762 profile = __salt__["config.option"](profile)763 if orgname:764 switch_org(orgname, profile)765 response = requests.post(766 "{0}/api/datasources".format(profile["grafana_url"]),767 json=kwargs,768 auth=_get_auth(profile),769 headers=_get_headers(profile),770 timeout=profile.get("grafana_timeout", 3),771 )772 if response.status_code >= 400:773 response.raise_for_status()774 return response.json()775def update_datasource(datasourceid, orgname=None, profile="grafana", **kwargs):776 """777 Update a datasource.778 datasourceid779 Id of the datasource.780 name781 Name of the data source.782 type783 Type of the datasource ('graphite', 'influxdb' etc.).784 access785 Use proxy or direct.786 url787 The URL to the data source API.788 user789 Optional - user to authenticate with the data source.790 password791 Optional - password to authenticate with the data source.792 database793 Optional - database to use with the data source.794 basicAuth795 Optional - set to True to use HTTP basic auth to authenticate with the796 data source.797 basicAuthUser798 Optional - HTTP basic auth username.799 basicAuthPassword800 Optional - HTTP basic auth password.801 jsonData802 Optional - additional json data to post (eg. "timeInterval").803 isDefault804 Optional - set data source as default.805 withCredentials806 Optional - Whether credentials such as cookies or auth headers should807 be sent with cross-site requests.808 typeLogoUrl809 Optional - Logo to use for this datasource.810 profile811 Configuration profile used to connect to the Grafana instance.812 Default is 'grafana'.813 CLI Example:814 .. code-block:: bash815 salt '*' grafana4.update_datasource <datasourceid>816 """817 if isinstance(profile, string_types):818 profile = __salt__["config.option"](profile)819 response = requests.put(820 "{0}/api/datasources/{1}".format(profile["grafana_url"], datasourceid),821 json=kwargs,822 auth=_get_auth(profile),823 headers=_get_headers(profile),824 timeout=profile.get("grafana_timeout", 3),825 )826 if response.status_code >= 400:827 response.raise_for_status()828 # temporary fix for https://github.com/grafana/grafana/issues/6869829 # return response.json()830 return {}831def delete_datasource(datasourceid, orgname=None, profile="grafana"):832 """833 Delete a datasource.834 datasourceid835 Id of the datasource.836 profile837 Configuration profile used to connect to the Grafana instance.838 Default is 'grafana'.839 CLI Example:840 .. code-block:: bash841 salt '*' grafana4.delete_datasource <datasource_id>842 """843 if isinstance(profile, string_types):844 profile = __salt__["config.option"](profile)845 response = requests.delete(846 "{0}/api/datasources/{1}".format(profile["grafana_url"], datasourceid),847 auth=_get_auth(profile),848 headers=_get_headers(profile),849 timeout=profile.get("grafana_timeout", 3),850 )851 if response.status_code >= 400:852 response.raise_for_status()853 return response.json()854def get_dashboard(slug, orgname=None, profile="grafana"):855 """856 Get a dashboard.857 slug858 Slug (name) of the dashboard.859 orgname860 Name of the organization.861 profile862 Configuration profile used to connect to the Grafana instance.863 Default is 'grafana'.864 CLI Example:865 .. code-block:: bash866 salt '*' grafana4.get_dashboard <slug>867 """868 if isinstance(profile, string_types):869 profile = __salt__["config.option"](profile)870 if orgname:871 switch_org(orgname, profile)872 response = requests.get(873 "{0}/api/dashboards/db/{1}".format(profile["grafana_url"], slug),874 auth=_get_auth(profile),875 headers=_get_headers(profile),876 timeout=profile.get("grafana_timeout", 3),877 )878 data = response.json()879 if response.status_code == 404:880 return None881 if response.status_code >= 400:882 response.raise_for_status()883 return data.get("dashboard")884def delete_dashboard(slug, orgname=None, profile="grafana"):885 """886 Delete a dashboard.887 slug888 Slug (name) of the dashboard.889 orgname890 Name of the organization.891 profile892 Configuration profile used to connect to the Grafana instance.893 Default is 'grafana'.894 CLI Example:895 .. code-block:: bash896 salt '*' grafana4.delete_dashboard <slug>897 """898 if isinstance(profile, string_types):899 profile = __salt__["config.option"](profile)900 if orgname:901 switch_org(orgname, profile)902 response = requests.delete(903 "{0}/api/dashboards/db/{1}".format(profile["grafana_url"], slug),904 auth=_get_auth(profile),905 headers=_get_headers(profile),906 timeout=profile.get("grafana_timeout", 3),907 )908 if response.status_code >= 400:909 response.raise_for_status()910 return response.json()911def create_update_dashboard(orgname=None, profile="grafana", **kwargs):912 """913 Create or update a dashboard.914 dashboard915 A dict that defines the dashboard to create/update.916 overwrite917 Whether the dashboard should be overwritten if already existing.918 orgname919 Name of the organization.920 profile921 Configuration profile used to connect to the Grafana instance.922 Default is 'grafana'.923 CLI Example:924 .. code-block:: bash925 salt '*' grafana4.create_update_dashboard dashboard=<dashboard> overwrite=True orgname=<orgname>926 """927 if isinstance(profile, string_types):928 profile = __salt__["config.option"](profile)929 if orgname:930 switch_org(orgname, profile)931 response = requests.post(932 "{0}/api/dashboards/db".format(profile.get("grafana_url")),933 json=kwargs,934 auth=_get_auth(profile),935 headers=_get_headers(profile),936 timeout=profile.get("grafana_timeout", 3),937 )938 if response.status_code >= 400:939 response.raise_for_status()...

Full Screen

Full Screen

twitter_api.py

Source:twitter_api.py Github

copy

Full Screen

...5 token_url = "https://api.twitter.com/oauth2/token"6 def __init__(self, key, secret):7 self.key = key 8 self.secret = secret9 self.auth_token = self._get_auth()10 def _url_encode(self, value):11 return urllib.quote(value)12 def _get_bearer_token(self, key, secret):13 return "%s:%s" % (self._url_encode(key), self._url_encode(secret))14 def _get_auth(self):15 bearer_token = self._get_bearer_token(self.key, self.secret).encode('base64')16 auth_param = "Basic %s" % bearer_token.replace("\n", "") 17 headers = { 18 "Authorization" : auth_param.strip(),19 "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",20 "Host:" : "api.twitter.com",21 } 22 body = "grant_type=client_credentials"23 requestor = httplib.HTTPSConnection('api.twitter.com')24 requestor.request("POST", self.token_url, body=body, headers=headers)25 response = requestor.getresponse()26 d = json.load(response)27 return d["access_token"]28 def get_timeline(self, username):29 auth_token = self._get_auth()30 url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=%s&include_rts=false" % username 31 32 auth_param = "Bearer %s" % auth_token.strip()33 headers = { 34 "Authorization" : auth_param,35 "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",36 "Accept" : "*/*"37 } 38 requestor = httplib.HTTPSConnection('api.twitter.com')39 requestor.request("GET", url, headers=headers)40 response = requestor.getresponse()41 return json.loads(response.read())42 def get_search(self, tag):43 auth_token = self._get_auth()44 url = "https://api.twitter.com/1.1/search/tweets.json?q=%s&result_type=mixed" % tag 45 auth_param = "Bearer %s" % auth_token.strip()46 headers = { 47 "Authorization" : auth_param,48 "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",49 "Accept" : "*/*"50 } 51 requestor = httplib.HTTPSConnection('api.twitter.com')52 requestor.request("GET", url, headers=headers)53 response = requestor.getresponse()54 return json.loads(response.read())55 def get_trends_closest(self, latitude, longitude):56 # https://api.twitter.com/1.1/trends/closest.json?lat=37.781157&long=-122.40061283111657 auth_token = self._get_auth()58 url = "https://api.twitter.com/1.1/trends/closest.json?lat=%s&long=%s" % (latitude, longitude) 59 60 auth_param = "Bearer %s" % auth_token.strip()61 headers = { 62 "Authorization" : auth_param,63 "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",64 "Accept" : "*/*"65 } 66 requestor = httplib.HTTPSConnection('api.twitter.com')67 requestor.request("GET", url, headers=headers)68 response = requestor.getresponse()69 return json.loads(response.read())70 def get_trends_place(self, woeid):71 # https://api.twitter.com/1.1/trends/place.json?id=172 auth_token = self._get_auth()73 url = "https://api.twitter.com/1.1/trends/place.json?id=%s" % woeid 74 75 auth_param = "Bearer %s" % auth_token.strip()76 headers = { 77 "Authorization" : auth_param,78 "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",79 "Accept" : "*/*"80 } 81 requestor = httplib.HTTPSConnection('api.twitter.com')82 requestor.request("GET", url, headers=headers)83 response = requestor.getresponse()...

Full Screen

Full Screen

ui_tokens.py

Source:ui_tokens.py Github

copy

Full Screen

...18 with path_notification_auth.open('w') as fd:19 json_dump(req['notification_auth'], fd)20 with path_user_jwt.open('w') as fd:21 json_dump(req['user_jwt'], fd)22def _get_auth(path):23 if not path.exists():24 update_tokens()25 from json import load as json_load26 with path.open() as fd:27 return json_load(fd)28def get_chat_auth():29 return _get_auth(path_chat_auth)30def get_incident_auth():31 return _get_auth(path_incident_auth)32def get_notification_auth():33 return _get_auth(path_notification_auth)34def get_user_jwt():35 return _get_auth(path_user_jwt)36def get_data():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful