Search in sources :

Example 1 with StorageClientNotFoundException

use of com.workoss.boot.storage.exception.StorageClientNotFoundException in project boot by workoss.

the class AbstractS3Client method getClient.

protected MinioClient getClient(String key, String action) {
    if (minioClient != null) {
        return minioClient;
    }
    if (!useStsToken()) {
        throw new StorageClientNotFoundException("00002", "Storage action:" + action + " key:" + key + " initClient error");
    }
    long now = System.currentTimeMillis();
    String cacheKey = StorageUtil.generateCacheKey(action, key);
    StorageStsToken storageStsToken = STS_TOKEN_CACHE.getIfPresent(cacheKey);
    boolean cacheusable = storageStsToken != null && storageStsToken.getExpiration().getTime() > now;
    if (!cacheusable) {
        storageStsToken = getStsToken(config, key, action);
        Date expiration = storageStsToken.getExpiration();
        if (expiration != null && expiration.getTime() - now > 3 * 60 * 1000) {
            STS_TOKEN_CACHE.put(cacheKey, storageStsToken);
        }
    }
    if (storageStsToken == null) {
        throw new StorageException("00002", "securityToken获取失败");
    }
    config.setEndpoint(storageStsToken.getEndpoint().replaceAll(config.getBucketName() + StorageUtil.DOT, ""));
    return this.createClient(config, storageStsToken);
}
Also used : StorageException(com.workoss.boot.storage.exception.StorageException) Date(java.util.Date) StorageClientNotFoundException(com.workoss.boot.storage.exception.StorageClientNotFoundException)

Aggregations

StorageClientNotFoundException (com.workoss.boot.storage.exception.StorageClientNotFoundException)1 StorageException (com.workoss.boot.storage.exception.StorageException)1 Date (java.util.Date)1