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 @@ -13,7 +13,10 @@ filegroup(
1313
1414java_library (
1515 name = "credential_module" ,
16- srcs = ["CredentialModule.java" ],
16+ srcs = [
17+ "CredentialModule.java" ,
18+ "SystemMillisTicker.java" ,
19+ ],
1720 deps = [
1821 "//src/main/java/com/google/devtools/build/lib:runtime" ,
1922 "//src/main/java/com/google/devtools/build/lib/authandtls" ,
@@ -26,7 +29,10 @@ java_library(
2629 name = "credentialhelper" ,
2730 srcs = glob (
2831 ["*.java" ],
29- exclude = ["CredentialModule.java" ],
32+ exclude = [
33+ "CredentialModule.java" ,
34+ "SystemMillisTicker.java" ,
35+ ],
3036 ),
3137 deps = [
3238 "//src/main/java/com/google/devtools/build/lib/events" ,
Original file line number Diff line number Diff line change 2727/** A module whose sole purpose is to hold the credential cache which is shared by other modules. */
2828public class CredentialModule extends BlazeModule {
2929 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 ();
3134
3235 /** Returns the credential cache. */
3336 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