Skip to content

Commit

Permalink
Merge branch 'main' into infer-azure-tenant-id
Browse files Browse the repository at this point in the history
# Conflicts:
#	databricks/sdk/azure.py
#	databricks/sdk/credentials_provider.py
  • Loading branch information
mgyucht committed Jul 18, 2024
2 parents 0069bd6 + eace94d commit 7cee99c
Show file tree
Hide file tree
Showing 414 changed files with 5,663 additions and 2,283 deletions.
3 changes: 2 additions & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"formatter": "yapf -pri $FILENAMES && autoflake -i $FILENAMES && isort $FILENAMES",
"changelog_config": ".codegen/changelog_config.yml",
"template_libraries": [
".codegen/lib.tmpl"
],
Expand All @@ -12,7 +13,7 @@
".codegen/error_overrides.py.tmpl": "databricks/sdk/errors/overrides.py"
},
"samples": {
".codegen/example.py.tmpl": "examples/{{.Service.SnakeName}}/{{.Method.SnakeName}}_{{.SnakeName}}.py"
".codegen/example.py.tmpl": "examples/{{if .IsAccount}}account{{else}}workspace{{end}}/{{.Service.SnakeName}}/{{.Method.SnakeName}}_{{.SnakeName}}.py"
},
"version": {
"databricks/sdk/version.py": "__version__ = '$VERSION'"
Expand Down
42 changes: 35 additions & 7 deletions .codegen/__init__.py.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import databricks.sdk.core as client
import databricks.sdk.dbutils as dbutils
from databricks.sdk.credentials_provider import CredentialsProvider
from databricks.sdk.credentials_provider import CredentialsStrategy

from databricks.sdk.mixins.files import DbfsExt
from databricks.sdk.mixins.compute import ClustersExt
Expand Down Expand Up @@ -46,10 +46,12 @@ class WorkspaceClient:
debug_headers: bool = None,
product="unknown",
product_version="0.0.0",
credentials_provider: CredentialsProvider = None,
credentials_strategy: CredentialsStrategy = None,
credentials_provider: CredentialsStrategy = None,
config: client.Config = None):
if not config:
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
credentials_strategy=credentials_strategy,
credentials_provider=credentials_provider,
debug_truncate_bytes=debug_truncate_bytes,
debug_headers=debug_headers,
Expand All @@ -59,8 +61,20 @@ class WorkspaceClient:
self._dbutils = _make_dbutils(self._config)
self._api_client = client.ApiClient(self._config)

{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent)}}
self._{{.SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent) .HasDataPlaneAPI (not .IsDataPlane)}}
{{.SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}

{{- range .Services}}
{{- if and (not .IsAccounts) (not .HasParent)}}
{{- if .IsDataPlane}}
self._{{.SnakeName}} = {{template "api" .}}(self._api_client, {{.ControlPlaneService.SnakeName}})
{{- else if .HasDataPlaneAPI}}
self._{{.SnakeName}} = {{.SnakeName}}
{{- else}}
self._{{.SnakeName}} = {{template "api" .}}(self._api_client)
{{- end -}}
{{- end -}}
{{end}}

@property
def config(self) -> client.Config:
Expand Down Expand Up @@ -101,10 +115,12 @@ class AccountClient:
debug_headers: bool = None,
product="unknown",
product_version="0.0.0",
credentials_provider: CredentialsProvider = None,
credentials_strategy: CredentialsStrategy = None,
credentials_provider: CredentialsStrategy = None,
config: client.Config = None):
if not config:
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
credentials_strategy=credentials_strategy,
credentials_provider=credentials_provider,
debug_truncate_bytes=debug_truncate_bytes,
debug_headers=debug_headers,
Expand All @@ -113,8 +129,20 @@ class AccountClient:
self._config = config.copy()
self._api_client = client.ApiClient(self._config)

{{- range .Services}}{{if and .IsAccounts (not .HasParent)}}
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
{{- range .Services}}{{if and .IsAccounts (not .HasParent) .HasDataPlaneAPI (not .IsDataPlane)}}
{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}

