|
19 | 19 | import build.bazel.remote.execution.v2.DigestFunction;
|
20 | 20 | import build.bazel.remote.execution.v2.ServerCapabilities;
|
21 | 21 | import com.google.auth.Credentials;
|
| 22 | +import com.google.auto.value.AutoValue; |
22 | 23 | import com.google.common.annotations.VisibleForTesting;
|
23 | 24 | import com.google.common.base.Ascii;
|
24 | 25 | import com.google.common.base.Preconditions;
|
|
50 | 51 | import com.google.devtools.build.lib.authandtls.Netrc;
|
51 | 52 | import com.google.devtools.build.lib.authandtls.NetrcCredentials;
|
52 | 53 | import com.google.devtools.build.lib.authandtls.NetrcParser;
|
| 54 | +import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperEnvironment; |
| 55 | +import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialHelperProvider; |
53 | 56 | import com.google.devtools.build.lib.bazel.repository.downloader.Downloader;
|
54 | 57 | import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader;
|
55 | 58 | import com.google.devtools.build.lib.buildeventstream.LocalFilesArtifactUploader;
|
|
78 | 81 | import com.google.devtools.build.lib.runtime.BuildEventArtifactUploaderFactory;
|
79 | 82 | import com.google.devtools.build.lib.runtime.Command;
|
80 | 83 | import com.google.devtools.build.lib.runtime.CommandEnvironment;
|
| 84 | +import com.google.devtools.build.lib.runtime.CommandLinePathFactory; |
81 | 85 | import com.google.devtools.build.lib.runtime.RepositoryRemoteExecutor;
|
82 | 86 | import com.google.devtools.build.lib.runtime.RepositoryRemoteExecutorFactory;
|
83 | 87 | import com.google.devtools.build.lib.runtime.ServerBuilder;
|
@@ -1130,4 +1134,53 @@ static Credentials newCredentials(
|
1130 | 1134 |
|
1131 | 1135 | return creds;
|
1132 | 1136 | }
|
| 1137 | + |
| 1138 | + @VisibleForTesting |
| 1139 | + static CredentialHelperProvider newCredentialHelperProvider( |
| 1140 | + CredentialHelperEnvironment environment, |
| 1141 | + CommandLinePathFactory pathFactory, |
| 1142 | + List<String> inputs) |
| 1143 | + throws IOException { |
| 1144 | + Preconditions.checkNotNull(environment); |
| 1145 | + Preconditions.checkNotNull(pathFactory); |
| 1146 | + Preconditions.checkNotNull(inputs); |
| 1147 | + |
| 1148 | + CredentialHelperProvider.Builder builder = CredentialHelperProvider.builder(); |
| 1149 | + for (String input : inputs) { |
| 1150 | + ScopedCredentialHelper helper = parseCredentialHelperFlag(environment, pathFactory, input); |
| 1151 | + builder.add(helper.getScope(), helper.getPath()); |
| 1152 | + } |
| 1153 | + return builder.build(); |
| 1154 | + } |
| 1155 | + |
| 1156 | + @VisibleForTesting |
| 1157 | + static ScopedCredentialHelper parseCredentialHelperFlag( |
| 1158 | + CredentialHelperEnvironment environment, CommandLinePathFactory pathFactory, String input) |
| 1159 | + throws IOException { |
| 1160 | + Preconditions.checkNotNull(environment); |
| 1161 | + Preconditions.checkNotNull(pathFactory); |
| 1162 | + Preconditions.checkNotNull(input); |
| 1163 | + |
| 1164 | + int pos = input.indexOf('='); |
| 1165 | + if (pos > 0) { |
| 1166 | + String scope = input.substring(0, pos); |
| 1167 | + String path = input.substring(pos + 1); |
| 1168 | + return new AutoValue_RemoteModule_ScopedCredentialHelper( |
| 1169 | + Optional.of(scope), pathFactory.create(environment.getClientEnvironment(), path)); |
| 1170 | + } |
| 1171 | + |
| 1172 | + // `input` does not specify a scope. |
| 1173 | + return new AutoValue_RemoteModule_ScopedCredentialHelper( |
| 1174 | + Optional.empty(), pathFactory.create(environment.getClientEnvironment(), input)); |
| 1175 | + } |
| 1176 | + |
| 1177 | + @VisibleForTesting |
| 1178 | + @AutoValue |
| 1179 | + static abstract class ScopedCredentialHelper { |
| 1180 | + /** Returns the scope of the credential helper (if any). */ |
| 1181 | + public abstract Optional<String> getScope(); |
| 1182 | + |
| 1183 | + /** Returns the path of the credential helper. */ |
| 1184 | + public abstract Path getPath(); |
| 1185 | + } |
1133 | 1186 | }
|
0 commit comments