예제 #1
0
    def to_json(self, user):
        rv = super(AddonS3NodeSettings, self).to_json(user)

        user_settings = user.get_addon('s3')

        rv.update({
            'bucket':
            self.bucket or '',
            'has_bucket':
            self.bucket is not None,
            'user_is_owner': (self.user_settings
                              and self.user_settings.owner == user),
            'user_has_auth':
            bool(user_settings) and user_settings.has_auth,
            'node_has_auth':
            self.has_auth,
            'owner':
            None,
            'bucket_list':
            None,
            'is_registration':
            self.owner.is_registration,
        })

        if self.has_auth:
            rv['owner'] = self.user_settings.owner.fullname
            rv['owner_url'] = self.user_settings.owner.url
            rv['bucket_list'] = get_bucket_drop_down(self.user_settings)
            rv['node_has_auth'] = True

        return rv
예제 #2
0
파일: model.py 프로젝트: lbanner/osf.io
    def to_json(self, user):
        rv = super(AddonS3NodeSettings, self).to_json(user)

        user_settings = user.get_addon('s3')

        rv.update({
            'bucket': self.bucket or '',
            'has_bucket': self.bucket is not None,
            'user_is_owner': (
                self.user_settings and self.user_settings.owner == user
            ),
            'user_has_auth': bool(user_settings) and user_settings.has_auth,
            'node_has_auth': self.has_auth,
            'owner': None,
            'bucket_list': None,
            'is_registration': self.owner.is_registration,
        })

        if self.has_auth:
            rv['owner'] = self.user_settings.owner.fullname
            rv['owner_url'] = self.user_settings.owner.url
            rv['bucket_list'] = get_bucket_drop_down(self.user_settings)
            rv['node_has_auth'] = True

        return rv
예제 #3
0
def create_new_bucket(node_addon, **kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    bucket_name = request.json.get('bucket_name')

    if not utils.validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.',
            'title': 'Invalid bucket name',
        }, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {'buckets': utils.get_bucket_drop_down(user_settings)}
    except S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, http.NOT_ACCEPTABLE
    except S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, http.NOT_ACCEPTABLE
    except BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, http.NOT_ACCEPTABLE
예제 #4
0
파일: crud.py 프로젝트: GageGaskins/osf.io
def create_new_bucket(node_addon, **kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    bucket_name = request.json.get('bucket_name')

    if not utils.validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.',
            'title': 'Invalid bucket name',
        }, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {
            'buckets': utils.get_bucket_drop_down(user_settings)
        }
    except S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, http.NOT_ACCEPTABLE
    except S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, http.NOT_ACCEPTABLE
    except BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, http.NOT_ACCEPTABLE
예제 #5
0
파일: config.py 프로젝트: pazthor/osf.io
def s3_bucket_list(auth, node_addon, user_addon, **kwargs):

    return {'buckets': get_bucket_drop_down(user_addon)}
예제 #6
0
def s3_bucket_list(auth, node_addon, user_addon, **kwargs):
    return {
        'buckets': get_bucket_drop_down(user_addon)
    }