Compare commits

..

No commits in common. "dda138fa63163d87ff78d6e757c8bf3fdf2937b9" and "f6232f5aaec40812893bef5b04fa34b83327ced6" have entirely different histories.

209 changed files with 1752 additions and 6996 deletions

View File

@ -11,7 +11,6 @@
"toolchain": { "toolchain": {
"required": ["go"], "required": ["go"],
"post_generate": [ "post_generate": [
"go test -timeout 240s -run TestConsistentDatabricksSdkVersion github.com/databricks/cli/internal/build",
"go run ./bundle/internal/schema/*.go ./bundle/schema/jsonschema.json", "go run ./bundle/internal/schema/*.go ./bundle/schema/jsonschema.json",
"echo 'bundle/internal/tf/schema/\\*.go linguist-generated=true' >> ./.gitattributes", "echo 'bundle/internal/tf/schema/\\*.go linguist-generated=true' >> ./.gitattributes",
"echo 'go.sum linguist-generated=true' >> ./.gitattributes", "echo 'go.sum linguist-generated=true' >> ./.gitattributes",

View File

@ -5,7 +5,6 @@ package {{(.TrimPrefix "account").SnakeName}}
import ( import (
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/databricks-sdk-go/service/{{.Package.Name}}" "github.com/databricks/databricks-sdk-go/service/{{.Package.Name}}"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -232,15 +231,9 @@ func new{{.PascalName}}() *cobra.Command {
{{- if .Request }} {{- if .Request }}
{{ if .CanUseJson }} {{ if .CanUseJson }}
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req) err = {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
}{{end}}{{ if .MustUseJson }}else { }{{end}}{{ if .MustUseJson }}else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -1,65 +0,0 @@
package mutator
import (
"context"
"net/url"
"strconv"
"strings"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/diag"
)
type initializeURLs struct {
}
// InitializeURLs makes sure the URL field of each resource is configured.
// NOTE: since this depends on an extra API call, this mutator adds some extra
// latency. As such, it should only be used when needed.
// This URL field is used for the output of the 'bundle summary' CLI command.
func InitializeURLs() bundle.Mutator {
return &initializeURLs{}
}
func (m *initializeURLs) Name() string {
return "InitializeURLs"
}
func (m *initializeURLs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
workspaceId, err := b.WorkspaceClient().CurrentWorkspaceID(ctx)
if err != nil {
return diag.FromErr(err)
}
orgId := strconv.FormatInt(workspaceId, 10)
host := b.WorkspaceClient().Config.CanonicalHostName()
initializeForWorkspace(b, orgId, host)
return nil
}
func initializeForWorkspace(b *bundle.Bundle, orgId string, host string) error {
baseURL, err := url.Parse(host)
if err != nil {
return err
}
// Add ?o=<workspace id> only if <workspace id> wasn't in the subdomain already.
// The ?o= is needed when vanity URLs / legacy workspace URLs are used.
// If it's not needed we prefer to leave it out since these URLs are rather
// long for most terminals.
//
// See https://docs.databricks.com/en/workspace/workspace-details.html for
// further reading about the '?o=' suffix.
if !strings.Contains(baseURL.Hostname(), orgId) {
values := baseURL.Query()
values.Add("o", orgId)
baseURL.RawQuery = values.Encode()
}
for _, group := range b.Config.Resources.AllResources() {
for _, r := range group.Resources {
r.InitializeURL(*baseURL)
}
}
return nil
}

View File

@ -1,130 +0,0 @@
package mutator
import (
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/ml"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/databricks/databricks-sdk-go/service/serving"
"github.com/stretchr/testify/require"
)
func TestInitializeURLs(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
Host: "https://mycompany.databricks.com/",
},
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
ID: "1",
JobSettings: &jobs.JobSettings{Name: "job1"},
},
},
Pipelines: map[string]*resources.Pipeline{
"pipeline1": {
ID: "3",
PipelineSpec: &pipelines.PipelineSpec{Name: "pipeline1"},
},
},
Experiments: map[string]*resources.MlflowExperiment{
"experiment1": {
ID: "4",
Experiment: &ml.Experiment{Name: "experiment1"},
},
},
Models: map[string]*resources.MlflowModel{
"model1": {
ID: "a model uses its name for identifier",
Model: &ml.Model{Name: "a model uses its name for identifier"},
},
},
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
"servingendpoint1": {
ID: "my_serving_endpoint",
CreateServingEndpoint: &serving.CreateServingEndpoint{
Name: "my_serving_endpoint",
},
},
},
RegisteredModels: map[string]*resources.RegisteredModel{
"registeredmodel1": {
ID: "8",
CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{
Name: "my_registered_model",
},
},
},
QualityMonitors: map[string]*resources.QualityMonitor{
"qualityMonitor1": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "catalog.schema.qualityMonitor1",
},
},
},
Schemas: map[string]*resources.Schema{
"schema1": {
ID: "catalog.schema",
CreateSchema: &catalog.CreateSchema{
Name: "schema",
},
},
},
Clusters: map[string]*resources.Cluster{
"cluster1": {
ID: "1017-103929-vlr7jzcf",
ClusterSpec: &compute.ClusterSpec{
ClusterName: "cluster1",
},
},
},
},
},
}
expectedURLs := map[string]string{
"job1": "https://mycompany.databricks.com/jobs/1?o=123456",
"pipeline1": "https://mycompany.databricks.com/pipelines/3?o=123456",
"experiment1": "https://mycompany.databricks.com/ml/experiments/4?o=123456",
"model1": "https://mycompany.databricks.com/ml/models/a%20model%20uses%20its%20name%20for%20identifier?o=123456",
"servingendpoint1": "https://mycompany.databricks.com/ml/endpoints/my_serving_endpoint?o=123456",
"registeredmodel1": "https://mycompany.databricks.com/explore/data/models/8?o=123456",
"qualityMonitor1": "https://mycompany.databricks.com/explore/data/catalog/schema/qualityMonitor1?o=123456",
"schema1": "https://mycompany.databricks.com/explore/data/catalog/schema?o=123456",
"cluster1": "https://mycompany.databricks.com/compute/clusters/1017-103929-vlr7jzcf?o=123456",
}
initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
for _, group := range b.Config.Resources.AllResources() {
for key, r := range group.Resources {
require.Equal(t, expectedURLs[key], r.GetURL(), "Unexpected URL for "+key)
}
}
}
func TestInitializeURLsWithoutOrgId(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
ID: "1",
JobSettings: &jobs.JobSettings{Name: "job1"},
},
},
},
},
}
initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
}

View File

