2023-05-22 19:27:22 +00:00
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package workspace_bindings
import (
2024-08-15 13:23:07 +00:00
"fmt"
2023-05-22 19:27:22 +00:00
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/spf13/cobra"
)
2023-07-25 18:19:07 +00:00
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var cmdOverrides [ ] func ( * cobra . Command )
func New ( ) * cobra . Command {
cmd := & cobra . Command {
Use : "workspace-bindings" ,
2023-10-16 06:56:06 +00:00
Short : ` A securable in Databricks can be configured as __OPEN__ or __ISOLATED__. ` ,
Long : ` A securable in Databricks can be configured as __OPEN__ or __ISOLATED__ . An
__OPEN__ securable can be accessed from any workspace , while an __ISOLATED__
securable can only be accessed from a configured list of workspaces . This API
allows you to configure ( bind ) securables to workspaces .
2023-05-22 19:27:22 +00:00
2023-10-16 06:56:06 +00:00
NOTE : The __isolation_mode__ is configured for the securable itself ( using its
Update method ) and the workspace bindings are only consulted when the
securable ' s __isolation_mode__ is set to __ISOLATED__ .
A securable ' s workspace bindings can be configured by a metastore admin or the
owner of the securable .
The original path ( / api / 2.1 / unity - catalog / workspace - bindings / catalogs / { name } )
is deprecated . Please use the new path
( / api / 2.1 / unity - catalog / bindings / { securable_type } / { securable_name } ) which
introduces the ability to bind a securable in READ_ONLY mode ( catalogs only ) .
2024-08-15 13:23:07 +00:00
Securable types that support binding : - catalog - storage_credential -
external_location ` ,
2023-07-25 18:19:07 +00:00
GroupID : "catalog" ,
Annotations : map [ string ] string {
"package" : "catalog" ,
} ,
}
2024-03-06 09:53:44 +00:00
// Add methods
cmd . AddCommand ( newGet ( ) )
cmd . AddCommand ( newGetBindings ( ) )
cmd . AddCommand ( newUpdate ( ) )
cmd . AddCommand ( newUpdateBindings ( ) )
2023-07-25 18:19:07 +00:00
// Apply optional overrides to this command.
for _ , fn := range cmdOverrides {
fn ( cmd )
}
return cmd
2023-05-22 19:27:22 +00:00
}
// start get command
2023-07-25 18:19:07 +00:00
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var getOverrides [ ] func (
* cobra . Command ,
* catalog . GetWorkspaceBindingRequest ,
)
2023-05-22 19:27:22 +00:00
2023-07-25 18:19:07 +00:00
func newGet ( ) * cobra . Command {
cmd := & cobra . Command { }
2023-05-22 19:27:22 +00:00
2023-07-25 18:19:07 +00:00
var getReq catalog . GetWorkspaceBindingRequest
// TODO: short flags
cmd . Use = "get NAME"
cmd . Short = ` Get catalog workspace bindings. `
cmd . Long = ` Get catalog workspace bindings .
2023-05-22 19:27:22 +00:00
Gets workspace bindings of the catalog . The caller must be a metastore admin
2023-11-30 16:22:23 +00:00
or an owner of the catalog .
Arguments :
NAME : The name of the catalog . `
2023-07-25 18:19:07 +00:00
cmd . Annotations = make ( map [ string ] string )
2023-05-22 19:27:22 +00:00
2023-07-25 18:19:07 +00:00
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 1 )
2023-05-26 12:46:08 +00:00
return check ( cmd , args )
2023-07-25 18:19:07 +00:00
}
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
2023-05-22 19:27:22 +00:00
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
2023-07-03 11:20:30 +00:00
getReq . Name = args [ 0 ]
2023-05-22 19:27:22 +00:00
response , err := w . WorkspaceBindings . Get ( ctx , getReq )
if err != nil {
return err
}
return cmdio . Render ( ctx , response )
2023-07-25 18:19:07 +00:00
}
2023-06-15 14:56:36 +00:00
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
2023-07-25 18:19:07 +00:00
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range getOverrides {
fn ( cmd , & getReq )
}
return cmd
}
2023-10-16 06:56:06 +00:00
// start get-bindings command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var getBindingsOverrides [ ] func (
* cobra . Command ,
* catalog . GetBindingsRequest ,
)
func newGetBindings ( ) * cobra . Command {
cmd := & cobra . Command { }
var getBindingsReq catalog . GetBindingsRequest
// TODO: short flags
2024-08-15 13:23:07 +00:00
cmd . Flags ( ) . IntVar ( & getBindingsReq . MaxResults , "max-results" , getBindingsReq . MaxResults , ` Maximum number of workspace bindings to return. ` )
cmd . Flags ( ) . StringVar ( & getBindingsReq . PageToken , "page-token" , getBindingsReq . PageToken , ` Opaque pagination token to go to next page based on previous query. ` )
2023-10-16 06:56:06 +00:00
cmd . Use = "get-bindings SECURABLE_TYPE SECURABLE_NAME"
cmd . Short = ` Get securable workspace bindings. `
cmd . Long = ` Get securable workspace bindings .
Gets workspace bindings of the securable . The caller must be a metastore admin
2023-11-30 16:22:23 +00:00
or an owner of the securable .
Arguments :
2024-08-15 13:23:07 +00:00
SECURABLE_TYPE : The type of the securable to bind to a workspace .
2023-11-30 16:22:23 +00:00
SECURABLE_NAME : The name of the securable . `
2023-10-16 06:56:06 +00:00
cmd . Annotations = make ( map [ string ] string )
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 2 )
2023-10-16 06:56:06 +00:00
return check ( cmd , args )
}
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
2024-08-15 13:23:07 +00:00
_ , err = fmt . Sscan ( args [ 0 ] , & getBindingsReq . SecurableType )
2023-10-16 06:56:06 +00:00
if err != nil {
2024-08-15 13:23:07 +00:00
return fmt . Errorf ( "invalid SECURABLE_TYPE: %s" , args [ 0 ] )
2023-10-16 06:56:06 +00:00
}
2024-08-15 13:23:07 +00:00
getBindingsReq . SecurableName = args [ 1 ]
response := w . WorkspaceBindings . GetBindings ( ctx , getBindingsReq )
return cmdio . RenderIterator ( ctx , response )
2023-10-16 06:56:06 +00:00
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range getBindingsOverrides {
fn ( cmd , & getBindingsReq )
}
return cmd
}
2023-05-22 19:27:22 +00:00
// start update command
2023-07-25 18:19:07 +00:00
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var updateOverrides [ ] func (
* cobra . Command ,
* catalog . UpdateWorkspaceBindings ,
)
func newUpdate ( ) * cobra . Command {
cmd := & cobra . Command { }
var updateReq catalog . UpdateWorkspaceBindings
var updateJson flags . JsonFlag
2023-05-22 19:27:22 +00:00
// TODO: short flags
2023-07-25 18:19:07 +00:00
cmd . Flags ( ) . Var ( & updateJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
2023-05-22 19:27:22 +00:00
// TODO: array: assign_workspaces
// TODO: array: unassign_workspaces
2023-07-25 18:19:07 +00:00
cmd . Use = "update NAME"
cmd . Short = ` Update catalog workspace bindings. `
cmd . Long = ` Update catalog workspace bindings .
2023-05-22 19:27:22 +00:00
Updates workspace bindings of the catalog . The caller must be a metastore
2023-11-30 16:22:23 +00:00
admin or an owner of the catalog .
Arguments :
NAME : The name of the catalog . `
2023-07-25 18:19:07 +00:00
cmd . Annotations = make ( map [ string ] string )
2023-05-22 19:27:22 +00:00
2023-07-25 18:19:07 +00:00
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 1 )
2023-05-26 12:46:08 +00:00
return check ( cmd , args )
2023-07-25 18:19:07 +00:00
}
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
2023-05-22 19:27:22 +00:00
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
2023-07-03 11:20:30 +00:00
2023-05-26 12:46:08 +00:00
if cmd . Flags ( ) . Changed ( "json" ) {
err = updateJson . Unmarshal ( & updateReq )
if err != nil {
return err
}
2023-05-22 19:27:22 +00:00
}
2023-07-03 11:20:30 +00:00
updateReq . Name = args [ 0 ]
2023-05-22 19:27:22 +00:00
response , err := w . WorkspaceBindings . Update ( ctx , updateReq )
if err != nil {
return err
}
return cmdio . Render ( ctx , response )
2023-07-25 18:19:07 +00:00
}
2023-06-15 14:56:36 +00:00
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
2023-07-25 18:19:07 +00:00
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range updateOverrides {
fn ( cmd , & updateReq )
}
return cmd
}
2023-10-16 06:56:06 +00:00
// start update-bindings command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var updateBindingsOverrides [ ] func (
* cobra . Command ,
* catalog . UpdateWorkspaceBindingsParameters ,
)
func newUpdateBindings ( ) * cobra . Command {
cmd := & cobra . Command { }
var updateBindingsReq catalog . UpdateWorkspaceBindingsParameters
var updateBindingsJson flags . JsonFlag
// TODO: short flags
cmd . Flags ( ) . Var ( & updateBindingsJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
// TODO: array: add
// TODO: array: remove
cmd . Use = "update-bindings SECURABLE_TYPE SECURABLE_NAME"
cmd . Short = ` Update securable workspace bindings. `
cmd . Long = ` Update securable workspace bindings .
Updates workspace bindings of the securable . The caller must be a metastore
2023-11-30 16:22:23 +00:00
admin or an owner of the securable .
Arguments :
2024-08-15 13:23:07 +00:00
SECURABLE_TYPE : The type of the securable to bind to a workspace .
2023-11-30 16:22:23 +00:00
SECURABLE_NAME : The name of the securable . `
2023-10-16 06:56:06 +00:00
cmd . Annotations = make ( map [ string ] string )
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 2 )
2023-10-16 06:56:06 +00:00
return check ( cmd , args )
}
cmd . PreRunE = root . MustWorkspaceClient
cmd . RunE = func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
ctx := cmd . Context ( )
w := root . WorkspaceClient ( ctx )
if cmd . Flags ( ) . Changed ( "json" ) {
err = updateBindingsJson . Unmarshal ( & updateBindingsReq )
if err != nil {
return err
}
}
2024-08-15 13:23:07 +00:00
_ , err = fmt . Sscan ( args [ 0 ] , & updateBindingsReq . SecurableType )
if err != nil {
return fmt . Errorf ( "invalid SECURABLE_TYPE: %s" , args [ 0 ] )
}
2023-10-16 06:56:06 +00:00
updateBindingsReq . SecurableName = args [ 1 ]
response , err := w . WorkspaceBindings . UpdateBindings ( ctx , updateBindingsReq )
if err != nil {
return err
}
return cmdio . Render ( ctx , response )
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd . ValidArgsFunction = cobra . NoFileCompletions
// Apply optional overrides to this command.
for _ , fn := range updateBindingsOverrides {
fn ( cmd , & updateBindingsReq )
}
return cmd
}
2023-05-22 19:27:22 +00:00
// end service WorkspaceBindings