mirror of https://github.com/databricks/cli.git
add cases for the target flag
This commit is contained in:
parent
c442378f45
commit
152d982c9b
|
@ -0,0 +1,10 @@
|
||||||
|
bundle:
|
||||||
|
name: foobar
|
||||||
|
|
||||||
|
targets:
|
||||||
|
pat:
|
||||||
|
default: true
|
||||||
|
|
||||||
|
oauth:
|
||||||
|
workspace:
|
||||||
|
client_id: client_id
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"headers": {
|
||||||
|
"Authorization": [
|
||||||
|
"Bearer [DATABRICKS_TOKEN]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/2.0/preview/scim/v2/Me"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"headers": {
|
||||||
|
"Authorization": [
|
||||||
|
"Bearer [DATABRICKS_TOKEN]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/2.0/preview/scim/v2/Me"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/oidc/.well-known/oauth-authorization-server"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"headers": {
|
||||||
|
"Authorization": [
|
||||||
|
"Basic Y2xpZW50X2lkOmNsaWVudC1zZWNyZXQ="
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "POST",
|
||||||
|
"path": "/oidc/v1/token",
|
||||||
|
"raw_body": "grant_type=client_credentials\u0026scope=all-apis"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"headers": {
|
||||||
|
"Authorization": [
|
||||||
|
"Bearer oauth-token"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/api/2.0/preview/scim/v2/Me"
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -- databricks current-user me
|
||||||
|
{
|
||||||
|
"id":"[USERID]",
|
||||||
|
"userName":"[USERNAME]"
|
||||||
|
}
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -t pat -- databricks current-user me
|
||||||
|
{
|
||||||
|
"id":"[USERID]",
|
||||||
|
"userName":"[USERNAME]"
|
||||||
|
}
|
||||||
|
|
||||||
|
>>> errcode [CLI] bundle exec -t pat -- databricks current-user me -t oauth
|
||||||
|
Error: cannot resolve bundle auth configuration: validate: more than one authorization method configured: oauth and pat. Config: host=[DATABRICKS_URL], token=***, client_id=client_id, databricks_cli_path=[CLI]. Env: DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_CLI_PATH
|
||||||
|
Error: Command exited with code: 1
|
||||||
|
|
||||||
|
Exit code: 1
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -t oauth -- databricks current-user me
|
||||||
|
{
|
||||||
|
"id":"[USERID]",
|
||||||
|
"userName":"[USERNAME]"
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Default target
|
||||||
|
trace $CLI bundle exec -- databricks current-user me
|
||||||
|
|
||||||
|
# Explicitly select default target
|
||||||
|
trace $CLI bundle exec -t pat -- databricks current-user me
|
||||||
|
|
||||||
|
# Conflicting targets selected. This should fail because for the child command
|
||||||
|
# pat would be configured via environment variables and oauth via the CLI resulting
|
||||||
|
# in more than one authorization method configured.
|
||||||
|
trace errcode $CLI bundle exec -t pat -- databricks current-user me -t oauth
|
||||||
|
|
||||||
|
# Explicitly select oauth target
|
||||||
|
export DATABRICKS_TOKEN=""
|
||||||
|
export DATABRICKS_CLIENT_SECRET="client-secret"
|
||||||
|
trace $CLI bundle exec -t oauth -- databricks current-user me
|
|
@ -0,0 +1,2 @@
|
||||||
|
RecordRequests = true
|
||||||
|
IncludeRequestHeaders = ["Authorization"]
|
|
@ -14,6 +14,27 @@ import (
|
||||||
|
|
||||||
// TODO: test that -- works with flags as well.
|
// TODO: test that -- works with flags as well.
|
||||||
|
|
||||||
|
// TODO: Can bundle auth be resolved twice? What about:
|
||||||
|
// databricks bundle exec -t foo -- databricks jobs list -t bar?
|
||||||
|
// OR
|
||||||
|
// databricks bundle exec -- databricks jobs list -t bar?
|
||||||
|
// OR
|
||||||
|
// databricks bundle exec -- databricks jobs list?
|
||||||
|
// OR
|
||||||
|
// databricks bundle exec -t foo -- databricks jobs list?
|
||||||
|
//
|
||||||
|
// For the first two, undefined behavior is fine. For the latter two we need to ensure
|
||||||
|
// that the target from exec is respected.
|
||||||
|
//
|
||||||
|
// Add tests for all four of these cases.
|
||||||
|
// --> Do I need similar tests for --profile as well?
|
||||||
|
// --> Also add test for what happens with a default target?
|
||||||
|
|
||||||
|
// TODO: Add acceptance test that flags are indeed not parsed by the exec command and
|
||||||
|
// instead are parsed by the child command.
|
||||||
|
|
||||||
|
// # TODO: Table test casing the target permutations
|
||||||
|
|
||||||
func newExecCommand() *cobra.Command {
|
func newExecCommand() *cobra.Command {
|
||||||
execCmd := &cobra.Command{
|
execCmd := &cobra.Command{
|
||||||
Use: "exec",
|
Use: "exec",
|
||||||
|
@ -41,7 +62,13 @@ Examples:
|
||||||
|
|
||||||
childCmd := exec.Command(args[0], args[1:]...)
|
childCmd := exec.Command(args[0], args[1:]...)
|
||||||
|
|
||||||
childCmd.Env = auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
env := auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
||||||
|
// TODO: Test that this works correctly for all permutations.
|
||||||
|
// TODO: Do the same for profile flag.
|
||||||
|
// TODO: TODO: What happens here if a default target is resolved? When
|
||||||
|
// no targets are defined?
|
||||||
|
env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target)
|
||||||
|
childCmd.Env = env
|
||||||
|
|
||||||
// Execute all scripts from the bundle root directory. This behavior can
|
// Execute all scripts from the bundle root directory. This behavior can
|
||||||
// be surprising in isolation, but we do it to keep the behavior consistent
|
// be surprising in isolation, but we do it to keep the behavior consistent
|
||||||
|
|
Loading…
Reference in New Issue