@ -699,9 +699,6 @@ func TestTranslatePathJobEnvironments(t *testing.T) {
"../dist/env2.whl", "../dist/env2.whl",
"simplejson", "simplejson",
"/Workspace/Users/foo@bar.com/test.whl", "/Workspace/Users/foo@bar.com/test.whl",
"--extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple foobar",
"foobar --extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple",
"https://foo@bar.com/packages/pypi/simple",
}, },
}, },
}, },
@ -722,9 +719,6 @@ func TestTranslatePathJobEnvironments(t *testing.T) {
assert.Equal(t, strings.Join([]string{".", "dist", "env2.whl"}, string(os.PathSeparator)), b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[1]) assert.Equal(t, strings.Join([]string{".", "dist", "env2.whl"}, string(os.PathSeparator)), b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[1])
assert.Equal(t, "simplejson", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[2]) assert.Equal(t, "simplejson", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[2])
assert.Equal(t, "/Workspace/Users/foo@bar.com/test.whl", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[3]) assert.Equal(t, "/Workspace/Users/foo@bar.com/test.whl", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[3])
assert.Equal(t, "--extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple foobar", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[4])
assert.Equal(t, "foobar --extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[5])
assert.Equal(t, "https://foo@bar.com/packages/pypi/simple", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[6])
} }
func TestTranslatePathWithComplexVariables(t *testing.T) { func TestTranslatePathWithComplexVariables(t *testing.T) {

View File

@ -3,7 +3,6 @@ package config
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
"github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -31,53 +30,6 @@ type ConfigResource interface {
// Terraform equivalent name of the resource. For example "databricks_job" // Terraform equivalent name of the resource. For example "databricks_job"
// for jobs and "databricks_pipeline" for pipelines. // for jobs and "databricks_pipeline" for pipelines.
TerraformResourceName() string TerraformResourceName() string
// GetName returns the in-product name of the resource.
GetName() string
// GetURL returns the URL of the resource.
GetURL() string
// InitializeURL initializes the URL field of the resource.
InitializeURL(baseURL url.URL)
}
// ResourceGroup represents a group of resources of the same type.
// It includes a description of the resource type and a map of resources.
type ResourceGroup struct {
Description ResourceDescription
Resources map[string]ConfigResource
}
// collectResourceMap collects resources of a specific type into a ResourceGroup.
func collectResourceMap[T ConfigResource](
description ResourceDescription,
input map[string]T,
) ResourceGroup {
resources := make(map[string]ConfigResource)
for key, resource := range input {
resources[key] = resource
}
return ResourceGroup{
Description: description,
Resources: resources,
}
}
// AllResources returns all resources in the bundle grouped by their resource type.
func (r *Resources) AllResources() []ResourceGroup {
descriptions := SupportedResources()
return []ResourceGroup{
collectResourceMap(descriptions["jobs"], r.Jobs),
collectResourceMap(descriptions["pipelines"], r.Pipelines),
collectResourceMap(descriptions["models"], r.Models),
collectResourceMap(descriptions["experiments"], r.Experiments),
collectResourceMap(descriptions["model_serving_endpoints"], r.ModelServingEndpoints),
collectResourceMap(descriptions["registered_models"], r.RegisteredModels),
collectResourceMap(descriptions["quality_monitors"], r.QualityMonitors),
collectResourceMap(descriptions["schemas"], r.Schemas),
collectResourceMap(descriptions["clusters"], r.Clusters),
}
} }
func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) { func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) {
@ -109,71 +61,20 @@ func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error)
} }
type ResourceDescription struct { type ResourceDescription struct {
// Singular and plural name when used to refer to the configuration.
SingularName string SingularName string
PluralName string
// Singular and plural title when used in summaries / terminal UI.
SingularTitle string
PluralTitle string
} }
// The keys of the map corresponds to the resource key in the bundle configuration. // The keys of the map corresponds to the resource key in the bundle configuration.
func SupportedResources() map[string]ResourceDescription { func SupportedResources() map[string]ResourceDescription {
return map[string]ResourceDescription{ return map[string]ResourceDescription{
"jobs": { "jobs": {SingularName: "job"},
SingularName: "job", "pipelines": {SingularName: "pipeline"},
PluralName: "jobs", "models": {SingularName: "model"},
SingularTitle: "Job", "experiments": {SingularName: "experiment"},
PluralTitle: "Jobs", "model_serving_endpoints": {SingularName: "model_serving_endpoint"},
}, "registered_models": {SingularName: "registered_model"},
"pipelines": { "quality_monitors": {SingularName: "quality_monitor"},
SingularName: "pipeline", "schemas": {SingularName: "schema"},
PluralName: "pipelines", "clusters": {SingularName: "cluster"},
SingularTitle: "Pipeline",
PluralTitle: "Pipelines",
},
"models": {
SingularName: "model",
PluralName: "models",
SingularTitle: "Model",
PluralTitle: "Models",
},
"experiments": {
SingularName: "experiment",
PluralName: "experiments",
SingularTitle: "Experiment",
PluralTitle: "Experiments",
},
"model_serving_endpoints": {
SingularName: "model_serving_endpoint",
PluralName: "model_serving_endpoints",
SingularTitle: "Model Serving Endpoint",
PluralTitle: "Model Serving Endpoints",
},
"registered_models": {
SingularName: "registered_model",
PluralName: "registered_models",
SingularTitle: "Registered Model",
PluralTitle: "Registered Models",
},
"quality_monitors": {
SingularName: "quality_monitor",
PluralName: "quality_monitors",
SingularTitle: "Quality Monitor",
PluralTitle: "Quality Monitors",
},
"schemas": {
SingularName: "schema",
PluralName: "schemas",
SingularTitle: "Schema",
PluralTitle: "Schemas",
},
"clusters": {
SingularName: "cluster",
PluralName: "clusters",
SingularTitle: "Cluster",
PluralTitle: "Clusters",
},
} }
} }

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -15,7 +13,6 @@ type Cluster struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
*compute.ClusterSpec *compute.ClusterSpec
} }
@ -40,19 +37,3 @@ func (s *Cluster) Exists(ctx context.Context, w *databricks.WorkspaceClient, id
func (s *Cluster) TerraformResourceName() string { func (s *Cluster) TerraformResourceName() string {
return "databricks_cluster" return "databricks_cluster"
} }
func (s *Cluster) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("compute/clusters/%s", s.ID)
s.URL = baseURL.String()
}
func (s *Cluster) GetName() string {
return s.ClusterName
}
func (s *Cluster) GetURL() string {
return s.URL
}

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"strconv" "strconv"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
@ -16,7 +14,6 @@ type Job struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
*jobs.JobSettings *jobs.JobSettings
} }
@ -47,19 +44,3 @@ func (j *Job) Exists(ctx context.Context, w *databricks.WorkspaceClient, id stri
func (j *Job) TerraformResourceName() string { func (j *Job) TerraformResourceName() string {
return "databricks_job" return "databricks_job"
} }
func (j *Job) InitializeURL(baseURL url.URL) {
if j.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("jobs/%s", j.ID)
j.URL = baseURL.String()
}
func (j *Job) GetName() string {
return j.Name
}
func (j *Job) GetURL() string {
return j.URL
}

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -15,7 +13,6 @@ type MlflowExperiment struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
*ml.Experiment *ml.Experiment
} }
@ -42,19 +39,3 @@ func (s *MlflowExperiment) Exists(ctx context.Context, w *databricks.WorkspaceCl
func (s *MlflowExperiment) TerraformResourceName() string { func (s *MlflowExperiment) TerraformResourceName() string {
return "databricks_mlflow_experiment" return "databricks_mlflow_experiment"
} }
func (s *MlflowExperiment) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/experiments/%s", s.ID)
s.URL = baseURL.String()
}
func (s *MlflowExperiment) GetName() string {
return s.Name
}
func (s *MlflowExperiment) GetURL() string {
return s.URL
}

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -15,7 +13,6 @@ type MlflowModel struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
*ml.Model *ml.Model
} }
@ -42,19 +39,3 @@ func (s *MlflowModel) Exists(ctx context.Context, w *databricks.WorkspaceClient,
func (s *MlflowModel) TerraformResourceName() string { func (s *MlflowModel) TerraformResourceName() string {
return "databricks_mlflow_model" return "databricks_mlflow_model"
} }
func (s *MlflowModel) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/models/%s", s.ID)
s.URL = baseURL.String()
}
func (s *MlflowModel) GetName() string {
return s.Name
}
func (s *MlflowModel) GetURL() string {
return s.URL
}

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -25,7 +23,6 @@ type ModelServingEndpoint struct {
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
} }
func (s *ModelServingEndpoint) UnmarshalJSON(b []byte) error { func (s *ModelServingEndpoint) UnmarshalJSON(b []byte) error {
@ -50,19 +47,3 @@ func (s *ModelServingEndpoint) Exists(ctx context.Context, w *databricks.Workspa
func (s *ModelServingEndpoint) TerraformResourceName() string { func (s *ModelServingEndpoint) TerraformResourceName() string {
return "databricks_model_serving" return "databricks_model_serving"
} }
func (s *ModelServingEndpoint) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("ml/endpoints/%s", s.ID)
s.URL = baseURL.String()
}
func (s *ModelServingEndpoint) GetName() string {
return s.Name
}
func (s *ModelServingEndpoint) GetURL() string {
return s.URL
}

View File

@ -2,8 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -15,7 +13,6 @@ type Pipeline struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"` Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
*pipelines.PipelineSpec *pipelines.PipelineSpec
} }
@ -42,19 +39,3 @@ func (p *Pipeline) Exists(ctx context.Context, w *databricks.WorkspaceClient, id
func (p *Pipeline) TerraformResourceName() string { func (p *Pipeline) TerraformResourceName() string {
return "databricks_pipeline" return "databricks_pipeline"
} }
func (p *Pipeline) InitializeURL(baseURL url.URL) {
if p.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("pipelines/%s", p.ID)
p.URL = baseURL.String()
}
func (p *Pipeline) GetName() string {
return p.Name
}
func (s *Pipeline) GetURL() string {
return s.URL
}

View File

@ -2,9 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"strings"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -23,7 +20,6 @@ type QualityMonitor struct {
ID string `json:"id,omitempty" bundle:"readonly"` ID string `json:"id,omitempty" bundle:"readonly"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
} }
func (s *QualityMonitor) UnmarshalJSON(b []byte) error { func (s *QualityMonitor) UnmarshalJSON(b []byte) error {
@ -48,19 +44,3 @@ func (s *QualityMonitor) Exists(ctx context.Context, w *databricks.WorkspaceClie
func (s *QualityMonitor) TerraformResourceName() string { func (s *QualityMonitor) TerraformResourceName() string {
return "databricks_quality_monitor" return "databricks_quality_monitor"
} }
func (s *QualityMonitor) InitializeURL(baseURL url.URL) {
if s.TableName == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/%s", strings.ReplaceAll(s.TableName, ".", "/"))
s.URL = baseURL.String()
}
func (s *QualityMonitor) GetName() string {
return s.TableName
}
func (s *QualityMonitor) GetURL() string {
return s.URL
}

View File

@ -2,9 +2,6 @@ package resources
import ( import (
"context" "context"
"fmt"
"net/url"
"strings"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go"
@ -27,7 +24,6 @@ type RegisteredModel struct {
*catalog.CreateRegisteredModelRequest *catalog.CreateRegisteredModelRequest
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
} }
func (s *RegisteredModel) UnmarshalJSON(b []byte) error { func (s *RegisteredModel) UnmarshalJSON(b []byte) error {
@ -52,19 +48,3 @@ func (s *RegisteredModel) Exists(ctx context.Context, w *databricks.WorkspaceCli
func (s *RegisteredModel) TerraformResourceName() string { func (s *RegisteredModel) TerraformResourceName() string {
return "databricks_registered_model" return "databricks_registered_model"
} }
func (s *RegisteredModel) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/models/%s", strings.ReplaceAll(s.ID, ".", "/"))
s.URL = baseURL.String()
}
func (s *RegisteredModel) GetName() string {
return s.Name
}
func (s *RegisteredModel) GetURL() string {
return s.URL
}

View File

@ -1,12 +1,6 @@
package resources package resources
import ( import (
"context"
"fmt"
"net/url"
"strings"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal" "github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/catalog"
) )
@ -22,31 +16,6 @@ type Schema struct {
*catalog.CreateSchema *catalog.CreateSchema
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
URL string `json:"url,omitempty" bundle:"internal"`
}
func (s *Schema) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
return false, fmt.Errorf("schema.Exists() is not supported")
}
func (s *Schema) TerraformResourceName() string {
return "databricks_schema"
}
func (s *Schema) InitializeURL(baseURL url.URL) {
if s.ID == "" {
return
}
baseURL.Path = fmt.Sprintf("explore/data/%s", strings.ReplaceAll(s.ID, ".", "/"))
s.URL = baseURL.String()
}
func (s *Schema) GetURL() string {
return s.URL
}
func (s *Schema) GetName() string {
return s.Name
} }
func (s *Schema) UnmarshalJSON(b []byte) error { func (s *Schema) UnmarshalJSON(b []byte) error {

View File

@ -63,37 +63,17 @@ func TestCustomMarshallerIsImplemented(t *testing.T) {
} }
} }
func TestResourcesAllResourcesCompleteness(t *testing.T) {
r := Resources{}
rt := reflect.TypeOf(r)
// Collect set of includes resource types
var types []string
for _, group := range r.AllResources() {
types = append(types, group.Description.PluralName)
}
for i := 0; i < rt.NumField(); i++ {
field := rt.Field(i)
jsonTag := field.Tag.Get("json")
if idx := strings.Index(jsonTag, ","); idx != -1 {
jsonTag = jsonTag[:idx]
}
assert.Contains(t, types, jsonTag, "Field %s is missing in AllResources", field.Name)
}
}
func TestSupportedResources(t *testing.T) { func TestSupportedResources(t *testing.T) {
// Please add your resource to the SupportedResources() function in resources.go if you add a new resource. expected := map[string]ResourceDescription{}
actual := SupportedResources()
typ := reflect.TypeOf(Resources{}) typ := reflect.TypeOf(Resources{})
for i := 0; i < typ.NumField(); i++ { for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i) field := typ.Field(i)
jsonTags := strings.Split(field.Tag.Get("json"), ",") jsonTags := strings.Split(field.Tag.Get("json"), ",")
pluralName := jsonTags[0] singularName := strings.TrimSuffix(jsonTags[0], "s")
assert.Equal(t, actual[pluralName].PluralName, pluralName) expected[jsonTags[0]] = ResourceDescription{SingularName: singularName}
} }
// Please add your resource to the SupportedResources() function in resources.go
// if you are adding a new resource.
assert.Equal(t, expected, SupportedResources())
} }

View File

@ -2,7 +2,9 @@ package terraform
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"sort"
"github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/bundle/config/resources"
@ -12,6 +14,244 @@ import (
tfjson "github.com/hashicorp/terraform-json" tfjson "github.com/hashicorp/terraform-json"
) )
func conv(from any, to any) {
buf, _ := json.Marshal(from)
json.Unmarshal(buf, &to)
}
func convPermissions(acl []resources.Permission) *schema.ResourcePermissions {
if len(acl) == 0 {
return nil
}
resource := schema.ResourcePermissions{}
for _, ac := range acl {
resource.AccessControl = append(resource.AccessControl, convPermission(ac))
}
return &resource
}
func convPermission(ac resources.Permission) schema.ResourcePermissionsAccessControl {
dst := schema.ResourcePermissionsAccessControl{
PermissionLevel: ac.Level,
}
if ac.UserName != "" {
dst.UserName = ac.UserName
}
if ac.GroupName != "" {
dst.GroupName = ac.GroupName
}
if ac.ServicePrincipalName != "" {
dst.ServicePrincipalName = ac.ServicePrincipalName
}
return dst
}
func convGrants(acl []resources.Grant) *schema.ResourceGrants {
if len(acl) == 0 {
return nil
}
resource := schema.ResourceGrants{}
for _, ac := range acl {
resource.Grant = append(resource.Grant, schema.ResourceGrantsGrant{
Privileges: ac.Privileges,
Principal: ac.Principal,
})
}
return &resource
}
// BundleToTerraform converts resources in a bundle configuration
// to the equivalent Terraform JSON representation.
//
// Note: This function is an older implementation of the conversion logic. It is
// no longer used in any code paths. It is kept around to be used in tests.
// New resources do not need to modify this function and can instead can define
// the conversion login in the tfdyn package.
func BundleToTerraform(config *config.Root) *schema.Root {
tfroot := schema.NewRoot()
tfroot.Provider = schema.NewProviders()
tfroot.Resource = schema.NewResources()
noResources := true
for k, src := range config.Resources.Jobs {
noResources = false
var dst schema.ResourceJob
conv(src, &dst)
if src.JobSettings != nil {
sort.Slice(src.JobSettings.Tasks, func(i, j int) bool {
return src.JobSettings.Tasks[i].TaskKey < src.JobSettings.Tasks[j].TaskKey
})
for _, v := range src.Tasks {
var t schema.ResourceJobTask
conv(v, &t)
for _, v_ := range v.Libraries {
var l schema.ResourceJobTaskLibrary
conv(v_, &l)
t.Library = append(t.Library, l)
}
// Convert for_each_task libraries
if v.ForEachTask != nil {
for _, v_ := range v.ForEachTask.Task.Libraries {
var l schema.ResourceJobTaskForEachTaskTaskLibrary
conv(v_, &l)
t.ForEachTask.Task.Library = append(t.ForEachTask.Task.Library, l)
}
}
dst.Task = append(dst.Task, t)
}
for _, v := range src.JobClusters {
var t schema.ResourceJobJobCluster
conv(v, &t)
dst.JobCluster = append(dst.JobCluster, t)
}
// Unblock downstream work. To be addressed more generally later.
if git := src.GitSource; git != nil {
dst.GitSource = &schema.ResourceJobGitSource{
Url: git.GitUrl,
Branch: git.GitBranch,
Commit: git.GitCommit,
Provider: string(git.GitProvider),
Tag: git.GitTag,
}
}
for _, v := range src.Parameters {
var t schema.ResourceJobParameter
conv(v, &t)
dst.Parameter = append(dst.Parameter, t)
}
}
tfroot.Resource.Job[k] = &dst
// Configure permissions for this resource.
if rp := convPermissions(src.Permissions); rp != nil {
rp.JobId = fmt.Sprintf("${databricks_job.%s.id}", k)
tfroot.Resource.Permissions["job_"+k] = rp
}
}
for k, src := range config.Resources.Pipelines {
noResources = false
var dst schema.ResourcePipeline
conv(src, &dst)
if src.PipelineSpec != nil {
for _, v := range src.Libraries {
var l schema.ResourcePipelineLibrary
conv(v, &l)
dst.Library = append(dst.Library, l)
}
for _, v := range src.Clusters {
var l schema.ResourcePipelineCluster
conv(v, &l)
dst.Cluster = append(dst.Cluster, l)
}
for _, v := range src.Notifications {
var l schema.ResourcePipelineNotification
conv(v, &l)
dst.Notification = append(dst.Notification, l)
}
}
tfroot.Resource.Pipeline[k] = &dst
// Configure permissions for this resource.
if rp := convPermissions(src.Permissions); rp != nil {
rp.PipelineId = fmt.Sprintf("${databricks_pipeline.%s.id}", k)
tfroot.Resource.Permissions["pipeline_"+k] = rp
}
}
for k, src := range config.Resources.Models {
noResources = false
var dst schema.ResourceMlflowModel
conv(src, &dst)
tfroot.Resource.MlflowModel[k] = &dst
// Configure permissions for this resource.
if rp := convPermissions(src.Permissions); rp != nil {
rp.RegisteredModelId = fmt.Sprintf("${databricks_mlflow_model.%s.registered_model_id}", k)
tfroot.Resource.Permissions["mlflow_model_"+k] = rp
}
}
for k, src := range config.Resources.Experiments {
noResources = false
var dst schema.ResourceMlflowExperiment
conv(src, &dst)
tfroot.Resource.MlflowExperiment[k] = &dst
// Configure permissions for this resource.
if rp := convPermissions(src.Permissions); rp != nil {
rp.ExperimentId = fmt.Sprintf("${databricks_mlflow_experiment.%s.id}", k)
tfroot.Resource.Permissions["mlflow_experiment_"+k] = rp
}
}
for k, src := range config.Resources.ModelServingEndpoints {
noResources = false
var dst schema.ResourceModelServing
conv(src, &dst)
tfroot.Resource.ModelServing[k] = &dst
// Configure permissions for this resource.
if rp := convPermissions(src.Permissions); rp != nil {
rp.ServingEndpointId = fmt.Sprintf("${databricks_model_serving.%s.serving_endpoint_id}", k)
tfroot.Resource.Permissions["model_serving_"+k] = rp
}
}
for k, src := range config.Resources.RegisteredModels {
noResources = false
var dst schema.ResourceRegisteredModel
conv(src, &dst)
tfroot.Resource.RegisteredModel[k] = &dst
// Configure permissions for this resource.
if rp := convGrants(src.Grants); rp != nil {
rp.Function = fmt.Sprintf("${databricks_registered_model.%s.id}", k)
tfroot.Resource.Grants["registered_model_"+k] = rp
}
}
for k, src := range config.Resources.QualityMonitors {
noResources = false
var dst schema.ResourceQualityMonitor
conv(src, &dst)
tfroot.Resource.QualityMonitor[k] = &dst
}
for k, src := range config.Resources.Clusters {
noResources = false
var dst schema.ResourceCluster
conv(src, &dst)
tfroot.Resource.Cluster[k] = &dst
}
// We explicitly set "resource" to nil to omit it from a JSON encoding.
// This is required because the terraform CLI requires >= 1 resources defined
// if the "resource" property is used in a .tf.json file.
if noResources {
tfroot.Resource = nil
}
return tfroot
}
// BundleToTerraformWithDynValue converts resources in a bundle configuration // BundleToTerraformWithDynValue converts resources in a bundle configuration
// to the equivalent Terraform JSON representation. // to the equivalent Terraform JSON representation.
func BundleToTerraformWithDynValue(ctx context.Context, root dyn.Value) (*schema.Root, error) { func BundleToTerraformWithDynValue(ctx context.Context, root dyn.Value) (*schema.Root, error) {

View File

@ -2,6 +2,7 @@ package terraform
import ( import (
"context" "context"
"encoding/json"
"reflect" "reflect"
"testing" "testing"
@ -20,27 +21,6 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func produceTerraformConfiguration(t *testing.T, config config.Root) *schema.Root {
vin, err := convert.FromTyped(config, dyn.NilValue)
require.NoError(t, err)
out, err := BundleToTerraformWithDynValue(context.Background(), vin)
require.NoError(t, err)
return out
}
func convertToResourceStruct[T any](t *testing.T, resource *T, data any) {
require.NotNil(t, resource)
require.NotNil(t, data)
// Convert data to a dyn.Value.
vin, err := convert.FromTyped(data, dyn.NilValue)
require.NoError(t, err)
// Convert the dyn.Value to a struct.
err = convert.ToTyped(resource, vin)
require.NoError(t, err)
}
func TestBundleToTerraformJob(t *testing.T) { func TestBundleToTerraformJob(t *testing.T) {
var src = resources.Job{ var src = resources.Job{
JobSettings: &jobs.JobSettings{ JobSettings: &jobs.JobSettings{
@ -78,9 +58,8 @@ func TestBundleToTerraformJob(t *testing.T) {
}, },
} }
var resource schema.ResourceJob out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Job["my_job"].(*schema.ResourceJob)
convertToResourceStruct(t, &resource, out.Resource.Job["my_job"])
assert.Equal(t, "my job", resource.Name) assert.Equal(t, "my job", resource.Name)
assert.Len(t, resource.JobCluster, 1) assert.Len(t, resource.JobCluster, 1)
@ -89,6 +68,8 @@ func TestBundleToTerraformJob(t *testing.T) {
assert.Equal(t, "param1", resource.Parameter[0].Name) assert.Equal(t, "param1", resource.Parameter[0].Name)
assert.Equal(t, "param2", resource.Parameter[1].Name) assert.Equal(t, "param2", resource.Parameter[1].Name)
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformJobPermissions(t *testing.T) { func TestBundleToTerraformJobPermissions(t *testing.T) {
@ -109,14 +90,15 @@ func TestBundleToTerraformJobPermissions(t *testing.T) {
}, },
} }
var resource schema.ResourcePermissions out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Permissions["job_my_job"].(*schema.ResourcePermissions)
convertToResourceStruct(t, &resource, out.Resource.Permissions["job_my_job"])
assert.NotEmpty(t, resource.JobId) assert.NotEmpty(t, resource.JobId)
assert.Len(t, resource.AccessControl, 1) assert.Len(t, resource.AccessControl, 1)
assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName) assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName)
assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel) assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformJobTaskLibraries(t *testing.T) { func TestBundleToTerraformJobTaskLibraries(t *testing.T) {
@ -146,14 +128,15 @@ func TestBundleToTerraformJobTaskLibraries(t *testing.T) {
}, },
} }
var resource schema.ResourceJob out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Job["my_job"].(*schema.ResourceJob)
convertToResourceStruct(t, &resource, out.Resource.Job["my_job"])
assert.Equal(t, "my job", resource.Name) assert.Equal(t, "my job", resource.Name)
require.Len(t, resource.Task, 1) require.Len(t, resource.Task, 1)
require.Len(t, resource.Task[0].Library, 1) require.Len(t, resource.Task[0].Library, 1)
assert.Equal(t, "mlflow", resource.Task[0].Library[0].Pypi.Package) assert.Equal(t, "mlflow", resource.Task[0].Library[0].Pypi.Package)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformForEachTaskLibraries(t *testing.T) { func TestBundleToTerraformForEachTaskLibraries(t *testing.T) {
@ -189,14 +172,15 @@ func TestBundleToTerraformForEachTaskLibraries(t *testing.T) {
}, },
} }
var resource schema.ResourceJob out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Job["my_job"].(*schema.ResourceJob)
convertToResourceStruct(t, &resource, out.Resource.Job["my_job"])
assert.Equal(t, "my job", resource.Name) assert.Equal(t, "my job", resource.Name)
require.Len(t, resource.Task, 1) require.Len(t, resource.Task, 1)
require.Len(t, resource.Task[0].ForEachTask.Task.Library, 1) require.Len(t, resource.Task[0].ForEachTask.Task.Library, 1)
assert.Equal(t, "mlflow", resource.Task[0].ForEachTask.Task.Library[0].Pypi.Package) assert.Equal(t, "mlflow", resource.Task[0].ForEachTask.Task.Library[0].Pypi.Package)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformPipeline(t *testing.T) { func TestBundleToTerraformPipeline(t *testing.T) {
@ -246,9 +230,8 @@ func TestBundleToTerraformPipeline(t *testing.T) {
}, },
} }
var resource schema.ResourcePipeline out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Pipeline["my_pipeline"].(*schema.ResourcePipeline)
convertToResourceStruct(t, &resource, out.Resource.Pipeline["my_pipeline"])
assert.Equal(t, "my pipeline", resource.Name) assert.Equal(t, "my pipeline", resource.Name)
assert.Len(t, resource.Library, 2) assert.Len(t, resource.Library, 2)
@ -258,6 +241,8 @@ func TestBundleToTerraformPipeline(t *testing.T) {
assert.Equal(t, resource.Notification[1].Alerts, []string{"on-update-failure", "on-flow-failure"}) assert.Equal(t, resource.Notification[1].Alerts, []string{"on-update-failure", "on-flow-failure"})
assert.Equal(t, resource.Notification[1].EmailRecipients, []string{"jane@doe.com", "john@doe.com"}) assert.Equal(t, resource.Notification[1].EmailRecipients, []string{"jane@doe.com", "john@doe.com"})
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformPipelinePermissions(t *testing.T) { func TestBundleToTerraformPipelinePermissions(t *testing.T) {
@ -278,14 +263,15 @@ func TestBundleToTerraformPipelinePermissions(t *testing.T) {
}, },
} }
var resource schema.ResourcePermissions out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Permissions["pipeline_my_pipeline"].(*schema.ResourcePermissions)
convertToResourceStruct(t, &resource, out.Resource.Permissions["pipeline_my_pipeline"])
assert.NotEmpty(t, resource.PipelineId) assert.NotEmpty(t, resource.PipelineId)
assert.Len(t, resource.AccessControl, 1) assert.Len(t, resource.AccessControl, 1)
assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName) assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName)
assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel) assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformModel(t *testing.T) { func TestBundleToTerraformModel(t *testing.T) {
@ -314,9 +300,8 @@ func TestBundleToTerraformModel(t *testing.T) {
}, },
} }
var resource schema.ResourceMlflowModel out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.MlflowModel["my_model"].(*schema.ResourceMlflowModel)
convertToResourceStruct(t, &resource, out.Resource.MlflowModel["my_model"])
assert.Equal(t, "name", resource.Name) assert.Equal(t, "name", resource.Name)
assert.Equal(t, "description", resource.Description) assert.Equal(t, "description", resource.Description)
@ -326,6 +311,8 @@ func TestBundleToTerraformModel(t *testing.T) {
assert.Equal(t, "k2", resource.Tags[1].Key) assert.Equal(t, "k2", resource.Tags[1].Key)
assert.Equal(t, "v2", resource.Tags[1].Value) assert.Equal(t, "v2", resource.Tags[1].Value)
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformModelPermissions(t *testing.T) { func TestBundleToTerraformModelPermissions(t *testing.T) {
@ -349,14 +336,15 @@ func TestBundleToTerraformModelPermissions(t *testing.T) {
}, },
} }
var resource schema.ResourcePermissions out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Permissions["mlflow_model_my_model"].(*schema.ResourcePermissions)
convertToResourceStruct(t, &resource, out.Resource.Permissions["mlflow_model_my_model"])
assert.NotEmpty(t, resource.RegisteredModelId) assert.NotEmpty(t, resource.RegisteredModelId)
assert.Len(t, resource.AccessControl, 1) assert.Len(t, resource.AccessControl, 1)
assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName) assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName)
assert.Equal(t, "CAN_READ", resource.AccessControl[0].PermissionLevel) assert.Equal(t, "CAN_READ", resource.AccessControl[0].PermissionLevel)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformExperiment(t *testing.T) { func TestBundleToTerraformExperiment(t *testing.T) {
@ -374,12 +362,13 @@ func TestBundleToTerraformExperiment(t *testing.T) {
}, },
} }
var resource schema.ResourceMlflowExperiment out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.MlflowExperiment["my_experiment"].(*schema.ResourceMlflowExperiment)
convertToResourceStruct(t, &resource, out.Resource.MlflowExperiment["my_experiment"])
assert.Equal(t, "name", resource.Name) assert.Equal(t, "name", resource.Name)
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformExperimentPermissions(t *testing.T) { func TestBundleToTerraformExperimentPermissions(t *testing.T) {
@ -403,14 +392,15 @@ func TestBundleToTerraformExperimentPermissions(t *testing.T) {
}, },
} }
var resource schema.ResourcePermissions out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Permissions["mlflow_experiment_my_experiment"].(*schema.ResourcePermissions)
convertToResourceStruct(t, &resource, out.Resource.Permissions["mlflow_experiment_my_experiment"])
assert.NotEmpty(t, resource.ExperimentId) assert.NotEmpty(t, resource.ExperimentId)
assert.Len(t, resource.AccessControl, 1) assert.Len(t, resource.AccessControl, 1)
assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName) assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName)
assert.Equal(t, "CAN_READ", resource.AccessControl[0].PermissionLevel) assert.Equal(t, "CAN_READ", resource.AccessControl[0].PermissionLevel)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformModelServing(t *testing.T) { func TestBundleToTerraformModelServing(t *testing.T) {
@ -446,9 +436,8 @@ func TestBundleToTerraformModelServing(t *testing.T) {
}, },
} }
var resource schema.ResourceModelServing out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.ModelServing["my_model_serving_endpoint"].(*schema.ResourceModelServing)
convertToResourceStruct(t, &resource, out.Resource.ModelServing["my_model_serving_endpoint"])
assert.Equal(t, "name", resource.Name) assert.Equal(t, "name", resource.Name)
assert.Equal(t, "model_name", resource.Config.ServedModels[0].ModelName) assert.Equal(t, "model_name", resource.Config.ServedModels[0].ModelName)
@ -458,6 +447,8 @@ func TestBundleToTerraformModelServing(t *testing.T) {
assert.Equal(t, "model_name-1", resource.Config.TrafficConfig.Routes[0].ServedModelName) assert.Equal(t, "model_name-1", resource.Config.TrafficConfig.Routes[0].ServedModelName)
assert.Equal(t, 100, resource.Config.TrafficConfig.Routes[0].TrafficPercentage) assert.Equal(t, 100, resource.Config.TrafficConfig.Routes[0].TrafficPercentage)
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformModelServingPermissions(t *testing.T) { func TestBundleToTerraformModelServingPermissions(t *testing.T) {
@ -499,14 +490,15 @@ func TestBundleToTerraformModelServingPermissions(t *testing.T) {
}, },
} }
var resource schema.ResourcePermissions out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Permissions["model_serving_my_model_serving_endpoint"].(*schema.ResourcePermissions)
convertToResourceStruct(t, &resource, out.Resource.Permissions["model_serving_my_model_serving_endpoint"])
assert.NotEmpty(t, resource.ServingEndpointId) assert.NotEmpty(t, resource.ServingEndpointId)
assert.Len(t, resource.AccessControl, 1) assert.Len(t, resource.AccessControl, 1)
assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName) assert.Equal(t, "jane@doe.com", resource.AccessControl[0].UserName)
assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel) assert.Equal(t, "CAN_VIEW", resource.AccessControl[0].PermissionLevel)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformRegisteredModel(t *testing.T) { func TestBundleToTerraformRegisteredModel(t *testing.T) {
@ -527,15 +519,16 @@ func TestBundleToTerraformRegisteredModel(t *testing.T) {
}, },
} }
var resource schema.ResourceRegisteredModel out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.RegisteredModel["my_registered_model"].(*schema.ResourceRegisteredModel)
convertToResourceStruct(t, &resource, out.Resource.RegisteredModel["my_registered_model"])
assert.Equal(t, "name", resource.Name) assert.Equal(t, "name", resource.Name)
assert.Equal(t, "catalog", resource.CatalogName) assert.Equal(t, "catalog", resource.CatalogName)
assert.Equal(t, "schema", resource.SchemaName) assert.Equal(t, "schema", resource.SchemaName)
assert.Equal(t, "comment", resource.Comment) assert.Equal(t, "comment", resource.Comment)
assert.Nil(t, out.Data) assert.Nil(t, out.Data)
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformRegisteredModelGrants(t *testing.T) { func TestBundleToTerraformRegisteredModelGrants(t *testing.T) {
@ -561,14 +554,15 @@ func TestBundleToTerraformRegisteredModelGrants(t *testing.T) {
}, },
} }
var resource schema.ResourceGrants out := BundleToTerraform(&config)
out := produceTerraformConfiguration(t, config) resource := out.Resource.Grants["registered_model_my_registered_model"].(*schema.ResourceGrants)
convertToResourceStruct(t, &resource, out.Resource.Grants["registered_model_my_registered_model"])
assert.NotEmpty(t, resource.Function) assert.NotEmpty(t, resource.Function)
assert.Len(t, resource.Grant, 1) assert.Len(t, resource.Grant, 1)
assert.Equal(t, "jane@doe.com", resource.Grant[0].Principal) assert.Equal(t, "jane@doe.com", resource.Grant[0].Principal)
assert.Equal(t, "EXECUTE", resource.Grant[0].Privileges[0]) assert.Equal(t, "EXECUTE", resource.Grant[0].Privileges[0])
bundleToTerraformEquivalenceTest(t, &config)
} }
func TestBundleToTerraformDeletedResources(t *testing.T) { func TestBundleToTerraformDeletedResources(t *testing.T) {
@ -1160,3 +1154,25 @@ func AssertFullResourceCoverage(t *testing.T, config *config.Root) {
} }
} }
} }
func assertEqualTerraformRoot(t *testing.T, a, b *schema.Root) {
ba, err := json.Marshal(a)
require.NoError(t, err)
bb, err := json.Marshal(b)
require.NoError(t, err)
assert.JSONEq(t, string(ba), string(bb))
}
func bundleToTerraformEquivalenceTest(t *testing.T, config *config.Root) {
t.Run("dyn equivalence", func(t *testing.T) {
tf1 := BundleToTerraform(config)
vin, err := convert.FromTyped(config, dyn.NilValue)
require.NoError(t, err)
tf2, err := BundleToTerraformWithDynValue(context.Background(), vin)
require.NoError(t, err)
// Compare roots
assertEqualTerraformRoot(t, tf1, tf2)
})
}

View File

@ -40,7 +40,7 @@ func (clusterConverter) Convert(ctx context.Context, key string, vin dyn.Value,
// Configure permissions for this resource. // Configure permissions for this resource.
if permissions := convertPermissionsResource(ctx, vin); permissions != nil { if permissions := convertPermissionsResource(ctx, vin); permissions != nil {
permissions.ClusterId = fmt.Sprintf("${databricks_cluster.%s.id}", key) permissions.JobId = fmt.Sprintf("${databricks_cluster.%s.id}", key)
out.Permissions["cluster_"+key] = permissions out.Permissions["cluster_"+key] = permissions
} }

View File

@ -81,7 +81,7 @@ func TestConvertCluster(t *testing.T) {
// Assert equality on the permissions // Assert equality on the permissions
assert.Equal(t, &schema.ResourcePermissions{ assert.Equal(t, &schema.ResourcePermissions{
ClusterId: "${databricks_cluster.my_cluster.id}", JobId: "${databricks_cluster.my_cluster.id}",
AccessControl: []schema.ResourcePermissionsAccessControl{ AccessControl: []schema.ResourcePermissionsAccessControl{
{ {
PermissionLevel: "CAN_RUN", PermissionLevel: "CAN_RUN",

View File

@ -57,12 +57,6 @@ func IsLibraryLocal(dep string) bool {
} }
} }
// If the dependency starts with --, it's a pip flag option which is a valid
// entry for environment dependencies but not a local path
if containsPipFlag(dep) {
return false
}
// If the dependency is a requirements file, it's not a valid local path // If the dependency is a requirements file, it's not a valid local path
if strings.HasPrefix(dep, "-r") { if strings.HasPrefix(dep, "-r") {
return false return false
@ -76,11 +70,6 @@ func IsLibraryLocal(dep string) bool {
return IsLocalPath(dep) return IsLocalPath(dep)
} }
func containsPipFlag(input string) bool {
re := regexp.MustCompile(`--[a-zA-Z0-9-]+`)
return re.MatchString(input)
}
// ^[a-zA-Z0-9\-_]+: Matches the package name, allowing alphanumeric characters, dashes (-), and underscores (_). // ^[a-zA-Z0-9\-_]+: Matches the package name, allowing alphanumeric characters, dashes (-), and underscores (_).
// \[.*\])?: Optionally matches any extras specified in square brackets, e.g., [security]. // \[.*\])?: Optionally matches any extras specified in square brackets, e.g., [security].
// ((==|!=|<=|>=|~=|>|<)\d+(\.\d+){0,2}(\.\*)?): Optionally matches version specifiers, supporting various operators (==, !=, etc.) followed by a version number (e.g., 2.25.1). // ((==|!=|<=|>=|~=|>|<)\d+(\.\d+){0,2}(\.\*)?): Optionally matches version specifiers, supporting various operators (==, !=, etc.) followed by a version number (e.g., 2.25.1).

View File

@ -13,6 +13,7 @@ import (
const CAN_MANAGE = "CAN_MANAGE" const CAN_MANAGE = "CAN_MANAGE"
const CAN_VIEW = "CAN_VIEW" const CAN_VIEW = "CAN_VIEW"
const CAN_RUN = "CAN_RUN" const CAN_RUN = "CAN_RUN"
const IS_OWNER = "IS_OWNER"
var allowedLevels = []string{CAN_MANAGE, CAN_VIEW, CAN_RUN} var allowedLevels = []string{CAN_MANAGE, CAN_VIEW, CAN_RUN}
var levelsMap = map[string](map[string]string){ var levelsMap = map[string](map[string]string){

View File

@ -1,56 +0,0 @@
package permissions
import (
"context"
"fmt"
"strings"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/diag"
)
type validateSharedRootPermissions struct {
}
func ValidateSharedRootPermissions() bundle.Mutator {
return &validateSharedRootPermissions{}
}
func (*validateSharedRootPermissions) Name() string {
return "ValidateSharedRootPermissions"
}
func (*validateSharedRootPermissions) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
if isWorkspaceSharedRoot(b.Config.Workspace.RootPath) {
return isUsersGroupPermissionSet(b)
}
return nil
}
func isWorkspaceSharedRoot(path string) bool {
return strings.HasPrefix(path, "/Workspace/Shared/")
}
// isUsersGroupPermissionSet checks that top-level permissions set for bundle contain group_name: users with CAN_MANAGE permission.
func isUsersGroupPermissionSet(b *bundle.Bundle) diag.Diagnostics {
var diags diag.Diagnostics
allUsers := false
for _, p := range b.Config.Permissions {
if p.GroupName == "users" && p.Level == CAN_MANAGE {
allUsers = true
break
}
}
if !allUsers {
diags = diags.Append(diag.Diagnostic{
Severity: diag.Warning,
Summary: fmt.Sprintf("the bundle root path %s is writable by all workspace users", b.Config.Workspace.RootPath),
Detail: "The bundle is configured to use /Workspace/Shared, which will give read/write access to all users. If this is intentional, add CAN_MANAGE for 'group_name: users' permission to your bundle configuration. If the deployment should be restricted, move it to a restricted folder such as /Workspace/Users/<username or principal name>.",
})
}
return diags
}

View File

@ -1,66 +0,0 @@
package permissions
import (
"context"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/require"
)
func TestValidateSharedRootPermissionsForShared(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
RootPath: "/Workspace/Shared/foo/bar",
},
Permissions: []resources.Permission{
{Level: CAN_MANAGE, GroupName: "users"},
},
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job_1": {JobSettings: &jobs.JobSettings{Name: "job_1"}},
"job_2": {JobSettings: &jobs.JobSettings{Name: "job_2"}},
},
},
},
}
m := mocks.NewMockWorkspaceClient(t)
b.SetWorkpaceClient(m.WorkspaceClient)
diags := bundle.Apply(context.Background(), b, bundle.Seq(ValidateSharedRootPermissions()))
require.Empty(t, diags)
}
func TestValidateSharedRootPermissionsForSharedError(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
RootPath: "/Workspace/Shared/foo/bar",
},
Permissions: []resources.Permission{
{Level: CAN_MANAGE, UserName: "foo@bar.com"},
},
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job_1": {JobSettings: &jobs.JobSettings{Name: "job_1"}},
"job_2": {JobSettings: &jobs.JobSettings{Name: "job_2"}},
},
},
},
}
m := mocks.NewMockWorkspaceClient(t)
b.SetWorkpaceClient(m.WorkspaceClient)
diags := bundle.Apply(context.Background(), b, bundle.Seq(ValidateSharedRootPermissions()))
require.Len(t, diags, 1)
require.Equal(t, "the bundle root path /Workspace/Shared/foo/bar is writable by all workspace users", diags[0].Summary)
require.Equal(t, diag.Warning, diags[0].Severity)
}

View File

@ -16,10 +16,6 @@ func ApplyWorkspaceRootPermissions() bundle.Mutator {
return &workspaceRootPermissions{} return &workspaceRootPermissions{}
} }
func (*workspaceRootPermissions) Name() string {
return "ApplyWorkspaceRootPermissions"
}
// Apply implements bundle.Mutator. // Apply implements bundle.Mutator.
func (*workspaceRootPermissions) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { func (*workspaceRootPermissions) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
err := giveAccessForWorkspaceRoot(ctx, b) err := giveAccessForWorkspaceRoot(ctx, b)
@ -30,6 +26,10 @@ func (*workspaceRootPermissions) Apply(ctx context.Context, b *bundle.Bundle) di
return nil return nil
} }
func (*workspaceRootPermissions) Name() string {
return "ApplyWorkspaceRootPermissions"
}
func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error { func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error {
permissions := make([]workspace.WorkspaceObjectAccessControlRequest, 0) permissions := make([]workspace.WorkspaceObjectAccessControlRequest, 0)

View File

@ -69,6 +69,6 @@ func TestApplyWorkspaceRootPermissions(t *testing.T) {
WorkspaceObjectType: "directories", WorkspaceObjectType: "directories",
}).Return(nil, nil) }).Return(nil, nil)
diags := bundle.Apply(context.Background(), b, bundle.Seq(ValidateSharedRootPermissions(), ApplyWorkspaceRootPermissions())) diags := bundle.Apply(context.Background(), b, ApplyWorkspaceRootPermissions())
require.Empty(t, diags) require.NoError(t, diags.Error())
} }

View File

@ -76,11 +76,8 @@ func Initialize() bundle.Mutator {
mutator.TranslatePaths(), mutator.TranslatePaths(),
trampoline.WrapperWarning(), trampoline.WrapperWarning(),
permissions.ValidateSharedRootPermissions(),
permissions.ApplyBundlePermissions(), permissions.ApplyBundlePermissions(),
permissions.FilterCurrentUser(), permissions.FilterCurrentUser(),
metadata.AnnotateJobs(), metadata.AnnotateJobs(),
metadata.AnnotatePipelines(), metadata.AnnotatePipelines(),
terraform.Initialize(), terraform.Initialize(),

View File

@ -1,16 +1,13 @@
package render package render
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"text/template" "text/template"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/databricks-sdk-go/service/iam"
"github.com/fatih/color" "github.com/fatih/color"
@ -31,7 +28,49 @@ var renderFuncMap = template.FuncMap{
}, },
} }
const summaryHeaderTemplate = `{{- if .Name -}} const errorTemplate = `{{ "Error" | red }}: {{ .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 warningTemplate = `{{ "Warning" | yellow }}: {{ .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 }}
{{- 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 summaryTemplate = `{{- if .Name -}}
Name: {{ .Name | bold }} Name: {{ .Name | bold }}
{{- if .Target }} {{- if .Target }}
Target: {{ .Target | bold }} Target: {{ .Target | bold }}
@ -48,30 +87,12 @@ Workspace:
Path: {{ .Path | bold }} Path: {{ .Path | bold }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{ end -}}`
const resourcesTemplate = `Resources: {{ end -}}
{{- range . }}
{{ .GroupName }}: {{ .Trailer }}
{{- range .Resources }}
{{ .Key | bold }}:
Name: {{ .Name }}
URL: {{ if .URL }}{{ .URL | cyan }}{{ else }}{{ "(not deployed)" | cyan }}{{ end }}
{{- end }}
{{- end }}
` `
type ResourceGroup struct {
GroupName string
Resources []ResourceInfo
}
type ResourceInfo struct {
Key string
Name string
URL string
}
func pluralize(n int, singular, plural string) string { func pluralize(n int, singular, plural string) string {
if n == 1 { if n == 1 {
return fmt.Sprintf("%d %s", n, singular) return fmt.Sprintf("%d %s", n, singular)
@ -94,20 +115,20 @@ func buildTrailer(diags diag.Diagnostics) string {
case len(parts) >= 3: case len(parts) >= 3:
first := strings.Join(parts[:len(parts)-1], ", ") first := strings.Join(parts[:len(parts)-1], ", ")
last := parts[len(parts)-1] last := parts[len(parts)-1]
return fmt.Sprintf("Found %s, and %s\n", first, last) return fmt.Sprintf("Found %s, and %s", first, last)
case len(parts) == 2: case len(parts) == 2:
return fmt.Sprintf("Found %s and %s\n", parts[0], parts[1]) return fmt.Sprintf("Found %s and %s", parts[0], parts[1])
case len(parts) == 1: case len(parts) == 1:
return fmt.Sprintf("Found %s\n", parts[0]) return fmt.Sprintf("Found %s", parts[0])
default: default:
// No diagnostics to print. // No diagnostics to print.
return color.GreenString("Validation OK!\n") return color.GreenString("Validation OK!")
} }
} }
func renderSummaryHeaderTemplate(out io.Writer, b *bundle.Bundle) error { func renderSummaryTemplate(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
if b == nil { if b == nil {
return renderSummaryHeaderTemplate(out, &bundle.Bundle{}) return renderSummaryTemplate(out, &bundle.Bundle{}, diags)
} }
var currentUser = &iam.User{} var currentUser = &iam.User{}
@ -118,20 +139,36 @@ func renderSummaryHeaderTemplate(out io.Writer, b *bundle.Bundle) error {
} }
} }
t := template.Must(template.New("summary").Funcs(renderFuncMap).Parse(summaryHeaderTemplate)) t := template.Must(template.New("summary").Funcs(renderFuncMap).Parse(summaryTemplate))
err := t.Execute(out, map[string]any{ err := t.Execute(out, map[string]any{
"Name": b.Config.Bundle.Name, "Name": b.Config.Bundle.Name,
"Target": b.Config.Bundle.Target, "Target": b.Config.Bundle.Target,
"User": currentUser.UserName, "User": currentUser.UserName,
"Path": b.Config.Workspace.RootPath, "Path": b.Config.Workspace.RootPath,
"Host": b.Config.Workspace.Host, "Host": b.Config.Workspace.Host,
"Trailer": buildTrailer(diags),
}) })
return err return err
} }
func renderDiagnosticsOnly(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error { func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
errorT := template.Must(template.New("error").Funcs(renderFuncMap).Parse(errorTemplate))
warningT := template.Must(template.New("warning").Funcs(renderFuncMap).Parse(warningTemplate))
recommendationT := template.Must(template.New("recommendation").Funcs(renderFuncMap).Parse(recommendationTemplate))
// Print errors and warnings.
for _, d := range diags { for _, d := range diags {
var t *template.Template
switch d.Severity {
case diag.Error:
t = errorT
case diag.Warning:
t = warningT
case diag.Recommendation:
t = recommendationT
}
for i := range d.Locations { for i := range d.Locations {
if b == nil { if b == nil {
break break
@ -146,9 +183,15 @@ func renderDiagnosticsOnly(out io.Writer, b *bundle.Bundle, diags diag.Diagnosti
} }
} }
} }
// Render the diagnostic with the appropriate template.
err := t.Execute(out, d)
if err != nil {
return fmt.Errorf("failed to render template: %w", err)
}
} }
return cmdio.RenderDiagnostics(out, diags) return nil
} }
// RenderOptions contains options for rendering diagnostics. // RenderOptions contains options for rendering diagnostics.
@ -158,73 +201,19 @@ type RenderOptions struct {
RenderSummaryTable bool RenderSummaryTable bool
} }
// RenderDiagnostics renders the diagnostics in a human-readable format. // RenderTextOutput renders the diagnostics in a human-readable format.
func RenderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics, opts RenderOptions) error { func RenderTextOutput(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics, opts RenderOptions) error {
err := renderDiagnosticsOnly(out, b, diags) err := renderDiagnostics(out, b, diags)
if err != nil { if err != nil {
return fmt.Errorf("failed to render diagnostics: %w", err) return fmt.Errorf("failed to render diagnostics: %w", err)
} }
if opts.RenderSummaryTable { if opts.RenderSummaryTable {
if b != nil { err = renderSummaryTemplate(out, b, diags)
err = renderSummaryHeaderTemplate(out, b) if err != nil {
if err != nil { return fmt.Errorf("failed to render summary: %w", err)
return fmt.Errorf("failed to render summary: %w", err)
}
io.WriteString(out, "\n")
} }
trailer := buildTrailer(diags)
io.WriteString(out, trailer)
} }
return nil return nil
} }
func RenderSummary(ctx context.Context, out io.Writer, b *bundle.Bundle) error {
if err := renderSummaryHeaderTemplate(out, b); err != nil {
return err
}
var resourceGroups []ResourceGroup
for _, group := range b.Config.Resources.AllResources() {
resources := make([]ResourceInfo, 0, len(group.Resources))
for key, resource := range group.Resources {
resources = append(resources, ResourceInfo{
Key: key,
Name: resource.GetName(),
URL: resource.GetURL(),
})
}
if len(resources) > 0 {
resourceGroups = append(resourceGroups, ResourceGroup{
GroupName: group.Description.PluralTitle,
Resources: resources,
})
}
}
if err := renderResourcesTemplate(out, resourceGroups); err != nil {
return fmt.Errorf("failed to render resources template: %w", err)
}
return nil
}
// Helper function to sort and render resource groups using the template
func renderResourcesTemplate(out io.Writer, resourceGroups []ResourceGroup) error {
// Sort everything to ensure consistent output
sort.Slice(resourceGroups, func(i, j int) bool {
return resourceGroups[i].GroupName < resourceGroups[j].GroupName
})
for _, group := range resourceGroups {
sort.Slice(group.Resources, func(i, j int) bool {
return group.Resources[i].Key < group.Resources[j].Key
})
}
t := template.Must(template.New("resources").Funcs(renderFuncMap).Parse(resourcesTemplate))
return t.Execute(out, resourceGroups)
}

View File

@ -2,21 +2,14 @@ package render
import ( import (
"bytes" "bytes"
"context"
"io"
"testing" "testing"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn"
"github.com/databricks/databricks-sdk-go/service/catalog" assert "github.com/databricks/cli/libs/dyn/dynassert"
"github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/databricks-sdk-go/service/iam"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/databricks/databricks-sdk-go/service/serving"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -333,7 +326,7 @@ func TestRenderTextOutput(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
writer := &bytes.Buffer{} writer := &bytes.Buffer{}
err := RenderDiagnostics(writer, tc.bundle, tc.diags, tc.opts) err := RenderTextOutput(writer, tc.bundle, tc.diags, tc.opts)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tc.expected, writer.String()) assert.Equal(t, tc.expected, writer.String())
@ -475,7 +468,7 @@ func TestRenderDiagnostics(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
writer := &bytes.Buffer{} writer := &bytes.Buffer{}
err := renderDiagnosticsOnly(writer, bundle, tc.diags) err := renderDiagnostics(writer, bundle, tc.diags)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tc.expected, writer.String()) assert.Equal(t, tc.expected, writer.String())
@ -486,105 +479,8 @@ func TestRenderDiagnostics(t *testing.T) {
func TestRenderSummaryTemplate_nilBundle(t *testing.T) { func TestRenderSummaryTemplate_nilBundle(t *testing.T) {
writer := &bytes.Buffer{} writer := &bytes.Buffer{}
err := renderSummaryHeaderTemplate(writer, nil) err := renderSummaryTemplate(writer, nil, nil)
require.NoError(t, err) require.NoError(t, err)
io.WriteString(writer, buildTrailer(nil))
assert.Equal(t, "Validation OK!\n", writer.String()) assert.Equal(t, "Validation OK!\n", writer.String())
} }
func TestRenderSummary(t *testing.T) {
ctx := context.Background()
// Create a mock bundle with various resources
b := &bundle.Bundle{
Config: config.Root{
Bundle: config.Bundle{
Name: "test-bundle",
Target: "test-target",
},
Workspace: config.Workspace{
Host: "https://mycompany.databricks.com/",
},
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
ID: "1",
URL: "https://url1",
JobSettings: &jobs.JobSettings{Name: "job1-name"},
},
"job2": {
ID: "2",
URL: "https://url2",
JobSettings: &jobs.JobSettings{Name: "job2-name"},
},
},
Pipelines: map[string]*resources.Pipeline{
"pipeline2": {
ID: "4",
// no URL
PipelineSpec: &pipelines.PipelineSpec{Name: "pipeline2-name"},
},
"pipeline1": {
ID: "3",
URL: "https://url3",
PipelineSpec: &pipelines.PipelineSpec{Name: "pipeline1-name"},
},
},
Schemas: map[string]*resources.Schema{
"schema1": {
ID: "catalog.schema",
CreateSchema: &catalog.CreateSchema{
Name: "schema",
},
// no URL
},
},
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
"endpoint1": {
ID: "7",
CreateServingEndpoint: &serving.CreateServingEndpoint{
Name: "my_serving_endpoint",
},
URL: "https://url4",
},
},
},
},
}
writer := &bytes.Buffer{}
err := RenderSummary(ctx, writer, b)
require.NoError(t, err)
expectedSummary := `Name: test-bundle
Target: test-target
Workspace:
Host: https://mycompany.databricks.com/
Resources:
Jobs:
job1:
Name: job1-name
URL: https://url1
job2:
Name: job2-name
URL: https://url2
Model Serving Endpoints:
endpoint1:
Name: my_serving_endpoint
URL: https://url4
Pipelines:
pipeline1:
Name: pipeline1-name
URL: https://url3
pipeline2:
Name: pipeline2-name
URL: (not deployed)
Schemas:
schema1:
Name: schema
URL: (not deployed)
`
assert.Equal(t, expectedSummary, writer.String())
}

View File

@ -1,33 +0,0 @@
bundle:
name: issue_1828
variables:
# One entry for each of the underlying YAML (or [dyn.Kind]) types.
# The test confirms we can convert to and from the typed configuration without losing information.
map:
default:
foo: bar
sequence:
default:
- foo
- bar
string:
default: foo
bool:
default: true
int:
default: 42
float:
default: 3.14
time:
default: 2021-01-01
nil:
default:

View File

@ -1,48 +0,0 @@
package config_tests
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIssue1828(t *testing.T) {
b := load(t, "./issue_1828")
if assert.Contains(t, b.Config.Variables, "map") {
assert.Equal(t, map[string]any{
"foo": "bar",
}, b.Config.Variables["map"].Default)
}
if assert.Contains(t, b.Config.Variables, "sequence") {
assert.Equal(t, []any{
"foo",
"bar",
}, b.Config.Variables["sequence"].Default)
}
if assert.Contains(t, b.Config.Variables, "string") {
assert.Equal(t, "foo", b.Config.Variables["string"].Default)
}
if assert.Contains(t, b.Config.Variables, "bool") {
assert.Equal(t, true, b.Config.Variables["bool"].Default)
}
if assert.Contains(t, b.Config.Variables, "int") {
assert.Equal(t, 42, b.Config.Variables["int"].Default)
}
if assert.Contains(t, b.Config.Variables, "float") {
assert.Equal(t, 3.14, b.Config.Variables["float"].Default)
}
if assert.Contains(t, b.Config.Variables, "time") {
assert.Equal(t, "2021-01-01", b.Config.Variables["time"].Default)
}
if assert.Contains(t, b.Config.Variables, "nil") {
assert.Equal(t, nil, b.Config.Variables["nil"].Default)
}
}

View File

@ -205,15 +205,9 @@ func newUpdateRuleSet() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateRuleSetJson.Unmarshal(&updateRuleSetReq) err = updateRuleSetJson.Unmarshal(&updateRuleSetReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -78,15 +78,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -322,15 +316,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -90,15 +90,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -129,15 +129,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -88,15 +88,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -326,15 +320,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.IntegrationId = args[0] updateReq.IntegrationId = args[0]

View File

@ -185,15 +185,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -107,15 +107,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -127,15 +127,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -97,15 +97,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -364,15 +358,9 @@ func newPatch() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := patchJson.Unmarshal(&patchReq) err = patchJson.Unmarshal(&patchReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -458,15 +446,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -132,15 +132,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -417,15 +411,9 @@ func newReplace() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := replaceJson.Unmarshal(&replaceReq) err = replaceJson.Unmarshal(&replaceReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
replaceReq.IpAccessListId = args[0] replaceReq.IpAccessListId = args[0]
@ -517,15 +505,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -162,15 +162,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -375,15 +369,9 @@ func newPatchStatus() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := patchStatusJson.Unmarshal(&patchStatusReq) err = patchStatusJson.Unmarshal(&patchStatusReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
patchStatusReq.LogDeliveryConfigurationId = args[0] patchStatusReq.LogDeliveryConfigurationId = args[0]

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &createReq.WorkspaceId) _, err = fmt.Sscan(args[0], &createReq.WorkspaceId)
@ -349,15 +343,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId)

View File

@ -80,15 +80,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -310,15 +304,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.MetastoreId = args[0] updateReq.MetastoreId = args[0]

View File

@ -96,15 +96,9 @@ func newCreateNetworkConnectivityConfiguration() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createNetworkConnectivityConfigurationJson.Unmarshal(&createNetworkConnectivityConfigurationReq) err = createNetworkConnectivityConfigurationJson.Unmarshal(&createNetworkConnectivityConfigurationReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -193,15 +187,9 @@ func newCreatePrivateEndpointRule() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createPrivateEndpointRuleJson.Unmarshal(&createPrivateEndpointRuleReq) err = createPrivateEndpointRuleJson.Unmarshal(&createPrivateEndpointRuleReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
createPrivateEndpointRuleReq.NetworkConnectivityConfigId = args[0] createPrivateEndpointRuleReq.NetworkConnectivityConfigId = args[0]

View File

@ -97,15 +97,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {

View File

@ -189,15 +189,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -109,15 +109,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -417,15 +411,9 @@ func newReplace() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := replaceJson.Unmarshal(&replaceReq) err = replaceJson.Unmarshal(&replaceReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
replaceReq.PrivateAccessSettingsId = args[0] replaceReq.PrivateAccessSettingsId = args[0]

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -321,15 +315,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.IntegrationId = args[0] updateReq.IntegrationId = args[0]

View File

@ -95,15 +95,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -364,15 +358,9 @@ func newPatch() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := patchJson.Unmarshal(&patchReq) err = patchJson.Unmarshal(&patchReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -460,15 +448,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -88,15 +88,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
createReq.MetastoreId = args[0] createReq.MetastoreId = args[0]
@ -346,15 +340,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.MetastoreId = args[0] updateReq.MetastoreId = args[0]

View File

@ -87,15 +87,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -80,15 +80,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }

View File

@ -103,15 +103,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -380,15 +374,9 @@ func newPatch() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := patchJson.Unmarshal(&patchReq) err = patchJson.Unmarshal(&patchReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -477,15 +465,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -104,15 +104,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {

View File

@ -273,15 +273,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId)

View File

@ -133,15 +133,9 @@ func newCreate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -557,15 +551,9 @@ func newUpdate() *cobra.Command {
a := root.AccountClient(ctx) a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -42,9 +42,9 @@ func makeCommand(method string) *cobra.Command {
var path = args[0] var path = args[0]
var request any var request any
diags := payload.Unmarshal(&request) err := payload.Unmarshal(&request)
if diags.HasError() { if err != nil {
return diags.Error() return err
} }
cfg := &config.Config{} cfg := &config.Config{}

View File

@ -78,7 +78,7 @@ func newDeployCommand() *cobra.Command {
} }
renderOpts := render.RenderOptions{RenderSummaryTable: false} renderOpts := render.RenderOptions{RenderSummaryTable: false}
err := render.RenderDiagnostics(cmd.OutOrStdout(), b, diags, renderOpts) err := render.RenderTextOutput(cmd.OutOrStdout(), b, diags, renderOpts)
if err != nil { if err != nil {
return fmt.Errorf("failed to render output: %w", err) return fmt.Errorf("failed to render output: %w", err)
} }

View File

@ -71,7 +71,7 @@ func (n *downloader) markNotebookForDownload(ctx context.Context, notebookPath *
ext := notebook.GetExtensionByLanguage(info) ext := notebook.GetExtensionByLanguage(info)
filename := path.Base(*notebookPath) + string(ext) filename := path.Base(*notebookPath) + ext
targetPath := filepath.Join(n.sourceDir, filename) targetPath := filepath.Join(n.sourceDir, filename)
n.files[targetPath] = *notebookPath n.files[targetPath] = *notebookPath

View File

@ -8,10 +8,8 @@ import (
"path/filepath" "path/filepath"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/deploy/terraform" "github.com/databricks/cli/bundle/deploy/terraform"
"github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/bundle/render"
"github.com/databricks/cli/cmd/bundle/utils" "github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
@ -21,8 +19,11 @@ import (
func newSummaryCommand() *cobra.Command { func newSummaryCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "summary", Use: "summary",
Short: "Summarize resources deployed by this bundle", Short: "Describe the bundle resources and their deployment states",
Args: root.NoArgs, Args: root.NoArgs,
// This command is currently intended for the Databricks VSCode extension only
Hidden: true,
} }
var forcePull bool var forcePull bool
@ -59,15 +60,14 @@ func newSummaryCommand() *cobra.Command {
} }
} }
diags = bundle.Apply(ctx, b, diags = bundle.Apply(ctx, b, terraform.Load())
bundle.Seq(terraform.Load(), mutator.InitializeURLs()))
if err := diags.Error(); err != nil { if err := diags.Error(); err != nil {
return err return err
} }
switch root.OutputType(cmd) { switch root.OutputType(cmd) {
case flags.OutputText: case flags.OutputText:
return render.RenderSummary(ctx, cmd.OutOrStdout(), b) return fmt.Errorf("%w, only json output is supported", errors.ErrUnsupported)
case flags.OutputJSON: case flags.OutputJSON:
buf, err := json.MarshalIndent(b.Config, "", " ") buf, err := json.MarshalIndent(b.Config, "", " ")
if err != nil { if err != nil {

View File

@ -54,7 +54,7 @@ func newValidateCommand() *cobra.Command {
switch root.OutputType(cmd) { switch root.OutputType(cmd) {
case flags.OutputText: case flags.OutputText:
renderOpts := render.RenderOptions{RenderSummaryTable: true} renderOpts := render.RenderOptions{RenderSummaryTable: true}
err := render.RenderDiagnostics(cmd.OutOrStdout(), b, diags, renderOpts) err := render.RenderTextOutput(cmd.OutOrStdout(), b, diags, renderOpts)
if err != nil { if err != nil {
return fmt.Errorf("failed to render output: %w", err) return fmt.Errorf("failed to render output: %w", err)
} }

View File

@ -93,15 +93,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -363,15 +357,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -360,15 +354,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Id = args[0] updateReq.Id = args[0]

View File

@ -113,15 +113,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -273,15 +267,9 @@ func newDeploy() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deployJson.Unmarshal(&deployReq) err = deployJson.Unmarshal(&deployReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
deployReq.AppName = args[0] deployReq.AppName = args[0]
@ -714,15 +702,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
setPermissionsReq.AppName = args[0] setPermissionsReq.AppName = args[0]
@ -954,15 +936,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Name = args[0] updateReq.Name = args[0]
@ -1029,15 +1005,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updatePermissionsReq.AppName = args[0] updatePermissionsReq.AppName = args[0]

View File

@ -145,15 +145,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -127,15 +127,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -105,15 +105,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -369,15 +363,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Name = args[0] updateReq.Name = args[0]

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -350,15 +344,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Name = args[0] updateReq.Name = args[0]

View File

@ -113,15 +113,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -191,15 +185,9 @@ func newDelete() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteJson.Unmarshal(&deleteReq) err = deleteJson.Unmarshal(&deleteReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -296,15 +284,9 @@ func newEdit() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := editJson.Unmarshal(&editReq) err = editJson.Unmarshal(&editReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -648,15 +630,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -735,15 +711,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -134,15 +134,9 @@ func newChangeOwner() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := changeOwnerJson.Unmarshal(&changeOwnerReq) err = changeOwnerJson.Unmarshal(&changeOwnerReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -274,15 +268,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -374,15 +362,9 @@ func newDelete() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteJson.Unmarshal(&deleteReq) err = deleteJson.Unmarshal(&deleteReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -537,15 +519,9 @@ func newEdit() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := editJson.Unmarshal(&editReq) err = editJson.Unmarshal(&editReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -641,15 +617,9 @@ func newEvents() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := eventsJson.Unmarshal(&eventsReq) err = eventsJson.Unmarshal(&eventsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1099,15 +1069,9 @@ func newPermanentDelete() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := permanentDeleteJson.Unmarshal(&permanentDeleteReq) err = permanentDeleteJson.Unmarshal(&permanentDeleteReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1197,15 +1161,9 @@ func newPin() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := pinJson.Unmarshal(&pinReq) err = pinJson.Unmarshal(&pinReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1302,15 +1260,9 @@ func newResize() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := resizeJson.Unmarshal(&resizeReq) err = resizeJson.Unmarshal(&resizeReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1418,15 +1370,9 @@ func newRestart() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := restartJson.Unmarshal(&restartReq) err = restartJson.Unmarshal(&restartReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1518,15 +1464,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -1668,15 +1608,9 @@ func newStart() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := startJson.Unmarshal(&startReq) err = startJson.Unmarshal(&startReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1778,15 +1712,9 @@ func newUnpin() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := unpinJson.Unmarshal(&unpinReq) err = unpinJson.Unmarshal(&unpinReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1896,15 +1824,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1983,15 +1905,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -130,15 +130,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -92,15 +92,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -361,15 +355,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -86,15 +86,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
createReq.ListingId = args[0] createReq.ListingId = args[0]
@ -325,15 +319,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -75,15 +75,9 @@ func newExchangeToken() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := exchangeTokenJson.Unmarshal(&exchangeTokenReq) err = exchangeTokenJson.Unmarshal(&exchangeTokenReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -75,15 +75,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -202,15 +196,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -78,15 +78,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -411,15 +405,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -199,15 +199,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -187,15 +187,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -132,15 +132,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -130,15 +130,9 @@ func newCreateExperiment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createExperimentJson.Unmarshal(&createExperimentReq) err = createExperimentJson.Unmarshal(&createExperimentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -209,15 +203,9 @@ func newCreateRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createRunJson.Unmarshal(&createRunReq) err = createRunJson.Unmarshal(&createRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -289,15 +277,9 @@ func newDeleteExperiment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteExperimentJson.Unmarshal(&deleteExperimentReq) err = deleteExperimentJson.Unmarshal(&deleteExperimentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -370,15 +352,9 @@ func newDeleteRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteRunJson.Unmarshal(&deleteRunReq) err = deleteRunJson.Unmarshal(&deleteRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -459,15 +435,9 @@ func newDeleteRuns() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteRunsJson.Unmarshal(&deleteRunsReq) err = deleteRunsJson.Unmarshal(&deleteRunsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -548,15 +518,9 @@ func newDeleteTag() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteTagJson.Unmarshal(&deleteTagReq) err = deleteTagJson.Unmarshal(&deleteTagReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1144,15 +1108,9 @@ func newLogBatch() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := logBatchJson.Unmarshal(&logBatchReq) err = logBatchJson.Unmarshal(&logBatchReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1216,15 +1174,9 @@ func newLogInputs() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := logInputsJson.Unmarshal(&logInputsReq) err = logInputsJson.Unmarshal(&logInputsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1302,15 +1254,9 @@ func newLogMetric() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := logMetricJson.Unmarshal(&logMetricReq) err = logMetricJson.Unmarshal(&logMetricReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1389,15 +1335,9 @@ func newLogModel() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := logModelJson.Unmarshal(&logModelReq) err = logModelJson.Unmarshal(&logModelReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1474,15 +1414,9 @@ func newLogParam() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := logParamJson.Unmarshal(&logParamReq) err = logParamJson.Unmarshal(&logParamReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1563,15 +1497,9 @@ func newRestoreExperiment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := restoreExperimentJson.Unmarshal(&restoreExperimentReq) err = restoreExperimentJson.Unmarshal(&restoreExperimentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1644,15 +1572,9 @@ func newRestoreRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := restoreRunJson.Unmarshal(&restoreRunReq) err = restoreRunJson.Unmarshal(&restoreRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1733,15 +1655,9 @@ func newRestoreRuns() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := restoreRunsJson.Unmarshal(&restoreRunsReq) err = restoreRunsJson.Unmarshal(&restoreRunsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1816,15 +1732,9 @@ func newSearchExperiments() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := searchExperimentsJson.Unmarshal(&searchExperimentsReq) err = searchExperimentsJson.Unmarshal(&searchExperimentsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1890,15 +1800,9 @@ func newSearchRuns() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := searchRunsJson.Unmarshal(&searchRunsReq) err = searchRunsJson.Unmarshal(&searchRunsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1970,15 +1874,9 @@ func newSetExperimentTag() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setExperimentTagJson.Unmarshal(&setExperimentTagReq) err = setExperimentTagJson.Unmarshal(&setExperimentTagReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2053,15 +1951,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
setPermissionsReq.ExperimentId = args[0] setPermissionsReq.ExperimentId = args[0]
@ -2140,15 +2032,9 @@ func newSetTag() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setTagJson.Unmarshal(&setTagReq) err = setTagJson.Unmarshal(&setTagReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2226,15 +2112,9 @@ func newUpdateExperiment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateExperimentJson.Unmarshal(&updateExperimentReq) err = updateExperimentJson.Unmarshal(&updateExperimentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2303,15 +2183,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updatePermissionsReq.ExperimentId = args[0] updatePermissionsReq.ExperimentId = args[0]
@ -2377,15 +2251,9 @@ func newUpdateRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateRunJson.Unmarshal(&updateRunReq) err = updateRunJson.Unmarshal(&updateRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }

View File

@ -112,15 +112,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -387,15 +381,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Name = args[0] updateReq.Name = args[0]

View File

@ -85,15 +85,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -387,15 +381,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -105,15 +105,9 @@ func newCreateMessage() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createMessageJson.Unmarshal(&createMessageReq) err = createMessageJson.Unmarshal(&createMessageReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
createMessageReq.SpaceId = args[0] createMessageReq.SpaceId = args[0]
@ -398,15 +392,9 @@ func newStartConversation() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := startConversationJson.Unmarshal(&startConversationReq) err = startConversationJson.Unmarshal(&startConversationReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
startConversationReq.SpaceId = args[0] startConversationReq.SpaceId = args[0]

View File

@ -103,15 +103,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -377,15 +371,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &updateReq.CredentialId) _, err = fmt.Sscan(args[0], &updateReq.CredentialId)

View File

@ -101,15 +101,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -373,15 +367,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.ScriptId = args[0] updateReq.ScriptId = args[0]

View File

@ -223,15 +223,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &updateReq.SecurableType) _, err = fmt.Sscan(args[0], &updateReq.SecurableType)

View File

@ -97,15 +97,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -364,15 +358,9 @@ func newPatch() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := patchJson.Unmarshal(&patchReq) err = patchJson.Unmarshal(&patchReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -458,15 +446,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -128,15 +128,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -212,15 +206,9 @@ func newDelete() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteJson.Unmarshal(&deleteReq) err = deleteJson.Unmarshal(&deleteReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -321,15 +309,9 @@ func newEdit() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := editJson.Unmarshal(&editReq) err = editJson.Unmarshal(&editReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -649,15 +631,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -736,15 +712,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -99,15 +99,9 @@ func newAdd() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := addJson.Unmarshal(&addReq) err = addJson.Unmarshal(&addReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -198,15 +192,9 @@ func newEdit() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := editJson.Unmarshal(&editReq) err = editJson.Unmarshal(&editReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -323,15 +311,9 @@ func newRemove() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := removeJson.Unmarshal(&removeReq) err = removeJson.Unmarshal(&removeReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {

View File

@ -133,15 +133,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -420,15 +414,9 @@ func newReplace() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := replaceJson.Unmarshal(&replaceReq) err = replaceJson.Unmarshal(&replaceReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
replaceReq.IpAccessListId = args[0] replaceReq.IpAccessListId = args[0]
@ -522,15 +510,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -116,15 +116,9 @@ func newCancelAllRuns() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := cancelAllRunsJson.Unmarshal(&cancelAllRunsReq) err = cancelAllRunsJson.Unmarshal(&cancelAllRunsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -199,15 +193,9 @@ func newCancelRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := cancelRunJson.Unmarshal(&cancelRunReq) err = cancelRunJson.Unmarshal(&cancelRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -303,15 +291,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -382,15 +364,9 @@ func newDelete() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteJson.Unmarshal(&deleteReq) err = deleteJson.Unmarshal(&deleteReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -481,15 +457,9 @@ func newDeleteRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deleteRunJson.Unmarshal(&deleteRunReq) err = deleteRunJson.Unmarshal(&deleteRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1173,15 +1143,9 @@ func newRepairRun() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := repairRunJson.Unmarshal(&repairRunReq) err = repairRunJson.Unmarshal(&repairRunReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1278,15 +1242,9 @@ func newReset() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := resetJson.Unmarshal(&resetReq) err = resetJson.Unmarshal(&resetReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -1374,15 +1332,9 @@ func newRunNow() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := runNowJson.Unmarshal(&runNowReq) err = runNowJson.Unmarshal(&runNowReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1484,15 +1436,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -1592,15 +1538,9 @@ func newSubmit() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := submitJson.Unmarshal(&submitReq) err = submitJson.Unmarshal(&submitReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -1692,15 +1632,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
if len(args) == 0 { if len(args) == 0 {
@ -1783,15 +1717,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -108,15 +108,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -186,15 +180,9 @@ func newCreateSchedule() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createScheduleJson.Unmarshal(&createScheduleReq) err = createScheduleJson.Unmarshal(&createScheduleReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -262,15 +250,9 @@ func newCreateSubscription() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createSubscriptionJson.Unmarshal(&createSubscriptionReq) err = createSubscriptionJson.Unmarshal(&createSubscriptionReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -888,15 +870,9 @@ func newMigrate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := migrateJson.Unmarshal(&migrateReq) err = migrateJson.Unmarshal(&migrateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -965,15 +941,9 @@ func newPublish() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := publishJson.Unmarshal(&publishReq) err = publishJson.Unmarshal(&publishReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
publishReq.DashboardId = args[0] publishReq.DashboardId = args[0]
@ -1158,15 +1128,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.DashboardId = args[0] updateReq.DashboardId = args[0]
@ -1236,15 +1200,9 @@ func newUpdateSchedule() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateScheduleJson.Unmarshal(&updateScheduleReq) err = updateScheduleJson.Unmarshal(&updateScheduleReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -190,15 +190,9 @@ func newInstall() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := installJson.Unmarshal(&installReq) err = installJson.Unmarshal(&installReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -257,15 +251,9 @@ func newUninstall() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := uninstallJson.Unmarshal(&uninstallReq) err = uninstallJson.Unmarshal(&uninstallReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")

View File

@ -112,15 +112,9 @@ func newAssign() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := assignJson.Unmarshal(&assignReq) err = assignJson.Unmarshal(&assignReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
_, err = fmt.Sscan(args[0], &assignReq.WorkspaceId) _, err = fmt.Sscan(args[0], &assignReq.WorkspaceId)
@ -207,15 +201,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -618,15 +606,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {
@ -708,15 +690,9 @@ func newUpdateAssignment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateAssignmentJson.Unmarshal(&updateAssignmentReq) err = updateAssignmentJson.Unmarshal(&updateAssignmentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if len(args) == 0 { if len(args) == 0 {

View File

@ -141,15 +141,9 @@ func newApproveTransitionRequest() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := approveTransitionRequestJson.Unmarshal(&approveTransitionRequestReq) err = approveTransitionRequestJson.Unmarshal(&approveTransitionRequestReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -241,15 +235,9 @@ func newCreateComment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createCommentJson.Unmarshal(&createCommentReq) err = createCommentJson.Unmarshal(&createCommentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -334,15 +322,9 @@ func newCreateModel() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createModelJson.Unmarshal(&createModelReq) err = createModelJson.Unmarshal(&createModelReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -421,15 +403,9 @@ func newCreateModelVersion() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createModelVersionJson.Unmarshal(&createModelVersionReq) err = createModelVersionJson.Unmarshal(&createModelVersionReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -517,15 +493,9 @@ func newCreateTransitionRequest() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createTransitionRequestJson.Unmarshal(&createTransitionRequestReq) err = createTransitionRequestJson.Unmarshal(&createTransitionRequestReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -600,15 +570,9 @@ func newCreateWebhook() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createWebhookJson.Unmarshal(&createWebhookReq) err = createWebhookJson.Unmarshal(&createWebhookReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} else { } else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
@ -1115,15 +1079,9 @@ func newGetLatestVersions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := getLatestVersionsJson.Unmarshal(&getLatestVersionsReq) err = getLatestVersionsJson.Unmarshal(&getLatestVersionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1671,15 +1629,9 @@ func newRejectTransitionRequest() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := rejectTransitionRequestJson.Unmarshal(&rejectTransitionRequestReq) err = rejectTransitionRequestJson.Unmarshal(&rejectTransitionRequestReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1763,15 +1715,9 @@ func newRenameModel() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := renameModelJson.Unmarshal(&renameModelReq) err = renameModelJson.Unmarshal(&renameModelReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -1961,15 +1907,9 @@ func newSetModelTag() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setModelTagJson.Unmarshal(&setModelTagReq) err = setModelTagJson.Unmarshal(&setModelTagReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2056,15 +1996,9 @@ func newSetModelVersionTag() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setModelVersionTagJson.Unmarshal(&setModelVersionTagReq) err = setModelVersionTagJson.Unmarshal(&setModelVersionTagReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2142,15 +2076,9 @@ func newSetPermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := setPermissionsJson.Unmarshal(&setPermissionsReq) err = setPermissionsJson.Unmarshal(&setPermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
setPermissionsReq.RegisteredModelId = args[0] setPermissionsReq.RegisteredModelId = args[0]
@ -2238,15 +2166,9 @@ func newTestRegistryWebhook() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := testRegistryWebhookJson.Unmarshal(&testRegistryWebhookReq) err = testRegistryWebhookJson.Unmarshal(&testRegistryWebhookReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2337,15 +2259,9 @@ func newTransitionStage() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := transitionStageJson.Unmarshal(&transitionStageReq) err = transitionStageJson.Unmarshal(&transitionStageReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2434,15 +2350,9 @@ func newUpdateComment() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateCommentJson.Unmarshal(&updateCommentReq) err = updateCommentJson.Unmarshal(&updateCommentReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2520,15 +2430,9 @@ func newUpdateModel() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateModelJson.Unmarshal(&updateModelReq) err = updateModelJson.Unmarshal(&updateModelReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2604,15 +2508,9 @@ func newUpdateModelVersion() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateModelVersionJson.Unmarshal(&updateModelVersionReq) err = updateModelVersionJson.Unmarshal(&updateModelVersionReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
@ -2684,15 +2582,9 @@ func newUpdatePermissions() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updatePermissionsJson.Unmarshal(&updatePermissionsReq) err = updatePermissionsJson.Unmarshal(&updatePermissionsReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updatePermissionsReq.RegisteredModelId = args[0] updatePermissionsReq.RegisteredModelId = args[0]
@ -2771,15 +2663,9 @@ func newUpdateWebhook() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateWebhookJson.Unmarshal(&updateWebhookReq) err = updateWebhookJson.Unmarshal(&updateWebhookReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {

View File

@ -377,15 +377,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.FullName = args[0] updateReq.FullName = args[0]

View File

@ -84,15 +84,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
@ -319,15 +313,9 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) err = updateJson.Unmarshal(&updateReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }
updateReq.Id = args[0] updateReq.Id = args[0]

View File

@ -79,15 +79,9 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) err = createJson.Unmarshal(&createReq)
if diags.HasError() { if err != nil {
return diags.Error() return err
}
if len(diags) > 0 {
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
if err != nil {
return err
}
} }
} }

Some files were not shown because too many files have changed in this diff Show More