{{- range .Services}}
{{- if and .IsAccounts (not .HasParent)}}
{{- if .IsDataPlane}}
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client, {{.ControlPlaneService.SnakeName}})
{{- else if .HasDataPlaneAPI}}
self._{{(.TrimPrefix "account").SnakeName}} = {{(.TrimPrefix "account").SnakeName}}
{{- else}}
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client)
{{- end -}}
{{- end -}}
{{end}}

@property
def config(self) -> client.Config:
Expand Down
2 changes: 1 addition & 1 deletion .codegen/_openapi_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9bb7950fa3390afb97abaa552934bc0a2e069de5
7437dabb9dadee402c1fc060df4c1ce8cc5369f0
44 changes: 38 additions & 6 deletions .codegen/changelog.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Version changelog

## {{.Version}}
{{- range .GroupChanges}}

{{range .Changes -}}
### {{.Type.Message}}
{{range .Changes}}
* {{.}}.
{{end}}{{- if .ApiChanges}}
API Changes:
{{range .ApiChanges}}
* {{.Action}} {{template "what" .}}{{if .Extra}} {{.Extra}}{{with .Other}} {{template "what" .}}{{end}}{{end}}.
{{- end}}
{{end}}
{{if .ApiChanges}}
### API Changes:
{{range .ApiChanges.GroupDiff}}
* {{.Action}} {{template "group-what" .}}{{if .Extra}} {{.Extra}}{{with .Other}} {{template "other-what" .}}{{end}}{{end}}.
{{- end}}

OpenAPI SHA: {{.Sha}}, Date: {{.Changed}}
Expand All @@ -20,7 +24,35 @@ Dependency updates:

## {{.PrevVersion}}

{{- define "what" -}}
{{- define "group-what" -}}
{{if gt (len .Changes) 1 -}} {{template "single-what" .Changes.First}}{{end -}}
{{range .Changes.Middle -}}, {{template "single-what" .}}{{end -}}
{{if gt (len .Changes) 1}} and {{end}}{{template "single-what" .Changes.Last}}{{template "suffix-what" .}}
{{- end -}}

{{- define "single-what" -}}
{{if eq .X "package" -}}
`databricks.sdk.service.{{.Package.Name}}`
{{- else if eq .X "service" -}}
{{template "service" .Service}}
{{- else if eq .X "method" -}}
`{{.Method.SnakeName}}()`
{{- else if eq .X "entity" -}}
{{template "entity" .Entity}}
{{- else if eq .X "field" -}}
`{{.Field.SnakeName}}`
{{- end}}
{{- end -}}

{{- define "suffix-what" -}}
{{if eq .Type "package" }} package{{if gt (len .Changes) 1}}s{{end}}
{{- else if eq .Type "method" }} method{{if gt (len .Changes) 1}}s{{end}} for {{template "service" .Parent.Service}}
{{- else if eq .Type "entity" }} dataclass{{if gt (len .Changes) 1}}es{{end}}
{{- else if eq .Type "field" }} field{{if gt (len .Changes) 1}}s{{end}} for {{template "entity" .Parent.Entity}}
{{- end}}
{{- end -}}

{{- define "other-what" -}}
{{if eq .X "package" -}}
`databricks.sdk.service.{{.Package.Name}}` package
{{- else if eq .X "service" -}}
Expand Down
14 changes: 14 additions & 0 deletions .codegen/changelog_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
change_types:
- message: New Features and Improvements
tag: "[Feature]"
- message: Bug Fixes
tag: "[Fix]"
- message: Documentation
tag: "[Doc]"
- message: Internal Changes
tag: "[Internal]"
# Does not appear in the Changelog. Only for PR validation.
- message: Release
tag: "[Release]"
# Default for messages without a tag
- message: Other Changes
67 changes: 53 additions & 14 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ from typing import Dict, List, Any, Iterator, Type, Callable, Optional, BinaryIO
import time
import random
import logging
import requests

