forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[remote/downloader] Migrate
Downloader
to take Credentials
Progress on bazelbuild#15856
- Loading branch information
Showing
16 changed files
with
123 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/google/devtools/build/lib/authandtls/staticcredentials/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("@rules_java//java:defs.bzl", "java_library") | ||
|
||
package(default_visibility = ["//src:__subpackages__"]) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
java_library( | ||
name = "staticcredentials", | ||
srcs = glob(["*.java"]), | ||
deps = [ | ||
"//third_party:auth", | ||
"//third_party:guava", | ||
], | ||
) |
51 changes: 51 additions & 0 deletions
51
...in/java/com/google/devtools/build/lib/authandtls/staticcredentials/StaticCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.google.devtools.build.lib.authandtls.staticcredentials; | ||
|
||
import com.google.auth.Credentials; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** Implementation of {@link Credentials} which provides a static set of credentials. */ | ||
public final class StaticCredentials extends Credentials { | ||
private final ImmutableMap<URI, Map<String, List<String>>> credentials; | ||
|
||
public StaticCredentials(Map<URI, Map<String, List<String>>> credentials) { | ||
Preconditions.checkNotNull(credentials); | ||
|
||
this.credentials = ImmutableMap.copyOf(credentials); | ||
} | ||
|
||
public Map<URI, Map<String, List<String>>> getMapForMigration() { | ||
return credentials; | ||
} | ||
|
||
@Override | ||
public String getAuthenticationType() { | ||
return "static"; | ||
} | ||
|
||
@Override | ||
public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException { | ||
Preconditions.checkNotNull(uri); | ||
|
||
return credentials.getOrDefault(uri, ImmutableMap.of()); | ||
} | ||
|
||
@Override | ||
public boolean hasRequestMetadata() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasRequestMetadataOnly() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void refresh() { | ||
// Can't refresh static credentials. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.