Skip to content

Commit 1d38fdc

Browse files
authored
Add enum for schema grant privileges (#3396)
## Changes Add an enum for schema grant privileges. It follows documented privileges in Terraform documentation: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/grants#schema-grants ## Why Using enums gives better typing in JSON schema and allows generating enums in Python code ## Tests By inspecting the resulting JSON schema
1 parent 4550b49 commit 1d38fdc

File tree

5 files changed

+171
-8
lines changed

5 files changed

+171
-8
lines changed

bundle/config/resources/schema.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,54 @@ import (
1414
"github.com/databricks/databricks-sdk-go/service/catalog"
1515
)
1616

17+
type SchemaGrantPrivilege string
18+
19+
const (
20+
SchemaGrantPrivilegeAllPrivileges SchemaGrantPrivilege = "ALL_PRIVILEGES"
21+
SchemaGrantPrivilegeApplyTag SchemaGrantPrivilege = "APPLY_TAG"
22+
SchemaGrantPrivilegeCreateFunction SchemaGrantPrivilege = "CREATE_FUNCTION"
23+
SchemaGrantPrivilegeCreateTable SchemaGrantPrivilege = "CREATE_TABLE"
24+
SchemaGrantPrivilegeCreateVolume SchemaGrantPrivilege = "CREATE_VOLUME"
25+
SchemaGrantPrivilegeManage SchemaGrantPrivilege = "MANAGE"
26+
SchemaGrantPrivilegeUseSchema SchemaGrantPrivilege = "USE_SCHEMA"
27+
SchemaGrantPrivilegeExecute SchemaGrantPrivilege = "EXECUTE"
28+
SchemaGrantPrivilegeModify SchemaGrantPrivilege = "MODIFY"
29+
SchemaGrantPrivilegeRefresh SchemaGrantPrivilege = "REFRESH"
30+
SchemaGrantPrivilegeSelect SchemaGrantPrivilege = "SELECT"
31+
SchemaGrantPrivilegeReadVolume SchemaGrantPrivilege = "READ_VOLUME"
32+
SchemaGrantPrivilegeWriteVolume SchemaGrantPrivilege = "WRITE_VOLUME"
33+
)
34+
35+
// Values returns all valid SchemaGrantPrivilege values
36+
func (SchemaGrantPrivilege) Values() []SchemaGrantPrivilege {
37+
return []SchemaGrantPrivilege{
38+
SchemaGrantPrivilegeAllPrivileges,
39+
SchemaGrantPrivilegeApplyTag,
40+
SchemaGrantPrivilegeCreateFunction,
41+
SchemaGrantPrivilegeCreateTable,
42+
SchemaGrantPrivilegeCreateVolume,
43+
SchemaGrantPrivilegeManage,
44+
SchemaGrantPrivilegeUseSchema,
45+
SchemaGrantPrivilegeExecute,
46+
SchemaGrantPrivilegeModify,
47+
SchemaGrantPrivilegeRefresh,
48+
SchemaGrantPrivilegeSelect,
49+
SchemaGrantPrivilegeReadVolume,
50+
SchemaGrantPrivilegeWriteVolume,
51+
}
52+
}
53+
54+
// SchemaGrant holds the grant level settings for a single principal in Unity Catalog.
55+
// Multiple of these can be defined on any schema.
56+
type SchemaGrant struct {
57+
Privileges []SchemaGrantPrivilege `json:"privileges"`
58+
59+
Principal string `json:"principal"`
60+
}
61+
1762
type Schema struct {
1863
// List of grants to apply on this schema.
19-
Grants []Grant `json:"grants,omitempty"`
64+
Grants []SchemaGrant `json:"grants,omitempty"`
2065

2166
// Full name of the schema (catalog_name.schema_name). This value is read from
2267
// the terraform state after deployment succeeds.

bundle/deploy/terraform/tfdyn/convert_schema_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ func TestConvertSchema(t *testing.T) {
2525
},
2626
StorageRoot: "root",
2727
},
28-
Grants: []resources.Grant{
28+
Grants: []resources.SchemaGrant{
2929
{
30-
Privileges: []string{"EXECUTE"},
31-
Principal: "[email protected]",
30+
Privileges: []resources.SchemaGrantPrivilege{
31+
resources.SchemaGrantPrivilegeExecute,
32+
},
33+
Principal: "[email protected]",
3234
},
3335
{
34-
Privileges: []string{"RUN"},
35-
Principal: "[email protected]",
36+
Privileges: []resources.SchemaGrantPrivilege{
37+
resources.SchemaGrantPrivilegeSelect,
38+
},
39+
Principal: "[email protected]",
3640
},
3741
},
3842
}
@@ -67,7 +71,7 @@ func TestConvertSchema(t *testing.T) {
6771
Principal: "[email protected]",
6872
},
6973
{
70-
Privileges: []string{"RUN"},
74+
Privileges: []string{"SELECT"},
7175
Principal: "[email protected]",
7276
},
7377
},

bundle/internal/schema/annotations.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ github.com/databricks/cli/bundle/config/resources.PipelinePermission:
664664
"user_name":
665665
"description": |-
666666
PLACEHOLDER
667+
github.com/databricks/cli/bundle/config/resources.SchemaGrant:
668+
"principal":
669+
"description": |-
670+
PLACEHOLDER
671+
"privileges":
672+
"description": |-
673+
PLACEHOLDER
667674
github.com/databricks/cli/bundle/config/resources.SecretScope:
668675
"backend_type":
669676
"description": |-

bundle/internal/schema/annotations_openapi_overrides.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,35 @@ github.com/databricks/cli/bundle/config/resources.RegisteredModel:
424424
"grants":
425425
"description": |-
426426
PLACEHOLDER
427+
github.com/databricks/cli/bundle/config/resources.SchemaGrantPrivilege:
428+
"_":
429+
"enum":
430+
- |-
431+
ALL_PRIVILEGES
432+
- |-
433+
APPLY_TAG
434+
- |-
435+
CREATE_FUNCTION
436+
- |-
437+
CREATE_TABLE
438+
- |-
439+
CREATE_VOLUME
440+
- |-
441+
MANAGE
442+
- |-
443+
USE_SCHEMA
444+
- |-
445+
EXECUTE
446+
- |-
447+
MODIFY
448+
- |-
449+
REFRESH
450+
- |-
451+
SELECT
452+
- |-
453+
READ_VOLUME
454+
- |-
455+
WRITE_VOLUME
427456
github.com/databricks/cli/bundle/config/resources.Schema:
428457
"_":
429458
"markdown_description": |-

bundle/schema/jsonschema.json

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

0 commit comments

Comments
 (0)