From 85a6144de9fe71fe084f0e4f3cc9f60b5d4fd364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 14 Feb 2021 18:42:55 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=9D=20Improve=20dev=20env=20setup?= =?UTF-8?q?=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/development/environment.rst | 52 ++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index f53227f03..93756517b 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -1,14 +1,15 @@ .. _sec-development-environment: +************************************ Setting up a Development environment -==================================== +************************************ .. _sec-development-environment-source: Obtaining, building and running the source ------------------------------------------- +========================================== -This describes the general steps in obtaining, building and running. OS specific instructions can be found +This describes the **general, platform agnostic** steps in obtaining, building and running. OS specific instructions can be found below. * Prerequisites: @@ -80,10 +81,11 @@ Go to the directory `docs` and you can then build the documentation: * ``sphinx-build -b html . _build`` The documentation will be available in the newly created ``_build`` directory. You can simply browse it locally by opening ``index.html`` + .. _sec-development-environment-source-linux: Linux -..... +----- This assumes you'll host your OctoPrint development checkout at ``~/devel/OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -126,7 +128,7 @@ You can then start OctoPrint via ``octoprint`` after activating one of the two v .. _sec-development-environment-windows: Windows -....... +------- This assumes you'll host your OctoPrint development checkout at ``C:\Devel\OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -135,17 +137,18 @@ First download & install: * `Git for Windows `_ * `Latest *stable* Python 2.7 and Python 3.8 releases from python.org `_ - (at the time of writing those are ``2.7.18`` and ``3.8.4``) + (at the time of writing those are ``2.7.18`` and ``3.8.7``) * make sure to have the installer add Python to the ``PATH`` and have it install ``pip`` too * it's recommended to install Python 2.7 into ``C:\Python27`` and Python 3 into ``C:\Python38`` - if you select different install locations please substitute accordingly + * it's also recommended to have both versions get installed for all users * `Microsoft Visual C++ Compiler for Python 2.7 `_ * `Build Tools For Visual Studio 2019 `_ * install "C++ build tools" and ensure the latest versions of "MSVCv142 - VS 2019 C++ x64/x86 build tools" and - "Windows 10 SDK" are checked. + "Windows 10 SDK" are checked under individual components. Open the Git Bash you just installed and in that: @@ -158,18 +161,43 @@ Open the Git Bash you just installed and in that: virtualenv --python=C:\Python27\python.exe venv2 virtualenv --python=C:\Python38\python.exe venv3 source ./venv2/Scripts/activate - pip install --upgrade pip + python -m pip install --upgrade pip pip install -e .[develop,plugins] source ./venv3/Scripts/activate pip install --upgrade pip - pip install -e .[develop,plugins,docs] + python -m pip install -e .[develop,plugins,docs] pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs +.. _sec-development-environment-windows-optional: + +Optional but recommended tools +.............................. + +These are some tools that are recommended but not required to have on hand: + + * `Visual Studio Code `_ + * `Windows Terminal `_ + + Add the following profile to ``profiles.list`` in the settings, that will allow you to + easily start Git Bash from the terminal: + + .. code-block:: js + + { + "guid": "{3df4550c-eebd-496c-a189-e55f2f8b01ce}", + "hidden": false, + "name": "Git Bash", + "commandline": "C:\\Program Files\\Git\\bin\\bash.exe --login -i", + "startingDirectory": "C:\\Devel", + "tabTitle": "Git Bash", + "suppressApplicationTitle": true + }, + .. _sec-development-environment-mac: Mac OS X -........ +-------- .. note:: @@ -220,7 +248,7 @@ You'll need a user account with administrator privileges. .. _sec-development-environment-ides: IDE Setup ---------- +========= .. todo:: @@ -231,7 +259,7 @@ IDE Setup .. _sec-development-environment-ides-pycharm: PyCharm -....... +------- - "File" > "Open ...", select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - Register virtual environments: From 47eeb0eb00e0f3983015d3e344a350548ca30799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Feb 2021 17:10:50 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9D=20Add=20some=20more=20examples?= =?UTF-8?q?=20for=20socket=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix a problem with a config example's markup --- docs/api/push.rst | 26 ++++++++++++++++++++++++++ docs/features/accesscontrol.rst | 1 + docs/jsclientlib/browser.rst | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/docs/api/push.rst b/docs/api/push.rst index c9c6a4b04..36f6f1820 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -68,6 +68,32 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve "auth": "someuser:LGZ0trf8By" } + Example for a auth roundtrip with only an API key, using the :ref:`JS Client Library `: + + .. sourcecode:: javascript + + var client = new OctoPrintClient({baseurl: "http://example.com/octoprint1/", apikey: "apikey1"}); + client.socket.connect(); + client.browser.passiveLogin().done(function(response) { + client.socket.sendAuth(response.name, response.session).done(function() { + // the socket is now authenticated + }) + }) + + .. mermaid:: + + sequenceDiagram + participant Client + participant API + participant Websocket + + Client->>API: GET /api/login?passive=true&apikey=... + API->>Client: { name: ..., session: ..., ... } + + note over Client auth = name + ":" + session + + Client->>Websocket: { "auth": auth } + * ``throttle``: Usually, OctoPrint will push the general state update in the ``current`` message twice per second. For some clients that might still be too fast, so they can signal a different factor to OctoPrint utilizing the diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index 23bf90b75..62a548768 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -177,6 +177,7 @@ further down there's also a dedicated list of steps for OctoPi specifically. salt line): .. code-block:: yaml + accessControl: salt: aabbccddee1234523452345 autologinLocal: true diff --git a/docs/jsclientlib/browser.rst b/docs/jsclientlib/browser.rst index d44ba08bf..e71c26a60 100644 --- a/docs/jsclientlib/browser.rst +++ b/docs/jsclientlib/browser.rst @@ -29,6 +29,25 @@ Tries to perform a passive login into OctoPrint, using existing session data stored in the browser's cookies. + .. code-block:: javascript + + OctoPrint.browser.passiveLogin() + .done(function(response) { + // do something with the response + }) + + .. code-block:: javascript + + var client = new OctoPrintClient({ + baseurl: "https://example.com/", + apikey: "..." + }); + client.browser.passiveLogin() + .done(function(response) { + // do something with the response, e.g. authenticate with the socket + // via response.name and response.session + }) + :param object opts: Additional request options :returns Promise: A `jQuery Promise `_ for the request's response From 281c4b698c0e3cea31b4bcfdb13e60d45ec44ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Feb 2021 17:21:19 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9D=20Merge=20auth=20example=20wit?= =?UTF-8?q?h=20existing=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/push.rst | 13 ++----------- docs/jsclientlib/base.rst | 8 ++++---- docs/jsclientlib/socket.rst | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/api/push.rst b/docs/api/push.rst index 36f6f1820..f316ba70c 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -68,17 +68,8 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve "auth": "someuser:LGZ0trf8By" } - Example for a auth roundtrip with only an API key, using the :ref:`JS Client Library `: - - .. sourcecode:: javascript - - var client = new OctoPrintClient({baseurl: "http://example.com/octoprint1/", apikey: "apikey1"}); - client.socket.connect(); - client.browser.passiveLogin().done(function(response) { - client.socket.sendAuth(response.name, response.session).done(function() { - // the socket is now authenticated - }) - }) + An example for an auth roundtrip with only an API key using the :ref:`JS Client Library ` + can be found :ref:`here `. .. mermaid:: diff --git a/docs/jsclientlib/base.rst b/docs/jsclientlib/base.rst index 63833f0dc..37416fd10 100644 --- a/docs/jsclientlib/base.rst +++ b/docs/jsclientlib/base.rst @@ -14,13 +14,13 @@ The client library instance's options. The following keys are currently supported: - ``apikey`` - The API Key to use for requests against the OctoPrint API. Should usually be - the anonymous UI API Key provided on the socket. - ``baseurl`` The base URL of the OctoPrint API + ``apikey`` + The API Key to use for requests against the OctoPrint API. If left unset, you'll + need to authenticate your session through a login. + ``locale`` The locale to set in ``X-Locale`` headers on API requests. Useful for API endpoints that might return localized content. diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 70b9bc5dc..fc4223546 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -114,9 +114,13 @@ Instructs the server to decrease the message rate by 500ms. +.. _sec-jsclient-socket-authsample: + Sample to setup an authed socket ================================ +If you have a username and a password: + .. code-block:: javascript OctoPrint.socket.connect(); @@ -125,6 +129,20 @@ Sample to setup an authed socket OctoPrint.socket.sendAuth("myusername", response.session); }); +If you have an API key: + +.. code-block:: javascript + + var client = new OctoPrintClient({ + baseurl: "http://example.com/", + apikey: "abcdef" + }); + client.socket.connect(); + client.browser.passiveLogin() + .done(function(response) { + client.socket.sendAuth(response.name, response.session); + }); + .. _sec-jsclient-socket-throttling: Communication Throttling From 68660035b612a70c020746e99db17e4c3fb9b827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Feb 2021 17:22:37 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9D=20Fix=20diagram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/push.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/push.rst b/docs/api/push.rst index f316ba70c..5210ad599 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -81,7 +81,7 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve Client->>API: GET /api/login?passive=true&apikey=... API->>Client: { name: ..., session: ..., ... } - note over Client auth = name + ":" + session + note over Client: auth = name ":" session Client->>Websocket: { "auth": auth }