Exemple #1
0
    def execute(self):

        """
        update user email and/or role
        """
        self.result.format = skytask.output_format_json

        if self.apply:
            try:
                # attempt to update user information
                if self.email:
                    update_email(self.username, self.email)
                if self.role:
                    upsert_userroles(self.username, self.role)

                self.result.status = sky_cfg.API_STATUS_SUCCESS
                self.result.output = 'user updated: {0}'.format(find_user(self.username)[0])

            except (skybase.exceptions.SkyBaseError, sqlite3.Error) as e:
                self.result.output = simple_error_format(e)
                self.result.status = sky_cfg.API_STATUS_FAIL

        else:
            self.result.status = sky_cfg.API_STATUS_SUCCESS
            self.result.output = 'user not updated: {0}; --apply required'.format(find_user(self.username)[0])

        return self.result
Exemple #2
0
    def execute(self):
        """
        give the user name and role, create password and create a record in dbauth, return username, password, role
        """
        self.result.format = skytask.output_format_json

        if self.apply:
            try:
                # attempt to new user records from options
                create_user(self.username, self.secret, self.email, self.role)

                # attempt to read newly created record
                user_record = find_user(self.username)[0]

                # check for non-empty list of records; find_user() returns single/unique
                if user_record:
                    self.result.status = sky_cfg.API_STATUS_SUCCESS
                    self.result.output = 'user added: {0}'.format(
                        find_user(self.username)[0])
                else:
                    self.result.status = sky_cfg.API_STATUS_FAIL
                    self.result.output = 'failure to create new user record: {0}'.format(
                        simple_error_format(
                            SkyBaseUserIdNotFoundError(self.username)))
            except (skybase.exceptions.SkyBaseError, sqlite3.Error) as e:
                self.result.output = simple_error_format(e)
                self.result.status = sky_cfg.API_STATUS_FAIL

        else:
            self.result.status = sky_cfg.API_STATUS_SUCCESS
            self.result.output = 'user record to be added: {0}; --apply required'.format(
                self.username)

        return self.result
Exemple #3
0
    def execute(self):
        """
        update user email and/or role
        """
        self.result.format = skytask.output_format_json

        if self.apply:
            try:
                # attempt to update user information
                if self.email:
                    update_email(self.username, self.email)
                if self.role:
                    upsert_userroles(self.username, self.role)

                self.result.status = sky_cfg.API_STATUS_SUCCESS
                self.result.output = 'user updated: {0}'.format(
                    find_user(self.username)[0])

            except (skybase.exceptions.SkyBaseError, sqlite3.Error) as e:
                self.result.output = simple_error_format(e)
                self.result.status = sky_cfg.API_STATUS_FAIL

        else:
            self.result.status = sky_cfg.API_STATUS_SUCCESS
            self.result.output = 'user not updated: {0}; --apply required'.format(
                find_user(self.username)[0])

        return self.result
Exemple #4
0
    def execute(self):

        """
        give the user name and role, create password and create a record in dbauth, return username, password, role
        """
        self.result.format = skytask.output_format_json

        if self.apply:
            try:
                # attempt to new user records from options
                create_user(self.username, self.secret, self.email, self.role)

                # attempt to read newly created record
                user_record = find_user(self.username)[0]

                # check for non-empty list of records; find_user() returns single/unique
                if user_record:
                    self.result.status = sky_cfg.API_STATUS_SUCCESS
                    self.result.output = 'user added: {0}'.format(find_user(self.username)[0])
                else:
                    self.result.status = sky_cfg.API_STATUS_FAIL
                    self.result.output = 'failure to create new user record: {0}'.format(
                        simple_error_format(SkyBaseUserIdNotFoundError(self.username))
                    )
            except (skybase.exceptions.SkyBaseError, sqlite3.Error) as e:
                self.result.output = simple_error_format(e)
                self.result.status = sky_cfg.API_STATUS_FAIL

        else:
            self.result.status = sky_cfg.API_STATUS_SUCCESS
            self.result.output = 'user record to be added: {0}; --apply required'.format(self.username)

        return self.result