Commit ad9ff99f authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Merge

parents 93d514fe 9976d932
Pipeline #62886 passed with stages
in 2 minutes and 16 seconds
......@@ -31,7 +31,7 @@ env:
CUSTOM_SCOPE: stub
ENVIRONMENT: stub
AWS_REGION: stub
CI_COMMIT_TAG: v0.0.9
CI_COMMIT_TAG: v0.0.8
phases:
install:
......@@ -49,6 +49,8 @@ phases:
# run unit tests
- cp osdu_api/test/osdu_api.ini osdu_api.ini
- rm -r osdu_api/test/providers-unit-tests
- rm -r osdu_api/test/libs-unit-tests
- python -m unittest discover osdu_api/test
- rm osdu_api.ini
......@@ -56,7 +58,7 @@ phases:
- export AWS_ACCOUNT_ID=`aws sts get-caller-identity | grep Account | cut -d':' -f 2 | cut -d'"' -f 2`
- aws codeartifact login --tool twine --domain osdu-dev --domain-owner ${AWS_ACCOUNT_ID} --repository osdu-python
- python setup.py sdist bdist_wheel
- twine upload --skip-existing --repository codeartifact dist/osdu_api-0.0.9.tar.gz
- twine upload --skip-existing --repository codeartifact dist/osdu_api-0.0.8.tar.gz
artifacts:
......
......@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
import os
from configparser import SafeConfigParser
import os
......@@ -46,7 +47,6 @@ class BaseClient:
"""
config_manager = config_manager or DefaultConfigManager()
self.data_partition_id = config_manager.get('environment', 'data_partition_id')
self.provider = config_manager.get('provider', 'name')
self.data_workflow_url = config_manager.get('environment', 'data_workflow_url')
......@@ -63,11 +63,6 @@ class BaseClient:
self.use_service_principal = config_manager.getbool('environment', 'use_service_principal', False)
if self.use_service_principal:
self.service_principal_module_name = config_manager.get('provider', 'service_principal_module_name')
config_parser = SafeConfigParser(os.environ)
config_file_name = 'osdu_api.ini'
found_names = config_parser.read(config_file_name)
if config_file_name not in found_names:
raise Exception('Could not find osdu_api.ini config file')
if data_partition_id is None:
self.data_partition_id = config_manager.get('environment', 'data_partition_id')
......
......@@ -68,7 +68,7 @@ class DefaultConfigManager(BaseConfigManager):
:rtype: configparser.ConfigParser
"""
config_file_path = config_file_path or os.environ.get("OSDU_API_CONFIG_INI") or "osdu_api.ini"
parser = configparser.ConfigParser()
parser = configparser.ConfigParser(os.environ)
config_read_results = parser.read(config_file_path)
if not config_read_results:
raise configparser.Error(f"Could not find the config file in '{config_file_path}'.")
......
......@@ -14,8 +14,11 @@
from osdu_api.clients.legal.legal_client import LegalClient
from osdu_api.model.legal.legal_tag import LegalTag
from osdu_api.model.legal.legal_tag_properties import LegalTagProperties
from osdu_api.configuration.config_manager import DefaultConfigManager
import os
legal_client = LegalClient("opendes")
os.environ['BASE_URL'] = 'https://suttonsp.dev.osdu.aws'
legal_client = LegalClient(DefaultConfigManager(), "opendes")
legal_tag_properties = LegalTagProperties(['US'], 'A1234', 2222222222222, 'default', 'Public Domain Data', 'Public', 'No Personal Data', 'EAR99')
......
......@@ -15,7 +15,7 @@
storage_url=%(BASE_URL)s/api/storage/v2
search_url=%(BASE_URL)s/api/search/v2
legal_url=%(BASE_URL)s/api/legal/v1
data_workflow_url=%(BASE_URL)s/api/data-workflow/v1
data_workflow_url=deprecated
file_dms_url=%(BASE_URL)s/api/filedms/v2
dataset_url=%(BASE_URL)s/api/dataset/v1
entitlements_url=%(BASE_URL)s/api/entitlements/v1
......
......@@ -27,7 +27,7 @@ class TestDefaultConfigManager:
@pytest.fixture
def default_config_file(self):
cwd = os.getcwd()
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
path = shutil.copy(config_file, cwd)
yield path
os.remove(path)
......@@ -37,12 +37,12 @@ class TestDefaultConfigManager:
DefaultConfigManager()
def test_configmanager_with_env_var(self):
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
os.environ["OSDU_API_CONFIG_INI"] = config_file
DefaultConfigManager()
def test_configmanager_with_passed_directly(self):
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
DefaultConfigManager(config_file)
def test_raise_error_if_no_file(self):
......
......@@ -13,23 +13,23 @@
# limitations under the License.
[environment]
data_partition_id=opendes
storage_url=%(STORAGE_BASE_URL)s/api/storage/v2
search_url=%(SEARCH_BASE_URL)s/api/search/v2
legal_url=%(LEGAL_BASE_URL)s/api/legal/v1
data_workflow_url=%(DATA_WORKFLOW_BASE_URL)s/api/data-workflow/v1
entitlements_url=%(ENTITLEMENTS_BASE_URL)s/api/entitlements/v1
file_dms_url=%(FILE_DMS_BASE_URL)s/api/filedms/v2
dataset_url=%(DATASET_REGISTRY_BASE_URL)s/api/dataset-registry/v1
schema_url=%(SCHEMA_BASE_URL)s/api/schema-service/v1
storage_url=blah/api/storage/v2
search_url=blah/api/search/v2
legal_url=blah/api/legal/v1
data_workflow_url=blah/api/data-workflow/v1
entitlements_url=blah/api/entitlements/v1
file_dms_url=blah/api/filedms/v2
dataset_url=blah/api/dataset-registry/v1
schema_url=blah/api/schema-service/v1
ingestion_workflow_url=stub
use_service_principal=True
[provider]
name=aws
service_principal_module_name=service_principal_util
token_url=%(AUTH_TOKEN_URL)s
aws_oauth_custom_scope=%(CUSTOM_SCOPE)s
client_id_ssm_path=/osdu/%(ENVIRONMENT)s/client-credentials-client-id
client_secret_name=/osdu/%(ENVIRONMENT)s/client_credenials_secret
token_url_ssm_path=/osdu/blah/oauth-token-uri
aws_oauth_custom_scope_ssm_path=/osdu/blah/oauth-custom-scope
client_id_ssm_path=/osdu/blah/client-credentials-client-id
client_secret_name=/osdu/blah/client_credentials_secret
client_secret_dict_key=client_credentials_client_secret
region_name=%(AWS_REGION)s
\ No newline at end of file
region_name=blah
\ No newline at end of file
......@@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import os
import mock
import responses
from osdu_api.clients.base_client import BaseClient
from osdu_api.model.http_method import HttpMethod
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestBaseClient(unittest.TestCase):
......@@ -28,7 +28,7 @@ class TestBaseClient(unittest.TestCase):
# Arrange
# Act
client = BaseClient("opendes")
client = BaseClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
# Assert
mocked_token_method.assert_called()
......@@ -37,7 +37,7 @@ class TestBaseClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, mocked_token_method):
# Arrange
client = BaseClient("opendes")
client = BaseClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
responses.add(responses.PUT, 'http://stubbed', json={'response': 'true'}, status=200)
......
......@@ -14,11 +14,12 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.data_workflow.data_workflow_client import DataWorkflowClient
from osdu_api.model.data_workflow.start_workflow import StartWorkflow
from osdu_api.model.http_method import HttpMethod
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestDataWorkflowClient(unittest.TestCase):
......@@ -27,7 +28,7 @@ class TestDataWorkflowClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = DataWorkflowClient("opendes")
client = DataWorkflowClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.data_workflow_url = 'stubbed url'
client.headers = {}
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.dataset.dataset_registry_client import DatasetRegistryClient
from osdu_api.model.dataset.create_dataset_registries_request import CreateDatasetRegistriesRequest
......@@ -23,6 +23,7 @@ from osdu_api.model.storage.acl import Acl
from osdu_api.model.storage.legal import Legal
from osdu_api.model.storage.record import Record
from osdu_api.model.storage.record_ancestry import RecordAncestry
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestDatasetRegistryClient(unittest.TestCase):
......@@ -31,7 +32,7 @@ class TestDatasetRegistryClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = DatasetRegistryClient("opendes")
client = DatasetRegistryClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.dataset_registry_url = 'stubbed url'
client.headers = {}
......
......@@ -14,10 +14,11 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.entitlements.entitlements_client import EntitlementsClient
from osdu_api.model.entitlements.group import Group
from osdu_api.configuration.config_manager import DefaultConfigManager
class Test_Entitlments_Client(unittest.TestCase):
......@@ -26,7 +27,7 @@ class Test_Entitlments_Client(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_file_upload(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = EntitlementsClient("opendes")
client = EntitlementsClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.entitlements_url = 'stubbed url'
client.headers = {}
......
......@@ -13,10 +13,12 @@
# limitations under the License.
import unittest
import mock
import os
from osdu_api.clients.ingestion_workflow.ingestion_workflow_client import IngestionWorkflowClient
from osdu_api.clients.base_client import BaseClient
from osdu_api.model.http_method import HttpMethod
from osdu_api.model.ingestion_workflow.create_workflow_request import CreateWorkflowRequest
from osdu_api.configuration.config_manager import DefaultConfigManager
......@@ -26,7 +28,7 @@ class TestIngestionWorkflowClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = IngestionWorkflowClient()
client = IngestionWorkflowClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), data_partition_id="osdu")
client.service_principal_token = 'stubbed'
client.ingestion_workflow_url = 'stubbed url'
client.headers = {}
......
......@@ -14,9 +14,10 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.legal.legal_client import LegalClient
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestLegalClient(unittest.TestCase):
......@@ -25,7 +26,7 @@ class TestLegalClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_file_upload(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = LegalClient("opendes")
client = LegalClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.legal_url = 'stubbed url'
client.headers = {}
......
......@@ -15,7 +15,7 @@
import json
import types
import unittest
import os
import mock
from osdu_api.clients.base_client import BaseClient
......@@ -25,6 +25,7 @@ from osdu_api.model.storage.acl import Acl
from osdu_api.model.storage.legal import Legal
from osdu_api.model.storage.record import Record
from osdu_api.model.storage.record_ancestry import RecordAncestry
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestRecordClient(unittest.TestCase):
......@@ -98,7 +99,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_create_update_records_model_record(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient("opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -113,7 +114,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_latest_record_version(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient("opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -130,7 +131,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_specific_record_version(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient("opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -148,7 +149,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_record_versions(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient("opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......
......@@ -14,11 +14,12 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.search.search_client import SearchClient
from osdu_api.model.http_method import HttpMethod
from osdu_api.model.search.query_request import QueryRequest
from osdu_api.configuration.config_manager import DefaultConfigManager
class TestSeachClient(unittest.TestCase):
......@@ -27,7 +28,7 @@ class TestSeachClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = SearchClient("opendes")
client = SearchClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.data_workflow_url = 'stubbed url'
client.headers = {}
......
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