Skip to content
Snippets Groups Projects
Commit cfcbf98e authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Changed logic with default legal file.

parent 5a4e9be0
No related branches found
No related tags found
2 merge requests!620Update version of default branch to 0.27.0-SNAPSHOT,!492Changed logic with default legal file.
Pipeline #230012 failed
Showing
with 238 additions and 465 deletions
......@@ -46,7 +46,6 @@ Defined in default application property file but possible to override:
| `LOG_PREFIX` | `legal` | Logging prefix | no | - |
| `AUTHORIZE_API` | `http://entitlements/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment | |
| `PARTITION_API` | ex `http://partition/api/partition/v1` | Partition service endpoint | no | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name, if `true` then bucket name will be `<project id>-<tenant name>-legal-service-configuration` otherwise `<tenant name>-legal-service-configuration` | no | - |
| `PARTITION_AUTH_ENABLED` | `false` | Disable auth token provisioning for requests to Partition service | no | - |
| `PARTITION_PROPERTIES_LEGAL_BUCKET_NAME` | ex `legal.bucket.name` | Name of partition property for legal bucket name value | yes | - |
......@@ -316,7 +315,7 @@ These buckets must be defined in tenants’ dedicated object store servers. OBM
<tr>
<td>&lt;PartitionInfo.name>-legal-service-configuration
<strong>OR</strong> (if $ENABLE_FULL_BUCKET_NAME == true)
<strong>OR</strong>
<p>
&lt;PartitionInfo.projectId>-&lt;PartitionInfo.name>-legal-service-configuration
</td>
......@@ -336,7 +335,6 @@ You will need to have the following environment variables defined.
| `HOST_URL` | `http://localhsot:8080/api/legal/v1/` | - | yes | - |
| `MY_TENANT` | `osdu` | OSDU tenant used for testing | yes | - |
| `SKIP_HTTP_TESTS` | ex `true` | jetty server returns 403 when running locally when deployed jettyserver is not used and the app returns a 302 so just run against deployed version only when checking http -> https redirects. Use 'true' for Google Cloud Run | yes | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name | no | - |
| `BAREMETAL_PROJECT_ID` | ex `osdu-anthos` | project id used to specify bucket name if `ENABLE_FULL_BUCKET_NAME`=true | no | - |
| `TEST_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$INTEGRATION_TESTER` | yes | -- |
| `TEST_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$INTEGRATION_TESTER` | -- |
......@@ -361,3 +359,20 @@ Execute following command to build code and run all the integration tests:
$ (cd testing/legal-test-core/ && mvn clean install)
$ (cd testing/legal-test-baremetal/ && mvn clean test)
```
## License
Copyright © Google LLC
Copyright © EPAM Systems
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](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.
\ No newline at end of file
......@@ -20,7 +20,6 @@ import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.obm.core.Driver;
import org.opengroup.osdu.legal.config.AppServiceConfig;
import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory;
......@@ -30,7 +29,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class StorageReaderFactoryImpl implements IStorageReaderFactory {
private final AppServiceConfig config;
private final Driver storage;
private final PartitionPropertyResolver partitionPropertyResolver;
......@@ -40,11 +38,6 @@ public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Override
public IStorageReader getReader(TenantInfo tenant, String projectRegion) {
return new StorageReaderImpl(
tenant,
projectRegion,
storage,
config.isEnableFullBucketName(),
partitionPropertyResolver,
partitionPropertyNames);
tenant, storage, partitionPropertyResolver, partitionPropertyNames);
}
}
......@@ -17,7 +17,6 @@
package org.opengroup.osdu.legal.countries;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
......@@ -28,7 +27,8 @@ import org.opengroup.osdu.core.obm.core.model.Blob;
import org.opengroup.osdu.core.obm.core.persistence.ObmDestination;
import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.springframework.http.MediaType;
import java.util.Objects;
@RequiredArgsConstructor
@Slf4j
......@@ -40,15 +40,16 @@ public class StorageReaderImpl implements IStorageReader {
private TenantInfo tenantInfo;
private Driver storage;
protected static final String BUCKET_NAME = "legal-service-configuration";
protected static final String BUCKET_NAME = "legal-config";
private static final String FILE_NAME = "Legal_COO.json";
private boolean isFullBucketName = false;
public StorageReaderImpl(TenantInfo tenantInfo, String projectRegion, Driver storage,
boolean enableFullBucketName, PartitionPropertyResolver partitionPropertyResolver,
public StorageReaderImpl(
TenantInfo tenantInfo,
Driver storage,
PartitionPropertyResolver partitionPropertyResolver,
PartitionPropertyNames partitionPropertyNames) {
this.tenantInfo = tenantInfo;
this.isFullBucketName = enableFullBucketName;
this.storage = storage;
this.partitionPropertyResolver = partitionPropertyResolver;
this.partitionPropertyNames = partitionPropertyNames;
......@@ -58,29 +59,24 @@ public class StorageReaderImpl implements IStorageReader {
public byte[] readAllBytes() {
byte[] content = null;
try {
if (storage.getBucket(getTenantBucketName(), getDestination()) == null) {
storage.createBucket(getTenantBucketName(), getDestination());
String tenantBucketName = getTenantBucketName();
ObmDestination destination = getDestination();
if (Objects.isNull(storage.getBucket(getTenantBucketName(), getDestination()))) {
log.warn("Bucket %s is not existing.".formatted(tenantBucketName));
return new byte[0];
}
if (Objects.isNull(storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination()))) {
Blob emptyBlob = Blob.builder()
.bucket(getTenantBucketName())
.name(FILE_NAME)
.contentType(MediaType.APPLICATION_JSON.toString())
.build();
storage.createBlob(emptyBlob, new byte[0], getDestination());
content = storage.getBlobContent(getTenantBucketName(), FILE_NAME, getDestination());
return content;
Blob blob = storage.getBlob(tenantBucketName, FILE_NAME, destination);
if (Objects.isNull(blob)) {
log.warn("File %s in bucket %s is not existing.".formatted(FILE_NAME, tenantBucketName));
} else {
Blob blob = storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination());
if (Objects.nonNull(blob)) {
content = storage.getBlobContent(getTenantBucketName(), FILE_NAME, getDestination());
}
content = storage.getBlobContent(getTenantBucketName(), FILE_NAME, getDestination());
}
} catch (ObmDriverRuntimeException e) {
log.error(e.getMessage(), e);
throw e;
}
return content;
return content == null ? new byte[0] : content;
}
protected String getTenantBucketName() {
......@@ -88,16 +84,12 @@ public class StorageReaderImpl implements IStorageReader {
.getOptionalPropertyValue(
partitionPropertyNames.getLegalBucketName(), tenantInfo.getDataPartitionId())
.orElseGet(
() -> {
if (Objects.nonNull(isFullBucketName) && isFullBucketName) {
return this.tenantInfo.getProjectId()
() ->
this.tenantInfo.getProjectId()
+ "-"
+ this.tenantInfo.getName()
+ "-"
+ BUCKET_NAME;
}
return this.tenantInfo.getName() + "-" + BUCKET_NAME;
});
+ BUCKET_NAME);
}
private ObmDestination getDestination() {
......
/*
* Copyright 2020-2023 Google LLC
* Copyright 2020-2023 EPAM Systems, Inc
* Copyright 2020-2023 Google LLC
* Copyright 2020-2023 EPAM Systems, Inc
*
* 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
* 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
* https://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.
* 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.
*/
package org.opengroup.osdu.legal.countries;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.opengroup.osdu.legal.countries.StorageReaderImpl.BUCKET_NAME;
import static org.powermock.api.mockito.PowerMockito.when;
import java.util.Optional;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
......@@ -39,56 +32,42 @@ import org.opengroup.osdu.core.obm.core.model.Bucket;
import org.opengroup.osdu.core.obm.core.persistence.ObmDestination;
import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(MockitoJUnitRunner.class)
public class StorageReaderImplTests {
private static final String TENANT_1 = "tenant1";
private static final String FILE_NAME = "Legal_COO.json";
private static final String BUCKET_FULL_NAME = "tenant1-legal-service-configuration";
private static final String BUCKET_FULL_NAME = "tenant1-tenant1-legal-config";
@Mock
private TenantInfo tenantInfo;
@Mock private TenantInfo tenantInfo;
@Mock
private Driver storage;
@Mock private Driver storage;
@Mock
private PartitionPropertyNames partitionPropertyNames;
@Mock private PartitionPropertyNames partitionPropertyNames;
@Mock
private PartitionPropertyResolver partitionPropertyResolver;
@Mock private PartitionPropertyResolver partitionPropertyResolver;
@InjectMocks
private StorageReaderImpl sut;
private String bucketName;
@InjectMocks private StorageReaderImpl sut;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
bucketName = "legal-service-configuration";
}
@Test
public void should_createBucketAndObject_when_bucketDoesNotExist() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination())).thenReturn(
new byte[0]);
byte[] bytes = sut.readAllBytes();
assertNotNull(bytes);
}
@Test
public void should_returnAllBytes_when_bucketExistsAndFileExist() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(
new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME,
getDestination())).thenReturn(
Blob.builder().build());
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(Blob.builder().build());
byte[] expectedBytes = "test".getBytes();
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(expectedBytes);
......@@ -98,41 +77,27 @@ public class StorageReaderImplTests {
}
@Test
public void should_returnFullBucketName_when_IsFullBucketName_is_true() {
public void should_returnEmptyArray_when_bucketNotExists() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn("projectId1");
String bucketName = tenantInfo.getProjectId() + "-" + tenantInfo.getName() + "-" + BUCKET_NAME;
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo, null, storage, true, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
}
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
@Test
public void should_returnBucketName_when_IsFullBucketName_is_false() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME;
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo, null, storage, false, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
byte[] bytes = sut.readAllBytes();
assertTrue(bytes.length == 0);
}
@Test
@Ignore
public void should_returnBucketName_when_IsFullBucketName_is_null() {
public void should_returnEmptyArray_when_FileBucketNull() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn("projectId1");
String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME;
TenantInfo tenantInfo1 = new TenantInfo();
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo1, null, null, false, partitionPropertyResolver, partitionPropertyNames);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(Blob.builder().build());
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination())).thenReturn(null);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
byte[] bytes = sut.readAllBytes();
assertTrue(bytes.length == 0);
}
@Test
......@@ -141,10 +106,9 @@ public class StorageReaderImplTests {
when(partitionPropertyResolver.getOptionalPropertyValue(
partitionPropertyNames.getLegalBucketName(), tenantInfo.getDataPartitionId()))
.thenReturn(Optional.of("partition-bucket-name"));
TenantInfo tenantInfo1 = new TenantInfo();
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo1, null, null, false, partitionPropertyResolver, partitionPropertyNames);
tenantInfo, storage, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals("partition-bucket-name", resultBucketName);
......@@ -153,4 +117,4 @@ public class StorageReaderImplTests {
private ObmDestination getDestination() {
return ObmDestination.builder().partitionId(TENANT_1).build();
}
}
\ No newline at end of file
}
......@@ -20,13 +20,13 @@ Define the following environment variables.
Must have:
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `SPRING_PROFILES_ACTIVE` | ex `anthos` | Spring profile that activate default configuration for Google Cloud environment | false | - |
| `<POSTGRES_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | Potgres user, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | yes | - |
| `<MINIO_SECRETKEY_ENV_VARIABLE_NAME>` | ex `password` | Minio password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
| `<AMQP_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | RabbitMQ password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
| `<AMQP_ADMIN_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | RabbitMQ Admin password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
| name | value | description | sensitive? | source |
|-------------------------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|--------|
| `SPRING_PROFILES_ACTIVE` | ex `anthos` | Spring profile that activate default configuration for Google Cloud environment | false | - |
| `<POSTGRES_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | Potgres user, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | yes | - |
| `<MINIO_SECRETKEY_ENV_VARIABLE_NAME>` | ex `password` | Minio password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
| `<AMQP_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | RabbitMQ password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
| `<AMQP_ADMIN_PASSWORD_ENV_VARIABLE_NAME>` | ex `password` | RabbitMQ Admin password, name of that variable not defined at the service level, the name will be received through partition service. Each tenant can have it's own ENV name value, and it must be present in ENV of Indexer service, see [Partition properties set](#Properties-set-in-Partition-service) | false | - |
Defined in default application property file but possible to override:
......@@ -35,23 +35,22 @@ Defined in default application property file but possible to override:
| `LOG_PREFIX` | `legal` | Logging prefix | no | - |
| `AUTHORIZE_API` | `http://entitlements/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment | |
| `PARTITION_API` | ex `http://partition/api/partition/v1` | Partition service endpoint | no | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name, if `true` then bucket name will be `<project id>-<tenant name>-legal-service-configuration` otherwise `<tenant name>-legal-service-configuration` | no | - |
| `PARTITION_AUTH_ENABLED` | `false` | Disable auth token provisioning for requests to Partition service | no | - |
| `PARTITION_PROPERTIES_LEGAL_BUCKET_NAME` | ex `legal.bucket.name` | Name of partition property for legal bucket name value | yes | - |
These variables define service behavior, and are used to switch between `baremetal` or `gc` environments, their overriding and usage in mixed mode was not tested.
Usage of spring profiles is preferred.
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `OPENID_PROVIDER_CLIENT_ID` | `*****` | Client id that represents this service and serves to request tokens, example `workload-identity-legal` |yes| - |
| `OPENID_PROVIDER_CLIENT_SECRET` | `*****` | This client secret that serves to request tokens| yes | - |
| `OPENID_PROVIDER_URL` | `https://keycloack.com/auth/realms/master` | URL of OpenID Connect provider, it will be used as `<OpenID URL> + /.well-known/openid-configuration` to auto configure endpoint for token request | no | - |
| `PARTITION_AUTH_ENABLED` | ex `true` or `false` | Disable or enable auth token provisioning for requests to Partition service | no | - |
| `OSMDRIVER` | `postgres`| Osm driver mode that defines which KV storage will be used | no | - |
| `OBMDRIVER` | `minio` | Obm driver mode that defines which object storage will be used | no | - |
| `OQMDRIVER` | `rabbitmq` | Oqm driver mode that defines which message broker will be used | no | - |
| `SERVICE_TOKEN_PROVIDER` | `GCP` or `OPENID` |Service account token provider, `GCP` means use Google service account `OPEIND` means use OpenId provider like `Keycloak` | no | - |
| name | value | description | sensitive? | source |
|---------------------------------|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|------------|--------|
| `OPENID_PROVIDER_CLIENT_ID` | `*****` | Client id that represents this service and serves to request tokens, example `workload-identity-legal` | yes | - |
| `OPENID_PROVIDER_CLIENT_SECRET` | `*****` | This client secret that serves to request tokens | yes | - |
| `OPENID_PROVIDER_URL` | `https://keycloack.com/auth/realms/master` | URL of OpenID Connect provider, it will be used as `<OpenID URL> + /.well-known/openid-configuration` to auto configure endpoint for token request | no | - |
| `PARTITION_AUTH_ENABLED` | ex `true` or `false` | Disable or enable auth token provisioning for requests to Partition service | no | - |
| `OSMDRIVER` | `postgres` | Osm driver mode that defines which KV storage will be used | no | - |
| `OBMDRIVER` | `minio` | Obm driver mode that defines which object storage will be used | no | - |
| `OQMDRIVER` | `rabbitmq` | Oqm driver mode that defines which message broker will be used | no | - |
| `SERVICE_TOKEN_PROVIDER` | `GCP` or `OPENID` | Service account token provider, `GCP` means use Google service account `OPEIND` means use OpenId provider like `Keycloak` | no | - |
### Properties set in Partition service:
......@@ -84,11 +83,11 @@ It can be overridden by:
**Propertyset:**
| Property | Description |
| --- | --- |
| osm.postgres.datasource.url | server URL |
| osm.postgres.datasource.username | username |
| osm.postgres.datasource.password | password |
| Property | Description |
|----------------------------------|-------------|
| osm.postgres.datasource.url | server URL |
| osm.postgres.datasource.username | username |
| osm.postgres.datasource.password | password |
<details><summary>Example of a definition for a single tenant</summary>
......@@ -168,19 +167,19 @@ It can be overridden by:
**Property Set** (for two types of connection: messaging and admin operations):
| Property | Description |
| --- | --- |
| oqm.rabbitmq.amqp.host | messaging hostname or IP |
| oqm.rabbitmq.amqp.port | - port |
| oqm.rabbitmq.amqp.path | - path |
| oqm.rabbitmq.amqp.username | - username |
| oqm.rabbitmq.amqp.password | - password |
| oqm.rabbitmq.admin.schema | admin host schema |
| oqm.rabbitmq.admin.host | - host name |
| oqm.rabbitmq.admin.port | - port |
| oqm.rabbitmq.admin.path | - path |
| oqm.rabbitmq.admin.username | - username |
| oqm.rabbitmq.admin.password | - password |
| Property | Description |
|-----------------------------|--------------------------|
| oqm.rabbitmq.amqp.host | messaging hostname or IP |
| oqm.rabbitmq.amqp.port | - port |
| oqm.rabbitmq.amqp.path | - path |
| oqm.rabbitmq.amqp.username | - username |
| oqm.rabbitmq.amqp.password | - password |
| oqm.rabbitmq.admin.schema | admin host schema |
| oqm.rabbitmq.admin.host | - host name |
| oqm.rabbitmq.admin.port | - port |
| oqm.rabbitmq.admin.path | - path |
| oqm.rabbitmq.admin.username | - username |
| oqm.rabbitmq.admin.password | - password |
<details><summary>Example of a single tenant definition</summary>
......@@ -270,11 +269,11 @@ It can be overridden by:
**Propertyset** (for two types of connection: messaging and admin operations):
| Property | Description |
| --- | --- |
| obm.minio.endpoint | - url |
| obm.minio.credentials.access.key | - username |
| obm.minio.credentials.secret.key | - password |
| Property | Description |
|----------------------------------|-------------|
| obm.minio.endpoint | - url |
| obm.minio.credentials.access.key | - username |
| obm.minio.credentials.secret.key | - password |
<details><summary>Example of a single tenant definition</summary>
......@@ -318,9 +317,9 @@ These buckets must be defined in tenants’ dedicated object store servers. OBM
<tr>
<td>&lt;PartitionInfo.name>-legal-service-configuration
<strong>OR</strong> (if $ENABLE_FULL_BUCKET_NAME == true)
<strong>OR</strong>
<p>
&lt;PartitionInfo.projectId>-&lt;PartitionInfo.name>-legal-service-configuration
&lt;PartitionInfo.projectId>-&lt;PartitionInfo.name>-legal-config
</td>
<td>CreateBucket, CRUDObject
</td>
......@@ -338,8 +337,7 @@ You will need to have the following environment variables defined.
| `HOST_URL` | `http://localhsot:8080/api/legal/v1/` | - | yes | - |
| `MY_TENANT` | `osdu` | OSDU tenant used for testing | yes | - |
| `SKIP_HTTP_TESTS` | ex `true` | jetty server returns 403 when running locally when deployed jettyserver is not used and the app returns a 302 so just run against deployed version only when checking http -> https redirects. Use 'true' for Google Cloud Run | yes | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name | no | - |
| `BAREMETAL_PROJECT_ID` | ex `osdu-anthos` | project id used to specify bucket name if `ENABLE_FULL_BUCKET_NAME`=true | no | - |
| `BAREMETAL_PROJECT_ID` | ex `osdu-anthos` | project id used to specify bucket name | no | - |
| `TEST_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$INTEGRATION_TESTER` | yes | -- |
| `TEST_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$INTEGRATION_TESTER` | -- |
| `TEST_OPENID_PROVIDER_URL` | `https://keycloak.com/auth/realms/osdu` | OpenID provider url | yes | -- |
......@@ -351,8 +349,8 @@ You will need to have the following environment variables defined.
**Entitlements configuration for integration accounts**
| INTEGRATION_TESTER |
| --- |
| INTEGRATION_TESTER |
|------------------------------------------------------------------------------------------------------------------------------------------------------|
| users<br/>service.entitlements.user<br/>service.legal.admin<br/>service.legal.editor<br/>service.legal.user<br/>data.test1<br/>data.integration.test |
Execute following command to build code and run all the integration tests:
......@@ -363,3 +361,20 @@ Execute following command to build code and run all the integration tests:
$ (cd testing/legal-test-core/ && mvn clean install)
$ (cd testing/legal-test-baremetal/ && mvn clean test)
```
## License
Copyright © Google LLC
Copyright © EPAM Systems
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](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.
\ No newline at end of file
......@@ -21,9 +21,9 @@ Define the following environment variables.
Must have:
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `SPRING_PROFILES_ACTIVE` | ex `gcp` | Spring profile that activate default configuration for Google Cloud environment | false | - |
| name | value | description | sensitive? | source |
|--------------------------|----------|---------------------------------------------------------------------------------|------------|--------|
| `SPRING_PROFILES_ACTIVE` | ex `gcp` | Spring profile that activate default configuration for Google Cloud environment | false | - |
Defined in default application property file but possible to override:
......@@ -32,22 +32,21 @@ Defined in default application property file but possible to override:
| `LOG_PREFIX` | `legal` | Logging prefix | no | - |
| `AUTHORIZE_API` | `http://entitlements/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment | |
| `PARTITION_API` | ex `http://partition/api/partition/v1` | Partition service endpoint | no | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name, if `true` then bucket name will be `<project id>-<tenant name>-legal-service-configuration` otherwise `<tenant name>-legal-service-configuration` | no | - |
| `SERVICE_TOKEN_PROVIDER` | `GCP` | Service account token provider, `GCP` means use Google service account | no | - |
| `PARTITION_AUTH_ENABLED` | `true` | Enable auth token provisioning for requests to Partition service | no | - |
| `GOOGLE_APPLICATION_CREDENTIALS` | ex `/path/to/directory/service-key.json` | Service account credentials, serves to gain access to cloud resources and to request tokens | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
| `PARTITION_PROPERTIES_LEGAL_BUCKET_NAME` | ex `legal.bucket.name` | Name of partition property for legal bucket name value | yes | - |
| `PARTITION_PROPERTIES_LEGAL_BUCKET_NAME` | ex `legal.bucket.name` | Name of partition property for legal bucket name value | yes | - |
These variables define service behavior, and are used to switch between `baremetal` or `gc` environments, their overriding and usage in mixed mode was not tested.
Usage of spring profiles is preferred.
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `PARTITION_AUTH_ENABLED` | ex `true` or `false` | Disable or enable auth token provisioning for requests to Partition service | no | - |
| `OQMDRIVER` | `rabbitmq` or `pubsub` | Oqm driver mode that defines which message broker will be used | no | - |
| `OSMDRIVER` | `datastore`| Osm driver mode that defines which KV storage will be used | no | - |
| `OBMDRIVER` | `gcs` | Obm driver mode that defines which object storage will be used | no | - |
| `SERVICE_TOKEN_PROVIDER` | `GCP` or `OPENID` |Service account token provider, `GCP` means use Google service account `OPEIND` means use OpenId provider like `Keycloak` | no | - |
| name | value | description | sensitive? | source |
|--------------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------|------------|--------|
| `PARTITION_AUTH_ENABLED` | ex `true` or `false` | Disable or enable auth token provisioning for requests to Partition service | no | - |
| `OQMDRIVER` | `rabbitmq` or `pubsub` | Oqm driver mode that defines which message broker will be used | no | - |
| `OSMDRIVER` | `datastore` | Osm driver mode that defines which KV storage will be used | no | - |
| `OBMDRIVER` | `gcs` | Obm driver mode that defines which object storage will be used | no | - |
| `SERVICE_TOKEN_PROVIDER` | `GCP` or `OPENID` | Service account token provider, `GCP` means use Google service account `OPEIND` means use OpenId provider like `Keycloak` | no | - |
### Running Locally
......@@ -99,9 +98,9 @@ These buckets must be defined in tenants’ “data” Google Cloud projects tha
<tr>
<td>&lt;PartitionInfo.name>-legal-service-configuration
**OR** (if $ENABLE_FULL_BUCKET_NAME == true)
<strong>OR</strong>
<p>
&lt;PartitionInfo.projectId>-&lt;PartitionInfo.name>-legal-service-configuration
&lt;PartitionInfo.projectId>-&lt;PartitionInfo.name>-legal-config
</td>
<td>CreateBucket, CRUDObject
</td>
......@@ -113,8 +112,8 @@ These buckets must be defined in tenants’ “data” Google Cloud projects tha
TBD
| Required roles |
| --- |
| - |
|----------------|
| - |
### Running E2E Tests
......@@ -130,7 +129,6 @@ You will need to have the following environment variables defined.
| `HOST_URL` | `http://localhsot:8080/api/legal/v1/` | - | yes | - |
| `MY_TENANT` | `osdu` | OSDU tenant used for testing | yes | - |
| `SKIP_HTTP_TESTS` | ex `true` | jetty server returns 403 when running locally when deployed jettyserver is not used and the app returns a 302 so just run against deployed version only when checking http -> https redirects. Use 'true' for Google Cloud Run | yes | - |
| `ENABLE_FULL_BUCKET_NAME` | ex `true` | Full bucket name | no | - |
| `PARTITION_API` | ex `http://localhost:8080/api/partition/v1 ` | Partition service host | no | -- |
**Entitlements configuration for integration accounts**
......@@ -147,3 +145,20 @@ Execute following command to build code and run all the integration tests:
$ (cd testing/legal-test-core/ && mvn clean install)
$ (cd testing/legal-test-gc/ && mvn clean test)
```
## License
Copyright © Google LLC
Copyright © EPAM Systems
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](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.
\ No newline at end of file
# Copyright 2017-2019, Schlumberger
#
# 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.
service: os-legal
runtime: java
env: flex
runtime_config:
jdk: openjdk8
api_version: 1
threadsafe: yes
resources:
cpu: 1
memory_gb: 2.4
disk_size_gb: 10
handlers:
- url: /.*
script: this field is required, but ignored
env_variables:
SPRING_PROFILES_ACTIVE: "ENVIRONMENT"
ENABLE_FULL_BUCKET_NAME: 'ENABLE_FULL_BUCKET_NAME_VAR'
\ No newline at end of file
......@@ -20,7 +20,6 @@ import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.gcp.obm.driver.Driver;
import org.opengroup.osdu.legal.config.GcpAppServiceConfig;
import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory;
......@@ -30,7 +29,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class StorageReaderFactoryImpl implements IStorageReaderFactory {
private final GcpAppServiceConfig config;
private final Driver storage;
private final PartitionPropertyResolver partitionPropertyResolver;
......@@ -40,11 +38,6 @@ public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Override
public IStorageReader getReader(TenantInfo tenant, String projectRegion) {
return new StorageReaderImpl(
tenant,
projectRegion,
storage,
config.isEnableFullBucketName(),
partitionPropertyResolver,
partitionPropertyNames);
tenant, storage, partitionPropertyResolver, partitionPropertyNames);
}
}
......@@ -19,8 +19,6 @@ package org.opengroup.osdu.legal.countries;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.gcp.obm.driver.Driver;
......@@ -42,13 +40,15 @@ public class StorageReaderImpl implements IStorageReader {
private TenantInfo tenantInfo;
private Driver storage;
protected static final String BUCKET_NAME = "legal-service-configuration";
protected static final String BUCKET_NAME = "legal-config";
private static final String FILE_NAME = "Legal_COO.json";
private boolean isFullBucketName = false;
public StorageReaderImpl(TenantInfo tenantInfo, String projectRegion, Driver storage, boolean enableFullBucketName, PartitionPropertyResolver partitionPropertyResolver, PartitionPropertyNames partitionPropertyNames) {
public StorageReaderImpl(
TenantInfo tenantInfo,
Driver storage,
PartitionPropertyResolver partitionPropertyResolver,
PartitionPropertyNames partitionPropertyNames) {
this.tenantInfo = tenantInfo;
this.isFullBucketName = enableFullBucketName;
this.storage = storage;
this.partitionPropertyResolver = partitionPropertyResolver;
this.partitionPropertyNames = partitionPropertyNames;
......@@ -58,27 +58,22 @@ public class StorageReaderImpl implements IStorageReader {
public byte[] readAllBytes() {
byte[] content = null;
try {
if (Objects.isNull(storage.getBucket(getTenantBucketName(), getDestination()))) {
log.error("Bucket %s is not existing.".formatted(getTenantBucketName()));
throw new AppException(
HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal error.", "Internal error.");
String tenantBucketName = getTenantBucketName();
ObmDestination destination = getDestination();
if (Objects.isNull(storage.getBucket(tenantBucketName, destination))) {
log.warn("Bucket %s is not existing.".formatted(tenantBucketName));
return new byte[0];
}
if (Objects.isNull(storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination()))) {
log.error(
"File %s in bucket %s is not existing.".formatted(FILE_NAME, getTenantBucketName()));
throw new AppException(
HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal error.", "Internal error.");
Blob blob = storage.getBlob(tenantBucketName, FILE_NAME, destination);
if (Objects.isNull(blob)) {
log.warn("File %s in bucket %s is not existing.".formatted(FILE_NAME, tenantBucketName));
} else {
Blob blob = storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination());
if (Objects.nonNull(blob)) {
content = storage.getBlobContent(getTenantBucketName(), FILE_NAME, getDestination());
}
content = storage.getBlobContent(tenantBucketName, FILE_NAME, destination);
}
} catch (ObmDriverRuntimeException e) {
log.error(e.getMessage(), e);
throw e;
}
return content;
return content == null ? new byte[0] : content;
}
protected String getTenantBucketName() {
......@@ -86,16 +81,12 @@ public class StorageReaderImpl implements IStorageReader {
.getOptionalPropertyValue(
partitionPropertyNames.getLegalBucketName(), tenantInfo.getDataPartitionId())
.orElseGet(
() -> {
if (Objects.nonNull(isFullBucketName) && isFullBucketName) {
return this.tenantInfo.getProjectId()
() ->
this.tenantInfo.getProjectId()
+ "-"
+ this.tenantInfo.getName()
+ "-"
+ BUCKET_NAME;
}
return this.tenantInfo.getName() + "-" + BUCKET_NAME;
});
+ BUCKET_NAME);
}
private ObmDestination getDestination() {
......
......@@ -10,10 +10,6 @@ logging.level.org.springframework.web=${LOG_LEVEL:INFO}
JAVA_HEAP_OPTS=-Xms4096M -Xmx4096M
JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45
# Legal service config
ENABLE_FULL_BUCKET_NAME=true
enable-full-bucket-name=${ENABLE_FULL_BUCKET_NAME}
# OQM config
pub-sub-legal-tags-topic=legaltags-changed
......
......@@ -18,18 +18,15 @@
package org.opengroup.osdu.legal.countries;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.gcp.obm.driver.Driver;
import org.opengroup.osdu.core.gcp.obm.driver.ObmDriverRuntimeException;
import org.opengroup.osdu.core.gcp.obm.model.Blob;
import org.opengroup.osdu.core.gcp.obm.model.Bucket;
import org.opengroup.osdu.core.gcp.obm.persistence.ObmDestination;
......@@ -38,7 +35,7 @@ import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.opengroup.osdu.legal.countries.StorageReaderImpl.BUCKET_NAME;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(MockitoJUnitRunner.class)
......@@ -46,48 +43,31 @@ public class StorageReaderImplTests {
private static final String TENANT_1 = "tenant1";
private static final String FILE_NAME = "Legal_COO.json";
private static final String BUCKET_FULL_NAME = "tenant1-legal-service-configuration";
private static final String BUCKET_FULL_NAME = "tenant1-tenant1-legal-config";
@Mock
private TenantInfo tenantInfo;
@Mock private TenantInfo tenantInfo;
@Mock
private Driver storage;
@Mock private Driver storage;
@Mock
private PartitionPropertyNames partitionPropertyNames;
@Mock private PartitionPropertyNames partitionPropertyNames;
@Mock
private PartitionPropertyResolver partitionPropertyResolver;
@Mock private PartitionPropertyResolver partitionPropertyResolver;
@InjectMocks
private StorageReaderImpl sut;
private String bucketName;
@InjectMocks private StorageReaderImpl sut;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
bucketName = "legal-service-configuration";
}
@Test(expected = AppException.class)
public void should_throw_Exception_when_bucketDoesNotExist() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
sut.readAllBytes();
}
@Test
public void should_returnAllBytes_when_bucketExistsAndFileExist() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(
new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME,
getDestination())).thenReturn(
Blob.builder().build());
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(Blob.builder().build());
byte[] expectedBytes = "test".getBytes();
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(expectedBytes);
......@@ -97,41 +77,27 @@ public class StorageReaderImplTests {
}
@Test
public void should_returnFullBucketName_when_IsFullBucketName_is_true() {
public void should_returnEmptyArray_when_bucketNotExists() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn("projectId1");
String bucketName = tenantInfo.getProjectId() + "-" + tenantInfo.getName() + "-" + BUCKET_NAME;
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo, null, storage, true, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
}
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
@Test
public void should_returnBucketName_when_IsFullBucketName_is_false() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME;
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo, null, storage, false, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
byte[] bytes = sut.readAllBytes();
assertTrue(bytes.length == 0);
}
@Test
@Ignore
public void should_returnBucketName_when_IsFullBucketName_is_null() {
public void should_returnEmptyArray_when_FileBucketNull() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn("projectId1");
String bucketName = tenantInfo.getName() + "-" + BUCKET_NAME;
TenantInfo tenantInfo1 = new TenantInfo();
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo1, null, null, false, partitionPropertyResolver, partitionPropertyNames);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(tenantInfo.getProjectId()).thenReturn(TENANT_1);
when(storage.getBucket(BUCKET_FULL_NAME, getDestination())).thenReturn(new Bucket(TENANT_1));
when(storage.getBlob(BUCKET_FULL_NAME, FILE_NAME, getDestination()))
.thenReturn(Blob.builder().build());
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination())).thenReturn(null);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals(bucketName, resultBucketName);
byte[] bytes = sut.readAllBytes();
assertTrue(bytes.length == 0);
}
@Test
......@@ -140,10 +106,9 @@ public class StorageReaderImplTests {
when(partitionPropertyResolver.getOptionalPropertyValue(
partitionPropertyNames.getLegalBucketName(), tenantInfo.getDataPartitionId()))
.thenReturn(Optional.of("partition-bucket-name"));
TenantInfo tenantInfo1 = new TenantInfo();
StorageReaderImpl storageReader =
new StorageReaderImpl(
tenantInfo1, null, null, false, partitionPropertyResolver, partitionPropertyNames);
tenantInfo, storage, partitionPropertyResolver, partitionPropertyNames);
String resultBucketName = storageReader.getTenantBucketName();
assertEquals("partition-bucket-name", resultBucketName);
......@@ -152,4 +117,4 @@ public class StorageReaderImplTests {
private ObmDestination getDestination() {
return ObmDestination.builder().partitionId(TENANT_1).build();
}
}
\ No newline at end of file
}
......@@ -18,25 +18,12 @@
package legal.util;
import com.google.common.base.Strings;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import legal.service.PartitionService;
import legal.util.conf.CloudObjectStorageFactory;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.legal.util.LegalTagUtils;
@Log
@Slf4j
public class AnthosLegalTagUtils extends LegalTagUtils {
private static final String BUCKET_NAME = "legal-service-configuration";
private static final String FILE_NAME = "Legal_COO.json";
private static final CloudObjectStorageFactory storageFactory = new CloudObjectStorageFactory();
private static final OpenIDTokenProvider tokenProvider = new OpenIDTokenProvider();
public AnthosLegalTagUtils() {
......@@ -44,54 +31,6 @@ public class AnthosLegalTagUtils extends LegalTagUtils {
@Override
public synchronized void uploadTenantTestingConfigFile() {
try {
MinioClient client = storageFactory.getClient();
byte[] tenantConfigFileContent = getTenantConfigFileContent();
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Amz-Storage-Class", "REDUCED_REDUNDANCY");
ObjectWriteResponse objectWriteResponse = client.putObject(
PutObjectArgs.builder()
.bucket(getTenantBucketName())
.object(FILE_NAME)
.stream(new ByteArrayInputStream(tenantConfigFileContent), tenantConfigFileContent.length, -1)
.headers(headers)
.build());
System.out.println(objectWriteResponse);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getTenantBucketName() {
String tenantName = System.getProperty("MY_TENANT", System.getenv("MY_TENANT")).toLowerCase();
String projectName = System.getProperty("BAREMETAL_PROJECT_ID", System.getenv("BAREMETAL_PROJECT_ID")).toLowerCase();
String enableFullBucketName = System.getProperty("ENABLE_FULL_BUCKET_NAME", System.getenv("ENABLE_FULL_BUCKET_NAME"));
String legalBucketName;
try {
legalBucketName =
PartitionService.getPartitionProperty("partition.properties.legal.bucketName");
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
if (Objects.nonNull(legalBucketName)){
log.info("Bucket name is using from Partition Service");
return legalBucketName;
}
enableFullBucketName = (Strings.isNullOrEmpty(enableFullBucketName) ? "false"
: enableFullBucketName).toLowerCase();
String bucketName;
if (Boolean.parseBoolean(enableFullBucketName)) {
bucketName = projectName + "-" + tenantName + "-" + BUCKET_NAME;
} else {
bucketName = tenantName + "-" + BUCKET_NAME;
}
return bucketName;
}
@Override
......
......@@ -18,88 +18,21 @@
package org.opengroup.osdu.legal.util;
import com.google.api.client.util.Strings;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import com.google.common.collect.Lists;
import lombok.extern.java.Log;
import org.opengroup.osdu.legal.service.PartitionService;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.Objects;
@Log
@Slf4j
public class GCPLegalTagUtils extends LegalTagUtils {
private static final String BUCKET_NAME = "legal-service-configuration";
private static final String FILE_NAME = "Legal_COO.json";
@Override
public synchronized void uploadTenantTestingConfigFile() {
try {
String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
try (InputStream inputStream = new ByteArrayInputStream(Base64.getDecoder().decode(serviceAccountFile))) {
GoogleCredentials credentials = GoogleCredentials.fromStream(inputStream)
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
Storage storage = StorageOptions.newBuilder()
.setCredentials(credentials)
.setProjectId(System.getProperty("MY_TENANT_PROJECT", System.getenv("MY_TENANT_PROJECT")))
//.setProjectId(System.getenv("MY_TENANT_PROJECT"))
.build().getService();
BlobId blobId = BlobId.of(getTenantBucketName(), FILE_NAME);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("application/json").build();
storage.create(blobInfo, getTenantConfigFileContent());
}
}catch (IOException ex){
ex.printStackTrace();
}
}
private static String getTenantBucketName() {
String tenantName = System.getProperty("MY_TENANT", System.getenv("MY_TENANT")).toLowerCase();
String projectName =
System.getProperty("GCLOUD_PROJECT", System.getenv("GCLOUD_PROJECT")).toLowerCase();
String enableFullBucketName =
System.getProperty("ENABLE_FULL_BUCKET_NAME", System.getenv("ENABLE_FULL_BUCKET_NAME"));
String legalBucketName;
try {
legalBucketName =
PartitionService.getPartitionProperty("partition.properties.legal.bucketName");
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
@Override
public synchronized void uploadTenantTestingConfigFile() {}
if (Objects.nonNull(legalBucketName)){
log.info("Bucket name is using from Partition Service");
return legalBucketName;
@Override
public synchronized String accessToken() throws Exception {
if (Strings.isNullOrEmpty(token)) {
String serviceAccountFile =
System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
token = new GoogleServiceAccount(serviceAccountFile).getAuthToken();
}
enableFullBucketName =
(Strings.isNullOrEmpty(enableFullBucketName) ? "false" : enableFullBucketName)
.toLowerCase();
log.info("ENABLE_FULL_BUCKET_NAME = " + enableFullBucketName);
if (Boolean.parseBoolean(enableFullBucketName)) {
legalBucketName = projectName + "-" + tenantName + "-" + BUCKET_NAME;
} else {
legalBucketName = tenantName + "-" + BUCKET_NAME;
}
log.info("bucketName = " + legalBucketName);
return legalBucketName;
return "Bearer " + token;
}
@Override
public synchronized String accessToken() throws Exception {
if (Strings.isNullOrEmpty(token)) {
String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
token = new GoogleServiceAccount(serviceAccountFile).getAuthToken();
}
return "Bearer " + token;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment