Skip to content

Commit f21b2a7

Browse files
Support HEAD operation and response Headers (#547)
## Changes Support HEAD operation and response Headers ## Test - [X] make fmt - [X] make test - [X] run integration tests (both with current sha and master sha) --------- Signed-off-by: hectorcast-db <[email protected]> Co-authored-by: Miles Yucht <[email protected]>
1 parent 94abc16 commit f21b2a7

29 files changed

+611
-31
lines changed

.codegen/__init__.py.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class AccountClient:
153153
:param workspace: The workspace to construct a client for.
154154
:return: A ``WorkspaceClient`` for the given workspace.
155155
"""
156-
config = self._config.copy()
156+
config = self._config.deep_copy()
157157
config.host = config.environment.deployment_url(workspace.deployment_name)
158158
config.azure_workspace_resource_id = azure.get_azure_resource_id(workspace)
159159
config.account_id = None

.codegen/service.py.tmpl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ from databricks.sdk.service import {{.Package.Name}}{{end}}
2121
{{if .Fields -}}{{if not .IsRequest}}@dataclass
2222
class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Description}}
2323
"""{{.Comment " " 100}}"""
24-
{{end}}{{- range .RequiredFields | alphanumOnly}}
24+
{{end}}{{- range .RequiredFields}}
2525
{{template "safe-snake-name" .}}: {{template "type" .Entity}}{{if .Description}}
2626
"""{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
2727
{{end}}
28-
{{- range .NonRequiredFields | alphanumOnly}}
28+
{{- range .NonRequiredFields}}
2929
{{template "safe-snake-name" .}}: Optional[{{template "type" .Entity}}] = None{{if .Description}}
3030
"""{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
3131
{{end}}
32-
{{if .HasJsonField -}}
32+
{{if or .HasJsonField .HasHeaderField .HasByteStreamField -}}
3333
def as_dict(self) -> dict:
3434
"""Serializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} into a dictionary suitable for use as a JSON request body."""
3535
body = {}
36-
{{range .Fields | alphanumOnly}}if self.{{template "safe-snake-name" .}}{{with .Entity.IsPrimitive}} is not None{{end}}: body['{{.Name}}'] = {{template "as_request_type" .}}
36+
{{range .Fields}}if self.{{template "safe-snake-name" .}}{{with .Entity.IsPrimitive}} is not None{{end}}: body['{{.Name}}'] = {{template "as_request_type" .}}
3737
{{end -}}
3838
return body
3939

4040
@classmethod
4141
def from_dict(cls, d: Dict[str, any]) -> {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:
4242
"""Deserializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} from a dictionary."""
43-
return cls({{range $i, $f := .Fields | alphanumOnly}}{{if $i}}, {{end}}{{template "safe-snake-name" $f}}={{template "from_dict_type" $f}}{{end}})
43+
return cls({{range $i, $f := .Fields}}{{if $i}}, {{end}}{{template "safe-snake-name" $f}}={{template "from_dict_type" $f}}{{end}})
4444
{{end}}
4545
{{end}}
4646
{{else if .ArrayValue}}type {{.PascalName}} []{{template "type" .ArrayValue}}
@@ -187,6 +187,9 @@ class {{.Name}}API:{{if .Description}}
187187
{{template "method-serialize" .}}
188188
{{- end}}
189189
{{template "method-headers" . }}
190+
{{if and .Response .Response.HasHeaderField -}}
191+
{{template "method-response-headers" . }}
192+
{{- end}}
190193
{{template "method-call" .}}
191194

192195
{{if and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) }}
@@ -211,7 +214,7 @@ class {{.Name}}API:{{if .Description}}
211214
{{if or .Request.HasJsonField .Request.HasQueryField -}}
212215
{{if .Request.HasJsonField}}body = {}{{end}}{{if .Request.HasQueryField}}
213216
query = {}{{end}}
214-
{{- range .Request.Fields}}{{ if not .IsPath }}
217+
{{- range .Request.Fields}}{{ if and (not .IsPath) (not .IsHeader) }}
215218
{{- if .IsQuery }}
216219
if {{template "safe-snake-name" .}} is not None: query['{{.Name}}'] = {{template "method-param-bind" .}}{{end}}
217220
{{- if .IsJson }}
@@ -227,6 +230,12 @@ class {{.Name}}API:{{if .Description}}
227230
}
228231
{{- end }}
229232

233+
{{ define "method-response-headers" -}}
234+
response_headers = [
235+
{{- range $h := .ResponseHeaders}}'{{ $h.Name }}',{{ end -}}
236+
]
237+
{{- end }}
238+
230239
{{- define "method-param-bind" -}}
231240
{{- if not .Entity }}None # ERROR: No Type
232241
{{- else if .Entity.ArrayValue }}[
@@ -282,7 +291,7 @@ class {{.Name}}API:{{if .Description}}
282291
{{ if .Pagination.Token -}}
283292
if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']:
284293
return
285-
{{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
294+
{{if or (eq "GET" .Verb) (eq "HEAD" .Verb)}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
286295
{{- else if eq .Path "/api/2.0/clusters/events" -}}
287296
if 'next_page' not in json or not json['next_page']:
288297
return
@@ -307,9 +316,7 @@ class {{.Name}}API:{{if .Description}}
307316
{{if .Response -}}
308317
res = {{end}}{{template "method-do" .}}
309318
{{if .Response -}}
310-
{{- if .IsResponseByteStream -}}
311-
return {{.Response.PascalName}}({{.ResponseBodyField.CamelName}}=res)
312-
{{- else if .Response.ArrayValue -}}
319+
{{- if .Response.ArrayValue -}}
313320
return [{{.Response.ArrayValue.PascalName}}.from_dict(v) for v in res]
314321
{{- else if .Response.MapValue -}}
315322
return res
@@ -330,6 +337,9 @@ self._api.do('{{.Verb}}',
330337
{{- else if .Request.HasJsonField}}, body=body{{end}}
331338
{{end}}
332339
, headers=headers
340+
{{if and .Response .Response.HasHeaderField -}}
341+
, response_headers=response_headers
342+
{{- end}}
333343
{{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
334344
{{- if .IsResponseByteStream }}, raw=True{{ end }})
335345
{{- end}}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ examples/workspace/list_workspace_integration.py linguist-generated=true
285285
examples/workspace_assignment/list_workspace_assignment_on_aws.py linguist-generated=true
286286
examples/workspace_assignment/update_workspace_assignment_on_aws.py linguist-generated=true
287287
examples/workspace_bindings/get_catalog_workspace_bindings.py linguist-generated=true
288+
examples/workspace_bindings/update_catalog_workspace_bindings.py linguist-generated=true
288289
examples/workspace_conf/get_status_repos.py linguist-generated=true
289290
examples/workspaces/create_workspaces.py linguist-generated=true
290291
examples/workspaces/get_workspaces.py linguist-generated=true

databricks/sdk/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ def do(self,
135135
raw=raw,
136136
files=files,
137137
data=data)
138-
if raw:
139-
return StreamingResponse(response)
138+
140139
resp = dict()
141140
for header in response_headers if response_headers else []:
142141
resp[header] = response.headers.get(Casing.to_header_case(header))
142+
if raw:
143+
resp["contents"] = StreamingResponse(response)
144+
return resp
143145
if not len(response.content):
144146
return resp
145147

databricks/sdk/mixins/workspace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ def download(self, path: str, *, format: Optional[ExportFormat] = None) -> Binar
102102
"""
103103
query = {'path': path, 'direct_download': 'true'}
104104
if format: query['format'] = format.value
105-
return self._api.do('GET', '/api/2.0/workspace/export', query=query, raw=True)
105+
response = self._api.do('GET', '/api/2.0/workspace/export', query=query, raw=True)
106+
return response["contents"]

databricks/sdk/service/billing.py

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)