from ..data_plane import DataPlaneService
from ..errors import OperationTimeout, OperationFailed
from ._internal import _enum, _from_dict, _repeated_dict, _repeated_enum, Wait, _escape_multi_segment_path_parameter
from ..oauth import Token

_LOG = logging.getLogger('databricks.sdk')

Expand Down Expand Up @@ -104,8 +108,12 @@ class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Descriptio
class {{.PascalName}}API:{{if .Description}}
"""{{.Comment " " 110}}"""
{{end}}
def __init__(self, api_client):
def __init__(self, api_client{{if .IsDataPlane}}, control_plane{{end}}):
self._api = api_client
{{if .IsDataPlane -}}
self._control_plane = control_plane
self._data_plane_service = DataPlaneService()
{{end -}}
{{range .Subservices}}
self._{{.SnakeName}} = {{.PascalName}}API(self._api){{end}}

Expand Down Expand Up @@ -183,6 +191,9 @@ class {{.PascalName}}API:{{if .Description}}
{{if .Request -}}
{{template "method-serialize" .}}
{{- end}}
{{- if .Service.IsDataPlane}}
{{template "data-plane" .}}
{{- end}}
{{template "method-headers" . }}
{{if .Response.HasHeaderField -}}
{{template "method-response-headers" . }}
Expand All @@ -197,6 +208,27 @@ class {{.PascalName}}API:{{if .Description}}
{{end -}}
{{- end}}

{{define "data-plane" -}}
def info_getter():
response = self._control_plane.{{.Service.DataPlaneInfoMethod.SnakeName}}(
{{- range .Service.DataPlaneInfoMethod.Request.Fields }}
{{.SnakeName}} = {{.SnakeName}},
{{- end}}
)
if response.{{(index .DataPlaneInfoFields 0).SnakeName}} is None:
raise Exception("Resource does not support direct Data Plane access")
return response{{range .DataPlaneInfoFields}}.{{.SnakeName}}{{end}}

get_params = [{{- range .Service.DataPlaneInfoMethod.Request.Fields }}{{.SnakeName}},{{end}}]
data_plane_details = self._data_plane_service.get_data_plane_details('{{.SnakeName}}', get_params, info_getter, self._api.get_oauth_token)
token = data_plane_details.token

def auth(r: requests.PreparedRequest) -> requests.PreparedRequest:
authorization = f"{token.token_type} {token.access_token}"
r.headers["Authorization"] = authorization
return r
{{- end}}

{{define "method-parameters" -}}
self{{if .Request}}
{{- if .Request.MapValue }}, contents: {{template "type" .Request }}{{ end }}
Expand Down Expand Up @@ -324,19 +356,26 @@ class {{.PascalName}}API:{{if .Description}}
{{- end}}

{{define "method-do" -}}
self._api.do('{{.Verb}}',
{{ template "path" . }}
{{if .Request}}
{{- if .Request.HasQueryField}}, query=query{{end}}
{{- if .Request.MapValue}}, body=contents
{{- else if .Request.HasJsonField}}, body=body{{end}}
{{end}}
, headers=headers
{{if .Response.HasHeaderField -}}
, response_headers=response_headers
{{- end}}
{{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
{{- if .IsResponseByteStream }}, raw=True{{ end }})
self._api.do('{{.Verb}}',
{{- if .Service.IsDataPlane -}}
url=data_plane_details.endpoint_url
{{- else -}}
{{ template "path" . }}
{{- end -}}
{{if .Request}}
{{- if .Request.HasQueryField}}, query=query{{end}}
{{- if .Request.MapValue}}, body=contents
{{- else if .Request.HasJsonField}}, body=body{{end}}
{{end}}
, headers=headers
{{if .Response.HasHeaderField -}}
, response_headers=response_headers
{{- end}}
{{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
{{- if .Service.IsDataPlane -}}
,auth=auth
{{- end -}}
{{- if .IsResponseByteStream }}, raw=True{{ end }})
{{- end}}

{{- define "path" -}}
Expand Down
Loading

0 comments on commit 7cee99c

Please sign in to comment.