Python flask_restful.inputs.boolean() Examples

The following are 14 code examples of flask_restful.inputs.boolean(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_restful.inputs , or try the search function .
Example #1
Source File: deployments.py    From cloudify-manager with Apache License 2.0 6 votes vote down vote up
def put(self, deployment_id, **kwargs):
        """
        Create a deployment
        """
        validate_inputs({'deployment_id': deployment_id})
        request_schema = self.create_request_schema()
        request_dict = get_json_and_verify_params(request_schema)
        blueprint_id = request_dict['blueprint_id']
        bypass_maintenance = is_bypass_maintenance_mode()
        args = get_args_and_verify_arguments(
            [Argument('private_resource', type=boolean,
                      default=False)]
        )
        deployment = get_resource_manager().create_deployment(
            blueprint_id,
            deployment_id,
            private_resource=args.private_resource,
            visibility=None,
            inputs=request_dict.get('inputs', {}),
            bypass_maintenance=bypass_maintenance,
            skip_plugins_validation=self.get_skip_plugin_validation_flag(
                request_dict)
        )
        return deployment, 201 
Example #2
Source File: provider_context.py    From cloudify-manager with Apache License 2.0 6 votes vote down vote up
def post(self, **kwargs):
        """
        Create provider context
        """
        request_dict = get_json_and_verify_params({'context', 'name'})
        args = get_args_and_verify_arguments(
            [Argument('update', type=boolean, default=False)]
        )
        update = args['update']
        context = dict(
            id=PROVIDER_CONTEXT_ID,
            name=request_dict['name'],
            context=request_dict['context']
        )

        status_code = 200 if update else 201

        try:
            get_resource_manager().update_provider_context(update, context)
            return dict(status='ok'), status_code
        except dsl_parser_utils.ResolverInstantiationError as ex:
            raise manager_exceptions.ResolverInstantiationError(str(ex)) 
Example #3
Source File: NewPost.py    From maniwani with MIT License 6 votes vote down vote up
def get_request_data() -> reqparse.Namespace:
    "Returns data about a new post request."

    parser = reqparse.RequestParser()
    parser.add_argument("subject", type=str)
    parser.add_argument("body", type=str, required=True)
    parser.add_argument("useslip", type=inputs.boolean)
    parser.add_argument("spoiler", type=inputs.boolean)

    if not on_captcha_cooldown():
        captcha_method = app.config.get("CAPTCHA_METHOD")
        if captcha_method == "RECAPTCHA":
            parser.add_argument("recaptcha-token", type=str, required=True)
        elif captcha_method == "CAPTCHOULI":
            parser.add_argument("captchouli-id", type=str, required=True)
            for i in range(9):
                # For each image square
                parser.add_argument(f"captchouli-{i}", type=str, default=False)

    return parser.parse_args() 
Example #4
Source File: gateway.py    From floranet with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'host': fields.String,
            'eui': fields.Integer,
            'name': fields.String,
            'enabled': fields.Boolean,
            'power': fields.Integer,
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('host', type=str)
        self.parser.add_argument('eui', type=int)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('enabled', type=inputs.boolean)
        self.parser.add_argument('power', type=int)
        self.args = self.parser.parse_args() 
Example #5
Source File: deployments.py    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def delete(self, deployment_id, **kwargs):
        """
        Delete deployment by id
        """
        args = get_args_and_verify_arguments(
            [Argument('ignore_live_nodes', type=boolean,
                      default=False),
             Argument('delete_db_mode', type=boolean,
                      default=False),
             Argument('delete_logs', type=boolean,
                      default=False)]
        )

        bypass_maintenance = is_bypass_maintenance_mode()
        deployment = get_resource_manager().delete_deployment(
            deployment_id,
            bypass_maintenance,
            args.ignore_live_nodes,
            args.delete_db_mode,
            args.delete_logs)

        if args.delete_db_mode:
            # Delete deployment resources from file server
            deployment_folder = os.path.join(
                config.instance.file_server_root,
                FILE_SERVER_DEPLOYMENTS_FOLDER,
                utils.current_tenant.name,
                deployment.id)
            if os.path.exists(deployment_folder):
                shutil.rmtree(deployment_folder)
        return deployment, 200 
Example #6
Source File: executions.py    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def get(self, _include=None, **kwargs):
        """List executions"""
        args = get_args_and_verify_arguments(
            [Argument('deployment_id', required=False),
             Argument('include_system_workflows', type=boolean,
                      default=False)]
        )
        deployment_id_filter = ResourceManager.create_filters_dict(
            deployment_id=args.deployment_id)
        return get_resource_manager().list_executions(
            is_include_system_workflows=args.include_system_workflows,
            include=_include,
            filters=deployment_id_filter).items 
Example #7
Source File: blueprints.py    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def delete(self, blueprint_id, **kwargs):
        """
        Delete blueprint by id
        """
        query_args = get_args_and_verify_arguments(
            [Argument('force', type=boolean, default=False)])
        blueprint = get_resource_manager().delete_blueprint(
            blueprint_id,
            force=query_args.force)
        return blueprint, 200 
Example #8
Source File: deployments.py    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def put(self, deployment_id, **kwargs):
        """
        Create a deployment
        """
        rest_utils.validate_inputs({'deployment_id': deployment_id})
        request_schema = self.create_request_schema()
        request_dict = rest_utils.get_json_and_verify_params(request_schema)
        blueprint_id = request_dict['blueprint_id']
        bypass_maintenance = is_bypass_maintenance_mode()
        args = rest_utils.get_args_and_verify_arguments(
            [Argument('private_resource', type=boolean)]
        )
        visibility = rest_utils.get_visibility_parameter(
            optional=True,
            valid_values=VisibilityState.STATES
        )
        deployment = get_resource_manager().create_deployment(
            blueprint_id,
            deployment_id,
            inputs=request_dict.get('inputs', {}),
            bypass_maintenance=bypass_maintenance,
            private_resource=args.private_resource,
            visibility=visibility,
            skip_plugins_validation=self.get_skip_plugin_validation_flag(
                request_dict),
            site_name=_get_site_name(request_dict),
            runtime_only_evaluation=request_dict.get(
                'runtime_only_evaluation', False)
        )
        return deployment, 201 
Example #9
Source File: upload_manager.py    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def _prepare_and_submit_blueprint(cls,
                                      file_server_root,
                                      app_dir,
                                      blueprint_id,
                                      visibility):
        args = get_args_and_verify_arguments([
            Argument('private_resource', type=boolean),
            Argument('visibility'),
            Argument('application_file_name',
                     default='')])

        app_file_name = cls._extract_application_file(
            file_server_root, app_dir, args.application_file_name)

        # add to blueprints manager (will also dsl_parse it)
        try:
            blueprint = get_resource_manager().publish_blueprint(
                app_dir,
                app_file_name,
                file_server_root,
                blueprint_id,
                args.private_resource,
                visibility
            )

            # moving the app directory in the file server to be under a
            # directory named after the blueprint id
            tenant_dir = os.path.join(
                file_server_root,
                FILE_SERVER_BLUEPRINTS_FOLDER,
                current_tenant.name)
            mkdirs(tenant_dir)
            shutil.move(os.path.join(file_server_root, app_dir),
                        os.path.join(tenant_dir, blueprint.id))
            cls._process_plugins(file_server_root, blueprint.id)
            return blueprint
        except manager_exceptions.DslParseException as ex:
            shutil.rmtree(os.path.join(file_server_root, app_dir))
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex)) 
Example #10
Source File: auth_api.py    From gae-angular-material-starter with MIT License 5 votes vote down vote up
def post(self):
        """Creates new user account if provided valid arguments"""
        parser = reqparse.RequestParser()
        parser.add_argument('email', type=UserValidator.create('unique_email'), required=True)
        parser.add_argument('username', type=UserValidator.create('unique_username'))
        parser.add_argument('password', type=UserValidator.create('password'))
        parser.add_argument('remember', type=inputs.boolean, default=False)
        args = parser.parse_args()

        user_db = auth.create_user_db(
            auth_id=None,
            name='',
            username=args.username,
            email=args.email,
            verified=True if not config.CONFIG_DB.verify_email else False,
            password=args.password
        )
        user_db.put()

        if config.CONFIG_DB.verify_email:
            task.verify_user_email_notification(user_db)
            return make_empty_ok_response()

        # if users don't need to verify email, we automaticaly signin newly registered user
        auth.signin_user_db(user_db, remember=args.remember)
        return user_db.to_dict(include=User.get_private_properties()) 
Example #11
Source File: decorators.py    From gae-angular-material-starter with MIT License 5 votes vote down vote up
def parse_signin(func):
    """Parses credentials posted by client and loads appropriate user from datastore"""
    @functools.wraps(func)
    def decorated_function(*args, **kwargs): # pylint: disable=missing-docstring
        parser = reqparse.RequestParser()
        parser.add_argument('login', type=str, required=True)
        parser.add_argument('password', type=model.UserValidator.create('password'), required=True)
        parser.add_argument('remember', type=inputs.boolean, default=False)
        g.args = parser.parse_args()
        g.user_db = model.User.get_by_credentials(g.args.login, g.args.password)
        return func(*args, **kwargs)

    return decorated_function 
Example #12
Source File: auth.py    From gae-angular-material-starter with MIT License 5 votes vote down vote up
def save_request_params():
    """Function temporily saves 'remember' url parameter into users session.
    This is useful when we login via oauth, so redirects would wipe out our url parameters."""
    parser = reqparse.RequestParser()
    parser.add_argument('remember', type=inputs.boolean, default=False)
    args = parser.parse_args()
    flask.session['auth-params'] = {
        'remember': args.remember,
    } 
Example #13
Source File: device.py    From floranet with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'deveui': fields.Integer,
            'name': fields.String,
            'devclass': fields.String,
            'enabled': fields.Boolean,
            'otaa': fields.Boolean,
            'devaddr': fields.Integer,
            'appeui': fields.Integer,
            'appskey': fields.Integer,
            'nwkskey': fields.Integer,
            'tx_datr': fields.String,
            'snr_average': fields.Float,
            'appname': fields.String,
            'latitude': fields.Float,
            'longitude': fields.Float,
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('deveui', type=int)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('devclass', type=str)
        self.parser.add_argument('enabled', type=inputs.boolean)
        self.parser.add_argument('otaa', type=inputs.boolean)
        self.parser.add_argument('devaddr', type=int)
        self.parser.add_argument('appeui', type=int)
        self.parser.add_argument('nwkskey', type=int)
        self.parser.add_argument('appskey', type=int)
        self.parser.add_argument('appname', type=str)
        self.parser.add_argument('latitude', type=float)
        self.parser.add_argument('longitude', type=float)
        self.args = self.parser.parse_args() 
