forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticCredentials.java
51 lines (40 loc) · 1.28 KB
/
StaticCredentials.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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.
}
}