Exemplo n.º 1
0
 def decorated(*args, **kwargs):
     try:
         Authenticator.connect()
         return f(*args, **kwargs)
     except KeyError:
         log.warning("Could not refresh token")
         return {"Could not refresh token"}, 403
Exemplo n.º 2
0
    def notify_registry(self, tenant_id, status):

        headers = {"Authorization": os.getenv('AUTH_TOKEN')}
        payload = {
            'data': [{
                'tenant_id': tenant_id,
                'upload_id':
                self.uploader_id,  #to be changed later to uploader_id
                'status': status,
                'app_id': self.app_id
            }]
        }
        if 'local' in os.getenv("ENVIRONMENT", ""):
            payload['data'][0][
                'app_id'] = f"{self.app_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
            payload['data'][0][
                'upload_id'] = f"{self.uploader_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"

        notification_sent = requests.post(url=self.registration_url +
                                          '/status',
                                          headers=headers,
                                          json=payload)
        if notification_sent.status_code == 200:
            log.info("Notification registry service success!")
            return {"status": "success", "message": payload}, 200
        else:
            log.warning("Notification registry service failed!")
            return {"status": "fail", "message": payload}, 500
Exemplo n.º 3
0
    def register_uploader(self):

        if not self.auth_token:
            log.warning('Uploader not registered, no AUTH_TOKEN available')
            return {
                "status": "fail",
                "message": "Uploader not registered, no AUTH_TOKEN available"
            }, 403

        payload = {
            'data': [{
                "app_id": self.app_id,
                "upload_name": self.upload_name,
                "upload_id": self.
                uploader_id,  #TODO Field to be later renamed to uploader_id
                "accepted_file_types": self.accepted_file_types,
                "description": self.description,
                "flags": self.flags,
                "upload_url": self.base_url + self.upload_url,
                "upload_validation_url":
                self.base_url + self.upload_validation_url,
                "quota_validation_url":
                self.base_url + self.quota_validation_url,
                "status_check_url": self.base_url + self.status_check_url,
                "history_url": self.base_url + self.history_url,
                "status": self.status,
                "icon": self.icon,
            }]
        }

        if 'local' in os.getenv("ENVIRONMENT", ""):
            payload['data'][0][
                'app_id'] = f"{self.app_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
            payload['data'][0][
                'upload_id'] = f"{self.uploader_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
            payload['data'][0][
                'upload_name'] = f"{self.upload_name}-{os.getenv('PERSONAL_PREFIX', 'local')}"

        log.info(payload)

        headers = {"Authorization": self.auth_token}
        registration = requests.post(url=self.registration_url,
                                     json=payload,
                                     headers=headers)

        log.info(registration.content)

        if registration.status_code == 200:
            return {
                "status": "success",
                "message": "Uploader register successfully"
            }, 200

        else:
            log.warning("Could not register uploader")
            return {
                "status": "fail",
                "message": "Could not register uploader"
            }, 400
Exemplo n.º 4
0
    def register_app(self):

        if os.getenv('APP_AUTHENTICATED') != 'true':
            log.warning('App not registered, no auth token available')
            return {
                "status": "fail",
                "message": "App not registered, no auth token available"
            }, 401

        payload = {
            'data': [{
                "app_id":
                self.id,
                "name":
                self.name,
                "tenants_with_app_activated":
                self.activated_tenants_func(),
                "tenants_with_data_available":
                self.tenants_with_data_func(),
                "description":
                self.description,
                "flags":
                self.flags,
                "icon":
                self.icon,
                "refresh_registration_url":
                BASE_URL + self.refresh_registration_url,
                "app_activation_url":
                BASE_URL + self.app_activation_url,
                "editable_tables_url":
                BASE_URL + self.editable_tables_url,
                "history_report_url":
                BASE_URL + self.history_report_url,
                "tenant_registration_url":
                BASE_URL + self.tenant_registration_url
            }]
        }

        if 'local' in os.getenv("ENVIRONMENT", ""):
            payload['data'][0][
                'app_id'] = f"{self.id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
            payload['data'][0][
                'name'] = f"{self.name}-{os.getenv('PERSONAL_PREFIX', 'local')}"

        url = REGISTRY_SERVICE_URL + '/apps'
        headers = {"Authorization": os.getenv('AUTH_TOKEN')}
        registration = requests.post(url, json=payload, headers=headers)

        if registration.status_code != 200:
            log.warning(f"Could not register app {self.name}")
            return {"status": "fail", "message": "Could not register app"}, 500

        return {
            "status": "success",
            "message": "App registered successfully"
        }, 200
Exemplo n.º 5
0
 def decorated(*args, **kwargs):
     try:
         headers = {"Authorization": request.headers.get("Authorization")}
         response = requests.get(url=url_machine_check, headers=headers)
         if response.status_code != 200:
             return {"status": "unauthorized"}, 401
         return f(*args, **kwargs)
     except KeyError:
         log.warning("Unauthorized machine")
         return {"Missing Authorization information"}, 403
Exemplo n.º 6
0
 def decorated(*args, **kwargs):
     try:
         headers = {
             "TenantId": request.headers.get("TenantId"),
             "Authorization": request.headers.get("Authorization")
         }
         response = requests.get(url=url_auth_check, headers=headers)
         if response.status_code != 200:
             log.warning("Unauthorized user")
             return {"status": "unauthorized"}, 401
         return f(*args, **kwargs)
     except KeyError:
         return {"Missing Tenant or Authorization information"}, 403
Exemplo n.º 7
0
    def __init__(
        self,
        app_id: str = None,
        data_collection_name: str = None,
        utilization_collection_name: str = None,
        analysis_collection_name: str = None,
    ):
        if app_id:
            log.warning(
                "Parameter `app_id` is not required anymore. Will be removed in future versions"
            )

        self.schema = AnalysisStatusSchema
        self.data_collection_name = data_collection_name or mongo_data_collection_name
        self.utilization_collection_name = utilization_collection_name or mongo_utilization_collection_name
        self.analysis_collection_name = analysis_collection_name or mongo_analysis_collection_name
Exemplo n.º 8
0
    def register_report(self):
        if 'true' in os.getenv('APP_AUTHENTICATED', 'false'):
       
            payload = {
                'data': [{
                    "app_id": self.app_id,
                    "report_id": self.report_id,
                    "report_name": self.report_name,
                    "description": self.description,
                    "flags": self.flags,
                    "url": f'{os.getenv("APP_BASE_PATH")}{os.getenv("APP_URL_PREFIX")}/reports{self.url}',
                    "refresh_registry_url": self.refresh_registry_url,
                    "connected_apps": self.connected_apps
                }]
            }

            if 'local' in os.getenv("ENVIRONMENT", ""):
                payload[0]['app_id'] = f"{self.app_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
                payload[0]['report_id'] = f"{self.report_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"
                payload[0]['report_name'] = f"{self.report_name}-{os.getenv('PERSONAL_PREFIX', 'local')}"
                for c_app in payload[0]['connected_apps']:
                    if self.app_id == c_app:
                        c_app = f"{self.app_id}-{os.getenv('PERSONAL_PREFIX', 'local')}"

            log.info(payload)
            url = f'{os.getenv("REGISTRY_SERVICE_URL")}/reports'
            headers = {"Authorization": os.getenv('AUTH_TOKEN'), 'Accept': 'application/json'}
            registration = requests.post(
                url=url, json=payload, headers=headers
            )
            if registration.status_code == 200:
                return payload
            else:
                log.warning("Could not register reports")
                return False
        else:
            log.warning('App not registered, no auth token available')
            return False