Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchy committed Oct 18, 2024
1 parent 98d71ac commit 9d08452
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: Check formatting
run: mvn --errors spotless:check


unit-tests:
strategy:
fail-fast: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public String authType() {
}

public CliTokenSource tokenSourceFor(DatabricksConfig config, String resource) {
String azPath =
Optional.ofNullable(config.getEnv()).map(env -> env.get("AZ_PATH")).orElse("az");

List<String> cmd =
new ArrayList<>(
Arrays.asList(
"az", "account", "get-access-token", "--resource", resource, "--output", "json"));
azPath, "account", "get-access-token", "--resource", resource, "--output", "json"));
Optional<String> subscription = getSubscription(config);
if (subscription.isPresent()) {
// This will fail if the user has access to the workspace, but not to the subscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CliTokenSource extends RefreshableTokenSource {
private List<String> cmd;
private String tokenTypeField;
private String accessTokenField;
private String expiryField;
private Environment env;
private static final Logger LOG = LoggerFactory.getLogger(CliTokenSource.class);

public CliTokenSource(
List<String> cmd,
Expand Down Expand Up @@ -68,10 +71,13 @@ protected Token refresh() {
try {
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder.environment().putAll(env.getEnv());
LOG.debug("Executing command: " + cmd);
Process process = processBuilder.start();
int exitCode = process.waitFor();
String stdout = getProcessStream(process.getInputStream());
LOG.debug("stdout: " + stdout);
String stderr = getProcessStream(process.getErrorStream());
int exitCode = process.waitFor();
LOG.debug("stderr: " + stderr);
if (exitCode != 0) {
if (stderr.contains("not found")) {
throw new DatabricksException(stderr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,13 @@ public DatabricksConfig setAzureUseMsi(boolean azureUseMsi) {
return this;
}

/**
* @deprecated Use {@link #getAzureUseMsi()} instead.
*/
/* @deprecated Use {@link #getAzureUseMsi()} instead. */
@Deprecated()
public boolean getAzureUseMSI() {
return azureUseMsi;
}

/**
* @deprecated Use {@link #setAzureUseMsi(boolean)} instead.
*/
/* @deprecated Use {@link #setAzureUseMsi(boolean)} instead. */
@Deprecated
public DatabricksConfig setAzureUseMSI(boolean azureUseMsi) {
this.azureUseMsi = azureUseMsi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ void azureCliWorkspaceHeaderPresent() {
StaticEnv env =
new StaticEnv()
.with("HOME", TestOSUtils.resource("/testdata/azure"))
.with("PATH", "testdata:/bin");
.with("PATH", "/bin:testdata")
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"));
String azureWorkspaceResourceId =
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";
DatabricksConfig config =
Expand All @@ -32,7 +33,8 @@ void azureCliUserWithManagementAccess() {
StaticEnv env =
new StaticEnv()
.with("HOME", TestOSUtils.resource("/testdata/azure"))
.with("PATH", "testdata:/bin");
.with("PATH", "/bin:testdata")
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"));
String azureWorkspaceResourceId =
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";
DatabricksConfig config =
Expand All @@ -50,7 +52,8 @@ void azureCliUserNoManagementAccess() {
StaticEnv env =
new StaticEnv()
.with("HOME", TestOSUtils.resource("/testdata/azure"))
.with("PATH", "testdata:/bin")
.with("PATH", "/bin:testdata")
.with("AZ_PATH", TestOSUtils.resource("/testdata/az"))
.with("FAIL_IF", "https://management.core.windows.net/");
String azureWorkspaceResourceId =
"/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public static String resource(String file) {
if (resource == null) {
fail("Asset not found: " + file);
}
return resource.getFile();

String filePath = resource.getFile();
File f = new File(filePath);

// Make the file executable
if (!f.setExecutable(true)) {
fail("Failed to set the file as executable: " + file);
}

return filePath;
}
}
2 changes: 1 addition & 1 deletion databricks-sdk-java/src/test/resources/testdata/az
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

for arg in "$@"; do
if [[ "$arg" == "$FAIL_IF" ]]; then
echo "Failed"
/bin/echo "Failed"
exit 1
fi
done
Expand Down

0 comments on commit 9d08452

Please sign in to comment.