Commit b26d2b01 authored by Sviatoslav Nekhaienko's avatar Sviatoslav Nekhaienko
Browse files

Merge branches 'add-exeptions' and 'master' of...

Merge branches 'add-exeptions' and 'master' of https://community.opengroup.org/osdu/platform/system/storage into add-exeptions
parents 9eb1a2d0 54c4839e
Pipeline #5226 passed with stages
in 35 minutes and 49 seconds
## Type of change
- [ ] Bug Fix
- [ ] Feature
**Please provide link to gitlab issue or ADR(Architecture Decision Record)**
## Does this introduce a change in the core logic?
- [YES/NO]
## Does this introduce a change in the cloud provider implementation, if so which cloud?
- [ ] AWS
- [ ] Azure
- [ ] GCP
- [ ] IBM
## Does this introduce a breaking change?
- [YES/NO]
## What is the current behavior?
## What is the new/expected behavior?
## Have you added/updated Unit Tests and Integration Tests?
## Any other useful information
......@@ -539,11 +539,11 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty Reactive Streams Implementation (from )
- Netty/Buffer (from http://netty.io/)
- Netty/Buffer (from http://netty.io/)
......@@ -761,8 +761,8 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- Mockito (from http://www.mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- NanoHttpd-Core (from )
- Netty/Codec/HTTP (from )
- Netty/Codec/HTTP (from )
......@@ -901,7 +901,6 @@ The following software have components provided under the terms of this license:
- OSGi resource locator (from )
- Project Lombok (from https://projectlombok.org)
- Project Lombok (from https://projectlombok.org)
- SnakeYAML (from http://www.snakeyaml.org)
- javax.ws.rs-api (from http://jax-rs-spec.java.net)
- javax.ws.rs-api (from http://jax-rs-spec.java.net)
......@@ -996,17 +995,16 @@ The following software have components provided under the terms of this license:
- Microsoft Azure client library for Identity (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for KeyVault Secrets (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure common module for Storage (from https://github.com/Azure/azure-sdk-for-java)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty/Codec/HTTP (from )
- Netty/Codec/HTTP (from )
- Netty/Common (from )
- Netty/Common (from )
- Project Lombok (from https://projectlombok.org)
- Project Lombok (from https://projectlombok.org)
- SLF4J API Module (from http://www.slf4j.org)
- SLF4J API Module (from http://www.slf4j.org)
- Spring Data for Azure Cosmos DB SQL API (from https://github.com/Microsoft/spring-data-cosmosdb)
......@@ -1079,7 +1077,6 @@ The following software have components provided under the terms of this license:
- Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for Blob Storage (from https://github.com/Azure/azure-sdk-for-java)
- Project Lombok (from https://projectlombok.org)
- Project Lombok (from https://projectlombok.org)
- Spring Web (from https://github.com/spring-projects/spring-framework)
========================================================================
......
#####################
# README: Defines a template to be used as a starting point for defining a service pipeline
#####################
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- /**/*.md
- .gitignore
- images/
pr:
autoCancel: true
branches:
include:
- "*"
paths:
exclude:
- /**/*.md
- .gitignore
- images/
resources:
repositories:
- repository: osdu-infrastructure
type: git
name: osdu-r2/osdu-infrastructure
variables:
- group: "Azure Common Secrets"
- group: "Azure - Common"
- name: serviceName
value: "storage"
stages:
- template: devops/service-pipelines/build-stage.yml@osdu-infrastructure
parameters:
mavenGoal: "package"
mavenPublishJUnitResults: true
mavenOptions: "-P storage-azure"
copyFileContents: |
pom.xml
provider/storage-azure/maven/settings.xml
provider/storage-azure/pom.xml
provider/storage-azure/target/*-spring-boot.jar
copyFileContentsToFlatten: ""
mavenSettingsFile: "./maven/settings.xml"
serviceBase: ${{ variables.serviceName }}
testingRootFolder: "testing"
- template: devops/service-pipelines/deploy-stages.yml@osdu-infrastructure
parameters:
serviceName: ${{ variables.serviceName }}
testCoreMavenPomFile: "testing/storage-test-core/pom.xml"
testCoreMavenOptions: "--settings $(System.DefaultWorkingDirectory)/drop/deploy/testing/maven/settings.xml"
providers:
- name: Azure
environments: ["test"]
......@@ -29,7 +29,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<docker.image.prefix>opendes</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<os-core-common.version>0.0.18</os-core-common.version>
<os-core-common.version>0.3.6</os-core-common.version>
</properties>
<licenses>
......
......@@ -35,34 +35,31 @@
##### Authentication / Secrets #####
# Replace placeholder text with your own AWS secret access keys
# and rename to `.env` - do NOT check-in .env with your credentials! Leave it in .gitignore
AWS_ACCESS_KEY_ID=
AWS_SECRET_KEY=
AWS_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID>
AWS_SECRET_KEY=<YOUR_SECRET_KEY>
#### Urls/Ports #############
APPLICATION_PORT=
CACHE_CLUSTER_ENDPOINT=
CACHE_CLUSTER_PORT=
LEGALTAG_BASE_URL=
APPLICATION_PORT=8080
CACHE_CLUSTER_ENDPOINT=127.0.0.1
CACHE_CLUSTER_PORT=6379
LEGALTAG_BASE_URL=<YOUR_API_URL>
##### Other environment variables ##########################################################
JAVA_HEAP_MEMORY=
ENVIRONMENT=
AWS_REGION=
LOG_LEVEL=
ENVIRONMENT=dev
AWS_REGION=us-east-1
LOG_LEVEL=DEBUG
SSM_ENABLED=True
##### Integration test-specific - these are only used for integration tests, not the app ###
AWS_ACCESS_KEY_ID=
AWS_SECRET_KEY=
OTHER_RELEVANT_DATA_COUNTRIES=
AWS_COGNITO_CLIENT_ID=<YOUR_COGNITO_CLIENT_ID>
AWS_COGNITO_AUTH_FLOW=USER_PASSWORD_AUTH
AWS_COGNITO_AUTH_PARAMS_USER=<YOUR_AUTHORIZED_USER>
AWS_COGNITO_AUTH_PARAMS_USER_NO_ACCESS=test-user-without-access@testing.com
AWS_COGNITO_AUTH_PARAMS_PASSWORD=<YOUR_AUTHORIZED_USER_PASSWORD>
OTHER_RELEVANT_DATA_COUNTRIES=US
DEPLOY_ENV=empty
LEGAL_TAG=
TENANT_NAME=
AWS_COGNITO_CLIENT_ID=
AWS_COGNITO_AUTH_FLOW=
AWS_COGNITO_AUTH_PARAMS_PASSWORD=
AWS_COGNITO_AUTH_PARAMS_USER=
AWS_COGNITO_AUTH_PARAMS_USER_NO_ACCESS=
STORAGE_URL=
DOMAIN=
LEGAL_URL=
LEGAL_TAG=opendes-public-usa-dataset-1
TENANT_NAME=opendes
DOMAIN=testing.com
STORAGE_URL=<YOUR_API_URL>/api/storage/v2/
LEGAL_URL=<YOUR_API_URL>/api/legal/v1/
\ No newline at end of file
import boto3
import json
import os
import argparse
# Create the build-info.json
parser = argparse.ArgumentParser(description="")
# env - CODEBUILD_SOURCE_VERSION
parser.add_argument("--branch", type=str, help="")
# env - CODEBUILD_RESOLVED_SOURCE_VERSION
parser.add_argument("--commit", type=str, help="")
# env - CODEBUILD_BUILD_ID
parser.add_argument("--buildid", type=str, help="")
# env - CODEBUILD_BUILD_NUMBER
parser.add_argument("--buildnumber", type=str, help="")
# Get from directory name
parser.add_argument("--reponame", type=str, help="")
# env OUTPUT_DIR
parser.add_argument("--outdir", type=str, help="")
# full ecr image and tag, and any other artifacts
parser.add_argument("--artifact", type=str, action="append", help="")
args = parser.parse_args()
branch = args.branch
commitId = args.commit
buildId = args.buildid
buildNumber = args.buildnumber
repoName = args.reponame
outputDir = args.outdir
artifacts = args.artifact
buildInfoFilePath = os.path.join(".", outputDir, "build-info.json")
print(buildInfoFilePath)
commitArgs = {
"repositoryName": repoName,
"commitId": commitId
}
commitDetail = {
"commit": ""
}
# get the commit detail
try:
codecommit = boto3.client("codecommit")
commitDetail = codecommit.get_commit(**commitArgs)
except Exception as e:
print("Getting commit information from codecommit failed")
buildInfo = {
"branch": branch,
"build-id": buildId,
"build-number": buildNumber,
"repo": repoName,
"artifacts": artifacts,
"commit": commitDetail["commit"]
}
print(json.dumps(buildInfo, sort_keys=True, indent=4))
# write the build.json file to dist
f = open(buildInfoFilePath, "w")
f.write(json.dumps(buildInfo, sort_keys=True, indent=4))
f.close()
# Copyright © Amazon Web Services
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
version: 0.2
phases:
install:
runtime-versions:
java: openjdk8
commands:
- if [ $(echo $CODEBUILD_SOURCE_VERSION | grep -c ^refs/heads.*) -eq 1 ]; then echo "Branch name found"; else echo "This build only supports branch builds" && exit 1; fi
- apt-get update -y
- apt-get install -y maven
- java -version
- mvn -version
- echo $JAVA_HOME #WHY
- mkdir -p /root/.m2
- aws s3 sync s3://$M2_REPO_S3_BUCKET /root/.m2 # copy previous state of the shared libraries' .m2 folder from S3 to local
- cp ./provider/storage-aws/maven/settings.xml /root/.m2/settings.xml # copy the AWS-specific settings.xml to the CodeBuild instance's .m2 folder
- cat /root/.m2/settings.xml
pre_build:
commands:
- echo "Logging in to Amazon ECR..."
- $(aws ecr get-login --no-include-email --region $AWS_REGION) # authenticate with ECR via the AWS CLI
build:
commands:
- export REPO_NAME=${PWD##*/}
- export OUTPUT_DIR="dist"
- export BRANCH_NAME=`echo ${CODEBUILD_SOURCE_VERSION} | awk '{gsub("refs/heads/","");gsub("\\.","-");gsub("[[:space:]]","-")}1' | sed 's/\//-/g' | awk '{print tolower($0)}'`
- export ECR_TAG=`echo build.${BRANCH_NAME}.${CODEBUILD_BUILD_NUMBER}.${CODEBUILD_RESOLVED_SOURCE_VERSION} | cut -c 1-120`
- export ECR_IMAGE=${ECR_REGISTRY}:${ECR_TAG}
- export ECR_IMAGE_BRANCH_LATEST=${ECR_REGISTRY}:${BRANCH_NAME}
- export INTEGRATION_TEST_OUTPUT=${OUTPUT_DIR}/testing/integration
- export INTEGRATION_TEST_OUTPUT_BIN=${INTEGRATION_TEST_OUTPUT}/bin
- mkdir -p ${OUTPUT_DIR}/bin
- mkdir -p ${OUTPUT_DIR}/testing && mkdir -p ${INTEGRATION_TEST_OUTPUT} && mkdir -p ${INTEGRATION_TEST_OUTPUT}/bin
- echo "Placeholder" >> ${OUTPUT_DIR}/build-info.json # touched so that the output directory has some content incase the build fails so that testing reports are uploaded
- printenv
- echo "Building primary service assemblies..."
- mvn -B test install '-Pstorage-aws,!storage-gcp' -pl storage-core,provider/storage-aws -Ddeployment.environment=prod
# Suspended until further notice
# - echo "Copying assemblies to dist..."
# - cp ./provider/storage-aws/target/*spring-boot.jar ${OUTPUT_DIR}/bin # copy aws jars
# - cp ./storage-core/target/*.jar ${OUTPUT_DIR}/bin # copy core jar
- echo "Building integration testing assemblies and gathering artifacts..."
- ./testing/storage-test-aws/build-aws/prepare-dist.sh
- echo "Building docker image..."
- docker build -f provider/storage-aws/build-aws/Dockerfile -t ${ECR_IMAGE} .
- docker tag ${ECR_IMAGE} ${ECR_IMAGE_BRANCH_LATEST}
- echo "Pushing docker image..."
- docker push ${ECR_IMAGE}
- docker push ${ECR_IMAGE_BRANCH_LATEST}
- echo "Generate build-info.json"
- |
python provider/storage-aws/build-aws/build-info.py --branch ${CODEBUILD_SOURCE_VERSION} --commit ${CODEBUILD_RESOLVED_SOURCE_VERSION} \
--buildid ${CODEBUILD_BUILD_ID} --buildnumber ${CODEBUILD_BUILD_NUMBER} --reponame ${REPO_NAME} --outdir ${OUTPUT_DIR} \
--artifact ${ECR_IMAGE}
reports:
SurefireReports: # CodeBuild will create a report group called "SurefireReports".
files: #Store all of the files
- "storage-core/target/surefire-reports/**/*"
- "provider/storage-aws/target/surefire-reports/**/*"
base-directory: "." # Location of the reports
artifacts:
files:
- "**/*"
base-directory: "dist"
name: ${REPO_NAME}_${BRANCH_NAME}_$(date +%F)_${CODEBUILD_BUILD_NUMBER}.zip
cache:
paths:
- "/root/.m2/**/*"
\ No newline at end of file
......@@ -58,7 +58,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.2.0</version>
<version>0.3.5</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -45,7 +45,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.2.0</version>
<version>0.3.5</version>
</dependency>
<!-- Testing packages -->
......
......@@ -73,15 +73,14 @@ public class QueryRepositoryImpl implements IQueryRepository {
// Query by DataPartitionId global secondary index with User range key
SchemaDoc queryObject = new SchemaDoc();
queryObject.setDataPartitionId(headers.getPartitionId());
queryPageResult = queryHelper.queryByGSI(SchemaDoc.class,
queryObject, "User", headers.getUserEmail(), numRecords, cursor);
queryPageResult = queryHelper.queryByGSI(SchemaDoc.class, queryObject, numRecords, cursor);
for (SchemaDoc schemaDoc : queryPageResult.results) {
kinds.add(schemaDoc.getKind());
}
} catch (UnsupportedEncodingException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error parsing results",
e.getMessage(),e);
e.getMessage(), e);
}
// Set the cursor for the next page, if applicable
......@@ -94,8 +93,7 @@ public class QueryRepositoryImpl implements IQueryRepository {
}
@Override
public DatastoreQueryResult getAllRecordIdsFromKind(String kind, Integer limit, String cursor)
{
public DatastoreQueryResult getAllRecordIdsFromKind(String kind, Integer limit, String cursor) {
// Set the page size, or use the default constant
int numRecords = PAGE_SIZE;
if (limit != null) {
......@@ -111,10 +109,10 @@ public class QueryRepositoryImpl implements IQueryRepository {
QueryPageResult<RecordMetadataDoc> scanPageResults;
try {
scanPageResults = queryHelper.queryPage(RecordMetadataDoc.class, recordMetadataKey, "Status","active", numRecords, cursor);
scanPageResults = queryHelper.queryPage(RecordMetadataDoc.class, recordMetadataKey, "Status", "active", numRecords, cursor);
} catch (UnsupportedEncodingException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error parsing results",
e.getMessage(),e);
e.getMessage(), e);
}
dqr.setCursor(scanPageResults.cursor); // set the cursor for the next page, if applicable
scanPageResults.results.forEach(schemaDoc -> ids.add(schemaDoc.getId())); // extract the Kinds from the SchemaDocs
......@@ -138,7 +136,7 @@ public class QueryRepositoryImpl implements IQueryRepository {
AttributeValue pairAttributeValue = new AttributeValue(attributeValueSplit[1]);
cursorMap.put(keyValue[0], pairAttributeValue); // append the pair to the Map
}
} catch(Exception e) {
} catch (Exception e) {
throw new InvalidCursorException(e.getMessage());
}
return cursorMap;
......
......@@ -42,7 +42,7 @@ import java.util.List;
import static org.mockito.MockitoAnnotations.initMocks;
@RunWith(MockitoJUnitRunner.class)
@SpringBootTest(classes={StorageApplication.class})
@SpringBootTest(classes = {StorageApplication.class})
public class QueryRepositoryTest {
@InjectMocks
......@@ -93,9 +93,8 @@ public class QueryRepositoryTest {
QueryPageResult<SchemaDoc> expectedQueryPageResult = new QueryPageResult<>(cursor, expectedSchemaDocList);
Mockito.when(dpsHeaders.getPartitionId()).thenReturn(dataPartitionId);
Mockito.when(dpsHeaders.getUserEmail()).thenReturn(user);
Mockito.when(queryHelper.queryByGSI(Mockito.eq(SchemaDoc.class),
Mockito.anyObject(), Mockito.eq("User"), Mockito.eq(user), Mockito.anyInt(), Mockito.eq(cursor)))
Mockito.anyObject(), Mockito.anyInt(), Mockito.eq(cursor)))
.thenReturn(expectedQueryPageResult);
// Act
......@@ -127,14 +126,14 @@ public class QueryRepositoryTest {
RecordMetadataDoc recordMetadataKey = new RecordMetadataDoc();
recordMetadataKey.setKind(kind);
Mockito.when(queryHelper.queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq(cursor)))
Mockito.when(queryHelper.queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq(cursor)))
.thenReturn(expectedQueryPageResult);
// Act
DatastoreQueryResult datastoreQueryResult = repo.getAllRecordIdsFromKind(kind, 50, cursor);
// Assert
Mockito.verify(queryHelper, Mockito.times(1)).queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(),
Mockito.verify(queryHelper, Mockito.times(1)).queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyInt(), Mockito.eq(cursor));
Assert.assertEquals(expectedDatastoreQueryResult, datastoreQueryResult);
}
......
......@@ -40,6 +40,7 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `LOG_PREFIX` | `storage` | Logging prefix | no | - |
| `server.servlet.contextPath` | `/api/storage/v2/` | Servlet context path | no | - |
| `AUTHORIZE_API` | ex `https://foo-entitlements.azurewebsites.net` | Entitlements API endpoint | no | output of infrastructure deployment |
| `AUTHORIZE_API_KEY` | `********` | The API key clients will need to use when calling the entitlements | yes | -- |
| `LEGALTAG_API` | ex `https://foo-legal.azurewebsites.net` | Legal API endpoint | no | output of infrastructure deployment |
......
......@@ -13,6 +13,7 @@
# limitations under the License.
LOG_PREFIX=storage
server.servlet.contextPath=/api/storage/v2/
AUTHORIZE_API=${entitlements_service_endpoint}
AUTHORIZE_API_KEY=${entitlements_service_api_key}
......
......@@ -16,6 +16,7 @@ package org.opengroup.osdu.storage.provider.gcp;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.cloud.datastore.Cursor;
import com.google.cloud.storage.*;
import com.google.cloud.storage.Acl.Group;
import com.google.cloud.storage.Acl.Role;
......@@ -30,6 +31,7 @@ import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
......@@ -69,6 +71,9 @@ public class GoogleCloudStorage implements ICloudStorage {
@Autowired
private IStorageFactory storageFactory;
@Autowired
private IRecordsMetadataRepository<Cursor> recordRepository;
@Autowired
private ExecutorService threadPool;
......@@ -112,6 +117,47 @@ public class GoogleCloudStorage implements ICloudStorage {
}
}
@Override
public Map<String, org.opengroup.osdu.core.common.model.entitlements.Acl> updateObjectMetadata(List<RecordMetadata> recordsMetadata, List<String> recordsId, List<RecordMetadata> validMetadata, List<String> lockedRecords, Map<String, String> recordsIdMap) {
String bucket = getBucketName(this.tenant);
Storage storage = this.storageFactory.getStorage(this.headers.getUserEmail(), tenant.getServiceAccount(), tenant.getProjectId(), tenant.getName());
Map<String, org.opengroup.osdu.core.common.model.entitlements.Acl> originalAcls = new HashMap<>();
Map<String, RecordMetadata> currentRecords = this.recordRepository.get(recordsId);
for (RecordMetadata recordMetadata : recordsMetadata) {
String id = recordMetadata.getId();
String idWithVersion = recordsIdMap.get(id);
List<Acl> acls = this.constructObjectAcls(tenant.getServiceAccount(), recordMetadata.getAcl());
if (!id.equalsIgnoreCase(idWithVersion)) {
long previousVersion = Long.parseLong(idWithVersion.split(":")[3]);
long currentVersion = currentRecords.get(id).getLatestVersion();
if (previousVersion != currentVersion) {
lockedRecords.add(idWithVersion);
continue;
}
}
validMetadata.add(recordMetadata);
Blob blob = storage.get(bucket, recordMetadata.getVersionPath(recordMetadata.getLatestVersion()));
originalAcls.put(recordMetadata.getId(), currentRecords.get(id).getAcl());
blob.toBuilder().setAcl(acls).build().update();
}
return originalAcls;
}
@Override
public void revertObjectMetadata(List<RecordMetadata> recordsMetadata, Map<String, org.opengroup.osdu.core.common.model.entitlements.Acl> originalAcls) {
String bucket = getBucketName(this.tenant);
Storage storage = this.storageFactory.getStorage(this.headers.getUserEmail(), tenant.getServiceAccount(), tenant.getProjectId(), tenant.getName());
for (RecordMetadata recordMetadata : recordsMetadata) {
Blob blob = storage.get(bucket, recordMetadata.getVersionPath(recordMetadata.getLatestVersion()));
List<Acl> acls = this.constructObjectAcls(tenant.getServiceAccount(), originalAcls.get(recordMetadata.getId()));
blob.toBuilder().setAcl(acls).build().update();
}
}
@Override
public boolean hasAccess(RecordMetadata... records) {
......@@ -151,7 +197,7 @@ public class GoogleCloudStorage implements ICloudStorage {
}
public boolean hasAccessRobustToDataCorruption(String bucket, RecordMetadata record,
Storage storageClientUserCredential) {
Storage storageClientUserCredential) {
// Get the latest version from GCS by using datafier service account first,
// since gcs API can't distinguish 404 or 403
// If datafier can get meaning user does not have permission, if datafier can't
......@@ -333,7 +379,7 @@ public class GoogleCloudStorage implements ICloudStorage {