aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client
diff options
context:
space:
mode:
authorstark, steven <steven.stark@att.com>2020-10-15 12:34:35 -0700
committerstark, steven <steven.stark@att.com>2020-10-15 12:39:49 -0700
commita0984e365a7c610e9cb91cf73e5d09db2be6df6a (patch)
tree67b8aaaffb37b56105569f2233672db9e5720cbd /onap-client
parent82f201fb65094aad55b3e46634bad39713387c6e (diff)
[VVP] VVP onap-client enhancements
Adding capability for custom auth plugin (defaults to basic auth). During updates to VNF models, resource and policy objects are deletd and recreated. Issue-ID: VVP-477 Signed-off-by: stark, steven <steven.stark@att.com> Change-Id: Iba743176167c2b1df185666b08cbd79c6a559c9e
Diffstat (limited to 'onap-client')
-rw-r--r--onap-client/onap_client/aai/catalog/business_catalog.py24
-rw-r--r--onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py10
-rw-r--r--onap-client/onap_client/aai/client.py22
-rw-r--r--onap-client/onap_client/auth.py70
-rw-r--r--onap-client/onap_client/client/request.py3
-rw-r--r--onap-client/onap_client/etc/payloads/sdc_add_user.jinja7
-rw-r--r--onap-client/onap_client/exceptions.py8
-rw-r--r--onap-client/onap_client/lib.py1
-rw-r--r--onap-client/onap_client/sdc/catalog/license_model_catalog.py50
-rw-r--r--onap-client/onap_client/sdc/catalog/service_catalog.py95
-rw-r--r--onap-client/onap_client/sdc/catalog/vnf_catalog.py124
-rw-r--r--onap-client/onap_client/sdc/catalog/vsp_catalog.py65
-rw-r--r--onap-client/onap_client/sdc/client.py37
-rw-r--r--onap-client/onap_client/sdc/vnf.py24
-rw-r--r--onap-client/onap_client/sdnc/catalog/config_catalog.py6
-rw-r--r--onap-client/onap_client/sdnc/catalog/operations_catalog.py4
-rw-r--r--onap-client/onap_client/sdnc/client.py20
-rw-r--r--onap-client/onap_client/so/catalog/infra_catalog.py91
-rw-r--r--onap-client/onap_client/so/catalog/service_instantiation.py24
-rw-r--r--onap-client/onap_client/so/client.py22
-rw-r--r--onap-client/onap_client/util.py3
-rw-r--r--onap-client/onap_client/vid/catalog/maintenance_catalog.py10
-rw-r--r--onap-client/onap_client/vid/client.py22
-rw-r--r--onap-client/requirements.txt1
-rw-r--r--onap-client/setup.py10
25 files changed, 450 insertions, 303 deletions
diff --git a/onap-client/onap_client/aai/catalog/business_catalog.py b/onap-client/onap_client/aai/catalog/business_catalog.py
index 51c2409..9105ba7 100644
--- a/onap-client/onap_client/aai/catalog/business_catalog.py
+++ b/onap-client/onap_client/aai/catalog/business_catalog.py
@@ -64,7 +64,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_OWNING_ENTITIES": {
"verb": "GET",
@@ -81,7 +81,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_CUSTOMER": {
"verb": "GET",
@@ -99,7 +99,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_CUSTOMERS": {
"verb": "GET",
@@ -116,7 +116,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_PLATFORM": {
"verb": "GET",
@@ -134,7 +134,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_PLATFORMS": {
"verb": "GET",
@@ -151,7 +151,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_PROJECT": {
"verb": "GET",
@@ -169,7 +169,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_PROJECTS": {
"verb": "GET",
@@ -186,7 +186,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_LINES_OF_BUSINESS": {
"verb": "GET",
@@ -203,7 +203,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"CREATE_CUSTOMER": {
"verb": "PUT",
@@ -223,7 +223,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_CUSTOMER_SUBSCRIPTIONS": {
"verb": "GET",
@@ -241,7 +241,7 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_SERVICE_INSTANCES": {
"verb": "GET",
@@ -259,6 +259,6 @@ class BusinessClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py b/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py
index d22ab0e..e71f767 100644
--- a/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py
+++ b/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py
@@ -63,7 +63,7 @@ class CloudInfrastructureClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_CLOUD_REGION": {
"verb": "GET",
@@ -81,7 +81,7 @@ class CloudInfrastructureClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_CLOUD_REGION_TENANTS": {
"verb": "GET",
@@ -99,7 +99,7 @@ class CloudInfrastructureClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_ESR_LIST": {
"verb": "GET",
@@ -117,7 +117,7 @@ class CloudInfrastructureClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
"GET_VOLUME_GROUPS": {
"verb": "GET",
@@ -135,6 +135,6 @@ class CloudInfrastructureClient(AAIClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/aai/client.py b/onap-client/onap_client/aai/client.py
index c4ab03b..2f48e62 100644
--- a/onap-client/onap_client/aai/client.py
+++ b/onap-client/onap_client/aai/client.py
@@ -37,7 +37,9 @@
import uuid
from functools import partial
+from frozendict import frozendict
from onap_client.client.clients import Client
+from onap_client.auth import auth_handler
class AAIClient(Client):
@@ -63,6 +65,24 @@ class AAIClient(Client):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,),
+ "auth": self.auth,
},
}
+
+ @property
+ def aai_username(self):
+ """Username to authenticate to AAI"""
+ return self.config.aai.AAI_USERNAME
+
+ @property
+ def aai_password(self):
+ """Password to authenticate to AAI"""
+ return self.config.aai.AAI_PASSWORD
+
+ @property
+ def auth(self):
+ return auth_handler(
+ frozendict(self.config.aai.AUTH_PLUGIN) if self.config.aai.AUTH_PLUGIN else None,
+ self.aai_username,
+ self.aai_password,
+ )
diff --git a/onap-client/onap_client/auth.py b/onap-client/onap_client/auth.py
new file mode 100644
index 0000000..ccd1819
--- /dev/null
+++ b/onap-client/onap_client/auth.py
@@ -0,0 +1,70 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2020 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software 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.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# 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.
+#
+# ============LICENSE_END============================================
+from importlib import import_module
+from requests.auth import HTTPBasicAuth, AuthBase
+from inspect import getmembers, isclass
+from functools import lru_cache
+
+from onap_client.exceptions import AuthClassNotFound, AuthModuleNotDefined
+
+
+@lru_cache()
+def auth_handler(auth_plugin_config, username, password):
+ if not auth_plugin_config:
+ return HTTPBasicAuth(username, password)
+
+ if not auth_plugin_config.get("AUTH_MODULE"):
+ raise AuthModuleNotDefined("Property AUTH_MODULE was not defined in configuration file.")
+
+ auth_module = import_module(auth_plugin_config.get("AUTH_MODULE"))
+
+ auth_class = get_auth_class(auth_module)
+
+ return auth_class(username, password, **auth_plugin_config)
+
+
+def get_auth_class(auth_module):
+ """
+ Returns first Class definition in auth_module that inherits from AuthBase.
+ """
+ for name, obj in getmembers(
+ auth_module,
+ lambda x: isclass(x) and issubclass(x, AuthBase) and x != AuthBase
+ ):
+ return obj
+
+ raise AuthClassNotFound("No auth class found in module: {}".format(auth_module))
diff --git a/onap-client/onap_client/client/request.py b/onap-client/onap_client/client/request.py
index 84c8280..6563fb8 100644
--- a/onap-client/onap_client/client/request.py
+++ b/onap-client/onap_client/client/request.py
@@ -156,9 +156,6 @@ class APICatalogRequestObject:
self.resolve_uri()
def resolve_files(self):
- # TODO
- # is there a better way to figure out waht params are needed?
- # right now its hardcoded
file_type = self.file_parameters.get("file_type", "application/zip")
file_path = self.file_parameters.get("file_path")
if not file_path:
diff --git a/onap-client/onap_client/etc/payloads/sdc_add_user.jinja b/onap-client/onap_client/etc/payloads/sdc_add_user.jinja
new file mode 100644
index 0000000..0fc8a89
--- /dev/null
+++ b/onap-client/onap_client/etc/payloads/sdc_add_user.jinja
@@ -0,0 +1,7 @@
+{
+ "firstName": "{{first_name}}",
+ "lastName": "{{last_name}}",
+ "userId": "{{user_id}}",
+ "email": "{{email}}",
+ "role": "{{role}}"
+} \ No newline at end of file
diff --git a/onap-client/onap_client/exceptions.py b/onap-client/onap_client/exceptions.py
index fe7d5c0..3e55628 100644
--- a/onap-client/onap_client/exceptions.py
+++ b/onap-client/onap_client/exceptions.py
@@ -150,3 +150,11 @@ class ResourceCreationFailure(Exception):
class ResourceDeleteFailure(Exception):
pass
+
+
+class AuthClassNotFound(Exception):
+ pass
+
+
+class AuthModuleNotDefined(Exception):
+ pass
diff --git a/onap-client/onap_client/lib.py b/onap-client/onap_client/lib.py
index 31cfebb..c87c4df 100644
--- a/onap-client/onap_client/lib.py
+++ b/onap-client/onap_client/lib.py
@@ -36,6 +36,7 @@
# ============LICENSE_END============================================
import uuid
+
from datetime import datetime, timedelta
from onap_client import exceptions
diff --git a/onap-client/onap_client/sdc/catalog/license_model_catalog.py b/onap-client/onap_client/sdc/catalog/license_model_catalog.py
index 0a90ebf..87a9346 100644
--- a/onap-client/onap_client/sdc/catalog/license_model_catalog.py
+++ b/onap-client/onap_client/sdc/catalog/license_model_catalog.py
@@ -70,10 +70,7 @@ class LicenseModelClient(SDCClient):
"license_model_id": ("itemId",),
"license_model_version_id": ("version", "id"),
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_KEY_GROUP": {
"verb": "POST",
@@ -99,10 +96,7 @@ class LicenseModelClient(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"key_group_id": ("value",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_ENTITLEMENT_POOL": {
"verb": "POST",
@@ -128,10 +122,7 @@ class LicenseModelClient(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"entitlement_pool_id": ("value",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_FEATURE_GROUP": {
"verb": "POST",
@@ -158,10 +149,7 @@ class LicenseModelClient(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"feature_group_id": ("value",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_LICENSE_AGREEMENT": {
"verb": "POST",
@@ -183,10 +171,7 @@ class LicenseModelClient(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"license_agreement_id": ("value",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"SUBMIT_LICENSE_MODEL": {
"verb": "PUT",
@@ -207,10 +192,7 @@ class LicenseModelClient(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_LICENSE_MODEL": {
"verb": "GET",
@@ -234,10 +216,7 @@ class LicenseModelClient(SDCClient):
"license_model_id": ("id",),
"description": ("description",),
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_LICENSE_MODEL_VERSION_ATTRIBUTE": {
"verb": "GET",
@@ -256,10 +235,7 @@ class LicenseModelClient(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_LICENSE_MODEL_VERSIONS": {
"verb": "GET",
@@ -278,10 +254,7 @@ class LicenseModelClient(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_LICENSE_MODELS": {
"verb": "GET",
@@ -300,9 +273,6 @@ class LicenseModelClient(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"results": ("results",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdc/catalog/service_catalog.py b/onap-client/onap_client/sdc/catalog/service_catalog.py
index dad8456..33fb8be 100644
--- a/onap-client/onap_client/sdc/catalog/service_catalog.py
+++ b/onap-client/onap_client/sdc/catalog/service_catalog.py
@@ -83,10 +83,7 @@ class ServiceCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_service_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"CHECKOUT_CATALOG_SERVICE": {
"verb": "POST",
@@ -106,10 +103,7 @@ class ServiceCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_service_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_RESOURCE_INSTANCE": {
"verb": "POST",
@@ -138,10 +132,7 @@ class ServiceCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_instance_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"DELETE_RESOURCE_FROM_SERVICE": {
"verb": "DELETE",
@@ -160,10 +151,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"UPDATE_RESOURCE_VERSION": {
"verb": "POST",
@@ -186,10 +174,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"CHECKIN_SERVICE": {
"verb": "POST",
@@ -210,10 +195,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"REQUEST_SERVICE_CERTIFICATION": {
"verb": "POST",
@@ -234,10 +216,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"START_SERVICE_CERTIFICATION": {
"verb": "POST",
@@ -258,10 +237,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"FINISH_SERVICE_CERTIFICATION": {
"verb": "POST",
@@ -283,10 +259,7 @@ class ServiceCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_service_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"APPROVE_SERVICE_CERTIFICATION": {
"verb": "POST",
@@ -307,10 +280,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"DISTRIBUTE_SDC_SERVICE": {
"verb": "POST",
@@ -330,10 +300,7 @@ class ServiceCatalog(SDCClient):
# "X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_SERVICE_PROPERTY": {
"verb": "POST",
@@ -362,10 +329,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_SERVICE_INPUT": {
"verb": "POST",
@@ -392,10 +356,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"UPDATE_MODULE_DEPLOYMENT_PROPERTIES": {
"verb": "POST",
@@ -418,10 +379,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SDC_SERVICE": {
"verb": "GET",
@@ -440,10 +398,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SERVICES": {
"verb": "GET",
@@ -462,10 +417,7 @@ class ServiceCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"services": ("services",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SERVICE_DISTRIBUTION": {
"verb": "GET",
@@ -484,10 +436,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SERVICE_DISTRIBUTION_DETAILS": {
"verb": "GET",
@@ -506,10 +455,7 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SDC_CSAR": {
"verb": "GET",
@@ -528,9 +474,6 @@ class ServiceCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdc/catalog/vnf_catalog.py b/onap-client/onap_client/sdc/catalog/vnf_catalog.py
index 71b20ca..b04b0f5 100644
--- a/onap-client/onap_client/sdc/catalog/vnf_catalog.py
+++ b/onap-client/onap_client/sdc/catalog/vnf_catalog.py
@@ -75,10 +75,7 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"CERTIFY_CATALOG_RESOURCE": {
"verb": "POST",
@@ -100,10 +97,7 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_RESOURCE_INPUT": {
"verb": "POST",
@@ -130,10 +124,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"UPDATE_CATALOG_RESOURCE": {
"verb": "PUT",
@@ -154,10 +145,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"CHECKOUT_CATALOG_RESOURCE": {
"verb": "POST",
@@ -176,10 +164,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_RESOURCE_PROPERTY": {
"verb": "POST",
@@ -208,10 +193,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_RESOURCE_PROPERTY_NON_VF": {
"verb": "POST",
@@ -240,10 +222,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_RESOURCE_POLICY": {
"verb": "POST",
@@ -263,10 +242,26 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
+ "auth": self.auth,
+ },
+ "DELETE_CATALOG_RESOURCE_POLICY": {
+ "verb": "DELETE",
+ "description": "Deletes policy resource to a VNF.",
+ "uri": partial(
+ "{endpoint}{service_path}/{catalog_resource_id}/policies/{policy_id}".format,
+ endpoint=self.config.sdc.SDC_BE_ENDPOINT,
+ service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH,
),
+ "uri-parameters": ["catalog_resource_id", "policy_id"],
+ "success_code": 200,
+ "headers": {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "USER_ID": self.sdc_designer_user_id,
+ "X-TransactionId": str(uuid.uuid4()),
+ "X-FromAppId": self.config.application_id,
+ },
+ "auth": self.auth,
},
"ADD_CATALOG_POLICY_PROPERTY": {
"verb": "PUT",
@@ -293,10 +288,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_RESOURCE_GROUP": {
"verb": "POST",
@@ -316,10 +308,7 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_id": ("uniqueId",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_CATALOG_GROUP_PROPERTY": {
"verb": "PUT",
@@ -348,10 +337,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_GROUP_TO_INSTANCE": {
"verb": "POST",
@@ -372,10 +358,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_POLICY_TO_INSTANCE": {
"verb": "POST",
@@ -396,10 +379,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_RESOURCE_INSTANCE": {
"verb": "POST",
@@ -428,10 +408,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_RESOURCE_RELATIONSHIP": {
"verb": "POST",
@@ -461,10 +438,26 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
+ "auth": self.auth,
+ },
+ "DELETE_RESOURCE_FROM_VNF": {
+ "verb": "DELETE",
+ "description": "Delete a resource from a VNF.",
+ "uri": partial(
+ "{endpoint}{service_path}/{catalog_resource_id}/resourceInstance/{resource_id}".format,
+ endpoint=self.config.sdc.SDC_BE_ENDPOINT,
+ service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH,
),
+ "uri-parameters": ["catalog_resource_id", "resource_id"],
+ "success_code": 200,
+ "headers": {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "USER_ID": self.sdc_designer_user_id,
+ "X-TransactionId": str(uuid.uuid4()),
+ "X-FromAppId": self.config.application_id,
+ },
+ "auth": self.auth,
},
"GET_CATALOG_RESOURCE": {
"verb": "GET",
@@ -484,10 +477,7 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"catalog_resource_name": ("name",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_CATALOG_RESOURCE_METADATA": {
"verb": "GET",
@@ -506,10 +496,7 @@ class VNFCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_RESOURCES": {
"verb": "GET",
@@ -528,9 +515,6 @@ class VNFCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"resources": ("resources",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdc/catalog/vsp_catalog.py b/onap-client/onap_client/sdc/catalog/vsp_catalog.py
index f8ddb9b..19ca631 100644
--- a/onap-client/onap_client/sdc/catalog/vsp_catalog.py
+++ b/onap-client/onap_client/sdc/catalog/vsp_catalog.py
@@ -80,10 +80,7 @@ class VSPCatalog(SDCClient):
"software_product_id": ("itemId",),
"software_product_version_id": ("version", "id"),
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"UPDATE_SOFTWARE_PRODUCT": {
"verb": "POST",
@@ -106,10 +103,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"UPLOAD_HEAT_PACKAGE": {
"verb": "POST",
@@ -129,10 +123,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"VALIDATE_SOFTWARE_PRODUCT": {
"verb": "PUT",
@@ -151,10 +142,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"SUBMIT_SOFTWARE_PRODUCT": {
"verb": "PUT",
@@ -175,10 +163,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"PACKAGE_SOFTWARE_PRODUCT": {
"verb": "PUT",
@@ -199,10 +184,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SOFTWARE_PRODUCT": {
"verb": "GET",
@@ -222,10 +204,7 @@ class VSPCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"name": ("name",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SOFTWARE_PRODUCT_INFORMATION": {
"verb": "GET",
@@ -245,10 +224,7 @@ class VSPCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"name": ("name",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SOFTWARE_PRODUCT_VERSIONS": {
"verb": "GET",
@@ -271,10 +247,7 @@ class VSPCatalog(SDCClient):
"software_product_version_id": ("id",),
"description": ("description",),
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_SOFTWARE_PRODUCTS": {
"verb": "GET",
@@ -293,10 +266,7 @@ class VSPCatalog(SDCClient):
"X-FromAppId": self.config.application_id,
},
"return_data": {"results": ("results",)},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"GET_VSP_PERMISSIONS": {
"verb": "GET",
@@ -315,10 +285,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"ADD_VSP_CONTRIBUTER": {
"verb": "PUT",
@@ -339,10 +306,7 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
"MODIFY_VSP_OWNER": {
"verb": "PUT",
@@ -363,9 +327,6 @@ class VSPCatalog(SDCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
- ),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdc/client.py b/onap-client/onap_client/sdc/client.py
index 725cbeb..59c9b1b 100644
--- a/onap-client/onap_client/sdc/client.py
+++ b/onap-client/onap_client/sdc/client.py
@@ -35,9 +35,12 @@
#
# ============LICENSE_END============================================
import uuid
+from frozendict import frozendict
from functools import partial
+
from onap_client.client.clients import Client
+from onap_client.auth import auth_handler
class SDCClient(Client):
@@ -64,10 +67,7 @@ class SDCClient(Client):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- # "auth": (
- # self.sdc_designer_user_id,
- # self.config.sdc.SDC_DESIGNER_PASSWORD,
- # ),
+ "auth": self.auth,
},
"GET_RESOURCE_CATEGORIES": {
"verb": "GET",
@@ -83,10 +83,25 @@ class SDCClient(Client):
"Content-Type": "application/json",
"USER_ID": self.sdc_designer_user_id,
},
- "auth": (
- self.global_sdc_username,
- self.global_sdc_password,
+ "auth": self.auth,
+ },
+ "ADD_USER": {
+ "verb": "POST",
+ "description": "Add a user to SDC.",
+ "uri": partial(
+ "{endpoint}{service_path}".format,
+ endpoint=self.config.sdc.SDC_BE_ENDPOINT,
+ service_path=self.config.sdc.SDC_USER_PATH,
),
+ "payload": "{}/sdc_add_user.jinja".format(self.config.payload_directory),
+ "payload-parameters": ["first_name", "last_name", "user_id", "email", "role"],
+ "success_code": 201,
+ "headers": {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "USER_ID": self.sdc_ops_user_id,
+ },
+ "auth": self.auth,
},
}
@@ -125,3 +140,11 @@ class SDCClient(Client):
def sdc_governor_user_id(self):
"""Ops role User ID"""
return self.config.sdc.SDC_GOVERNOR_USER_ID
+
+ @property
+ def auth(self):
+ return auth_handler(
+ frozendict(self.config.sdc.AUTH_PLUGIN) if self.config.sdc.AUTH_PLUGIN else None,
+ self.global_sdc_username,
+ self.global_sdc_password,
+ )
diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py
index 4c42dbe..af5f71f 100644
--- a/onap-client/onap_client/sdc/vnf.py
+++ b/onap-client/onap_client/sdc/vnf.py
@@ -165,9 +165,14 @@ class VNF(Resource):
for policy in policies:
policy_name = policy.get("policy_name")
policy_id = self.policy_exists(policy_name)
- if not policy_id:
- policy_id = self.add_policy_resource(policy_name)
- self.associate_policy(policy_id, vm_type_instances)
+ if policy_id:
+ self.oc.sdc.vnf.delete_catalog_resource_policy(
+ policy_id=policy_id,
+ catalog_resource_id=self.catalog_resource_id
+ )
+
+ policy_id = self.add_policy_resource(policy_name)
+ self.associate_policy(policy_id, vm_type_instances)
for k, v in policy.get("properties", {}).items():
self.add_policy_property(policy_id, k, v)
@@ -198,7 +203,7 @@ class VNF(Resource):
resource_name = "{}-{}".format(resource_name, resource_name_index)
if self.resource_exists(resource_name):
- continue
+ self.delete_resource(resource_name)
catalog_resource_name = resource.get("catalog_resource_name")
resource_id = resource.get("resource_id")
@@ -285,6 +290,17 @@ class VNF(Resource):
return False
+ def delete_resource(self, resource_name):
+ component_instances = self.tosca.get("componentInstances", [])
+
+ for component in component_instances:
+ if component.get("name") == resource_name:
+ self.oc.sdc.vnf.delete_resource_from_vnf(
+ catalog_resource_id=self.catalog_resource_id,
+ resource_id=component.get("uniqueId")
+ )
+ return
+
def policy_exists(self, policy_name):
"""Checking the tosca model for a VF to see if a resource
has already been added
diff --git a/onap-client/onap_client/sdnc/catalog/config_catalog.py b/onap-client/onap_client/sdnc/catalog/config_catalog.py
index b3c5b1f..7bbf62a 100644
--- a/onap-client/onap_client/sdnc/catalog/config_catalog.py
+++ b/onap-client/onap_client/sdnc/catalog/config_catalog.py
@@ -63,7 +63,7 @@ class ConfigClient(SDNCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,),
+ "auth": self.auth,
},
"GET_SERVICE_INSTANCE": {
"verb": "GET",
@@ -81,7 +81,7 @@ class ConfigClient(SDNCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,),
+ "auth": self.auth,
},
"GET_VNF_INSTANCE": {
"verb": "GET",
@@ -99,6 +99,6 @@ class ConfigClient(SDNCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdnc/catalog/operations_catalog.py b/onap-client/onap_client/sdnc/catalog/operations_catalog.py
index 79e6f29..4763c9b 100644
--- a/onap-client/onap_client/sdnc/catalog/operations_catalog.py
+++ b/onap-client/onap_client/sdnc/catalog/operations_catalog.py
@@ -64,7 +64,7 @@ class OperationsClient(SDNCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,),
+ "auth": self.auth,
},
"VNF_API_PRELOAD": {
"verb": "POST",
@@ -82,6 +82,6 @@ class OperationsClient(SDNCClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/sdnc/client.py b/onap-client/onap_client/sdnc/client.py
index 1ebd04a..03b338e 100644
--- a/onap-client/onap_client/sdnc/client.py
+++ b/onap-client/onap_client/sdnc/client.py
@@ -34,7 +34,9 @@
# limitations under the License.
#
# ============LICENSE_END============================================
+from frozendict import frozendict
from onap_client.client.clients import Client
+from onap_client.auth import auth_handler
class SDNCClient(Client):
@@ -45,3 +47,21 @@ class SDNCClient(Client):
@property
def catalog_resources(self):
return {}
+
+ @property
+ def sdnc_username(self):
+ """Username to authenticate to SDNC"""
+ return self.config.sdnc.SDNC_USERNAME
+
+ @property
+ def sdnc_password(self):
+ """Password to authenticate to SDNC"""
+ return self.config.sdnc.SDNC_PASSWORD
+
+ @property
+ def auth(self):
+ return auth_handler(
+ frozendict(self.config.sdnc.AUTH_PLUGIN) if self.config.sdnc.AUTH_PLUGIN else None,
+ self.sdnc_username,
+ self.sdnc_password,
+ )
diff --git a/onap-client/onap_client/so/catalog/infra_catalog.py b/onap-client/onap_client/so/catalog/infra_catalog.py
new file mode 100644
index 0000000..9245004
--- /dev/null
+++ b/onap-client/onap_client/so/catalog/infra_catalog.py
@@ -0,0 +1,91 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2020 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software 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.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# 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.
+#
+# ============LICENSE_END============================================
+import uuid
+from functools import partial
+
+from onap_client.so.client import SOClient
+from onap_client.util import utility
+from onap_client.client.clients import get_client as Client
+
+
+class ServiceInstantiationClient(SOClient):
+ @property
+ def namespace(self):
+ return "infra"
+
+ @property
+ def catalog_resources(self):
+ return {
+ "GET_ACTIVE_REQUESTS": {
+ "verb": "GET",
+ "description": "Queries for the list of infraActiveRequests",
+ "uri": partial(
+ "{endpoint}/infraActiveRequests?size={size}&sort=startTime,DESC".format,
+ endpoint=self.config.so.SO_ENDPOINT,
+ ),
+ "uri-parameters": ["size"],
+ "success_code": 200,
+ "headers": {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "X-TransactionId": str(uuid.uuid4()),
+ "X-FromAppId": self.config.application_id,
+ },
+ "auth": self.auth,
+ },
+ }
+
+
+@utility
+def get_all_infra_requests(oc=None):
+ if not oc:
+ oc = Client()
+
+ infra_data = oc.so.infra.get_active_requests(size="20").response_data
+
+ total_elements = int(infra_data.get("page", {}).get("totalElements", 20))
+
+ return oc.so.infra.get_active_requests(size=total_elements).response_data
+
+
+@utility
+def get_recent_infra_requests(size, oc=None):
+ if not oc:
+ oc = Client()
+
+ return oc.so.infra.get_active_requests(size=size).response_data
+
diff --git a/onap-client/onap_client/so/catalog/service_instantiation.py b/onap-client/onap_client/so/catalog/service_instantiation.py
index 3874aef..e18aca1 100644
--- a/onap-client/onap_client/so/catalog/service_instantiation.py
+++ b/onap-client/onap_client/so/catalog/service_instantiation.py
@@ -81,7 +81,7 @@ class ServiceInstantiationClient(SOClient):
# "X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"DELETE_SERVICE_INSTANCE": {
"verb": "DELETE",
@@ -107,7 +107,7 @@ class ServiceInstantiationClient(SOClient):
# "X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"CREATE_VNF_INSTANCE": {
"verb": "POST",
@@ -147,7 +147,7 @@ class ServiceInstantiationClient(SOClient):
# "X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"DELETE_VNF_INSTANCE": {
"verb": "DELETE",
@@ -175,7 +175,7 @@ class ServiceInstantiationClient(SOClient):
"Content-Type": "application/json",
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"CREATE_VOLUME_MODULE_INSTANCE": {
"verb": "POST",
@@ -218,7 +218,7 @@ class ServiceInstantiationClient(SOClient):
"Content-Type": "application/json",
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"CREATE_MODULE_INSTANCE": {
"verb": "POST",
@@ -261,7 +261,7 @@ class ServiceInstantiationClient(SOClient):
"Content-Type": "application/json",
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"DELETE_MODULE_INSTANCE": {
"verb": "DELETE",
@@ -289,7 +289,7 @@ class ServiceInstantiationClient(SOClient):
"Content-Type": "application/json",
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"DELETE_VOLUME_MODULE_INSTANCE": {
"verb": "DELETE",
@@ -317,7 +317,7 @@ class ServiceInstantiationClient(SOClient):
"Content-Type": "application/json",
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"GET_REQUEST_STATUS": {
"verb": "GET",
@@ -335,7 +335,7 @@ class ServiceInstantiationClient(SOClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"GET_SERVICE_MODEL": {
"verb": "GET",
@@ -352,7 +352,7 @@ class ServiceInstantiationClient(SOClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"GET_SERVICE_MODEL_DETAILS": {
"verb": "GET",
@@ -369,7 +369,7 @@ class ServiceInstantiationClient(SOClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
"GET_MODULE_CUSTOMIZATION": {
"verb": "GET",
@@ -386,6 +386,6 @@ class ServiceInstantiationClient(SOClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/so/client.py b/onap-client/onap_client/so/client.py
index 3fa48ec..80e9443 100644
--- a/onap-client/onap_client/so/client.py
+++ b/onap-client/onap_client/so/client.py
@@ -35,7 +35,9 @@
#
# ============LICENSE_END============================================
from functools import partial
+from frozendict import frozendict
from onap_client.client.clients import Client
+from onap_client.auth import auth_handler
class SOClient(Client):
@@ -55,6 +57,24 @@ class SOClient(Client):
service_path=self.config.so.SO_HEALTH_CHECK_PATH,
),
"success_code": 200,
- "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD),
+ "auth": self.auth,
},
}
+
+ @property
+ def so_username(self):
+ """Username to authenticate to SO"""
+ return self.config.so.SO_USERNAME
+
+ @property
+ def so_password(self):
+ """Password to authenticate to SO"""
+ return self.config.so.SO_PASSWORD
+
+ @property
+ def auth(self):
+ return auth_handler(
+ frozendict(self.config.so.AUTH_PLUGIN) if self.config.so.AUTH_PLUGIN else None,
+ self.so_username,
+ self.so_password,
+ )
diff --git a/onap-client/onap_client/util.py b/onap-client/onap_client/util.py
index 2a9e3e7..c70d049 100644
--- a/onap-client/onap_client/util.py
+++ b/onap-client/onap_client/util.py
@@ -41,7 +41,6 @@ from prettytable import PrettyTable
def utility_cli(onap_client, cli_arguments):
functions = onap_client.utility_functions
-
if len(cli_arguments) == 0 or cli_arguments[0] == "--help":
help(functions)
else:
@@ -68,7 +67,7 @@ def utility_cli(onap_client, cli_arguments):
)
return
- if cli_arguments[0] == "--help":
+ if len(cli_arguments) and cli_arguments[0] == "--help":
help(functions)
return
diff --git a/onap-client/onap_client/vid/catalog/maintenance_catalog.py b/onap-client/onap_client/vid/catalog/maintenance_catalog.py
index 32f12ea..3a16387 100644
--- a/onap-client/onap_client/vid/catalog/maintenance_catalog.py
+++ b/onap-client/onap_client/vid/catalog/maintenance_catalog.py
@@ -65,7 +65,7 @@ class MaintenanceClient(VIDClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
"CREATE_LINE_OF_BUSINESS": {
"verb": "POST",
@@ -84,7 +84,7 @@ class MaintenanceClient(VIDClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
"CREATE_PLATFORM": {
"verb": "POST",
@@ -103,7 +103,7 @@ class MaintenanceClient(VIDClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
"CREATE_PROJECT": {
"verb": "POST",
@@ -122,7 +122,7 @@ class MaintenanceClient(VIDClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
"GET_CATEGORY_PARAMETERS": {
"verb": "GET",
@@ -139,6 +139,6 @@ class MaintenanceClient(VIDClient):
"X-TransactionId": str(uuid.uuid4()),
"X-FromAppId": self.config.application_id,
},
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
}
diff --git a/onap-client/onap_client/vid/client.py b/onap-client/onap_client/vid/client.py
index 109f5b3..97fafe6 100644
--- a/onap-client/onap_client/vid/client.py
+++ b/onap-client/onap_client/vid/client.py
@@ -35,7 +35,9 @@
#
# ============LICENSE_END============================================
from functools import partial
+from frozendict import frozendict
from onap_client.client.clients import Client
+from onap_client.auth import auth_handler
class VIDClient(Client):
@@ -55,6 +57,24 @@ class VIDClient(Client):
service_path=self.config.vid.VID_HEALTH_CHECK_PATH,
),
"success_code": 200,
- "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,),
+ "auth": self.auth,
},
}
+
+ @property
+ def vid_username(self):
+ """Username to authenticate to VID"""
+ return self.config.vid.VID_USERNAME
+
+ @property
+ def vid_password(self):
+ """Password to authenticate to VID"""
+ return self.config.vid.VID_PASSWORD
+
+ @property
+ def auth(self):
+ return auth_handler(
+ frozendict(self.config.vid.AUTH_PLUGIN) if self.config.vid.AUTH_PLUGIN else None,
+ self.vid_username,
+ self.vid_password,
+ )
diff --git a/onap-client/requirements.txt b/onap-client/requirements.txt
index 150c8c4..94f928b 100644
--- a/onap-client/requirements.txt
+++ b/onap-client/requirements.txt
@@ -41,3 +41,4 @@ PTable
simplejson
prettytable
importlib_resources
+frozendict
diff --git a/onap-client/setup.py b/onap-client/setup.py
index a6db762..1f2cb0a 100644
--- a/onap-client/setup.py
+++ b/onap-client/setup.py
@@ -41,13 +41,9 @@ import os
with open("README.md", "r") as fh:
long_description = fh.read()
-# datafiles = [("onap_client", ["etc/config.example.yaml"])]
-# for file in os.listdir("etc/payloads"):
-# datafiles.append(("onap_client/payloads", ["etc/payloads/{}".format(file)]))
-
setuptools.setup(
name="onap-client",
- version="1.1.0",
+ version="1.2.0",
author="Steven Stark",
author_email="steven.stark@att.com",
description="Python API wrapper for ONAP applications",
@@ -62,7 +58,6 @@ setuptools.setup(
license='Apache License, Version 2.0',
python_requires=">=3.6",
scripts=["bin/onap-client"],
- # data_files=datafiles,
include_package_data=True,
install_requires=[
"Jinja2>=2.10",
@@ -71,6 +66,7 @@ setuptools.setup(
"PTable>=0.9.2",
"simplejson>=3.17.0",
"prettytable>=0.7.2",
- "importlib_resources",
+ "importlib_resources>=3.0.0",
+ "frozendict>=1.2",
]
)