Example #1
0
    def PUT(self, section, option, value):
        """
        Set the value of an option.
        If the option does not exist, create it.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 ConfigurationError

        :param Rucio-Auth-Account: Account identifier.
        :param Rucio-Auth-Token: 32 character hex string.
        """

        try:
            config.set(section=section,
                       option=option,
                       value=value,
                       issuer=ctx.env.get('issuer'))
        except:
            raise generate_http_error(
                500, 'ConfigurationError',
                'Could not set value \'%s\' for section \'%s\' option \'%s\'' %
                (value, section, option))
        raise Created()
Example #2
0
    def put(self, section, option, value):
        """
        Set the value of an option.
        If the option does not exist, create it.

        .. :quickref: OptionSet; set config value.

        :status 201: Option successfully created or updated.
        :status 401: Invalid Auth Token.
        :status 500: Configuration Error.
        """

        try:
            config.set(section=section,
                       option=option,
                       value=value,
                       issuer=request.environ.get('issuer'))
        except ConfigurationError:
            return generate_http_error_flask(
                500, 'ConfigurationError',
                'Could not set value \'%s\' for section \'%s\' option \'%s\'' %
                (value, section, option))
        except Exception as error:
            print(format_exc())
            return error, 500
        return "Created", 201
Example #3
0
    def post(self):
        """
        Create or set the configuration option in the requested section.
        The request body is expected to contain a json {"section": {"option": "value"}}.

        .. :quickref: Config; set config value

        :status 201: Option successfully created or updated.
        :status 400: The input data is invalid or incomplete.
        :status 401: Invalid Auth Token.
        :status 500: Configuration Error.
        """
        parameters = json_parameters()
        for section, section_config in parameters.items():
            if not isinstance(section_config, dict):
                return generate_http_error_flask(400, ValueError.__name__, '')
            for option, value in section_config.items():
                try:
                    config.set(section=section,
                               option=option,
                               value=value,
                               issuer=request.environ.get('issuer'),
                               vo=request.environ.get('vo'))
                except ConfigurationError:
                    return generate_http_error_flask(
                        400, 'ConfigurationError',
                        f"Could not set value '{value}' for section '{section}' option '{option}'"
                    )
        return 'Created', 201
Example #4
0
    def POST(self):
        """
        Set the value of an option.
        If the option does not exist, create it.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            400 The input data is invalid or incomplete
            500 ConfigurationError

        :param Rucio-Auth-Account: Account identifier.
        :param Rucio-Auth-Token: 32 character hex string.
        """

        json_data = data().decode()
        try:
            input_data = json.loads(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter dictionary')

        section, option, value = _config_items_from_input(input_data)
        if section is None or option is None or value is None:
            raise generate_http_error(400, 'ValueError', 'Invalid input data')

        try:
            config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo'))
        except ConfigurationError:
            raise generate_http_error(500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option))
        except Exception as error:
            print(format_exc())
            raise InternalError(error)
        raise Created()
Example #5
0
    def PUT(self, section, option, value):
        """
        Set the value of an option.
        If the option does not exist, create it.
        TODO: remove this endpoint after migrating all clients to pass input data via a json body

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 ConfigurationError

        :param Rucio-Auth-Account: Account identifier.
        :param Rucio-Auth-Token: 32 character hex string.
        """

        try:
            config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo'))
        except ConfigurationError:
            raise generate_http_error(500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option))
        except Exception as error:
            print(format_exc())
            raise InternalError(error)
        raise Created()
Example #6
0
 def put(self, section, option, value):
     """
     ---
     summary: Create value
     description: Create or set the value of an option.
     tags:
       - Config
     parameters:
     - name: section
       in: path
       description: The section.
       schema:
         type: string
       style: simple
     - name: option
       in: path
       description: The option of the section.
       schema:
         type: string
       style: simple
     - name: value
       in: path
       description: The value to set.
       schema:
         type: string
       style: simple
     responses:
       201:
         description: OK
         content:
           application/json:
             schema:
               type: string
               enum: ['Created']
       401:
         description: Invalid Auth Token
       500:
         description: Value could not be set
         content:
           application/json:
             schema:
               type: string
               enum: ['Could not set value {} for section {} option {}']
       """
     try:
         config.set(section=section,
                    option=option,
                    value=value,
                    issuer=request.environ.get('issuer'),
                    vo=request.environ.get('vo'))
         return 'Created', 201
     except ConfigurationError as error:
         return generate_http_error_flask(
             500, error,
             f"Could not set value '{value}' for section '{section}' option '{option}'"
         )
Example #7
0
 def post(self):
     """
     ---
     summary: Create
     description: Create or set the configuration option in the requested section.
     tags:
       - Config
     requestBody:
       content:
         'application/json':
           schema:
             description: "The request body is expected to contain a json {'section': {'option': 'value'}}."
             type: object
     responses:
       201:
         description: OK
         content:
           application/json:
             schema:
               type: string
               enum: ['Created']
       401:
         description: Invalid Auth Token
       400:
         description: The input data was incomplete or invalid
       500:
         description: Configuration error
     """
     parameters = json_parameters()
     for section, section_config in parameters.items():
         if not isinstance(section_config, dict):
             return generate_http_error_flask(400, ValueError.__name__, '')
         for option, value in section_config.items():
             try:
                 config.set(section=section,
                            option=option,
                            value=value,
                            issuer=request.environ.get('issuer'),
                            vo=request.environ.get('vo'))
             except ConfigurationError:
                 return generate_http_error_flask(
                     400, 'ConfigurationError',
                     f"Could not set value '{value}' for section '{section}' option '{option}'"
                 )
     return 'Created', 201
Example #8
0
    def PUT(self, section, option, value):
        """
        Set the value of an option.
        If the option does not exist, create it.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 ConfigurationError

        :param Rucio-Auth-Account: Account identifier.
        :param Rucio-Auth-Token: 32 character hex string.
        """

        try:
            config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer'))
        except:
            raise generate_http_error(500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option))
        raise Created()
Example #9
0
    def put(self, section, option, value):
        """
        Set the value of an option.
        If the option does not exist, create it.

        .. :quickref: OptionSet; set config value.

        :status 201: Option successfully created or updated.
        :status 401: Invalid Auth Token.
        """
        try:
            config.set(section=section,
                       option=option,
                       value=value,
                       issuer=request.environ.get('issuer'),
                       vo=request.environ.get('vo'))
            return 'Created', 201
        except ConfigurationError as error:
            return generate_http_error_flask(
                500, error,
                f"Could not set value '{value}' for section '{section}' option '{option}'"
            )