示例#1
0
def _bento_orm_obj_to_pb(bento_obj, labels=None):
    # Backwards compatible support loading saved bundle created before 0.8.0
    if ('apis' in bento_obj.bento_service_metadata
            and bento_obj.bento_service_metadata['apis']):
        for api in bento_obj.bento_service_metadata['apis']:
            if 'handler_type' in api:
                api['input_type'] = api['handler_type']
                del api['handler_type']
            if 'handler_config' in api:
                api['input_config'] = api['handler_config']
                del api['handler_config']
            if 'output_type' not in api:
                api['output_type'] = 'DefaultOutput'

    bento_service_metadata_pb = ParseDict(bento_obj.bento_service_metadata,
                                          BentoServiceMetadata())
    bento_uri = BentoUri(uri=bento_obj.uri,
                         type=BentoUri.StorageType.Value(bento_obj.uri_type))
    if labels is not None:
        bento_service_metadata_pb.labels.update(labels)
    return BentoPB(
        name=bento_obj.name,
        version=bento_obj.version,
        uri=bento_uri,
        bento_service_metadata=bento_service_metadata_pb,
    )
def _bento_orm_obj_to_pb(bento_obj):
    bento_service_metadata_pb = ParseDict(bento_obj.bento_service_metadata,
                                          BentoServiceMetadata())
    bento_uri = BentoUri(uri=bento_obj.uri,
                         type=BentoUri.StorageType.Value(bento_obj.uri_type))
    return BentoPB(
        name=bento_obj.name,
        version=bento_obj.version,
        uri=bento_uri,
        bento_service_metadata=bento_service_metadata_pb,
    )
示例#3
0
    def add(self, bento_name, bento_version):
        object_name = self._get_object_name(bento_name, bento_version)
        try:
            bucket = self.gcs_client.bucket(self.bucket)
            blob = bucket.blob(object_name)

            response = blob.generate_signed_url(
                version="v4", expiration=self._expiration, method="PUT",
            )
        except Exception as e:
            raise YataiRepositoryException(
                "Not able to get pre-signed URL on GCS. Error: {}".format(e)
            )

        return BentoUri(
            type=self.uri_type,
            uri='gs://{}/{}'.format(self.bucket, object_name),
            gcs_presigned_url=response,
        )
示例#4
0
    def add(self, bento_name, bento_version):
        # Generate pre-signed s3 path for upload

        object_name = self._get_object_name(bento_name, bento_version)
        try:
            response = self.s3_client.generate_presigned_url(
                'put_object',
                Params={'Bucket': self.bucket, 'Key': object_name},
                ExpiresIn=self.expiration,
            )
        except Exception as e:
            raise YataiRepositoryException(
                "Not able to get pre-signed URL on S3. Error: {}".format(e)
            )

        return BentoUri(
            type=self.uri_type,
            uri='s3://{}/{}'.format(self.bucket, object_name),
            s3_presigned_url=response,
        )
    def add(self, bento_name, bento_version):
        # Full path containing saved BentoService bundle, it the base path with service
        # name and service version as prefix. e.g.:
        # with base_path = '/tmp/my_bento_repo/', the saved bento will resolve in
        # the directory: '/tmp/my_bento_repo/service_name/version/'
        target_dir = os.path.join(self.base_path, bento_name, bento_version)

        # Ensure parent directory exist
        Path(os.path.join(self.base_path), bento_name).mkdir(
            parents=True, exist_ok=True
        )

        # Raise if target bento version already exist in storage
        if os.path.exists(target_dir):
            raise YataiRepositoryException(
                "Existing BentoService bundle {name}:{version} found in repository: "
                "{target_dir}".format(
                    name=bento_name, version=bento_version, target_dir=target_dir
                )
            )

        return BentoUri(type=self.uri_type, uri=target_dir)