2024-03-06 09:53:44 +00:00
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package permission_migration
import (
"fmt"
"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/iam"
"github.com/spf13/cobra"
)
// 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 : "permission-migration" ,
Short : ` This spec contains undocumented permission migration APIs used in https://github.com/databrickslabs/ucx. ` ,
Long : ` This spec contains undocumented permission migration APIs used in
https : //github.com/databrickslabs/ucx.`,
GroupID : "iam" ,
Annotations : map [ string ] string {
"package" : "iam" ,
} ,
// This service is being previewed; hide from help output.
Hidden : true ,
}
// Add methods
cmd . AddCommand ( newMigratePermissions ( ) )
// Apply optional overrides to this command.
for _ , fn := range cmdOverrides {
fn ( cmd )
}
return cmd
}
// start migrate-permissions 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 migratePermissionsOverrides [ ] func (
* cobra . Command ,
* iam . PermissionMigrationRequest ,
)
func newMigratePermissions ( ) * cobra . Command {
cmd := & cobra . Command { }
var migratePermissionsReq iam . PermissionMigrationRequest
var migratePermissionsJson flags . JsonFlag
// TODO: short flags
cmd . Flags ( ) . Var ( & migratePermissionsJson , "json" , ` either inline JSON string or @path/to/file.json with request body ` )
cmd . Flags ( ) . IntVar ( & migratePermissionsReq . Size , "size" , migratePermissionsReq . Size , ` The maximum number of permissions that will be migrated. ` )
cmd . Use = "migrate-permissions WORKSPACE_ID FROM_WORKSPACE_GROUP_NAME TO_ACCOUNT_GROUP_NAME"
cmd . Short = ` Migrate Permissions. `
cmd . Long = ` Migrate Permissions .
Migrate a batch of permissions from a workspace local group to an account
group .
Arguments :
WORKSPACE_ID : WorkspaceId of the associated workspace where the permission migration
will occur . Both workspace group and account group must be in this
workspace .
FROM_WORKSPACE_GROUP_NAME : The name of the workspace group that permissions will be migrated from .
TO_ACCOUNT_GROUP_NAME : The name of the account group that permissions will be migrated to . `
cmd . Annotations = make ( map [ string ] string )
cmd . Args = func ( cmd * cobra . Command , args [ ] string ) error {
if cmd . Flags ( ) . Changed ( "json" ) {
2024-03-12 14:12:34 +00:00
err := root . ExactArgs ( 0 ) ( cmd , args )
2024-03-06 09:53:44 +00:00
if err != nil {
return fmt . Errorf ( "when --json flag is specified, no positional arguments are required. Provide 'workspace_id', 'from_workspace_group_name', 'to_account_group_name' in your JSON input" )
}
return nil
}
2024-03-12 14:12:34 +00:00
check := root . ExactArgs ( 3 )
2024-03-06 09:53:44 +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 = migratePermissionsJson . Unmarshal ( & migratePermissionsReq )
if err != nil {
return err
}
}
if ! cmd . Flags ( ) . Changed ( "json" ) {
_ , err = fmt . Sscan ( args [ 0 ] , & migratePermissionsReq . WorkspaceId )
if err != nil {
return fmt . Errorf ( "invalid WORKSPACE_ID: %s" , args [ 0 ] )
}
}
if ! cmd . Flags ( ) . Changed ( "json" ) {
migratePermissionsReq . FromWorkspaceGroupName = args [ 1 ]
}
if ! cmd . Flags ( ) . Changed ( "json" ) {
migratePermissionsReq . ToAccountGroupName = args [ 2 ]
}
response , err := w . PermissionMigration . MigratePermissions ( ctx , migratePermissionsReq )
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 migratePermissionsOverrides {
fn ( cmd , & migratePermissionsReq )
}
return cmd
}
// end service PermissionMigration