File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ filegroup(
10
10
11
11
java_library (
12
12
name = "credential_module" ,
13
- srcs = ["CredentialModule.java" ],
13
+ srcs = [
14
+ "CredentialModule.java" ,
15
+ "SystemMillisTicker.java" ,
16
+ ],
14
17
deps = [
15
18
"//src/main/java/com/google/devtools/build/lib:runtime" ,
16
19
"//src/main/java/com/google/devtools/build/lib/authandtls" ,
@@ -23,7 +26,10 @@ java_library(
23
26
name = "credentialhelper" ,
24
27
srcs = glob (
25
28
["*.java" ],
26
- exclude = ["CredentialModule.java" ],
29
+ exclude = [
30
+ "CredentialModule.java" ,
31
+ "SystemMillisTicker.java" ,
32
+ ],
27
33
),
28
34
deps = [
29
35
"//src/main/java/com/google/devtools/build/lib/events" ,
Original file line number Diff line number Diff line change 27
27
/** A module whose sole purpose is to hold the credential cache which is shared by other modules. */
28
28
public class CredentialModule extends BlazeModule {
29
29
private final Cache <URI , ImmutableMap <String , ImmutableList <String >>> credentialCache =
30
- Caffeine .newBuilder ().expireAfterWrite (Duration .ZERO ).build ();
30
+ Caffeine .newBuilder ()
31
+ .expireAfterWrite (Duration .ZERO )
32
+ .ticker (SystemMillisTicker .INSTANCE )
33
+ .build ();
31
34
32
35
/** Returns the credential cache. */
33
36
public Cache <URI , ImmutableMap <String , ImmutableList <String >>> getCredentialCache () {
Original file line number Diff line number Diff line change
1
+ // Copyright 2023 The Bazel Authors. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package com .google .devtools .build .lib .authandtls .credentialhelper ;
16
+
17
+ import com .github .benmanes .caffeine .cache .Ticker ;
18
+
19
+ /**
20
+ * SystemMillisTicker is a Ticker which uses the unix epoch as its fixed reference point.
21
+ *
22
+ * <p>It is preferable to com.github.benmanes.caffeine.cache.Ticker.SystemTicker because that class
23
+ * doesn't increment its time-source while the system is asleep, which isn't appropriate when
24
+ * expiring tokens which have wall-time-based expiry policies.
25
+ */
26
+ public class SystemMillisTicker implements Ticker {
27
+ public static final SystemMillisTicker INSTANCE = new SystemMillisTicker ();
28
+
29
+ private SystemMillisTicker () {}
30
+
31
+ @ Override
32
+ public long read () {
33
+ return System .currentTimeMillis () * 1_000_000 ;
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments