Skip to content

Commit

Permalink
Move newCredentialHelperProvider into GoogleAuthUtils
Browse files Browse the repository at this point in the history
Follow-up on bazelbuild#15930 due to
bazelbuild#15906

Progress on bazelbuild#15856
  • Loading branch information
Yannic committed Jul 21, 2022
1 parent 1c14552 commit e42252c
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 305 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ java_library(
],
)

java_library(
name = "runtime/command_line_path_factory",
srcs = [
"runtime/CommandLinePathFactory.java",
],
deps = [
"//src/main/java/com/google/devtools/build/lib/analysis:blaze_directories",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:guava",
],
)

java_library(
name = "runtime",
srcs = glob(
Expand All @@ -229,6 +242,7 @@ java_library(
"buildtool/BuildRequestOptions.java",
"runtime/BlazeCommandResult.java",
"runtime/CommandDispatcher.java",
"runtime/CommandLinePathFactory.java",
"runtime/KeepGoingOption.java",
"runtime/LoadingPhaseThreadsOption.java",
],
Expand All @@ -239,6 +253,7 @@ java_library(
":loading-phase-threads-option",
":runtime/blaze_command_result",
":runtime/command_dispatcher",
":runtime/command_line_path_factory",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:action_lookup_data",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/authandtls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ java_library(
name = "authandtls",
srcs = glob(["*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib:runtime/command_line_path_factory",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/common/options",
"//third_party:auth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperEnvironment;
import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperProvider;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.runtime.CommandLinePathFactory;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import io.grpc.CallCredentials;
Expand Down Expand Up @@ -338,4 +341,27 @@ static Optional<Credentials> newCredentialsFromNetrc(
"Failed to parse " + netrcFile.getPathString() + ": " + e.getMessage(), e);
}
}

@VisibleForTesting
public static CredentialHelperProvider newCredentialHelperProvider(
CredentialHelperEnvironment environment,
CommandLinePathFactory pathFactory,
List<AuthAndTLSOptions.UnresolvedScopedCredentialHelper> helpers)
throws IOException {
Preconditions.checkNotNull(environment);
Preconditions.checkNotNull(pathFactory);
Preconditions.checkNotNull(helpers);

CredentialHelperProvider.Builder builder = CredentialHelperProvider.builder();
for (AuthAndTLSOptions.UnresolvedScopedCredentialHelper helper : helpers) {
Optional<String> scope = helper.getScope();
Path path = pathFactory.create(environment.getClientEnvironment(), helper.getPath());
if (scope.isPresent()) {
builder.add(scope.get(), path);
} else {
builder.add(path);
}
}
return builder.build();
}
}
1 change: 0 additions & 1 deletion src/main/java/com/google/devtools/build/lib/remote/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context",
"//src/main/java/com/google/devtools/build/lib/analysis/platform:platform_utils",
"//src/main/java/com/google/devtools/build/lib/authandtls",
"//src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper",
"//src/main/java/com/google/devtools/build/lib/bazel/repository/downloader",
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
"//src/main/java/com/google/devtools/build/lib/clock",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import build.bazel.remote.execution.v2.DigestFunction;
import build.bazel.remote.execution.v2.ServerCapabilities;
import com.google.auth.Credentials;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
Expand All @@ -46,11 +45,8 @@
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.test.TestProvider;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions.UnresolvedScopedCredentialHelper;
import com.google.devtools.build.lib.authandtls.CallCredentialsProvider;
import com.google.devtools.build.lib.authandtls.GoogleAuthUtils;
import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperEnvironment;
import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperProvider;
import com.google.devtools.build.lib.bazel.repository.downloader.Downloader;
import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader;
import com.google.devtools.build.lib.buildeventstream.LocalFilesArtifactUploader;
Expand Down Expand Up @@ -79,7 +75,6 @@
import com.google.devtools.build.lib.runtime.BuildEventArtifactUploaderFactory;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.CommandLinePathFactory;
import com.google.devtools.build.lib.runtime.RepositoryRemoteExecutor;
import com.google.devtools.build.lib.runtime.RepositoryRemoteExecutorFactory;
import com.google.devtools.build.lib.runtime.ServerBuilder;
Expand Down Expand Up @@ -1044,29 +1039,6 @@ RemoteActionContextProvider getActionContextProvider() {
return actionContextProvider;
}

@VisibleForTesting
static CredentialHelperProvider newCredentialHelperProvider(
CredentialHelperEnvironment environment,
CommandLinePathFactory pathFactory,
List<UnresolvedScopedCredentialHelper> helpers)
throws IOException {
Preconditions.checkNotNull(environment);
Preconditions.checkNotNull(pathFactory);
Preconditions.checkNotNull(helpers);

CredentialHelperProvider.Builder builder = CredentialHelperProvider.builder();
for (UnresolvedScopedCredentialHelper helper : helpers) {
Optional<String> scope = helper.getScope();
Path path = pathFactory.create(environment.getClientEnvironment(), helper.getPath());
if (scope.isPresent()) {
builder.add(scope.get(), path);
} else {
builder.add(path);
}
}
return builder.build();
}

static Credentials newCredentials(
Map<String, String> clientEnv,
FileSystem fileSystem,
Expand Down Expand Up @@ -1095,14 +1067,4 @@ static Credentials newCredentials(

return credentials;
}

@VisibleForTesting
@AutoValue
abstract static class ScopedCredentialHelper {
/** Returns the scope of the credential helper (if any). */
public abstract Optional<String> getScope();

/** Returns the path of the credential helper. */
public abstract Path getPath();
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/google/devtools/build/lib/authandtls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ java_library(
],
),
deps = [
"//src/main/java/com/google/devtools/build/lib:runtime/command_line_path_factory",
"//src/main/java/com/google/devtools/build/lib/authandtls",
"//src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//src/main/java/com/google/devtools/common/options",
Expand Down

0 comments on commit e42252c

Please sign in to comment.