Example #14
Source File: upload_manager.py    From cloudify-manager with Apache License 2.0 4 votes vote down vote up
def _prepare_and_process_doc(self,
                                 data_id,
                                 file_server_root,
                                 archive_target_path,
                                 **kwargs):

        # support previous implementation
        wagon_target_path = archive_target_path

        # handle the archive_target_path, which may be zip or wagon
        if not self._is_wagon_file(archive_target_path):
            if not zipfile.is_zipfile(archive_target_path):
                raise manager_exceptions.InvalidPluginError(
                    'input can be only a wagon or a zip file.')
            archive_name = unzip(archive_target_path,
                                 logger=current_app.logger)
            os.remove(archive_target_path)
            shutil.move(archive_name, archive_target_path)
            try:
                wagon_target_path, _ = \
                    self._verify_archive(archive_target_path)
            except RuntimeError as re:
                raise manager_exceptions.InvalidPluginError(re.message)

        args = get_args_and_verify_arguments([
            Argument('title'),
            Argument('private_resource', type=boolean),
            Argument('visibility')])

        visibility = kwargs.get(_VISIBILITY, None)
        new_plugin = self._create_plugin_from_archive(data_id,
                                                      args.title,
                                                      wagon_target_path,
                                                      args.private_resource,
                                                      visibility)
        filter_by_name = {'package_name': new_plugin.package_name}
        sm = get_resource_manager().sm
        plugins = sm.list(Plugin, filters=filter_by_name)

        for plugin in plugins:
            if plugin.archive_name == new_plugin.archive_name:
                raise manager_exceptions.ConflictError(
                    'a plugin archive by the name of {archive_name} already '
                    'exists for package with name {package_name} and version '
                    '{version}'.format(archive_name=new_plugin.archive_name,
                                       package_name=new_plugin.package_name,
                                       version=new_plugin.package_version))
            if is_plugin_installing(new_plugin, plugin):
                raise manager_exceptions.ConflictError(
                    'a plugin archive by the name of {archive_name} for '
                    'package with name {package_name} and version {version} '
                    'is currently being installed'.format(
                        archive_name=new_plugin.archive_name,
                        package_name=new_plugin.package_name,
                        version=new_plugin.package_version))
        dest_path = new_plugin.archive_name
        new_plugin.archive_name = '{0}{1}'.format(INSTALLING_PREFIX,
                                                  new_plugin.archive_name)
        sm.put(new_plugin)
        return new_plugin, dest_path