Skip to content

Commit 33482eb

Browse files
committed
updates
Signed-off-by: Appu Goundan <[email protected]>
1 parent be5deff commit 33482eb

File tree

9 files changed

+62
-50
lines changed

9 files changed

+62
-50
lines changed

sigstore-java/src/main/java/dev/sigstore/tuf/FileSystemTufStore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public byte[] readTarget(String targetName) throws IOException {
7979
}
8080

8181
@Override
82-
public void setMeta(String roleName, SignedTufMeta<?> meta) throws IOException {
82+
public void writeMeta(String roleName, SignedTufMeta<?> meta) throws IOException {
8383
storeRole(roleName, meta);
8484
}
8585

8686
@Override
87-
public <T extends SignedTufMeta<?>> Optional<T> findMeta(String roleName, Class<T> tClass)
87+
public <T extends SignedTufMeta<?>> Optional<T> readMeta(String roleName, Class<T> tClass)
8888
throws IOException {
8989
Path roleFile = repoBaseDir.resolve(roleName + ".json");
9090
if (!roleFile.toFile().exists()) {
@@ -101,8 +101,8 @@ <T extends SignedTufMeta<?>> void storeRole(String roleName, T role) throws IOEx
101101
}
102102

103103
@Override
104-
public void setRoot(Root root) throws IOException {
105-
Optional<Root> trustedRoot = findMeta(RootRole.ROOT, Root.class);
104+
public void writeRoot(Root root) throws IOException {
105+
Optional<Root> trustedRoot = readMeta(RootRole.ROOT, Root.class);
106106
if (trustedRoot.isPresent()) {
107107
try {
108108
Files.move(

sigstore-java/src/main/java/dev/sigstore/tuf/MetaReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.util.Optional;
2222

23+
/** Interface that defines reading meta from local storage. */
2324
public interface MetaReader {
2425

2526
/**
@@ -31,6 +32,6 @@ public interface MetaReader {
3132
* @return an instance of the signed metadata for the role if it was found
3233
* @throws IOException if an error occurs reading from the backing store
3334
*/
34-
<T extends SignedTufMeta<? extends TufMeta>> Optional<T> findMeta(
35+
<T extends SignedTufMeta<? extends TufMeta>> Optional<T> readMeta(
3536
String roleName, Class<T> tClass) throws IOException;
3637
}

sigstore-java/src/main/java/dev/sigstore/tuf/MetaStore.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
import dev.sigstore.tuf.model.TufMeta;
2121
import java.io.IOException;
2222

23-
/** Interface that defined a mutable meta store functionality. */
23+
/** Interface that defines a mutable meta store functionality. */
2424
public interface MetaStore extends MetaReader {
2525

26+
/**
27+
* A generic string for identifying the local store in debug messages. A file system based
28+
* implementation might return the path being used for storage, while an in-memory store may just
29+
* return something like 'in-memory'.
30+
*/
2631
String getIdentifier();
2732

2833
/**
2934
* Generic method to store one of the {@link SignedTufMeta} resources in the local tuf store. Do
30-
* not use for Root role, use {@link #setRoot(Root)} instead.
35+
* not use for Root role, use {@link #writeRoot(Root)} instead.
3136
*
3237
* @param roleName the name of the role
3338
* @param meta the metadata to store
3439
* @throws IOException if writing the resource causes an IO error
3540
*/
36-
void setMeta(String roleName, SignedTufMeta<? extends TufMeta> meta) throws IOException;
41+
void writeMeta(String roleName, SignedTufMeta<? extends TufMeta> meta) throws IOException;
3742

3843
/**
3944
* Once you have ascertained that your root is trustworthy use this method to persist it to your
@@ -46,7 +51,7 @@ public interface MetaStore extends MetaReader {
4651
* @see <a
4752
* href="https://theupdateframework.github.io/specification/latest/#detailed-client-workflow">5.3.8</a>
4853
*/
49-
void setRoot(Root root) throws IOException;
54+
void writeRoot(Root root) throws IOException;
5055

5156
/**
5257
* This clears out the snapshot and timestamp metadata from the store, as required when snapshot

sigstore-java/src/main/java/dev/sigstore/tuf/PassthroughCacheMetaStore.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ public static PassthroughCacheMetaStore newPassthroughMetaCache(MetaStore localS
4545
}
4646

4747
@Override
48-
public void setRoot(Root root) throws IOException {
49-
// call storeRoot instead of generic storeMeta because it does extra work when storing on disk
50-
localStore.setRoot(root);
48+
public void writeRoot(Root root) throws IOException {
49+
// call writeRoot instead of generic writeMeta because it may do extra work when storing on disk
50+
localStore.writeRoot(root);
5151
cache.put(RootRole.ROOT, root);
5252
}
5353

5454
@Override
5555
@SuppressWarnings("unchecked")
56-
public <T extends SignedTufMeta<? extends TufMeta>> Optional<T> findMeta(
56+
public <T extends SignedTufMeta<? extends TufMeta>> Optional<T> readMeta(
5757
String roleName, Class<T> tClass) throws IOException {
5858
// check memory cache
5959
if (cache.containsKey(roleName)) {
6060
return Optional.of((T) cache.get(roleName));
6161
}
6262

6363
// check backing storage and write to memory if found
64-
var value = localStore.findMeta(roleName, tClass);
64+
var value = localStore.readMeta(roleName, tClass);
6565
value.ifPresent(v -> cache.put(roleName, v));
6666

6767
return value;
6868
}
6969

7070
@Override
71-
public void setMeta(String roleName, SignedTufMeta<? extends TufMeta> meta) throws IOException {
71+
public void writeMeta(String roleName, SignedTufMeta<? extends TufMeta> meta) throws IOException {
7272
if (Objects.equals(roleName, RootRole.ROOT)) {
73-
throw new IllegalArgumentException("Calling setMeta on root instead of setRoot");
73+
throw new IllegalArgumentException("Calling writeMeta on root instead of writeRoot");
7474
}
75-
localStore.setMeta(roleName, meta);
75+
localStore.writeMeta(roleName, meta);
7676
cache.put(roleName, meta);
7777
}
7878

sigstore-java/src/main/java/dev/sigstore/tuf/TargetReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919

20+
/** Interface that defines reading targets from local storage. */
2021
public interface TargetReader {
2122

2223
/**

sigstore-java/src/main/java/dev/sigstore/tuf/TargetStore.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
import java.io.IOException;
1919

20-
/** Interface that defined a mutable meta store functionality. */
20+
/** Interface that defines a mutable target store functionality. */
2121
public interface TargetStore extends TargetReader {
2222

23+
/**
24+
* A generic string for identifying the local store in debug messages. A file system based
25+
* implementation might return the path being used for storage, while an in-memory store may just
26+
* return something like 'in-memory'.
27+
*/
2328
String getIdentifier();
2429

2530
/**

sigstore-java/src/main/java/dev/sigstore/tuf/TrustedMetaStore.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String getIdentifier() {
6060
<T extends SignedTufMeta<? extends TufMeta>> T getMeta(String roleName, Class<T> tClass)
6161
throws IOException {
6262
return metaStore
63-
.findMeta(roleName, tClass)
63+
.readMeta(roleName, tClass)
6464
.orElseThrow(
6565
() ->
6666
new IllegalStateException(
@@ -70,51 +70,51 @@ <T extends SignedTufMeta<? extends TufMeta>> T getMeta(String roleName, Class<T>
7070
}
7171

7272
public void setRoot(Root root) throws IOException {
73-
metaStore.setRoot(root);
73+
metaStore.writeRoot(root);
7474
}
7575

7676
public Root getRoot() throws IOException {
7777
return getMeta(RootRole.ROOT, Root.class);
7878
}
7979

8080
public Optional<Root> findRoot() throws IOException {
81-
return metaStore.findMeta(RootRole.ROOT, Root.class);
81+
return metaStore.readMeta(RootRole.ROOT, Root.class);
8282
}
8383

8484
public void setTimestamp(Timestamp timestamp) throws IOException {
85-
metaStore.setMeta(RootRole.TIMESTAMP, timestamp);
85+
metaStore.writeMeta(RootRole.TIMESTAMP, timestamp);
8686
}
8787

8888
public Timestamp getTimestamp() throws IOException {
8989
return getMeta(RootRole.TIMESTAMP, Timestamp.class);
9090
}
9191

9292
public Optional<Timestamp> findTimestamp() throws IOException {
93-
return metaStore.findMeta(RootRole.TIMESTAMP, Timestamp.class);
93+
return metaStore.readMeta(RootRole.TIMESTAMP, Timestamp.class);
9494
}
9595

9696
public void setSnapshot(Snapshot snapshot) throws IOException {
97-
metaStore.setMeta(RootRole.SNAPSHOT, snapshot);
97+
metaStore.writeMeta(RootRole.SNAPSHOT, snapshot);
9898
}
9999

100100
public Snapshot getSnapshot() throws IOException {
101101
return getMeta(RootRole.SNAPSHOT, Snapshot.class);
102102
}
103103

104104
public Optional<Snapshot> findSnapshot() throws IOException {
105-
return metaStore.findMeta(RootRole.SNAPSHOT, Snapshot.class);
105+
return metaStore.readMeta(RootRole.SNAPSHOT, Snapshot.class);
106106
}
107107

108108
public void setTargets(Targets targets) throws IOException {
109-
metaStore.setMeta(RootRole.TARGETS, targets);
109+
metaStore.writeMeta(RootRole.TARGETS, targets);
110110
}
111111

112112
public Targets getTargets() throws IOException {
113113
return getMeta(RootRole.TARGETS, Targets.class);
114114
}
115115

116116
public Optional<Targets> findTargets() throws IOException {
117-
return metaStore.findMeta(RootRole.TARGETS, Targets.class);
117+
return metaStore.readMeta(RootRole.TARGETS, Targets.class);
118118
}
119119

120120
public void clearMetaDueToKeyRotation() throws IOException {

sigstore-java/src/test/java/dev/sigstore/tuf/FileSystemTufStoreTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ class FileSystemTufStoreTest {
3232
@Test
3333
void newFileSystemStore_empty(@TempDir Path repoBase) throws IOException {
3434
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
35-
assertFalse(tufStore.findMeta(RootRole.ROOT, Root.class).isPresent());
35+
assertFalse(tufStore.readMeta(RootRole.ROOT, Root.class).isPresent());
3636
}
3737

3838
@Test
3939
void newFileSystemStore_hasRepo(@TempDir Path repoBase) throws IOException {
4040
TestResources.setupRepoFiles(PROD_REPO, repoBase, "root.json");
4141
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
42-
assertTrue(tufStore.findMeta(RootRole.ROOT, Root.class).isPresent());
42+
assertTrue(tufStore.readMeta(RootRole.ROOT, Root.class).isPresent());
4343
}
4444

4545
@Test
4646
void setTrustedRoot_noPrevious(@TempDir Path repoBase) throws IOException {
4747
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
4848
assertFalse(repoBase.resolve("root.json").toFile().exists());
49-
tufStore.setRoot(TestResources.loadRoot(TestResources.UPDATER_REAL_TRUSTED_ROOT));
49+
tufStore.writeRoot(TestResources.loadRoot(TestResources.UPDATER_REAL_TRUSTED_ROOT));
5050
assertEquals(2, repoBase.toFile().list().length, "Expect 2: root.json plus the /targets dir.");
5151
assertTrue(repoBase.resolve("root.json").toFile().exists());
5252
assertTrue(repoBase.resolve("targets").toFile().isDirectory());
@@ -56,9 +56,9 @@ void setTrustedRoot_noPrevious(@TempDir Path repoBase) throws IOException {
5656
void setTrustedRoot_backupPerformed(@TempDir Path repoBase) throws IOException {
5757
TestResources.setupRepoFiles(PROD_REPO, repoBase, "root.json");
5858
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
59-
int version = tufStore.findMeta(RootRole.ROOT, Root.class).get().getSignedMeta().getVersion();
59+
int version = tufStore.readMeta(RootRole.ROOT, Root.class).get().getSignedMeta().getVersion();
6060
assertFalse(repoBase.resolve(version + ".root.json").toFile().exists());
61-
tufStore.setRoot(TestResources.loadRoot(TestResources.UPDATER_REAL_TRUSTED_ROOT));
61+
tufStore.writeRoot(TestResources.loadRoot(TestResources.UPDATER_REAL_TRUSTED_ROOT));
6262
assertTrue(repoBase.resolve(version + ".root.json").toFile().exists());
6363
}
6464

sigstore-java/src/test/java/dev/sigstore/tuf/PassthroughCacheMetaStoreTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,54 +61,54 @@ public void setup() throws IOException {
6161

6262
@Test
6363
public void root_test() throws Exception {
64-
assertTrue(fileSystemTufStore.findMeta(RootRole.ROOT, Root.class).isEmpty());
65-
assertTrue(passthroughCacheMetaStore.findMeta(RootRole.ROOT, Root.class).isEmpty());
64+
assertTrue(fileSystemTufStore.readMeta(RootRole.ROOT, Root.class).isEmpty());
65+
assertTrue(passthroughCacheMetaStore.readMeta(RootRole.ROOT, Root.class).isEmpty());
6666

67-
passthroughCacheMetaStore.setRoot(root);
67+
passthroughCacheMetaStore.writeRoot(root);
6868

69-
assertEquals(root, fileSystemTufStore.findMeta(RootRole.ROOT, Root.class).get());
70-
assertEquals(root, passthroughCacheMetaStore.findMeta(RootRole.ROOT, Root.class).get());
69+
assertEquals(root, fileSystemTufStore.readMeta(RootRole.ROOT, Root.class).get());
70+
assertEquals(root, passthroughCacheMetaStore.readMeta(RootRole.ROOT, Root.class).get());
7171
}
7272

7373
@Test
7474
public void root_canInitFromDisk() throws Exception {
75-
assertTrue(fileSystemTufStore.findMeta(RootRole.ROOT, Root.class).isEmpty());
76-
assertTrue(passthroughCacheMetaStore.findMeta(RootRole.ROOT, Root.class).isEmpty());
75+
assertTrue(fileSystemTufStore.readMeta(RootRole.ROOT, Root.class).isEmpty());
76+
assertTrue(passthroughCacheMetaStore.readMeta(RootRole.ROOT, Root.class).isEmpty());
7777

7878
try (BufferedWriter fileWriter = Files.newBufferedWriter(localStore.resolve("root.json"))) {
7979
GSON.get().toJson(root, fileWriter);
8080
}
8181

82-
assertEquals(root, fileSystemTufStore.findMeta(RootRole.ROOT, Root.class).get());
83-
assertEquals(root, passthroughCacheMetaStore.findMeta(RootRole.ROOT, Root.class).get());
82+
assertEquals(root, fileSystemTufStore.readMeta(RootRole.ROOT, Root.class).get());
83+
assertEquals(root, passthroughCacheMetaStore.readMeta(RootRole.ROOT, Root.class).get());
8484
}
8585

8686
@Test
8787
public void meta_test() throws Exception {
8888
// root uses special handling for writing, but the rest of them don't, so we just test
8989
// timestamp here arbitrarily
90-
assertTrue(fileSystemTufStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
91-
assertTrue(passthroughCacheMetaStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
90+
assertTrue(fileSystemTufStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
91+
assertTrue(passthroughCacheMetaStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
9292

93-
passthroughCacheMetaStore.setMeta(RootRole.TIMESTAMP, timestamp);
93+
passthroughCacheMetaStore.writeMeta(RootRole.TIMESTAMP, timestamp);
9494

95-
assertEquals(timestamp, fileSystemTufStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).get());
95+
assertEquals(timestamp, fileSystemTufStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).get());
9696
assertEquals(
97-
timestamp, passthroughCacheMetaStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).get());
97+
timestamp, passthroughCacheMetaStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).get());
9898
}
9999

100100
@Test
101101
public void timestamp_canInitFromDisk() throws Exception {
102-
assertTrue(fileSystemTufStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
103-
assertTrue(passthroughCacheMetaStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
102+
assertTrue(fileSystemTufStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
103+
assertTrue(passthroughCacheMetaStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).isEmpty());
104104

105105
try (BufferedWriter fileWriter =
106106
Files.newBufferedWriter(localStore.resolve("timestamp.json"))) {
107107
GSON.get().toJson(timestamp, fileWriter);
108108
}
109109

110-
assertEquals(timestamp, fileSystemTufStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).get());
110+
assertEquals(timestamp, fileSystemTufStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).get());
111111
assertEquals(
112-
timestamp, passthroughCacheMetaStore.findMeta(RootRole.TIMESTAMP, Timestamp.class).get());
112+
timestamp, passthroughCacheMetaStore.readMeta(RootRole.TIMESTAMP, Timestamp.class).get());
113113
}
114114
}

0 commit comments

Comments
 (0)