Beispiel #1
0
    def service_build_status_notifier(self, org_id, service_id, build_status):

        if build_status == BUILD_FAILURE_CODE:
            BUILD_FAIL_MESSAGE = "Build failed please check your components"
            org_uuid, service = ServicePublisherRepository(
            ).get_service_for_given_service_id_and_org_id(org_id, service_id)

            contacts = [
                contributor.get("email_id", "")
                for contributor in service.contributors
            ]

            service_comment = ServiceComment(org_uuid, service.uuid,
                                             "SERVICE_APPROVAL",
                                             "SERVICE_APPROVER",
                                             self._username,
                                             BUILD_FAIL_MESSAGE)
            ServicePublisherRepository().save_service_comments(service_comment)
            ServicePublisherRepository().save_service(
                self._username, service, ServiceStatus.CHANGE_REQUESTED.value)
            logger.info(
                f"Build failed for org_id {org_id}  and service_id {service_id}"
            )
            try:
                BUILD_STATUS_SUBJECT = "Build failed for your service {}"
                BUILD_STATUS_MESSAGE = "Build failed for your org_id {} and service_id {}"
                send_email_notification(
                    contacts, BUILD_STATUS_SUBJECT.format(service_id),
                    BUILD_STATUS_MESSAGE.format(org_id, service_id),
                    NOTIFICATION_ARN, boto_util)
            except:
                logger.info(
                    f"Error happened while sending build_status mail for {org_id} and contacts {contacts}"
                )
Beispiel #2
0
 def get_service_for_given_service_uuid(self):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if not service:
         return None
     service.comments = self.get_service_comments()
     return service.to_dict()
Beispiel #3
0
 def process_approval_comment(self, approval_type, state, comment, params):
     if approval_type == "organization":
         org = OrganizationPublisherRepository().get_org_for_org_id(
             org_id=params["org_id"])
         if org.org_state.state in [
                 OrganizationStatus.APPROVAL_PENDING.value,
                 OrganizationStatus.ONBOARDING.value
         ]:
             self.callback_verification_service(
                 org.uuid,
                 getattr(OrganizationStatus, state).value, self._username,
                 comment)
     elif approval_type == "service":
         org_uuid, service = ServicePublisherRepository(). \
             get_service_for_given_service_id_and_org_id(org_id=params["org_id"], service_id=params["service_id"])
         if service.service_state.state == ServiceStatus.APPROVAL_PENDING.value:
             ServicePublisherRepository().save_service(
                 username=self._username,
                 service=service,
                 state=getattr(ServiceStatus, state).value)
             service_comments = ServiceComment(
                 org_uuid=service.org_uuid,
                 service_uuid=service.uuid,
                 support_type=ServiceSupportType.SERVICE_APPROVAL.value,
                 user_type=UserType.SERVICE_APPROVER.value,
                 commented_by=self._username,
                 comment=comment)
             ServicePublisherRepository().save_service_comments(
                 service_comment=service_comments)
             slack_msg = f"Reviews for service with {service.service_id} is successfully submitted."
             # send_slack_notification(slack_msg=slack_msg, slack_url=SLACK_APPROVAL_CHANNEL_URL,
             #                         slack_channel="ai-approvals")
             recipients = [
                 contributor.get("email_id", "")
                 for contributor in service.contributors
             ]
             if not recipients:
                 logger.info(
                     f"Unable to find service contributors for service {service.service_id} under {params['org_id']}"
                 )
                 return
             notification_subject = f"Your service {service.service_id} is reviewed"
             notification_message = f"Your service {service.service_id} under {params['org_id']} is reviewed"
             send_email_notification(
                 recipients=recipients,
                 notification_subject=notification_subject,
                 notification_message=notification_message,
                 notification_arn=NOTIFICATION_ARN,
                 boto_util=boto_util)
         else:
             logger.info("Service state is not valid.")
     else:
         logger.info("Approval type is not valid")
    def publish_service_data(self):
        # Validate service metadata
        current_service = self.publish_service_data_to_ipfs()

        is_valid = Service.is_metadata_valid(
            service_metadata=current_service.to_metadata())
        logger.info(
            f"is_valid :: {is_valid} :: validated current_metadata :: {current_service.to_metadata()}"
        )
        if not is_valid:
            raise InvalidMetadataException()

        # Monitor blockchain and offchain changes
        current_org = OrganizationPublisherRepository().get_organization(
            org_uuid=self._org_uuid)
        existing_service_data = self.get_existing_service_details_from_contract_api(
            current_service.service_id, current_org.id)
        if existing_service_data:
            existing_metadata = ipfs_util.read_file_from_ipfs(
                existing_service_data["ipfs_hash"])
        else:
            existing_metadata = {}
        publish_to_blockchain = self.are_blockchain_attributes_got_updated(
            existing_metadata, current_service.to_metadata())
        existing_offchain_configs = self.get_existing_offchain_configs(
            existing_service_data)
        current_offchain_attributes = ServicePublisherRepository(
        ).get_offchain_service_config(org_uuid=self._org_uuid,
                                      service_uuid=self._service_uuid)
        new_offchain_attributes = self.get_offchain_changes(
            current_offchain_config=current_offchain_attributes.configs,
            existing_offchain_config=existing_offchain_configs,
            current_service=current_service)

        status = {"publish_to_blockchain": publish_to_blockchain}
        if publish_to_blockchain:
            filename = f"{METADATA_FILE_PATH}/{current_service.uuid}_service_metadata.json"
            ipfs_hash = ServicePublisherService.publish_to_ipfs(
                filename, current_service.to_metadata())
            status["service_metadata_ipfs_hash"] = "ipfs://" + ipfs_hash
        self.publish_offchain_service_configs(
            org_id=current_org.id,
            service_id=current_service.service_id,
            payload=json.dumps(new_offchain_attributes))
        # if there is no blockchain change update state as published
        # else status will be marked based event received from blockchain
        if not publish_to_blockchain:
            ServicePublisherRepository().save_service(
                username=self._username,
                service=current_service,
                state=ServiceStatus.PUBLISHED.value)
        return status
    def submit_service_for_approval(self, payload):

        user_as_contributor = [{"email_id": self._username, "name": ""}]
        payload["contributors"] = payload.get(
            "contributors", user_as_contributor) + user_as_contributor

        organization = OrganizationPublisherRepository().get_org_for_org_uuid(
            self._org_uuid)
        if not organization:
            raise OrganizationNotFoundException()
        if not organization.org_state:
            raise InvalidOrganizationStateException()
        if not organization.org_state.state == OrganizationStatus.PUBLISHED.value:
            raise OrganizationNotPublishedException()

        service = service_factory.create_service_entity_model(
            self._org_uuid, self._service_uuid, payload,
            ServiceStatus.APPROVAL_PENDING.value)

        # publish service data with test config on ipfs
        service = self.obj_service_publisher_domain_service.publish_service_data_to_ipfs(
            service, EnvironmentType.TEST.value)

        comments = payload.get("comments",
                               {}).get(UserType.SERVICE_PROVIDER.value, "")
        if bool(comments):
            service_provider_comment = service_factory. \
                create_service_comment_entity_model(org_uuid=self._org_uuid,
                                                    service_uuid=self._service_uuid,
                                                    support_type="SERVICE_APPROVAL",
                                                    user_type="SERVICE_PROVIDER",
                                                    commented_by=self._username,
                                                    comment=comments)
            ServicePublisherRepository().save_service_comments(
                service_provider_comment)
        service = ServicePublisherRepository().save_service(
            self._username, service, service.service_state.state)

        # publish service on test network
        response = self.obj_service_publisher_domain_service.publish_service_on_blockchain(
            org_id=organization.id,
            service=service,
            environment=EnvironmentType.TEST.value)

        # notify service contributors via email
        self.notify_service_contributor_when_user_submit_for_approval(
            organization.id, service.service_id, service.contributors)

        # notify approval team via slack
        self.notify_approval_team(service.service_id, service.display_name,
                                  organization.id, organization.name)
        return response
