Beispiel #1
0
    def put(self, account):
        """ update a parameter for a given account name

        .. :quickref: AccountParameter; Update account information.

        :param account: The account identifier.
        :status 200: OK.
        :status 400: Unknown status.
        :status 401: Invalid auth token.
        :status 404: Account not found.
        """
        parameters = json_parameters()
        for key, value in parameters.items():
            try:
                update_account(account,
                               key=key,
                               value=value,
                               issuer=request.environ.get('issuer'),
                               vo=request.environ.get('vo'))
            except ValueError:
                return generate_http_error_flask(400, ValueError.__name__,
                                                 f'Unknown value {value}')
            except AccessDenied as error:
                return generate_http_error_flask(401, error)
            except AccountNotFound as error:
                return generate_http_error_flask(404, error)

        return '', 200
Beispiel #2
0
    def put(self, account):
        """ update a parameter for a given account name

        .. :quickref: AccountParameter; Update account information.

        :param account: The account identifier.
        :status 200: OK.
        :status 400: Unknown status.
        :status 401: Invalid auth token.
        :status 404: Account not found.
        :status 500: Database exception.
        """
        json_data = request.data.decode()
        try:
            parameter = loads(json_data)
        except ValueError:
            return generate_http_error_flask(400, 'ValueError', 'cannot decode json parameter dictionary')
        for key, value in parameter.items():
            try:
                update_account(account, key=key, value=value, issuer=request.environ.get('issuer'), vo=request.environ.get('vo'))
            except ValueError:
                return generate_http_error_flask(400, 'ValueError', 'Unknown value %s' % value)
            except AccessDenied as error:
                return generate_http_error_flask(401, 'AccessDenied', error.args[0])
            except AccountNotFound as error:
                return generate_http_error_flask(404, 'AccountNotFound', error.args[0])
            except Exception as error:
                print(format_exc())
                return str(error), 500

        return '', 200
Beispiel #3
0
    def PUT(self, account):
        """ update a parameter for a given account name
        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            404 Not Found
            500 InternalError

        """
        json_data = data()
        try:
            parameter = loads(json_data)
        except ValueError:
            raise generate_http_error(
                400, 'ValueError', 'cannot decode json parameter dictionary')
        for key, value in parameter.items():
            try:
                update_account(account,
                               key=key,
                               value=value,
                               issuer=ctx.env.get('issuer'))
            except ValueError:
                raise generate_http_error(400, 'ValueError',
                                          'Unknown value %s' % value)
            except AccessDenied as error:
                raise generate_http_error(401, 'AccessDenied', error.args[0])
            except AccountNotFound as error:
                raise generate_http_error(404, 'AccountNotFound',
                                          error.args[0])
            except Exception as error:
                raise InternalError(error)

        raise OK()
Beispiel #4
0
    def put(self, account):
        """
        ---
        summary: Update
        description: Update a parameter for an account.
        tags:
          - Account
        parameters:
        - name: account
          in: path
          description: The account identifier.
          schema:
            type: string
          style: simple
        requestBody:
          content:
            'application/json':
              schema:
                description: Json object with key-value pairs corresponding to the new values of the parameters.
                type: object
        responses:
          200:
            description: OK
          401:
            description: Invalid Auth Token
          404:
            description: No account found.
          400:
            description: Unknown status
        """
        parameters = json_parameters()
        for key, value in parameters.items():
            try:
                update_account(account,
                               key=key,
                               value=value,
                               issuer=request.environ.get('issuer'),
                               vo=request.environ.get('vo'))
            except ValueError:
                return generate_http_error_flask(400, ValueError.__name__,
                                                 f'Unknown value {value}')
            except AccessDenied as error:
                return generate_http_error_flask(401, error)
            except AccountNotFound as error:
                return generate_http_error_flask(404, error)

        return '', 200
Beispiel #5
0
 def test_update_account(self):
     """ ACCOUNT (CORE): Test changing and quering account parameters """
     usr = account_name_generator()
     add_account(usr, 'USER', '*****@*****.**', 'root', **self.vo)
     assert get_account_info(usr, **self.vo)['status'] == AccountStatus.ACTIVE  # Should be active by default
     update_account(account=usr, key='status', value=AccountStatus.SUSPENDED, **self.vo)
     assert get_account_info(usr, **self.vo)['status'] == AccountStatus.SUSPENDED
     update_account(account=usr, key='status', value=AccountStatus.ACTIVE, **self.vo)
     assert get_account_info(usr, **self.vo)['status'] == AccountStatus.ACTIVE
     update_account(account=usr, key='email', value='test', **self.vo)
     email = get_account_info(account=usr, **self.vo)['email']
     assert email == 'test'
     del_account(usr, 'root', **self.vo)
Beispiel #6
0
 def test_update_account(self):
     """ ACCOUNT (CORE): Test changing and quering account parameters """
     usr = account_name_generator()
     add_account(usr, 'USER', '*****@*****.**', 'root')
     assert_equal(get_account_info(usr)['status'], AccountStatus.ACTIVE)  # Should be active by default
     update_account(account=usr, key='status', value=AccountStatus.SUSPENDED)
     assert_equal(get_account_info(usr)['status'], AccountStatus.SUSPENDED)
     update_account(account=usr, key='status', value=AccountStatus.ACTIVE)
     assert_equal(get_account_info(usr)['status'], AccountStatus.ACTIVE)
     update_account(account=usr, key='email', value='test')
     email = get_account_info(account=usr)['email']
     assert_equal(email, 'test')
     del_account(usr, 'root')