ein-jupyterhub: Early success getting version and authentication token

Some initial success querying jupyterhub for the version and getting an
authentication token for a user.
This commit is contained in:
John Miller 2017-07-20 18:25:40 -05:00
parent 6911f6c692
commit 21925e8122
3 changed files with 57 additions and 0 deletions

View file

@ -1,3 +1,4 @@
;; -*- mode: lisp; fill-column: 80; lexical-binding: t -*-
;;; ein-jupyterhub.el --- Interface to Jupyterhub
;; Copyright (C) 2016 - John Miller
@ -29,7 +30,53 @@
;;
;;; Code:
(require 'request)
(require 'deferred)
(defun ein:jupyterhub-authorization-url (url-or-port command)
(ein:url url-or-port "authorizations" command))
(defun ein:jupyterhub-api-url (url-or-port command)
(ein:url url-or-port "hub/api" command))
(defvar *ein:jupyterhub-version* nil)
(defun ein:jupyterhub-version (url-or-port)
(deferred:$
(ein:query-deferred
(ein:jupyterhub-api-url url-or-port "/")
:type "GET"
:parser #'ein:json-read)
(deferred:nextc it
(lambda (response)
(when (and response (request-response-data response))
(setq *ein:jupyterhub-version* (plist-get (request-response-data response) :version)))))))
(defun ein:jupyterhub-get-user-from-token (url-or-port token)
(deferred:$
(ein:query-deferred
(ein:url url-or-port "hub/api/authorizations/token" token))
(deferred:nextc it
(lambda (response)
(message "Response: %s" (request-response-data response))))))
(defun ein:jupyterhub-token-request (url-or-port username password)
(let ((url (ein:url url-or-port "hub/api/authorizations/token")))
(deferred:$
(deferred:try
(deferred:$
(ein:query-deferred
url
:type "POST"
:timeout ein:content-query-timeout
:parser #'ein:json-read
:data (json-encode`(("username" . ,username)
("password" . , password))))
(deferred:nextc it
(lambda (response)
(message "Received response %s" (request-response-data response)))))
:catch
(lambda (err) (message "error: %s" err))))))
(defun ein:hub-url (url-or-port &optional path)
(if path

View file

@ -5,6 +5,7 @@
(auto-complete "1.4.0")
(request "0.3")
(deferred "0.5")
(request-deferred "0.2.0")
(cl-generic "0.3")
(dash "2.13.0")
(skewer-mode "1.6.2")))

View file

@ -27,6 +27,7 @@
(eval-when-compile (require 'cl))
(require 'request)
(require 'request-deferred)
(require 'url)
(require 'ein-core)
@ -101,6 +102,14 @@ KEY, then call `request' with URL and SETTINGS. KEY is compared by
(puthash key response ein:query-running-process-table)
response)))
(defun* ein:query-deferred (url &rest settings
&key
(timeout ein:query-timeout)
&allow-other-keys)
""
(apply #'request-deferred (url-encode-url url)
(ein:query-prepare-header url settings)))
(defun ein:query-gc-running-process-table ()
"Garbage collect dead processes in `ein:query-running-process-table'."
(maphash