Beispiel #6
0
 def save_transaction_hash_for_published_service(self, payload):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if service.service_state.state == ServiceStatus.APPROVED.value:
         service.service_state = \
             ServiceFactory().create_service_state_entity_model(
                 self._org_uuid, self._service_uuid, ServiceStatus.PUBLISH_IN_PROGRESS.value,
                 payload.get("transaction_hash", ""))
         ServicePublisherRepository().save_service(
             self._username, service,
             ServiceStatus.PUBLISH_IN_PROGRESS.value)
     return StatusCode.OK
 def get_service_for_given_service_uuid(self):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if not service:
         return None
     service.comments = self.get_service_comments()
     offchain_service_config = ServicePublisherRepository(
     ).get_offchain_service_config(org_uuid=self._org_uuid,
                                   service_uuid=self._service_uuid)
     service_data = service.to_dict()
     if offchain_service_config.configs:
         service_data = self.map_offchain_service_config(
             offchain_service_config, service_data)
     return service_data
Beispiel #8
0
    def test_validate_proto(self, mock_proto_compile_response):
        mock_proto_compile_response.return_value = {"statusCode": 200}
        event = {
            "Records": [{
                "s3": {
                    "bucket": {
                        "name": "ropsten-marketplace-service-assets"
                    },
                    "object": {
                        "key":
                        "testorguuid/services/testserviceuuid/proto/20210618114940_proto_files.zip"
                    }
                }
            }]
        }
        response = update_service_assets(event=event, context=None)
        service = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(org_uuid="testorguuid",
                                             service_uuid="testserviceuuid")
        assert response["statusCode"] == 200
        assert service.assets == {
            "demo_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
                "build_id": "sample_build_id",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            },
            "hero_image": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
                "ipfs_hash":
                "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
            },
            "proto_files": {
                "url":
                "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/testorguuid/services/testserviceuuid/proto/20210618114940_proto_files.zip",
                "status": "SUCCEEDED"
            }
        }

        paths = [
            "testorguuid/assets/any", "testorguuid/assets/any/link/",
            "testorguuid/assets/any/val_ue"
        ]
        for path in paths:
            event = {
                "Records": [{
                    "s3": {
                        "bucket": {
                            "name": "ropsten-marketplace-service-assets"
                        },
                        "object": {
                            "key": path
                        }
                    }
                }]
            }
            response = update_service_assets(event=event, context=None)
            self.assertEqual(response["statusCode"], 200)
            self.assertEqual(json.loads(response["body"])["data"], None)
 def test_validate_hero_image(self):
     event = {
         "Records": [{
             "s3": {
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/assets/20210127060155_asset.jpeg",
                     "size": 6949,
                     "eTag": "c80928fa72a7ceb972b54a214c2181b3",
                     "sequencer": "0060CCFC79D1D7CCDF"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     assert response["statusCode"] == 200
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     print(service.to_dict())
     assert service.assets == {
         "demo_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
             "build_id": "sample_build_id",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         },
         "hero_image": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/assets/20210127060155_asset.jpeg"
         },
         "proto_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         }
     }
Beispiel #10
0
 def _save_service_comment(self, support_type, user_type, comment):
     service_provider_comment = ServiceFactory. \
         create_service_comment_entity_model(org_uuid=self._org_uuid,
                                             service_uuid=self._service_uuid,
                                             support_type=support_type,
                                             user_type=user_type,
                                             commented_by=self._username,
                                             comment=comment)
     ServicePublisherRepository().save_service_comments(
         service_provider_comment)
 def daemon_config(self, environment):
     organization = OrganizationPublisherRepository().get_org_for_org_uuid(
         self._org_uuid)
     if not organization:
         raise OrganizationNotFoundException()
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if not service:
         raise ServiceNotFoundException()
     organization_members = OrganizationPublisherRepository(
     ).get_org_member(org_uuid=self._org_uuid)
     network_name = NETWORKS[NETWORK_ID]["name"].lower()
     # this is how network name is set in daemon for mainnet
     network_name = "main" if network_name == "mainnet" else network_name
     if environment is EnvironmentType.TEST.value:
         daemon_config = {
             "allowed_user_flag":
             True,
             "allowed_user_addresses":
             [member.address for member in organization_members] +
             [BLOCKCHAIN_TEST_ENV["publisher_address"]],
             "authentication_addresses":
             [member.address for member in organization_members],
             "blockchain_enabled":
             False,
             "passthrough_enabled":
             True,
             "organization_id":
             organization.id,
             "service_id":
             service.service_id
         }
     elif environment is EnvironmentType.MAIN.value:
         daemon_config = {
             "ipfs_end_point":
             f"{IPFS_URL['url']}:{IPFS_URL['port']}",
             "blockchain_network_selected":
             network_name,
             "organization_id":
             organization.id,
             "service_id":
             service.service_id,
             "metering_end_point":
             f"https://{network_name}-marketplace.singularitynet.io",
             "authentication_addresses":
             [member.address for member in organization_members],
             "blockchain_enabled":
             True,
             "passthrough_enabled":
             True
         }
     else:
         raise EnvironmentNotFoundException()
     return daemon_config
Beispiel #12
0
 def create_and_send_view_service_modal(self, org_id, service_id,
                                        trigger_id):
     org_uuid, service = ServicePublisherRepository(). \
         get_service_for_given_service_id_and_org_id(org_id=org_id, service_id=service_id)
     service_comment = ServicePublisherRepository(). \
         get_last_service_comment(
         org_uuid=org_uuid, service_uuid=service.uuid, support_type=ServiceSupportType.SERVICE_APPROVAL.value,
         user_type=UserType.SERVICE_PROVIDER.value)
     comment = "No comment" if not service_comment else service_comment.comment
     view = self.generate_view_service_modal(org_id, service, None, comment)
     slack_payload = {"trigger_id": trigger_id, "view": view}
     OPEN_SLACK_VIEW_URL = "https://slack.com/api/views.open"
     headers = {
         "Authorization": SLACK_APPROVAL_OAUTH_ACCESS_TOKEN,
         "content-type": "application/json"
     }
     response = requests.post(url=OPEN_SLACK_VIEW_URL,
                              data=json.dumps(slack_payload),
                              headers=headers)
     logger.info(f"{response.status_code} | {response.text}")
 def save_service(self, payload):
     service = ServiceFactory().create_service_entity_model(
         self._org_uuid, self._service_uuid, payload,
         ServiceStatus.DRAFT.value)
     service = ServicePublisherRepository().save_service(
         self._username, service, ServiceStatus.DRAFT.value)
     comments = payload.get("comments",
                            {}).get(UserType.SERVICE_PROVIDER.value, "")
     if bool(comments):
         service_provider_comment = service_factory. \
             create_service_comment_entity_model(org_uuid=self._org_uuid,
                                                 service_uuid=self._service_uuid,
                                                 support_type="SERVICE_APPROVAL",
                                                 user_type="SERVICE_PROVIDER",
                                                 commented_by=self._username,
                                                 comment=comments)
         ServicePublisherRepository().save_service_comments(
             service_provider_comment)
         service.comments = self.get_service_comments()
     return service.to_dict()
Beispiel #14
0
 def get_service_comments(self):
     service_provider_comment = ServicePublisherRepository(
     ).get_last_service_comment(
         org_uuid=self._org_uuid,
         service_uuid=self._service_uuid,
         support_type=ServiceSupportType.SERVICE_APPROVAL.value,
         user_type=UserType.SERVICE_PROVIDER.value)
     approver_comment = ServicePublisherRepository(
     ).get_last_service_comment(
         org_uuid=self._org_uuid,
         service_uuid=self._service_uuid,
         support_type=ServiceSupportType.SERVICE_APPROVAL.value,
         user_type=UserType.SERVICE_APPROVER.value)
     return {
         UserType.SERVICE_PROVIDER.value:
         None if not service_provider_comment else
         f"{service_provider_comment.comment}",
         UserType.SERVICE_APPROVER.value:
         "<div></div>" if not approver_comment else
         f"<div>{approver_comment.comment}</div>"
     }
 def publish_service_data_to_ipfs(self):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if service.service_state.state == ServiceStatus.APPROVED.value:
         proto_url = service.assets.get("proto_files", {}).get("url", None)
         if proto_url is None:
             raise ServiceProtoNotFoundException
         filename = download_file_from_url(
             file_url=proto_url,
             file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}")
         logger.info(f"proto file Name Retrieved  = '{filename}` ")
         asset_ipfs_hash = publish_zip_file_in_ipfs(
             filename=filename,
             file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}",
             ipfs_client=IPFSUtil(IPFS_URL['url'], IPFS_URL['port']))
         service.proto = {
             "model_ipfs_hash": asset_ipfs_hash,
             "encoding": "proto",
             "service_type": "grpc"
         }
         service.assets["proto_files"]["ipfs_hash"] = asset_ipfs_hash
         ServicePublisherDomainService.publish_assets(service)
         service = ServicePublisherRepository().save_service(
             self._username, service, service.service_state.state)
         return service
     logger.info(
         f"Service status needs to be {ServiceStatus.APPROVED.value} to be eligible for publishing."
     )
     raise InvalidServiceStateException()
 def save_offline_service_configs(self, payload):
     demo_component_required = payload.get("assets",
                                           {}).get("demo_files",
                                                   {}).get("required", -1)
     if demo_component_required == -1:
         return
     offchain_service_config = OffchainServiceConfig(
         org_uuid=self._org_uuid,
         service_uuid=self._service_uuid,
         configs={"demo_component_required": str(demo_component_required)})
     ServicePublisherRepository().add_or_update_offline_service_config(
         offchain_service_config)
     return
 def get_list_of_orgs_with_services_submitted_for_approval():
     list_of_orgs_with_services = []
     services_review = ServicePublisherRepository(
     ).get_all_services_review_data()
     for service_review in services_review:
         list_of_orgs_with_services.append({
             "org_uuid":
             service_review.org_uuid,
             "services": [{
                 "service_uuid": service_review.service_uuid
             }],
         })
     return list_of_orgs_with_services
Beispiel #18
0
 def get_services_for_organization(self, payload):
     offset = payload.get("offset", DEFAULT_OFFSET)
     limit = payload.get("limit", DEFAULT_LIMIT)
     search_string = payload["q"]
     search_attribute = payload["s"]
     sort_by = payload["sort_by"].lower()
     order_by = payload["order_by"].lower()
     filter_parameters = {
         "offset":
         offset,
         "limit":
         limit,
         "search_string":
         search_string,
         "search_attribute":
         search_attribute
         if search_attribute in ALLOWED_ATTRIBUTES_FOR_SERVICE_SEARCH else
         DEFAULT_ATTRIBUTE_FOR_SERVICE_SEARCH,
         "sort_by":
         sort_by if sort_by in ALLOWED_ATTRIBUTES_FOR_SERVICE_SORT_BY else
         DEFAULT_ATTRIBUTES_FOR_SERVICE_SORT_BY,
         "order_by":
         order_by if order_by in ALLOWED_ATTRIBUTES_FOR_SERVICE_SORT_BY else
         DEFAULT_ATTRIBUTES_FOR_SERVICE_ORDER_BY
     }
     services = ServicePublisherRepository().get_services_for_organization(
         self._org_uuid, filter_parameters)
     search_result = [service.to_dict() for service in services]
     search_count = ServicePublisherRepository(
     ).get_total_count_of_services_for_organization(self._org_uuid,
                                                    filter_parameters)
     return {
         "total_count": search_count,
         "offset": offset,
         "limit": limit,
         "result": search_result
     }
Beispiel #19
0
    def save_service_attributes(self, payload):
        VALID_PATCH_ATTRIBUTE = ["groups"]
        service_db = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(self._org_uuid,
                                             self._service_uuid)
        service = ServiceFactory.convert_service_db_model_to_entity_model(
            service_db)

        for attribute, value in payload.items():
            if attribute in VALID_PATCH_ATTRIBUTE:
                if attribute == "groups":
                    service.groups = [
                        ServiceFactory.create_service_group_entity_model(
                            self._org_uuid, self._service_uuid, group)
                        for group in payload.get("groups", [])
                    ]
            else:
                raise Exception(
                    "Patching of other attributes not allowed as of now")

        saved_service = ServicePublisherRepository().save_service(
            self._username, service, service.service_state.state)

        return saved_service.to_dict()
    def get_list_of_service_pending_for_approval(limit):
        list_of_services = []
        services = ServicePublisherRepository(
        ).get_list_of_service_pending_for_approval(limit)
        for service in services:
            org = OrganizationPublisherRepository().get_org_for_org_uuid(
                org_uuid=service.org_uuid)
            list_of_services.append({
                "org_uuid": service.org_uuid,
                "org_id": org.id,
                "service_uuid": service.uuid,
                "service_id": service.service_id,
                "display_name": service.display_name,
                "requested_at": None
            })

        return list_of_services
Beispiel #21
0
 def test_validate_demo_component(self, mock_code_build):
     mock_code_build.return_value = {"build": {"id": "test_build_id"}}
     event = {
         "Records": [{
             "s3": {
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "testorguuid/services/testserviceuuid/component/example_service_component.zip"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="testorguuid",
                                          service_uuid="testserviceuuid")
     assert response["statusCode"] == 200
     assert json.loads(
         response["body"])["data"]["build_id"] == "test_build_id"
     assert service.assets["hero_image"] == {
         'url':
         'https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png',
         'ipfs_hash':
         'QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png'
     }
     assert service.assets["proto_files"] == {
         'url':
         'https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip',
         'ipfs_hash': 'QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy'
     }
     assert service.assets["demo_files"][
         "url"] == "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/testorguuid/services/testserviceuuid/component/example_service_component.zip"
     assert service.assets["demo_files"]["status"] == "PENDING"
     assert service.assets["demo_files"]["build_id"] == "test_build_id"
     assert True if (
         service.assets["demo_files"]["last_modified"]) else False == True
Beispiel #22
0
from registry.application.handlers.slack_chat_operation_handler import slack_interaction_handler
from registry.infrastructure.repositories.organization_repository import OrganizationPublisherRepository
from registry.infrastructure.repositories.service_publisher_repository import ServicePublisherRepository
from registry.infrastructure.models import Service as ServiceDBModel
from registry.infrastructure.models import ServiceState as ServiceStateDBModel
from registry.infrastructure.models import ServiceComment as ServiceCommentDBModel
from registry.infrastructure.models import Organization as OrganizationDBModel
from registry.infrastructure.models import OrganizationState as OrganizationStateDBModel
from registry.infrastructure.models import OrganizationAddress as OrganizationAddressDBModel
from registry.domain.models.organization import Organization as OrganizationDomainModel
from registry.constants import OrganizationStatus, ServiceStatus, OrganizationAddressType
from unittest.mock import patch
from urllib.parse import urlencode

org_repo = OrganizationPublisherRepository()
service_repo = ServicePublisherRepository()


class TestSlackChatOperation(TestCase):
    def setUp(self):
        pass

    @patch(
        "registry.application.services.slack_chat_operation.SlackChatOperation.validate_slack_user"
    )
    @patch(
        "registry.application.services.slack_chat_operation.SlackChatOperation.validate_slack_channel_id"
    )
    @patch(
        "registry.application.services.slack_chat_operation.SlackChatOperation.validate_slack_signature"
    )
Beispiel #23
0
 def setUp(self):
     self.org_repo = OrganizationPublisherRepository()
     self.service_repo = ServicePublisherRepository()
Beispiel #24
0
class TestServiceEventConsumer(unittest.TestCase):
    def setUp(self):
        self.org_repo = OrganizationPublisherRepository()
        self.service_repo = ServicePublisherRepository()

    @patch("common.ipfs_util.IPFSUtil",
           return_value=Mock(
               read_bytesio_from_ipfs=Mock(return_value=""),
               read_file_from_ipfs=Mock(
                   return_value=json.loads(json.dumps(service_metadata))),
               write_file_in_ipfs=Mock(return_value="Q3E12")))
    @patch("common.boto_utils.BotoUtils.invoke_lambda",
           return_value={"statusCode": StatusCode.CREATED})
    @patch('common.s3_util.S3Util.push_io_bytes_to_s3')
    @patch('common.blockchain_util.BlockChainUtil')
    @patch(
        'registry.consumer.service_event_consumer.ServiceEventConsumer._fetch_tags'
    )
    def test_on_service_created_event(self, mock_fetch_tags,
                                      mock_block_chain_util, mock_s3_push,
                                      mock_boto, mock_ipfs):
        org_uuid = str(uuid4())
        service_uuid = str(uuid4())
        self.org_repo.add_item(
            Organization(name="test_org",
                         org_id="test_org_id",
                         uuid=org_uuid,
                         org_type="organization",
                         description="that is the dummy org for testcases",
                         short_description="that is the short description",
                         url="https://dummy.url",
                         contacts=[],
                         assets={},
                         duns_no=12345678,
                         origin="PUBLISHER_DAPP",
                         groups=[],
                         addresses=[],
                         metadata_ipfs_uri="#dummyhashdummyhash"))
        self.service_repo.add_item(
            Service(org_uuid=org_uuid,
                    uuid=service_uuid,
                    display_name="test_display_name",
                    service_id="test_service_id",
                    metadata_uri="Qasdfghjklqwertyuiopzxcvbnm",
                    short_description="test_short_description",
                    description="test_description",
                    project_url="https://dummy.io",
                    ranking=1,
                    created_on=datetime.utcnow(),
                    updated_on=datetime.utcnow()))
        self.service_repo.add_item(
            ServiceState(row_id=randrange(10000),
                         org_uuid=org_uuid,
                         service_uuid=service_uuid,
                         state=ServiceStatus.DRAFT.value,
                         transaction_hash='0x1234',
                         created_by="dummy_user",
                         updated_by="dummy_user",
                         created_on=datetime.utcnow(),
                         updated_on=datetime.utcnow()))
        self.service_repo.add_item(
            ServiceGroup(row_id=randrange(1000),
                         org_uuid=org_uuid,
                         service_uuid=service_uuid,
                         group_id="test_group_id",
                         endpoints={
                             "https://dummydaemonendpoint.io": {
                                 "verfied": True
                             }
                         },
                         daemon_address=["0xq2w3e4rr5t6y7u8i9"],
                         free_calls=10,
                         free_call_signer_address="0xq2s3e4r5t6y7u8i9o0",
                         created_on=datetime.utcnow(),
                         updated_on=datetime.utcnow()))
        event = {
            "data": {
                'row_id': 202,
                'block_no': 6325625,
                'event': 'ServiceCreated',
                'json_str':
                "{'orgId': b'test_org_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'serviceId': b'test_service_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'metadataURI': b'ipfs://QmdGjaVYPMSGpC1qT3LDALSNCCu7JPf7j51H1GQirvQJYf\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'}",
                'processed': b'\x00',
                'transactionHash': '0x12345',
                'logIndex': '0',
                'error_code': 1,
                'error_msg': '',
                'row_updated': datetime(2019, 10, 21, 9, 59, 37),
                'row_created': datetime(2019, 10, 21, 9, 59, 37)
            },
            "name": "ServiceCreated"
        }

        mock_fetch_tags.return_value = ["tag1", "tag2"]
        mock_s3_push.return_value = "https://test-s3-push"
        service_event_consumer = ServiceCreatedEventConsumer(
            "wss://ropsten.infura.io/ws", "http://ipfs.singularitynet.io", 80,
            self.service_repo, self.org_repo)
        service_event_consumer.on_event(event=event)

        published_service = self.service_repo.get_service_for_given_service_uuid(
            org_uuid, service_uuid)

        self.assertEqual(["tag1", "tag2"], published_service.tags)
        self.assertEqual(ServiceStatus.PUBLISHED.value,
                         published_service.service_state.state)
        self.assertEqual(service_metadata["display_name"],
                         published_service.display_name)
        self.assertEqual(
            service_metadata["service_description"]["description"],
            published_service.description)
        self.assertEqual(
            service_metadata["service_description"]["short_description"],
            published_service.short_description)
        self.assertEqual(service_metadata["service_description"]["url"],
                         published_service.project_url)
        self.assertDictEqual(
            {
                "encoding": "proto",
                "service_type": "grpc",
                "model_ipfs_hash":
                "QmXqonxB9EvNBe11J8oCYXMQAtPKAb2x8CyFLmQpkvVaLf"
            }, published_service.proto)
        self.assertEqual(service_metadata["mpe_address"],
                         published_service.mpe_address)
        self.assertEqual(
            "ipfs://QmdGjaVYPMSGpC1qT3LDALSNCCu7JPf7j51H1GQirvQJYf",
            published_service.metadata_uri)
        self.assertDictEqual(service_metadata["contributors"][0],
                             published_service.contributors[0])

        group = published_service.groups[0]
        expected_group = service_metadata["groups"][0]

        self.assertEqual(expected_group["daemon_addresses"],
                         group.daemon_address)
        self.assertEqual(expected_group["group_name"], group.group_name)
        self.assertEqual(expected_group["endpoints"], group._get_endpoints())
        self.assertEqual(expected_group["free_calls"], group.free_calls)
        self.assertEqual(expected_group["free_call_signer_address"],
                         group.free_call_signer_address)
        self.assertEqual(expected_group["group_id"], group.group_id)
        self.assertEqual(expected_group["pricing"], group.pricing)

    @patch("common.ipfs_util.IPFSUtil",
           return_value=Mock(
               read_bytesio_from_ipfs=Mock(return_value=""),
               read_file_from_ipfs=Mock(
                   return_value=json.loads(json.dumps(service_metadata))),
               write_file_in_ipfs=Mock(return_value="Q3E12")))
    @patch('common.s3_util.S3Util.push_io_bytes_to_s3')
    @patch('common.blockchain_util.BlockChainUtil')
    @patch(
        'registry.consumer.service_event_consumer.ServiceEventConsumer._fetch_tags'
    )
    def test_on_service_created_event_from_snet_cli(self, mock_fetch_tags,
                                                    mock_block_chain_util,
                                                    mock_s3_push, mock_ipfs):
        org_uuid = str(uuid4())
        self.org_repo.add_item(
            Organization(name="test_org",
                         org_id="test_org_id",
                         uuid=org_uuid,
                         org_type="organization",
                         description="that is the dummy org for testcases",
                         short_description="that is the short description",
                         url="https://dummy.url",
                         contacts=[],
                         assets={},
                         duns_no=12345678,
                         origin="PUBLISHER_DAPP",
                         groups=[],
                         addresses=[],
                         metadata_ipfs_uri="#dummyhashdummyhash"))

        event = {
            "data": {
                'row_id': 202,
                'block_no': 6325625,
                'event': 'ServiceCreated',
                'json_str':
                "{'orgId': b'test_org_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'serviceId': b'test_service_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'metadataURI': b'ipfs://QmdGjaVYPMSGpC1qT3LDALSNCCu7JPf7j51H1GQirvQJYf\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'}",
                'processed': b'\x00',
                'transactionHash': '0x12345',
                'logIndex': '0',
                'error_code': 1,
                'error_msg': '',
                'row_updated': datetime(2019, 10, 21, 9, 59, 37),
                'row_created': datetime(2019, 10, 21, 9, 59, 37)
            },
            "name": "ServiceCreated"
        }

        mock_fetch_tags.return_value = ["tag1", "tag2"]
        mock_s3_push.return_value = "https://test-s3-push"
        service_event_consumer = ServiceCreatedEventConsumer(
            "wss://ropsten.infura.io/ws", "http://ipfs.singularitynet.io", 80,
            self.service_repo, self.org_repo)
        service_event_consumer.on_event(event=event)

        org_uuid, published_service = self.service_repo.get_service_for_given_service_id_and_org_id(
            "test_org_id", "test_service_id")
        self.assertEqual(["tag1", "tag2"], published_service.tags)
        self.assertEqual(ServiceStatus.PUBLISHED_UNAPPROVED.value,
                         published_service.service_state.state)
        self.assertEqual(service_metadata["display_name"],
                         published_service.display_name)
        self.assertEqual(
            service_metadata["service_description"]["description"],
            published_service.description)
        self.assertEqual(
            service_metadata["service_description"]["short_description"],
            published_service.short_description)
        self.assertEqual(service_metadata["service_description"]["url"],
                         published_service.project_url)
        self.assertDictEqual(
            {
                "encoding": "proto",
                "service_type": "grpc",
                "model_ipfs_hash":
                "QmXqonxB9EvNBe11J8oCYXMQAtPKAb2x8CyFLmQpkvVaLf"
            }, published_service.proto)
        self.assertEqual(service_metadata["mpe_address"],
                         published_service.mpe_address)
        self.assertDictEqual(service_metadata["contributors"][0],
                             published_service.contributors[0])

        group = published_service.groups[0]
        expected_group = service_metadata["groups"][0]

        self.assertEqual(expected_group["daemon_addresses"],
                         group.daemon_address)
        self.assertEqual(expected_group["group_name"], group.group_name)
        self.assertEqual(expected_group["endpoints"], group._get_endpoints())
        self.assertEqual(expected_group["free_calls"], group.free_calls)
        self.assertEqual(expected_group["free_call_signer_address"],
                         group.free_call_signer_address)
        self.assertEqual(expected_group["group_id"], group.group_id)
        self.assertEqual(expected_group["pricing"], group.pricing)

    def tearDown(self):
        self.org_repo.session.query(Organization).delete()
        self.org_repo.session.query(Service).delete()
        self.org_repo.session.query(ServiceGroup).delete()
        self.org_repo.session.query(ServiceState).delete()
        self.org_repo.session.query(ServiceReviewHistory).delete()
        self.org_repo.session.commit()
 def test_validate_demo_component(self, mock_code_build):
     mock_code_build.return_value = {"build": {"id": "test_build_id"}}
     event = {
         "Records": [{
             "eventVersion": "2.1",
             "eventSource": "aws:s3",
             "awsRegion": "us-east-1",
             "eventTime": "2021-06-16T15:49:00.312Z",
             "eventName": "ObjectCreated:Put",
             "userIdentity": {
                 "principalId": "AWS:AIDAXYSEM4MOPXXLSNUMO"
             },
             "requestParameters": {
                 "sourceIPAddress": "117.213.142.222"
             },
             "responseElements": {
                 "x-amz-request-id":
                 "XNESWXSYFNZA8HKK",
                 "x-amz-id-2":
                 "ir/3JEviL89t07LOtI2+oQE6X+EMtHWFOWyojXXNkNF/p2ZcsgeBg9X81dbZA2sj4gJw/CI8mhEfyJNcXdpPhkjcRqBYpwRHYH7vzMvrRsU="
             },
             "s3": {
                 "s3SchemaVersion": "1.0",
                 "configurationId": "b2733823-1355-4982-abdd-8f14cb7ddba4",
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/component/example_service_component.zip",
                     "size": 5248,
                     "eTag": "54ea849194040b43601f44ed53e5dc1b",
                     "sequencer": "0060CA1D6C80321671"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     assert response["statusCode"] == 200
     assert json.loads(
         response["body"])["data"]["build_id"] == "test_build_id"
     assert service.assets == {
         "demo_files": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/component/example_service_component.zip",
             "status": "PENDING",
             "build_id": "test_build_id"
         },
         "hero_image": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
             "ipfs_hash":
             "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
         },
         "proto_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         }
     }
    def test_demo_component_build_status_update(self):
        event = {
            "org_uuid": "test_org_uuid",
            "service_uuid": "test_service_uuid",
            "build_status": "0",
            "build_id": "sample_build_id",
            "filename": "incorrect_name.zip"
        }
        response = update_demo_component_build_status(event=event,
                                                      context=None)
        assert response["statusCode"] == 200
        service = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                             service_uuid="test_service_uuid")

        assert service.assets == {
            "demo_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy",
                "build_id": "sample_build_id"
            },
            "hero_image": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
                "ipfs_hash":
                "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
            },
            "proto_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            }
        }

        event = {
            "org_uuid": "test_org_uuid",
            "service_uuid": "test_service_uuid",
            "build_status": "0",
            "build_id": "sample_build_id",
            "filename": "20210228000436_component.zip"
        }
        response = update_demo_component_build_status(event=event,
                                                      context=None)
        assert response["statusCode"] == 200
        service = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                             service_uuid="test_service_uuid")
        assert service.assets == {
            "demo_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
                "status": "FAILED",
                "build_id": "sample_build_id",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            },
            "hero_image": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
                "ipfs_hash":
                "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
            },
            "proto_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            }
        }

        service_state = ServicePublisherRepository().get_service_state(
            status=ServiceStatus.CHANGE_REQUESTED.value)
        assert service_state[0].org_uuid == "test_org_uuid"
        assert service_state[0].service_uuid == "test_service_uuid"

        ServicePublisherRepository().update_service_status(
            service_uuid_list=["test_service_uuid"],
            prev_state=ServiceStatus.CHANGE_REQUESTED.value,
            next_state=ServiceStatus.APPROVAL_PENDING.value)
        event = {
            "org_uuid": "test_org_uuid",
            "service_uuid": "test_service_uuid",
            "build_status": "1",
            "build_id": "sample_build_id",
            "filename": "20210228000436_component.zip"
        }
        response = update_demo_component_build_status(event=event,
                                                      context=None)
        assert response["statusCode"] == 200
        service = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                             service_uuid="test_service_uuid")
        assert service.assets == {
            "demo_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
                "status": "SUCCEEDED",
                "build_id": "sample_build_id",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            },
            "hero_image": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
                "ipfs_hash":
                "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
            },
            "proto_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            }
        }
 def test_validate_proto(self, mock_proto_compile_response):
     mock_proto_compile_response.return_value = {"statusCode": 200}
     event = {
         "Records": [{
             "eventVersion": "2.1",
             "eventSource": "aws:s3",
             "awsRegion": "us-east-1",
             "eventTime": "2021-06-18T11:49:39.596Z",
             "eventName": "ObjectCreated:Put",
             "userIdentity": {
                 "principalId":
                 "AWS:AROAIJDMM5CI656XV7AOY:common-utility-rt-v2-upload"
             },
             "requestParameters": {
                 "sourceIPAddress": "18.210.102.181"
             },
             "responseElements": {
                 "x-amz-request-id":
                 "CK234N3ZN84W1TZ5",
                 "x-amz-id-2":
                 "9lHUaMDKbuCB9C6YnI6CjJuuWWhSiunQgXSnHHDK1+6ETaAjq95qSuYsqQGUhfbSOGStTohI3qiWpCjNrg36mFh4uTvh+PdW"
             },
             "s3": {
                 "s3SchemaVersion": "1.0",
                 "configurationId": "31f60a9a-a853-406c-b697-495098f6257d",
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/proto/20210618114940_proto_files.zip",
                     "size": 374,
                     "eTag": "57a5f8d4130aab3172c6aac7b898c4d7",
                     "sequencer": "0060CC8854D23C18E7"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     assert response["statusCode"] == 200
     assert service.assets == {
         "demo_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
             "build_id": "sample_build_id",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         },
         "hero_image": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
             "ipfs_hash":
             "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
         },
         "proto_files": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/proto/20210618114940_proto_files.zip",
             "status": "SUCCEEDED"
         }
     }
Beispiel #28
0
 def get_service_for_org_id_and_service_id(org_id, service_id):
     org_uuid, service = ServicePublisherRepository(
     ).get_service_for_given_service_id_and_org_id(org_id, service_id)
     if not service:
         return {}
     return service.to_dict()
Beispiel #29
0
 def get_service_id_availability_status(self, service_id):
     record_exist = ServicePublisherRepository(
     ).check_service_id_within_organization(self._org_uuid, service_id)
     if record_exist:
         return ServiceAvailabilityStatus.UNAVAILABLE.value
     return ServiceAvailabilityStatus.AVAILABLE.value
Beispiel #30
0
 def create_service(self, payload):
     service_uuid = uuid4().hex
     service = ServiceFactory().create_service_entity_model(
         self._org_uuid, service_uuid, payload, ServiceStatus.DRAFT.value)
     ServicePublisherRepository().add_service(service, self._username)
     return {"org_uuid": self._org_uuid, "service_uuid": service_uuid}