Skip to content

Instantly share code, notes, and snippets.

@tonyfraser
Last active September 25, 2019 21:19
Show Gist options
  • Save tonyfraser/1d6ac013f435cfc1f8e915da1330debb to your computer and use it in GitHub Desktop.
Save tonyfraser/1d6ac013f435cfc1f8e915da1330debb to your computer and use it in GitHub Desktop.
Get a marathon bearer token and use it to clear all paragraphs in a zeppelin notebook
//uses sttp module
import com.softwaremill.sttp.{HttpURLConnectionBackend, _}
import scala.util.parsing.json._
implicit lazy val backend = HttpURLConnectionBackend()
//first get a marathon bearer token.
val loginPostBody = "{ \"uid\": \"{username}\", \"password\": \"{password}\" }"
val tok = JSON.parseFull(
sttp
.headers("Content-Type" -> "application/json")
.body(loginPostBody)
.post(uri"https://{marathon-domain}/acs/api/v1/auth/login")
.send().body.right.get
)
.get.asInstanceOf[Map[String, String]]
.get("token")
.get
//Now hit the zeppelin instance and clear all the paragraphs from a given notebook.
sttp
.headers("Authorization" -> s"token=${tok}", "Content-Type" -> "application/json")
.put(uri"http://{marathon-domain}/service/{marathon-zeppelin-name}/api/notebook/2E617JZX1/clear")
.send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment