-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathapps.go
More file actions
87 lines (70 loc) · 2.42 KB
/
apps.go
File metadata and controls
87 lines (70 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package resources
import (
"context"
"net/url"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/apps"
)
type AppPermissionLevel string
// AppPermission holds the permission level setting for a single principal.
// Multiple of these can be defined on any app.
type AppPermission struct {
Level AppPermissionLevel `json:"level"`
UserName string `json:"user_name,omitempty"`
ServicePrincipalName string `json:"service_principal_name,omitempty"`
GroupName string `json:"group_name,omitempty"`
}
type App struct {
BaseResource
// SourceCodePath is a required field used by DABs to point to Databricks app source code
// on local disk and to the corresponding workspace path during app deployment.
SourceCodePath string `json:"source_code_path"`
// Config is an optional field which allows configuring the app following Databricks app configuration format like in app.yml.
// When this field is set, DABs read the configuration set in this field and write
// it to app.yml in the root of the source code folder in Databricks workspace.
// If there's app.yml defined locally, DABs will raise an error.
Config map[string]any `json:"config,omitempty"`
Permissions []AppPermission `json:"permissions,omitempty"`
apps.App // nolint App struct also defines Id and URL field with the same json tag "id" and "url"
}
func (a *App) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, a)
}
func (a App) MarshalJSON() ([]byte, error) {
return marshal.Marshal(a)
}
func (a *App) Exists(ctx context.Context, w *databricks.WorkspaceClient, name string) (bool, error) {
_, err := w.Apps.GetByName(ctx, name)
if err != nil {
log.Debugf(ctx, "app %s does not exist", name)
return false, err
}
return true, nil
}
func (*App) ResourceDescription() ResourceDescription {
return ResourceDescription{
SingularName: "app",
PluralName: "apps",
SingularTitle: "App",
PluralTitle: "Apps",
}
}
func (a *App) InitializeURL(baseURL url.URL) {
if a.ModifiedStatus == "" || a.ModifiedStatus == ModifiedStatusCreated {
return
}
baseURL.Path = "apps/" + a.GetName()
a.URL = baseURL.String()
}
func (a *App) GetName() string {
// Prefer name from the state - that is what is actually deployed
if a.ID != "" {
return a.ID
}
return a.Name
}
func (a *App) GetURL() string {
return a.URL
}