Skip to content

Commit 23f6c57

Browse files
committed
Revert "No preloading of buckets."
This reverts commit 87452aa
1 parent dc96a6f commit 23f6c57

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

hub/src/main/java/cloud/katta/protocols/hub/HubSession.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class HubSession extends HttpSession<HubApiClient> {
9090
private UserDto me;
9191
private ConfigDto config;
9292
private UserKeys userKeys;
93+
private AttributedList<Path> vaults;
9394

9495
public HubSession(final Host host, final X509TrustManager trust, final X509KeyManager key) {
9596
super(host, trust, key);
@@ -183,6 +184,15 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
183184
throw new InteroperabilityException(String.format("Unsupported storage configuration %s", storageProfile.getProtocol().name()));
184185
}
185186
}
187+
// Ensure vaults are registered
188+
try {
189+
vaults = new HubVaultListService(this, prompt).list(Home.root(), new DisabledListProgressListener());
190+
}
191+
finally {
192+
log.debug("Destroyed user keys {}", userKeys);
193+
// Short-lived
194+
userKeys.destroy();
195+
}
186196
}
187197
catch(ApiException e) {
188198
throw new HubExceptionMappingService().map(e);
@@ -243,7 +253,7 @@ public UserKeys getUserKeys() {
243253
@SuppressWarnings("unchecked")
244254
public <T> T _getFeature(final Class<T> type) {
245255
if(type == ListService.class) {
246-
return (T) new HubVaultListService(this);
256+
return (T) (ListService) (directory, listener) -> vaults;
247257
}
248258
if(type == Scheduler.class) {
249259
return (T) access;

hub/src/main/java/cloud/katta/protocols/hub/HubUVFVault.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ch.cyberduck.core.exception.BackgroundException;
1111
import ch.cyberduck.core.exception.ConnectionCanceledException;
1212
import ch.cyberduck.core.exception.InteroperabilityException;
13+
import ch.cyberduck.core.exception.UnsupportedException;
1314
import ch.cyberduck.core.features.AttributesFinder;
1415
import ch.cyberduck.core.features.Directory;
1516
import ch.cyberduck.core.features.Write;
@@ -63,17 +64,18 @@ public class HubUVFVault extends UVFVault {
6364
private final Session<?> storage;
6465

6566
private final Path home;
67+
private final LoginCallback prompt;
6668

67-
public HubUVFVault(final HubSession hub, final Path bucket, final HubStorageLocationService.StorageLocation location) throws ConnectionCanceledException {
68-
this(hub, UUID.fromString(new UUIDRandomStringService().random()), bucket, location);
69+
public HubUVFVault(final HubSession hub, final Path bucket, final HubStorageLocationService.StorageLocation location, final LoginCallback prompt) throws ConnectionCanceledException {
70+
this(hub, UUID.fromString(new UUIDRandomStringService().random()), bucket, location, prompt);
6971
}
7072

7173
/**
7274
* Constructor for factory creating new vault
7375
*
7476
* @param bucket Bucket
7577
*/
76-
public HubUVFVault(final HubSession hub, final UUID vaultId, final Path bucket, final HubStorageLocationService.StorageLocation location) throws ConnectionCanceledException {
78+
public HubUVFVault(final HubSession hub, final UUID vaultId, final Path bucket, final HubStorageLocationService.StorageLocation location, final LoginCallback prompt) throws ConnectionCanceledException {
7779
this(hub, vaultId, bucket,
7880
UvfMetadataPayload.create()
7981
.withStorage(new VaultMetadataJWEBackendDto()
@@ -83,25 +85,25 @@ public HubUVFVault(final HubSession hub, final UUID vaultId, final Path bucket,
8385
.nickname(null != bucket.attributes().getDisplayname() ? bucket.attributes().getDisplayname() : "Vault"))
8486
.withAutomaticAccessGrant(new VaultMetadataJWEAutomaticAccessGrantDto()
8587
.enabled(true)
86-
.maxWotDepth(null)));
88+
.maxWotDepth(null)), prompt);
8789
}
8890

8991
/**
9092
* Open from existing metadata
9193
*
9294
* @param vaultId Vault ID Used to lookup profile
9395
*/
94-
public HubUVFVault(final HubSession hub, final UUID vaultId, final UvfMetadataPayload vaultMetadata) throws ConnectionCanceledException {
96+
public HubUVFVault(final HubSession hub, final UUID vaultId, final UvfMetadataPayload vaultMetadata, final LoginCallback prompt) throws ConnectionCanceledException {
9597
this(hub, vaultId, new Path(vaultMetadata.storage().getDefaultPath(), EnumSet.of(Path.Type.directory, Path.Type.volume),
96-
new PathAttributes().setDisplayname(vaultMetadata.storage().getNickname())), vaultMetadata);
98+
new PathAttributes().setDisplayname(vaultMetadata.storage().getNickname())), vaultMetadata, prompt);
9799
}
98100

99-
public HubUVFVault(final HubSession hub, final UUID vaultId, final Path bucket, final UvfMetadataPayload vaultMetadata) throws ConnectionCanceledException {
101+
public HubUVFVault(final HubSession hub, final UUID vaultId, final Path bucket, final UvfMetadataPayload vaultMetadata, final LoginCallback prompt) throws ConnectionCanceledException {
100102
super(bucket);
101103
this.vaultId = vaultId;
102104
this.vaultMetadata = vaultMetadata;
103105
this.home = bucket;
104-
106+
this.prompt = prompt;
105107
final VaultMetadataJWEBackendDto vaultStorageMetadata = vaultMetadata.storage();
106108
final Protocol profile = ProtocolFactory.get().forName(vaultStorageMetadata.getProvider());
107109
log.debug("Loaded profile {} for UVF metadata {}", profile, vaultMetadata);
@@ -130,13 +132,13 @@ public Session<?> getStorage() {
130132
}
131133

132134
@Override
133-
public <T> T getFeature(final Session<?> hub, final Class<T> type, final T delegate) {
135+
public <T> T getFeature(final Session<?> hub, final Class<T> type, final T delegate) throws UnsupportedException {
134136
log.debug("Delegate to {} for feature {}", storage, type);
135137
// Ignore feature implementation but delegate to storage backend
136138
final T feature = storage._getFeature(type);
137139
if(null == feature) {
138140
log.warn("No feature {} available for {}", type, storage);
139-
return null;
141+
throw new UnsupportedException();
140142
}
141143
return super.getFeature(storage, type, feature);
142144
}
@@ -193,7 +195,7 @@ public Path create(final Session<?> session, final String region, final VaultCre
193195
new ProxyPreferencesReader(storage.getHost()).getProperty(S3AssumeRoleProtocol.S3_ASSUMEROLE_ROLEARN_CREATE_BUCKET));
194196
// No role chaining when creating vault
195197
configuration.setProperty(S3AssumeRoleProtocol.S3_ASSUMEROLE_ROLEARN_TAG, null);
196-
storage.open(ProxyFactory.get(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
198+
storage.open(ProxyFactory.get(), new DisabledHostKeyCallback(), prompt, new DisabledCancelCallback());
197199
final Path vault;
198200
if(false) {
199201
log.debug("Upload vault template to {}", storage);
@@ -243,7 +245,7 @@ public HubUVFVault load(final Session<?> session, final PasswordCallback prompt)
243245
try {
244246
log.debug("Connect to {}", storage);
245247
try {
246-
storage.open(ProxyFactory.get(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
248+
storage.open(ProxyFactory.get(), new DisabledHostKeyCallback(), this.prompt, new DisabledCancelCallback());
247249
}
248250
catch(BackgroundException e) {
249251
log.warn("Skip loading vault with failure {} connecting to storage", e.toString());

hub/src/main/java/cloud/katta/protocols/hub/HubVaultListService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package cloud.katta.protocols.hub;
66

77
import ch.cyberduck.core.AttributedList;
8-
import ch.cyberduck.core.DisabledPasswordCallback;
98
import ch.cyberduck.core.ListProgressListener;
109
import ch.cyberduck.core.ListService;
1110
import ch.cyberduck.core.LocaleFactory;
11+
import ch.cyberduck.core.LoginCallback;
1212
import ch.cyberduck.core.Path;
1313
import ch.cyberduck.core.exception.AccessDeniedException;
1414
import ch.cyberduck.core.exception.BackgroundException;
@@ -35,9 +35,11 @@ public class HubVaultListService implements ListService {
3535
private static final Logger log = LogManager.getLogger(HubVaultListService.class);
3636

3737
private final HubSession session;
38+
private final LoginCallback prompt;
3839

39-
public HubVaultListService(final HubSession session) {
40+
public HubVaultListService(final HubSession session, final LoginCallback prompt) {
4041
this.session = session;
42+
this.prompt = prompt;
4143
}
4244

4345
@Override
@@ -56,9 +58,9 @@ public AttributedList<Path> list(final Path directory, final ListProgressListene
5658
// Find storage configuration in vault metadata
5759
final VaultServiceImpl vaultService = new VaultServiceImpl(session);
5860
final UvfMetadataPayload vaultMetadata = vaultService.getVaultMetadataJWE(vaultDto.getId(), session.getUserKeys());
59-
final HubUVFVault vault = new HubUVFVault(session, vaultDto.getId(), vaultMetadata);
61+
final HubUVFVault vault = new HubUVFVault(session, vaultDto.getId(), vaultMetadata, prompt);
6062
try {
61-
registry.add(vault.load(session, new DisabledPasswordCallback()));
63+
registry.add(vault.load(session, prompt));
6264
vaults.add(vault.getHome());
6365
listener.chunk(directory, vaults);
6466
}

hub/src/test/java/cloud/katta/core/AbstractHubSynchronizeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ch.cyberduck.core.AttributedList;
99
import ch.cyberduck.core.DisabledConnectionCallback;
1010
import ch.cyberduck.core.DisabledListProgressListener;
11+
import ch.cyberduck.core.DisabledLoginCallback;
1112
import ch.cyberduck.core.ListService;
1213
import ch.cyberduck.core.OAuthTokens;
1314
import ch.cyberduck.core.Path;
@@ -246,7 +247,7 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
246247
.withAutomaticAccessGrant(new VaultMetadataJWEAutomaticAccessGrantDto()
247248
.enabled(true)
248249
.maxWotDepth(null));
249-
final HubUVFVault cryptomator = new HubUVFVault(hubSession, vaultId, bucket, vaultMetadata);
250+
final HubUVFVault cryptomator = new HubUVFVault(hubSession, vaultId, bucket, vaultMetadata, new DisabledLoginCallback());
250251
cryptomator.create(hubSession, location.getIdentifier(), new VaultCredentials(StringUtils.EMPTY));
251252

252253
final AttributedList<Path> vaults = hubSession.getFeature(ListService.class).list(Home.root(), new DisabledListProgressListener());

hub/src/test/java/cloud/katta/workflows/AbstractHubWorkflowTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package cloud.katta.workflows;
66

7+
import ch.cyberduck.core.DisabledLoginCallback;
78
import ch.cyberduck.core.Path;
89
import ch.cyberduck.core.UUIDRandomStringService;
910
import ch.cyberduck.core.vault.VaultCredentials;
@@ -78,7 +79,7 @@ public void testHubWorkflow(final HubTestConfig config) throws Exception {
7879
.withAutomaticAccessGrant(new VaultMetadataJWEAutomaticAccessGrantDto()
7980
.enabled(true)
8081
.maxWotDepth(3));
81-
final HubUVFVault cryptomator = new HubUVFVault(hubSession, vaultId, bucket, vaultMetadata);
82+
final HubUVFVault cryptomator = new HubUVFVault(hubSession, vaultId, bucket, vaultMetadata, new DisabledLoginCallback());
8283
cryptomator.create(hubSession, location.getIdentifier(), new VaultCredentials(StringUtils.EMPTY));
8384

8485
checkNumberOfVaults(hubSession, config, vaultId, 0, 0, 1, 0, 0);

0 commit comments

Comments
 (0)