Remove download by downloadId functionality (#1820)
This functionallity seems to get via AMQP (after some authentication) a private (wihtout need of authentication) url to an artifact assigned to the controller. By default, DDI or DMF shall provide proper urls (for direct download) to devices and if they have to be without authentication this shall be solved in different ways - for instance separate download server providing dedicated private / signed urls. This functinallity is not a real hawkBit part but more like something intended to solve some edge cases. Since it is complicated, heeds support, doesn't solve wide spread use cases, and could be achieved with other means - better to be removed. Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.Cache.ValueWrapper;
|
||||
import org.springframework.cache.CacheManager;
|
||||
|
||||
/**
|
||||
* A default implementation of the {@link DownloadIdCache} which uses the
|
||||
* {@link CacheManager} implementation to store the download-ids.
|
||||
*/
|
||||
public class DefaultDownloadIdCache implements DownloadIdCache {
|
||||
|
||||
static final String DOWNLOAD_ID_CACHE = "DownloadIdCache";
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* @param cacheManager the underlying cache-manager to store the download-ids
|
||||
*/
|
||||
public DefaultDownloadIdCache(final CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final String downloadId, final DownloadArtifactCache object) {
|
||||
getCache().put(downloadId, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadArtifactCache get(final String downloadId) {
|
||||
final ValueWrapper valueWrapper = getCache().get(downloadId);
|
||||
return (valueWrapper == null) ? null : (DownloadArtifactCache) valueWrapper.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(final String downloadId) {
|
||||
getCache().evict(downloadId);
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
final Cache cache = (cacheManager instanceof TenancyCacheManager)
|
||||
? ((TenancyCacheManager) cacheManager).getDirectCache(DOWNLOAD_ID_CACHE)
|
||||
: cacheManager.getCache(DOWNLOAD_ID_CACHE);
|
||||
return Objects.requireNonNull(cache, "Cache(s) returned by cache-manager must not be null!");
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
/**
|
||||
* Cache Object for downloading an artifact.
|
||||
*/
|
||||
public class DownloadArtifactCache {
|
||||
|
||||
private final DownloadType downloadType;
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param downloadType
|
||||
* the type for searching the artifact.
|
||||
* @param id
|
||||
* the searching id e.g. sha1, md5
|
||||
*/
|
||||
public DownloadArtifactCache(final DownloadType downloadType, final String id) {
|
||||
this.downloadType = downloadType;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public DownloadType getDownloadType() {
|
||||
return downloadType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((downloadType == null) ? 0 : downloadType.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final DownloadArtifactCache other = (DownloadArtifactCache) obj;
|
||||
if (downloadType != other.downloadType) {
|
||||
return false;
|
||||
}
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
/**
|
||||
* A interface declaration of the download-id-cache which allows to store
|
||||
* volatile generated download-IDs used to have a single unique download-request
|
||||
* e.g. for distributed download-server.
|
||||
*
|
||||
* A valid download-id is created during a successful download-authorization
|
||||
* request e.g. from a download-server. In the DMF response a unique
|
||||
* download-URL containing a generated download-id which can be used to download
|
||||
* the artifact using this single download-url.
|
||||
*
|
||||
* The {@link DownloadIdCache} handles storing this unique download-id from the
|
||||
* DMF authorization request until the actual artifact download-request via HTTP
|
||||
* with the unique ID is performed.
|
||||
*
|
||||
*/
|
||||
public interface DownloadIdCache {
|
||||
|
||||
/**
|
||||
* Puts a given artifact cache object with the given downloadId key into the
|
||||
* cache.
|
||||
*
|
||||
* @param downloadId
|
||||
* the ID to store the cache object to look it up later on
|
||||
* @param downloadArtifactCacheObject
|
||||
* the object to store into the cache
|
||||
*/
|
||||
void put(final String downloadId, final DownloadArtifactCache downloadArtifactCacheObject);
|
||||
|
||||
/**
|
||||
* Retrieves a {@link DownloadArtifactCache} by a given downloadId.
|
||||
*
|
||||
* @param downloadId
|
||||
* the ID to retrieve the artifact cache object
|
||||
* @return the found {@link DownloadArtifactCache} or {@code null} if none
|
||||
* exists for the given ID
|
||||
*/
|
||||
DownloadArtifactCache get(final String downloadId);
|
||||
|
||||
/**
|
||||
* Evicts a {@link DownloadArtifactCache} for the given downloadId
|
||||
*
|
||||
* @param downloadId
|
||||
* the ID to be evicted
|
||||
*/
|
||||
void evict(String downloadId);
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
/**
|
||||
* The type of the id which is saved.
|
||||
*/
|
||||
public enum DownloadType {
|
||||
BY_SHA1
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Unit Tests - Cache")
|
||||
@Story("Download ID Cache")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DefaultDownloadIdCacheTest {
|
||||
|
||||
@Mock
|
||||
private CacheManager cacheManagerMock;
|
||||
|
||||
@Mock
|
||||
private TenancyCacheManager tenancyCacheManagerMock;
|
||||
|
||||
@Mock
|
||||
private Cache cacheMock;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<String> cacheManagerKeyCaptor;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<DownloadArtifactCache> cacheManagerValueCaptor;
|
||||
|
||||
private DefaultDownloadIdCache underTest;
|
||||
|
||||
private final String knownKey = "12345";
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
underTest = new DefaultDownloadIdCache(cacheManagerMock);
|
||||
lenient().when(cacheManagerMock.getCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE)).thenReturn(cacheMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that putting key and value is delegated to the CacheManager implementation")
|
||||
void putKeyAndValueIsDelegatedToCacheManager() {
|
||||
final DownloadArtifactCache value = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey);
|
||||
|
||||
underTest.put(knownKey, value);
|
||||
|
||||
verify(cacheMock).put(cacheManagerKeyCaptor.capture(), cacheManagerValueCaptor.capture());
|
||||
|
||||
assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey);
|
||||
assertThat(cacheManagerValueCaptor.getValue()).isEqualTo(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that evicting a key is delegated to the CacheManager implementation")
|
||||
void evictKeyIsDelegatedToCacheManager() {
|
||||
|
||||
underTest.evict(knownKey);
|
||||
|
||||
verify(cacheMock).evict(cacheManagerKeyCaptor.capture());
|
||||
|
||||
assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that retrieving a value for a specific key is delegated to the CacheManager implementation")
|
||||
void getValueReturnsTheAssociatedValueForKey() {
|
||||
final String knownKey = "12345";
|
||||
final DownloadArtifactCache knownValue = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey);
|
||||
|
||||
when(cacheMock.get(knownKey)).thenReturn(new SimpleValueWrapper(knownValue));
|
||||
|
||||
final DownloadArtifactCache downloadArtifactCache = underTest.get(knownKey);
|
||||
|
||||
assertThat(downloadArtifactCache).isEqualTo(knownValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that retrieving a null value for a specific key is delegated to the CacheManager implementation")
|
||||
void getValueReturnsNullIfNoKeyIsAssociated() {
|
||||
|
||||
when(cacheMock.get(knownKey)).thenReturn(new SimpleValueWrapper(null));
|
||||
|
||||
final DownloadArtifactCache downloadArtifactCache = underTest.get(knownKey);
|
||||
|
||||
assertThat(downloadArtifactCache).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that TenancyCacheManager is using direct cache because download-ids are global unique and don't need to run as tenant aware")
|
||||
void tenancyCacheManagerIsUsingDirectCache() {
|
||||
|
||||
when(tenancyCacheManagerMock.getDirectCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE)).thenReturn(cacheMock);
|
||||
underTest = new DefaultDownloadIdCache(tenancyCacheManagerMock);
|
||||
|
||||
final DownloadArtifactCache value = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey);
|
||||
|
||||
underTest.put(knownKey, value);
|
||||
|
||||
verify(cacheMock).put(cacheManagerKeyCaptor.capture (), cacheManagerValueCaptor.capture());
|
||||
|
||||
verify(tenancyCacheManagerMock).getDirectCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE);
|
||||
assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey);
|
||||
assertThat(cacheManagerValueCaptor.getValue()).isEqualTo(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user