Commit a99c2e8a authored by Erik Leckner's avatar Erik Leckner
Browse files

file-azure

parent 2622b013
......@@ -76,6 +76,7 @@ public class LocationServiceImpl implements ILocationService {
validationService.validateFileLocationRequest(request);
String fileID = request.getFileID();
FileLocation fileLocation = fileLocationRepository.findByFileID(fileID);
if (fileLocation == null) {
......
......@@ -24,66 +24,66 @@ import javax.inject.Named;
@Configuration
public class AzureBootstrapConfig {
@Value("${azure.keyvault.url}")
private String keyVaultURL;
@Value("${azure.cosmosdb.database}")
private String cosmosDBName;
@Value("${azure.application-insights.instrumentation-key}")
private String appInsightsKey ;
@Value("${spring.application.name}")
private String springAppName ;
@Bean
@Named("APPINSIGHTS_KEY")
public String appInsightsKey() {
return appInsightsKey;
}
@Bean
@Named("spring.application.name")
public String springAppName() {
return springAppName;
}
@Bean
@Named("COSMOS_DB_NAME")
public String cosmosDBName() {
return cosmosDBName;
@Value("${azure.keyvault.url}")
private String keyVaultURL;
@Value("${azure.cosmosdb.database}")
private String cosmosDBName;
@Value("${azure.application-insights.instrumentation-key}")
private String appInsightsKey;
@Value("${spring.application.name}")
private String springAppName;
@Bean
@Named("APPINSIGHTS_KEY")
public String appInsightsKey() {
return appInsightsKey;
}
@Bean
@Named("spring.application.name")
public String springAppName() {
return springAppName;
}
@Bean
@Named("COSMOS_DB_NAME")
public String cosmosDBName() {
return cosmosDBName;
}
@Bean
@Named("KEY_VAULT_URL")
public String keyVaultURL() {
return keyVaultURL;
}
@Bean
@Named("COSMOS_ENDPOINT")
public String cosmosEndpoint(SecretClient kv) {
return getKeyVaultSecret(kv, "cosmos-endpoint");
}
@Bean
@Named("COSMOS_KEY")
public String cosmosKey(SecretClient kv) {
return getKeyVaultSecret(kv, "cosmos-primary-key");
}
String getKeyVaultSecret(SecretClient kv, String secretName) {
KeyVaultSecret secret = kv.getSecret(secretName);
if (secret == null) {
throw new IllegalStateException(String.format("No secret found with name %s", secretName));
}
@Bean
@Named("KEY_VAULT_URL")
public String keyVaultURL() {
return keyVaultURL;
String secretValue = secret.getValue();
if (secretValue == null) {
throw new IllegalStateException(String.format(
"Secret unexpectedly missing from KeyVault response for secret with name %s", secretName));
}
@Bean
@Named("COSMOS_ENDPOINT")
public String cosmosEndpoint(SecretClient kv) {
return getKeyVaultSecret(kv, "cosmos-endpoint");
}
@Bean
@Named("COSMOS_KEY")
public String cosmosKey(SecretClient kv) {
return getKeyVaultSecret(kv, "cosmos-primary-key");
}
String getKeyVaultSecret(SecretClient kv, String secretName) {
KeyVaultSecret secret = kv.getSecret(secretName);
if (secret == null) {
throw new IllegalStateException(String.format("No secret found with name %s", secretName));
}
String secretValue = secret.getValue();
if (secretValue == null) {
throw new IllegalStateException(String.format(
"Secret unexpectedly missing from KeyVault response for secret with name %s", secretName));
}
return secretValue;
}
return secretValue;
}
}
......@@ -20,7 +20,6 @@ import java.util.Date;
import java.util.Optional;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.file.provider.azure.model.entity.FileLocationEntity;
......@@ -49,7 +48,7 @@ public class FileLocationEntityRepository {
@Nullable
FileLocationEntity findByFileID(String fileID) {
if (fileID == null) {
throw new IllegalArgumentException("The given fileID is null");
return null;
}
Optional<FileLocationEntity> fileLocationEntity = cosmosStore.findItem(headers.getPartitionId(),cosmosDBName,fileLocationContainer,fileID,fileID,FileLocationEntity.class);
if (!fileLocationEntity.isPresent())
......
......@@ -30,6 +30,7 @@ import org.opengroup.osdu.file.provider.azure.storage.BlobId;
import org.opengroup.osdu.file.provider.azure.storage.BlobInfo;
import org.opengroup.osdu.file.provider.azure.storage.Storage;
import org.opengroup.osdu.file.provider.interfaces.IStorageRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Repository;
import org.springframework.web.util.UriUtils;
......@@ -43,16 +44,19 @@ public class StorageRepository implements IStorageRepository {
@Inject
final Storage storage;
private static String storageAccount;
@Value("${azure.storage.account}")
private static String azureStorageAccount;
private String storageAccount;
public StorageRepository(Storage storage) {
this.storage = storage;
this.storageAccount = getStorageAccount();
}
@Override
public SignedObject createSignedObject(String containerName, String filepath) {
log.debug("Creating the signed blob in container {} for path {}", containerName, filepath);
System.out.println(String.format("Creating the signed blob in container %s for path %s", containerName, filepath));
BlobId blobId = BlobId.of(containerName, filepath);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId)
.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE)
......@@ -70,7 +74,7 @@ public class StorageRepository implements IStorageRepository {
}
public static String getStorageAccount() {
return System.getProperty("AZURE_STORAGE_ACCOUNT", System.getenv("AZURE_STORAGE_ACCOUNT"));
return azureStorageAccount;
}
private URI getObjectUri(Blob blob) {
......
......@@ -28,9 +28,6 @@ import java.time.ZoneOffset;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.concurrent.TimeUnit;
/*
For a given blob object, generator a SAS Token that'll let bearers access the blob for 24 hours.
*/
@Log
@Component
public class AzureTokenServiceImpl {
......@@ -81,7 +78,6 @@ public class AzureTokenServiceImpl {
BlobServiceSasSignatureValues tokenProps = new BlobServiceSasSignatureValues(expires, readOnlyPerms);
String sasToken = tokenSource.generateUserDelegationSas(tokenProps, key);
String sasUri = String.format("%s?%s", blobUrl, sasToken);
System.out.println(String.format("sasUri=%s", sasUri));
return sasUri;
}
......@@ -91,7 +87,7 @@ public class AzureTokenServiceImpl {
private OffsetDateTime calcTokenExpirationDate(long duration, TimeUnit timeUnit) {
if (timeUnit == null) {
throw new UnsupportedTemporalTypeException("Unsupported temporal type");
throw new NullPointerException("Time unit cannot be nulll");
}
if (timeUnit == TimeUnit.DAYS) {
return OffsetDateTime.now(ZoneOffset.UTC).plusDays(duration);
......@@ -104,7 +100,7 @@ public class AzureTokenServiceImpl {
} else if (timeUnit == TimeUnit.HOURS){
return OffsetDateTime.now(ZoneOffset.UTC).plusHours(duration);
} else {
throw new UnsupportedTemporalTypeException("Unsupported temporal type");
throw new UnsupportedTemporalTypeException("Unsupported temporal type");
}
}
}
......@@ -25,6 +25,8 @@ import org.opengroup.osdu.file.provider.azure.model.constant.StorageConstant;
import org.opengroup.osdu.file.provider.azure.model.property.FileLocationProperties;
import org.opengroup.osdu.file.provider.interfaces.IStorageRepository;
import org.opengroup.osdu.file.provider.interfaces.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.time.Clock;
......@@ -89,7 +91,6 @@ public class StorageServiceImpl implements IStorageService {
log.debug("Created folderName {} for fileID {}", folderName, filename);
return format("%s/%s/%s", userDesID, folderName, filename);
//return format("%s/%s", folderName, filename);
}
}
......@@ -54,16 +54,19 @@ import java.util.concurrent.TimeUnit;
public class StorageImpl implements Storage {
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static String clientSecret = System.getProperty("AZURE_CLIENT_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"));
private static String clientId = System.getProperty("AZURE_CLIENT_ID", System.getenv("INTEGRATION_TESTER"));
private static String clientSecret = System.getProperty("AZURE_CLIENT_SECRET", System.getenv("CLIENT_SECRET"));
private static String clientId = System.getProperty("AZURE_CLIENT_ID", System.getenv("CLIENT_ID"));
private static String tenantId = System.getProperty("AZURE_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID"));
private static String azureStorageAccount = System.getProperty("AZURE_STORAGE_ACCOUNT", System.getenv("AZURE_STORAGE_ACCOUNT"));
private static String storageAccount;
@Inject
AzureTokenServiceImpl token;
public StorageImpl() {
this.storageAccount = getStorageAccount();
this.storageAccount = azureStorageAccount;
}
@Override
......@@ -94,7 +97,6 @@ public class StorageImpl implements Storage {
return null;
}
@SneakyThrows
@Override
public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit timeUnit) {
......@@ -106,7 +108,6 @@ public class StorageImpl implements Storage {
System.out.println(String.format("Signing the blob %s", blobURL));
log.debug("Signing the blob {}", blobURL);
String signedUrl = token.sign(blobURL, duration, timeUnit);
System.out.println(String.format("signedUrl: %s", signedUrl));
return new URL(signedUrl);
}
catch (MalformedURLException e) {
......
package org.opengroup.osdu.file.provider.azure.util;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.slf4j.Logger;
/* This mixin is used to fix https://github.com/microsoft/spring-data-cosmosdb/issues/423
Upgrading cosmosdb spring library will also solve this. The fix is in a major release which needs lot of changes
This mixin is injected in QueryRepositoryImpl constructor. After upgrade these can be deleted.
*/
public interface QueryItemMixIn {
@JsonIgnore
abstract Logger getLogger();
}
......@@ -26,6 +26,8 @@ azure.keyvault.url=${keyvault_url}
file.location.containerName=odes-os-file-temp
file.location.userId=common-user
azure.storage.account=${AZURE_STORAGE_ACCOUNT}
# Azure Application Insights configuration
azure.application-insights.instrumentation-key=${appinsights_key}
tenantInfo.container.name=TenantInfo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment