Esempio n. 1
0
    def validate_files_path(form, field):
        # Check the path given for the asset root exists

        if not field.data:
            return

        if field.data[0] != '/':
            raise validators.ValidationError('Path must be absolute')

        if not os.path.exists(field.data):
            raise validators.ValidationError('Path does not exist.')
Esempio n. 2
0
    def validate_aspect_ratio(form, field):

        if field.data:
            if (form.padding_top.data or form.padding_left.data
                    or form.padding_bottom.data or form.padding_right.data):
                raise validators.ValidationError(
                    'Not applicable when padding has been specified.')
Esempio n. 3
0
    def validate_access_key(form, field):

        access_key = field.data
        secret_key = form.secret_key.data
        bucket = form.bucket.data
        region = form.region.data

        if access_key and secret_key and bucket and region:

            client = botocore.session.get_session().create_client(
                's3',
                aws_access_key_id=access_key,
                aws_secret_access_key=secret_key,
                region_name=region)

            try:
                data = b'Hey, Hope you have a nice day! your friend Hangar51.'
                key = f'hangar51-settings-test-{uuid.uuid4().hex}'

                # Check we can write to the the bucket
                client.put_object(Bucket=bucket, Key=key, Body=data)

                # Check we can retrieve from the bucket
                client.get_object(Bucket=bucket, Key=key)

                # Check we can delete from the bucket
                client.delete_object(Bucket=bucket, Key=key)

            except (botocore.exceptions.BotoCoreError,
                    botocore.exceptions.ClientError) as e:

                raise validators.ValidationError(str(e))
Esempio n. 4
0
File: add.py Progetto: GetmeUK/h51
    def validate_api_allowed_ip_addresses(form, field):

        for ip_address in field.data:
            try:
                ipaddress.ip_address(ip_address)
            except ValueError:
                raise validators.ValidationError('Not a valid IP address: ' +
                                                 ip_address)
Esempio n. 5
0
File: add.py Progetto: GetmeUK/h51
    def validate_api_rate_limit_per_second(form, field):

        if field.data and field.data < 1:
            raise validators.ValidationError(
                'The rate limit must be set to 1 or more')