mirror of https://github.com/databricks/cli.git
wip
This commit is contained in:
parent
5abb009c4f
commit
489aba8d76
|
@ -220,10 +220,16 @@ func validatePauseStatus(b *bundle.Bundle) diag.Diagnostics {
|
||||||
if p == "" || p == config.Paused || p == config.Unpaused {
|
if p == "" || p == config.Paused || p == config.Unpaused {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// TODO: test this.
|
||||||
return diag.Diagnostics{{
|
return diag.Diagnostics{{
|
||||||
Summary: "Invalid value for trigger_pause_status, should be PAUSED or UNPAUSED",
|
Summary: "Invalid value for trigger_pause_status, should be PAUSED or UNPAUSED",
|
||||||
Severity: diag.Error,
|
Severity: diag.Error,
|
||||||
Locations: []dyn.Location{b.Config.GetLocation("presets.trigger_pause_status")},
|
LocationPathPairs: []diag.LocationPathPair{
|
||||||
|
{
|
||||||
|
L: b.Config.GetLocation("presets.trigger_pause_status"),
|
||||||
|
P: dyn.MustPathFromString("presets.trigger_pause_status"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,19 @@ func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagn
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: test this.
|
||||||
|
locationPathPaths := []diag.LocationPathPair{}
|
||||||
|
for _, l := range computeId.Locations() {
|
||||||
|
locationPathPaths = append(locationPathPaths, diag.LocationPathPair{
|
||||||
|
L: l,
|
||||||
|
P: computeIdPath,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
diags = diags.Append(diag.Diagnostic{
|
diags = diags.Append(diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: "compute_id is deprecated, please use cluster_id instead",
|
Summary: "compute_id is deprecated, please use cluster_id instead",
|
||||||
Locations: computeId.Locations(),
|
LocationPathPairs: locationPathPaths,
|
||||||
Paths: []dyn.Path{computeIdPath},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
clusterIdPath := p.Append(dyn.Key("cluster_id"))
|
clusterIdPath := p.Append(dyn.Key("cluster_id"))
|
||||||
|
|
|
@ -78,7 +78,13 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
|
||||||
diags = diags.Append(diag.Diagnostic{
|
diags = diags.Append(diag.Diagnostic{
|
||||||
Severity: diag.Error,
|
Severity: diag.Error,
|
||||||
Summary: "target with 'mode: development' cannot set trigger pause status to UNPAUSED by default",
|
Summary: "target with 'mode: development' cannot set trigger pause status to UNPAUSED by default",
|
||||||
Locations: []dyn.Location{b.Config.GetLocation("presets.trigger_pause_status")},
|
// TODO: test this.
|
||||||
|
LocationPathPairs: []diag.LocationPathPair{
|
||||||
|
{
|
||||||
|
L: b.Config.GetLocation("presets.trigger_pause_status"),
|
||||||
|
P: dyn.MustPathFromString("presets.trigger_pause_status"),
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +106,13 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
|
||||||
diags = diags.Append(diag.Diagnostic{
|
diags = diags.Append(diag.Diagnostic{
|
||||||
Severity: diag.Error,
|
Severity: diag.Error,
|
||||||
Summary: "prefix should contain the current username or ${workspace.current_user.short_name} to ensure uniqueness when using 'mode: development'",
|
Summary: "prefix should contain the current username or ${workspace.current_user.short_name} to ensure uniqueness when using 'mode: development'",
|
||||||
Locations: []dyn.Location{b.Config.GetLocation("presets.name_prefix")},
|
// TODO: test this.
|
||||||
|
LocationPathPairs: []diag.LocationPathPair{
|
||||||
|
{
|
||||||
|
L: b.Config.GetLocation("presets.name_prefix"),
|
||||||
|
P: dyn.MustPathFromString("presets.name_prefix"),
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return diags
|
return diags
|
||||||
|
|
|
@ -54,23 +54,23 @@ func parsePythonDiagnostics(input io.Reader) (diag.Diagnostics, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse path: %s", err)
|
return nil, fmt.Errorf("failed to parse path: %s", err)
|
||||||
}
|
}
|
||||||
var paths []dyn.Path
|
|
||||||
if path != nil {
|
|
||||||
paths = []dyn.Path{path}
|
|
||||||
}
|
|
||||||
|
|
||||||
var locations []dyn.Location
|
|
||||||
location := convertPythonLocation(parsedLine.Location)
|
location := convertPythonLocation(parsedLine.Location)
|
||||||
if location != (dyn.Location{}) {
|
|
||||||
locations = append(locations, location)
|
// TODO: test this.
|
||||||
|
locationPathPairs := []diag.LocationPathPair{}
|
||||||
|
if path != nil || location != (dyn.Location{}) {
|
||||||
|
locationPathPairs = append(locationPathPairs, diag.LocationPathPair{
|
||||||
|
L: location,
|
||||||
|
P: path,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
diag := diag.Diagnostic{
|
diag := diag.Diagnostic{
|
||||||
Severity: severity,
|
Severity: severity,
|
||||||
Summary: parsedLine.Summary,
|
Summary: parsedLine.Summary,
|
||||||
Detail: parsedLine.Detail,
|
Detail: parsedLine.Detail,
|
||||||
Locations: locations,
|
LocationPathPairs: locationPathPairs,
|
||||||
Paths: paths,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diags = diags.Append(diag)
|
diags = diags.Append(diag)
|
||||||
|
|
|
@ -47,12 +47,21 @@ func (m *rewriteWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di
|
||||||
for path, replacePath := range paths {
|
for path, replacePath := range paths {
|
||||||
if strings.Contains(vv, path) {
|
if strings.Contains(vv, path) {
|
||||||
newPath := strings.Replace(vv, path, replacePath, 1)
|
newPath := strings.Replace(vv, path, replacePath, 1)
|
||||||
|
|
||||||
|
locationPathPairs := []diag.LocationPathPair{}
|
||||||
|
for _, l := range v.Locations() {
|
||||||
|
locationPathPairs = append(locationPathPairs, diag.LocationPathPair{
|
||||||
|
L: l,
|
||||||
|
P: p,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: test this.
|
||||||
diags = append(diags, diag.Diagnostic{
|
diags = append(diags, diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: fmt.Sprintf("substring %q found in %q. Please update this to %q.", path, vv, newPath),
|
Summary: fmt.Sprintf("substring %q found in %q. Please update this to %q.", path, vv, newPath),
|
||||||
Detail: "For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths",
|
Detail: "For more information, please refer to: https://docs.databricks.com/en/release-notes/dev-tools/bundles.html#workspace-paths",
|
||||||
Locations: v.Locations(),
|
LocationPathPairs: locationPathPairs,
|
||||||
Paths: []dyn.Path{p},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remove the workspace prefix from the string.
|
// Remove the workspace prefix from the string.
|
||||||
|
|
|
@ -30,11 +30,19 @@ func (m *setRunAs) Name() string {
|
||||||
return "SetRunAs"
|
return "SetRunAs"
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportRunAsNotSupported(resourceType string, location dyn.Location, currentUser string, runAsUser string) diag.Diagnostics {
|
|
||||||
|
// TODO: CONTINUE with transformation to pair and test this.
|
||||||
|
func reportRunAsNotSupported(resourceType string, location dyn.Location, path dyn.Path, currentUser string, runAsUser string) diag.Diagnostics {
|
||||||
return diag.Diagnostics{{
|
return diag.Diagnostics{{
|
||||||
Summary: fmt.Sprintf("%s do not support a setting a run_as user that is different from the owner.\n"+
|
Summary: fmt.Sprintf("%s do not support a setting a run_as user that is different from the owner.\n"+
|
||||||
"Current identity: %s. Run as identity: %s.\n"+
|
"Current identity: %s. Run as identity: %s.\n"+
|
||||||
"See https://docs.databricks.com/dev-tools/bundles/run-as.html to learn more about the run_as property.", resourceType, currentUser, runAsUser),
|
"See https://docs.databricks.com/dev-tools/bundles/run-as.html to learn more about the run_as property.", resourceType, currentUser, runAsUser),
|
||||||
|
LocationPathPairs: []diag.LocationPathPair{
|
||||||
|
{
|
||||||
|
L: location,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
Locations: []dyn.Location{location},
|
Locations: []dyn.Location{location},
|
||||||
Severity: diag.Error,
|
Severity: diag.Error,
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -112,18 +112,19 @@ func renderSummaryTemplate(out io.Writer, b *bundle.Bundle, diags diag.Diagnosti
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
|
func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
|
||||||
|
// TODO: test this.
|
||||||
for _, d := range diags {
|
for _, d := range diags {
|
||||||
for i := range d.Locations {
|
for i := range d.LocationPathPairs {
|
||||||
if b == nil {
|
if b == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make location relative to bundle root
|
// Make location relative to bundle root
|
||||||
if d.Locations[i].File != "" {
|
if d.LocationPathPairs[i].L.File != "" {
|
||||||
out, err := filepath.Rel(b.BundleRootPath, d.Locations[i].File)
|
out, err := filepath.Rel(b.BundleRootPath, d.LocationPathPairs[i].L.File)
|
||||||
// if we can't relativize the path, just use path as-is
|
// if we can't relativize the path, just use path as-is
|
||||||
if err == nil {
|
if err == nil {
|
||||||
d.Locations[i].File = out
|
d.LocationPathPairs[i].L.File = out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,10 +394,7 @@ func fancyJSON(v any) ([]byte, error) {
|
||||||
|
|
||||||
const errorTemplate = `{{ "Error" | red }}: {{ .Summary }}
|
const errorTemplate = `{{ "Error" | red }}: {{ .Summary }}
|
||||||
{{- range $index, $element := .Paths }}
|
{{- range $index, $element := .Paths }}
|
||||||
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.P.String | green }} in {{ $element.L.String | cyan }}
|
||||||
{{- end }}
|
|
||||||
{{- range $index, $element := .Locations }}
|
|
||||||
{{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Detail }}
|
{{- if .Detail }}
|
||||||
|
|
||||||
|
@ -406,12 +403,11 @@ const errorTemplate = `{{ "Error" | red }}: {{ .Summary }}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// TODO: Only print "at" and "in" if both are not nil.
|
||||||
|
// TODO: also add tests for this.
|
||||||
const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
|
const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
|
||||||
{{- range $index, $element := .Paths }}
|
{{- range $index, $element := .Paths }}
|
||||||
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.P.String | green }} in {{ $element.L.String | cyan }}
|
||||||
{{- end }}
|
|
||||||
{{- range $index, $element := .Locations }}
|
|
||||||
{{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Detail }}
|
{{- if .Detail }}
|
||||||
|
|
||||||
|
@ -420,23 +416,9 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
// const recommendationTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }}
|
|
||||||
// {{- range $index, $element := .Paths }}
|
|
||||||
// {{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
|
||||||
// {{- end }}
|
|
||||||
// {{- range $index, $element := .Locations }}
|
|
||||||
// {{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }}
|
|
||||||
// {{- end }}
|
|
||||||
// {{- if .Detail }}
|
|
||||||
|
|
||||||
// {{ .Detail }}
|
|
||||||
// {{- end }}
|
|
||||||
|
|
||||||
// `
|
|
||||||
|
|
||||||
const recommendationTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }}
|
const recommendationTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }}
|
||||||
{{- range $index, $element := .LocationPathPairs}}
|
{{- range $index, $element := .LocationPathPairs}}
|
||||||
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.L.String | green }} in {{ $element.P.String | cyan }}
|
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.P.String | green }} in {{ $element.L.String | cyan }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Detail }}
|
{{- if .Detail }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue