import json
import logging
import os
-import requests
import uuid
-
from collections import Counter
-from rest_framework import status
+
+import requests
from requests.auth import HTTPBasicAuth
+from rest_framework import status
+
from catalog.packages import const
from catalog.pub.database.models import VnfPkgSubscriptionModel
from catalog.pub.exceptions import VnfPkgSubscriptionException, \
class CreateSubscription(object):
-
def __init__(self, data):
self.data = data
self.filter = ignore_case_get(self.data, "filter", {})
params = self.authentication.get("paramsBasic", {})
username = params.get("userName")
password = params.get("password")
- response = requests.get(self.callback_uri, auth=HTTPBasicAuth(username, password), timeout=2)
+ response = requests.get(self.callback_uri, auth=HTTPBasicAuth(username, password), timeout=2,
+ verify=False)
elif const.OAUTH2_CLIENT_CREDENTIALS in self.authentication.get("authType", ''):
# todo
pass
# todo
pass
else:
- response = requests.get(self.callback_uri, timeout=2)
+ response = requests.get(self.callback_uri, timeout=2, verify=False)
if response.status_code != status.HTTP_204_NO_CONTENT:
raise VnfPkgSubscriptionException(
"callbackUri %s returns %s status code." % (
def do_biz(self):
self.subscription_id = str(uuid.uuid4())
- self.check_callbackuri_connection()
self.check_valid_auth_info()
+ self.check_callbackuri_connection()
self.check_valid()
self.save_db()
subscription = VnfPkgSubscriptionModel.objects.get(
def check_valid_auth_info(self):
logger.debug("SubscribeNotification--post::> Validating Auth "
"details if provided")
- if self.authentication.get("paramsBasic", {}) and \
- const.BASIC not in self.authentication.get("authType"):
+ if self.authentication.get("paramsBasic", {}) and const.BASIC not in self.authentication.get("authType"):
raise VnfPkgSubscriptionException('Auth type should be ' + const.BASIC)
- if self.authentication.get("paramsOauth2ClientCredentials", {}) and \
- const.OAUTH2_CLIENT_CREDENTIALS not in self.authentication.get("authType"):
+ if self.authentication.get("paramsOauth2ClientCredentials", {}) \
+ and const.OAUTH2_CLIENT_CREDENTIALS not in self.authentication.get("authType"):
raise VnfPkgSubscriptionException('Auth type should be ' + const.OAUTH2_CLIENT_CREDENTIALS)
def check_filter_exists(self, sub):
return True
def check_valid(self):
+ links = ""
logger.debug("SubscribeNotification--post::> Checking DB if "
"callbackUri already exists")
subscriptions = VnfPkgSubscriptionModel.objects.filter(callback_uri=self.callback_uri)
- if not subscriptions.exists():
- return True
for subscription in subscriptions:
if self.check_filter_exists(subscription):
+ links = json.loads(subscription.links)
+ logger.error("Subscriptions has already exists with the same callbackUri and filter:%s" % links)
raise VnfPkgDuplicateSubscriptionException(
- "Already Subscription (%s) exists with the "
- "same callbackUri and filter" % subscription.subscription_id)
+ "/%s" % (links["self"]["href"]))
+
return True
def save_db(self):
class QuerySubscription(object):
-
def query_multi_subscriptions(self, params):
query_data = {}
logger.debug("QuerySubscription--get--multi--subscriptions--biz::> Check "
class TerminateSubscription(object):
-
def terminate(self, subscription_id):
logger.debug("TerminateSubscriptions--delete--biz::> "
"ID: %s" % subscription_id)