Giter Site home page Giter Site logo

shouchou / databricks-group-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ashishkr007/databricks-group-api

0.0 0.0 0.0 14 KB

The Groups API allows you to manage groups of users. This code will allow to access databricks group api from notebook. I written this code snipped for one of my requirement, where i have to send workspace security events/workspace event to security team. This is one of example to access Databricks Api but with this code you can access any databricks Api. The same this can be done with normal curl command also.

Scala 100.00%

databricks-group-api's Introduction

Databricks Group Api Access

How to get Groups/Users list using Databricks Rest Api.

The Groups API allows you to manage groups of users. This code will allow to access databricks group api from notebook. I written this code snipped for one of my requirement, where i have to send workspace security events to security team.
This is one of example to access Databricks Api but with this code you can access any databricks Api. like Clusters API

DBFS API

Workspace API

Jobs API

Groups API

Libraries API

Secrets API

SCIM API

Permissions API

Global Init Scripts API

Cluster Policies APIs

Token API

Token Management API

scala

def getHttpResponse(url:String,param_key:String,param_value:String):DataFrame={
  val client = HttpClientBuilder.create()
  .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
  .build()

  val builder = new URIBuilder(url)
  if(param_key!="")
  {
    builder.setParameter(param_key, param_value)
  }
  val httpGet = new HttpGet(builder.build());
  httpGet.setHeader("Accept", "application/json")
  httpGet.setHeader("Content-type", "application/json")
  httpGet.setHeader("Authorization", "Bearer "+dbws_token)
  val response = client.execute(httpGet)
  val inputStream = response.getEntity.getContent
  val content = scala.io.Source.fromInputStream(inputStream).mkString
  val df_gp_list = spark.read.json(Seq(content).toDS)
  df_gp_list
}

val df_gp_reponse=getHttpResponse("https://"+workspace_host+"/api/2.0/groups/list","","")
val df_gp_reponse=getHttpResponse("https://"+workspace_host+"/api/2.0/groups/list-members","group_name",gp_name)

python

import http.client
import mimetypes

conn = http.client.HTTPSConnection("adb-<********>.5.azuredatabricks.net")
payload = "{\r\n    \"group_name\": \"admins\"\r\n}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <your databricks token>'
}
conn.request("GET", "/api/2.0/groups/list-members", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

curl

curl --location --request GET 'https://adb-<*******>.5.azuredatabricks.net/api/2.0/groups/list-members' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your databricks token>' \
--data-raw '{
    "group_name": "admins"
}'

databricks-group-api's People

Contributors

ashishkr007 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.