|
18 | 18 | */
|
19 | 19 | package org.apache.polaris.core.storage.cache;
|
20 | 20 |
|
21 |
| -import java.util.Objects; |
| 21 | +import jakarta.annotation.Nullable; |
22 | 22 | import java.util.Set;
|
23 | 23 | import org.apache.polaris.core.entity.PolarisEntity;
|
24 | 24 | import org.apache.polaris.core.entity.PolarisEntityConstants;
|
| 25 | +import org.apache.polaris.immutables.PolarisImmutable; |
25 | 26 |
|
26 |
| -public final class StorageCredentialCacheKey { |
| 27 | +@PolarisImmutable |
| 28 | +public interface StorageCredentialCacheKey { |
27 | 29 |
|
28 |
| - private final String realmId; |
29 |
| - private final long catalogId; |
| 30 | + String realmId(); |
30 | 31 |
|
31 |
| - /** The serialized string of the storage config. */ |
32 |
| - private final String storageConfigSerializedStr; |
| 32 | + long catalogId(); |
33 | 33 |
|
34 |
| - private final boolean allowedListAction; |
35 |
| - private final Set<String> allowedReadLocations; |
| 34 | + @Nullable |
| 35 | + String storageConfigSerializedStr(); |
36 | 36 |
|
37 |
| - private final Set<String> allowedWriteLocations; |
| 37 | + boolean allowedListAction(); |
38 | 38 |
|
39 |
| - public StorageCredentialCacheKey( |
| 39 | + Set<String> allowedReadLocations(); |
| 40 | + |
| 41 | + Set<String> allowedWriteLocations(); |
| 42 | + |
| 43 | + static StorageCredentialCacheKey of( |
40 | 44 | String realmId,
|
41 | 45 | PolarisEntity entity,
|
42 | 46 | boolean allowedListAction,
|
43 | 47 | Set<String> allowedReadLocations,
|
44 | 48 | Set<String> allowedWriteLocations) {
|
45 |
| - this.realmId = realmId; |
46 |
| - this.catalogId = entity.getCatalogId(); |
47 |
| - this.storageConfigSerializedStr = |
| 49 | + String storageConfigSerializedStr = |
48 | 50 | entity
|
49 | 51 | .getInternalPropertiesAsMap()
|
50 | 52 | .get(PolarisEntityConstants.getStorageConfigInfoPropertyName());
|
51 |
| - this.allowedListAction = allowedListAction; |
52 |
| - this.allowedReadLocations = allowedReadLocations; |
53 |
| - this.allowedWriteLocations = allowedWriteLocations; |
54 |
| - } |
55 |
| - |
56 |
| - public String getRealmId() { |
57 |
| - return realmId; |
58 |
| - } |
59 |
| - |
60 |
| - public long getCatalogId() { |
61 |
| - return catalogId; |
62 |
| - } |
63 |
| - |
64 |
| - public String getStorageConfigSerializedStr() { |
65 |
| - return storageConfigSerializedStr; |
66 |
| - } |
67 |
| - |
68 |
| - public boolean isAllowedListAction() { |
69 |
| - return allowedListAction; |
70 |
| - } |
71 |
| - |
72 |
| - public Set<String> getAllowedReadLocations() { |
73 |
| - return allowedReadLocations; |
74 |
| - } |
75 |
| - |
76 |
| - public Set<String> getAllowedWriteLocations() { |
77 |
| - return allowedWriteLocations; |
78 |
| - } |
79 |
| - |
80 |
| - @Override |
81 |
| - public boolean equals(Object o) { |
82 |
| - if (this == o) return true; |
83 |
| - if (o == null || getClass() != o.getClass()) return false; |
84 |
| - StorageCredentialCacheKey cacheKey = (StorageCredentialCacheKey) o; |
85 |
| - return Objects.equals(realmId, cacheKey.getRealmId()) |
86 |
| - && catalogId == cacheKey.getCatalogId() |
87 |
| - && Objects.equals(storageConfigSerializedStr, cacheKey.getStorageConfigSerializedStr()) |
88 |
| - && allowedListAction == cacheKey.allowedListAction |
89 |
| - && Objects.equals(allowedReadLocations, cacheKey.allowedReadLocations) |
90 |
| - && Objects.equals(allowedWriteLocations, cacheKey.allowedWriteLocations); |
91 |
| - } |
92 |
| - |
93 |
| - @Override |
94 |
| - public int hashCode() { |
95 |
| - return Objects.hash( |
96 |
| - realmId, |
97 |
| - catalogId, |
98 |
| - storageConfigSerializedStr, |
99 |
| - allowedListAction, |
100 |
| - allowedReadLocations, |
101 |
| - allowedWriteLocations); |
102 |
| - } |
103 |
| - |
104 |
| - @Override |
105 |
| - public String toString() { |
106 |
| - return "StorageCredentialCacheKey{" |
107 |
| - + "realmId=" |
108 |
| - + realmId |
109 |
| - + ", catalogId=" |
110 |
| - + catalogId |
111 |
| - + ", storageConfigSerializedStr='" |
112 |
| - + storageConfigSerializedStr |
113 |
| - + '\'' |
114 |
| - + ", allowedListAction=" |
115 |
| - + allowedListAction |
116 |
| - + ", allowedReadLocations=" |
117 |
| - + allowedReadLocations |
118 |
| - + ", allowedWriteLocations=" |
119 |
| - + allowedWriteLocations |
120 |
| - + '}'; |
| 53 | + return ImmutableStorageCredentialCacheKey.builder() |
| 54 | + .realmId(realmId) |
| 55 | + .catalogId(entity.getCatalogId()) |
| 56 | + .storageConfigSerializedStr(storageConfigSerializedStr) |
| 57 | + .allowedListAction(allowedListAction) |
| 58 | + .allowedReadLocations(allowedReadLocations) |
| 59 | + .allowedWriteLocations(allowedWriteLocations) |
| 60 | + .build(); |
121 | 61 | }
|
122 | 62 | }
|
0 commit comments