{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Twitcher Client" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# disable ssl warnings\n", "import urllib3\n", "urllib3.disable_warnings()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from twitcher.client import TwitcherService\n", "base_url = 'http://localhost:8000'\n", "twitcher = TwitcherService(base_url, username='demo', password='demo', verify=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Register Client APP" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "client = twitcher.add_client_app(name='test1', redirect_uri='http://demo/test1')\n", "client" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Register WPS service in Twitcher OWS Proxy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "service = twitcher.register_service(name=\"emu_demo\", url=\"http://localhost:5000/wps\")\n", "service" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## WPS GetCapabilities request" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import requests\n", "\n", "url = \"{}/ows/proxy/emu_demo?service=WPS&request=GetCapabilities\".format(base_url)\n", "url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = requests.get(url, verify=False)\n", "resp.ok" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## WPS DescribeProcess request" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=DescribeProcess&identifier=hello\".format(base_url)\n", "url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = requests.get(url, verify=False)\n", "resp.ok" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## WPS Execute request ... restricted access" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux\".format(base_url)\n", "url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = requests.get(url, verify=False)\n", "resp.ok" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Access forbidden without access token." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "'AccessForbidden' in resp.text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get Access token for compute" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "compute_token = twitcher.fetch_token(client_id=client['client_id'], client_secret=client['client_secret'], scope='compute')\n", "compute_token" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add access token to parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux&access_token={}\".format(\n", " base_url, compute_token['access_token'])\n", "url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = requests.get(url, verify=False)\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "'Hello Tux' in resp.text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... or add access token to headers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "headers = {'Authorization': 'Bearer {}'.format(compute_token['access_token'])}\n", "headers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = requests.get(\n", " \"{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux\".format(base_url),\n", " headers=headers,\n", " verify=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "'Hello Tux' in resp.text" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }