コード例 #1
0
ファイル: container.py プロジェクト: iispokon/cfs-admin-api
    def upload(self, source, custom_name=None, custom_mime=None, exists=ExistValues.fail, data_inline=False, debug=False):
        """Upload a file or a string to CloudFS.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Upload%20File.html

        :param source:          Source of file data. String or path to a file.
        :param custom_name:     Name of file in CloudFS. If left blank, will use name of file in path.
        :param custom_mime:     Mine for new file. If left blank, mime will be detected.
        :param exists:          Behavior if the given name exists on CloudFS. Defaults to fail.
        :param data_inline:     Flag to indicate if the source is a string or a filename.
        :param debug:           If true, will print the the request and response to stdout.

        :returns:   New file object.
        :raises SessionNotLinked:       CloudFSRESTAdapter is not authenticated.
        :raises AuthenticatedError:     Based on CloudFS Error Code.
        """
        if self.in_share():
            raise operation_not_allowed("upload to folder in share")
        set_debug(self, debug)
        if not custom_name:
            custom_name = os.path.basename(source)

        file_data = source
        if not data_inline:
            file_data = open(file_data, 'rb')

        files = {'file':[custom_name, file_data]}

        if custom_mime:
            files['file'].append(custom_mime)

        upload_response = self.rest_interface.upload(self.path(), files, exists)
        return create_items_from_json(self.rest_interface, upload_response, self.path(), self.in_trash)[0]
コード例 #2
0
ファイル: container.py プロジェクト: iispokon/cfs-admin-api
    def save(self, if_conflict=VersionConflictValue.fail, debug=False):
        """Save changes to folder metadata.
        See notes on individual setters for quirks.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Alter%20Folder%20Meta.html

        :param if_conflict: Behavior if the local folder information is out of date.
        :param debug:       If true, will print the the request and response to stdout.

        :returns:   Updated folder object.
        :raises SessionNotLinked:       CloudFSRESTAdapter is not authenticated.
        :raises AuthenticatedError:     Based on CloudFS Error Code.
        """
        if self.in_share():
            raise operation_not_allowed("save changes to folder in share")
        set_debug(self, debug)
        changes = {'version':self.data['version']}
        for changed_key in self.changed_meta:
            changes[changed_key] = self.data[changed_key]

        self.changed_meta.clear()

        response = self.rest_interface.folder_alter_meta(self.path(), changes, if_conflict)
        self._initialize_self(response)
        return self
コード例 #3
0
ファイル: container.py プロジェクト: iispokon/cfs-admin-api
    def delete(self, commit=False, force=False, debug=False):
        """Delete folder.
        Folder will only be removed from trash if commit is True. This is the case for folders in or out of the trash, so folders
        that are in the trash already will treat delete(commit=False) calls as a no-op.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Delete%20Folder.html

        :param commit:  If true, will permanently remove file instead of moving it to trash. Defaults to False.
        :param force:   If true, will delete folder even if it contains items. Defaults to False.
        :param debug:   If true, will print the the request and response to stdout.

        :returns:   Dictionary with keys for success and the deleted folders last version.
        :raises SessionNotLinked:       CloudFSRESTAdapter is not authenticated.
        :raises AuthenticatedError:     Based on CloudFS Error Code.
        """
        if self.in_share():
            raise operation_not_allowed("delete folder in share")
        set_debug(self, debug)
        if self.in_trash:
            if commit:
                return self.rest_interface.delete_trash_item(self.path())
            else:
                # nop
                # we're already in the trash, does not make sense to make a delete call if commit is not true.
                return {}
        else:
            folder_to_delete = self.path()
            result = self.rest_interface.delete_folder(folder_to_delete, commit, force)
            if result['success'] and commit == False:
                self.in_trash = True
            return result
コード例 #4
0
    def account_state(self,
                      user_id,
                      username=None,
                      first_name=None,
                      last_name=None,
                      plan_code=None,
                      expiration_date=None,
                      grace=None,
                      ignore_otl=None,
                      plan_transition=None,
                      debug=False):
        """
        :param user_id:
        :param username:
        :param first_name:
        :param last_name:
        :param plan_code:
        :param expiration_date:
        :param grace:
        :param ignore_otl:
        :param plan_transition:
        :param debug:
        :return:
        """
        if not self.admin_rest_interface:
            raise operation_not_allowed(
                "Account updates without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

        return self.admin_rest_interface.account_state(
            user_id, username, first_name, last_name, plan_code,
            expiration_date, grace, ignore_otl, plan_transition)
コード例 #5
0
ファイル: session.py プロジェクト: gordillo/CloudFS-Python
    def create_account(
        self, username, password, email=None, first_name=None, last_name=None, log_in_to_created_user=False, debug=False
    ):
        """Create a user account associated with your CloudFS account.

        :note: Although this method creates a User object - the session associated with the user is _not_ linked. You must authenticate it before using it.

        REST Documentation: https://developer.bitcasa.com/cloudfs-rest-documentation/administration-operations/

        :param username:                Username for the user, must be at least 4 characters and less than 256 characters.
        :param password:                Password for the user, must be at least 6 characters and has no length limit.
        :param email:                   Email address for user. Optional.
        :param first_name:              Users' first name. Optional
        :param last_name:               Users' last name. Optional
        :param log_in_to_created_user:  If True, will log into the created user account in this session. Optional, defaults to False.
        :param debug:                   If True, will print the the request and response to stdout.
        :return:                        Newly created User.
        :rtype:                         User object.
        :raise OperationNotAllowed:
        """
        if not self.admin_rest_interface:
            raise operation_not_allowed("Account creation without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

        response = self.admin_rest_interface.create_account(username, password, email, first_name, last_name)
        if log_in_to_created_user:
            self.authenticate(username, password, debug)
        return User(self.rest_interface.get_copy(), response)
コード例 #6
0
ファイル: session.py プロジェクト: iispokon/cfs-admin-api
    def delete_account(self, user_id, debug=False):
        if not self.admin_rest_interface:
            raise operation_not_allowed("Account creation without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

            return self.admin_rest_interface.delete_account(user_id=user_id)
コード例 #7
0
    def delete_account(self, user_id, debug=False):
        if not self.admin_rest_interface:
            raise operation_not_allowed(
                "Account creation without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

            return self.admin_rest_interface.delete_account(user_id=user_id)
コード例 #8
0
    def restore(self, restore_method=RestoreValue.fail, method_argument=None, debug=False):
        """Restore item from trash.
        REST documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Recover%20Trash%20Item.html
        :param dest:
        :return:
        """
        if self.in_share():
            raise operation_not_allowed("restore item in share")
        if not self.in_trash:
            # TODO: Should we filter on this? It should be reliable - but we can't guarentee it.
            return None

        set_debug(self, debug)
        return self.rest_interface.restore_trash_item(self.path(), restore_method, method_argument)
コード例 #9
0
    def _prevent_unsupported_operation(self, method):
        messages = {
            'delete':{
                'share':   'delete file in share',
                'previous':'delete previous version of file'
            },
            'save':{
                'share':   'save file in share',
                'previous':'save changes to previous version of file'
            },
            'versions':{
                'share':   'list file versions in share'
            },
            'download':{
                'share':   'download file in share',
                'previous':'download previous version of file'
            },
            'read':{
                'share':   'read file in share',
                'previous':'read previous version of file'
            },
            'seek':{
                'share':   'seek in file in share',
                'previous':'seek in previous version of file'
            }
        }
        try:
            state_messages = messages[method]
        except KeyError:
            print "Failed to check that operation '{}' is allowed due to missing messages!".format(method)
            # do noting! D:
            return

        if self.in_share() and 'share' in state_messages:
            raise operation_not_allowed(state_messages['share'])
        if self.old_version and 'previous' in state_messages:
            raise operation_not_allowed(state_messages['previous'])
コード例 #10
0
    def create_account(self,
                       username,
                       password,
                       email=None,
                       first_name=None,
                       last_name=None,
                       account_plan_uuid=None,
                       current_date=None,
                       log_in_after_creation=False,
                       debug=False,
                       tkey=False):
        """Create a user account associated with your CloudFS account.

        Warning: This method is currently broken, and will almost certainly 500. If you're interested, or the method has
        since been fixed server side, call the method with force=true. The request format is not expected to change.

        Note: Although this method creates a User object - the session associated with the user is _not_ linked. You
        must authenticate it before using it.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Create%20Account.html

        :param username:                Username for the user, must be at least 4 characters and less than 256 characters.
        :param password:                Password for the user, must be at least 6 characters and has no length limit.
        :param email:                   Email address for user. Optional.
        :param first_name:              Users' first name. Optional
        :param last_name:               Users' last name. Optional
        :param log_in_after_creation:   If True, will log into the created user account in this session. Optional, defaults to False.
        :param debug:                   If True, will print the the request and response to stdout.
        :return:                        Newly created User object.
        :raise OperationNotAllowed:
        """
        if not self.admin_rest_interface:
            raise operation_not_allowed(
                "Account creation without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

        response = self.admin_rest_interface.create_account(
            username, password, email, first_name, last_name,
            account_plan_uuid, current_date, tkey)
        if log_in_after_creation:
            self.authenticate(username, password, debug)
        return User(self.rest_interface.get_copy(), response)
コード例 #11
0
    def promote(self, debug=False):
        """Promote this version of the file and replace the current version.

        This function will throw an exception if called on a file that is not a previous version.
        Updates this file object to the promoted & current file.

        :return:                        Updated version of file.
        :raises SessionNotLinked:       CloudFSRESTAdapter is not authenticated.
        :raises AuthenticatedError:     Based on CloudFS Error Code.
        """
        if not self.old_version:
            raise operation_not_allowed('promote the current version of the file')
        set_debug(self, debug)

        version = self._get('version', None)
        if not version:
            raise ValueError('{} did not have a version field in its data dictionary!:{} \nDid we have a massive & breaking API change?'.format(str(self), self.data))

        response = self.rest_interface.promote_file_version(self.path(), version)
        self._initialize_self(response)
        self.old_version = False
        return self
コード例 #12
0
ファイル: container.py プロジェクト: iispokon/cfs-admin-api
    def create_folder(self, container_or_name, exists=ExistValues.fail, debug=False):
        """Create a new folder in this folder.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Create%20Folder.html

        :param container_or_name:   Container or String name. If arg is a Container, will use that Containers name.
        :param debug:               If true, will print the the request and response to stdout.

        :returns:       New folder object.
        :raises SessionNotLinked:       CloudFSRESTAdapter is not authenticated.
        :raises AuthenticatedError:     Based on CloudFS Error Code.
        """
        if self.in_share():
            raise operation_not_allowed("create folder in share")
        set_debug(self, debug)

        if isinstance(container_or_name, Item):
            container_or_name = container_or_name.name

        post_path = self.path()
        new_folder_response = self.rest_interface.create_folder(post_path, container_or_name, exists)
        print "new_folder_response: {}".format(new_folder_response)
        return create_items_from_json(self.rest_interface, new_folder_response, self.path(), self.in_trash)[0]
コード例 #13
0
ファイル: session.py プロジェクト: iispokon/cfs-admin-api
    def account_state(self, user_id, username=None, first_name=None, last_name=None, plan_code=None,
                      expiration_date=None, grace=None, ignore_otl=None, plan_transition=None,
                      debug=False):
        """
        :param user_id:
        :param username:
        :param first_name:
        :param last_name:
        :param plan_code:
        :param expiration_date:
        :param grace:
        :param ignore_otl:
        :param plan_transition:
        :param debug:
        :return:
        """
        if not self.admin_rest_interface:
            raise operation_not_allowed("Account updates without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

        return self.admin_rest_interface.account_state(user_id, username, first_name, last_name,
                                                       plan_code, expiration_date, grace, ignore_otl, plan_transition)
コード例 #14
0
ファイル: session.py プロジェクト: iispokon/cfs-admin-api
    def create_account(self, username, password, email=None, first_name=None, last_name=None,
                       account_plan_uuid=None, current_date=None,
                       log_in_after_creation=False, debug=False,
                       tkey=False):
        """Create a user account associated with your CloudFS account.

        Warning: This method is currently broken, and will almost certainly 500. If you're interested, or the method has
        since been fixed server side, call the method with force=true. The request format is not expected to change.

        Note: Although this method creates a User object - the session associated with the user is _not_ linked. You
        must authenticate it before using it.

        REST Documentation: https://www.bitcasa.com/cloudfs-api-docs/api/Create%20Account.html

        :param username:                Username for the user, must be at least 4 characters and less than 256 characters.
        :param password:                Password for the user, must be at least 6 characters and has no length limit.
        :param email:                   Email address for user. Optional.
        :param first_name:              Users' first name. Optional
        :param last_name:               Users' last name. Optional
        :param log_in_after_creation:   If True, will log into the created user account in this session. Optional, defaults to False.
        :param debug:                   If True, will print the the request and response to stdout.
        :return:                        Newly created User object.
        :raise OperationNotAllowed:
        """
        if not self.admin_rest_interface:
            raise operation_not_allowed("Account creation without admin credentials")

        if debug:
            self.admin_rest_interface.debug_requests(1)

        response = self.admin_rest_interface.create_account(username, password, email, first_name, last_name,
                                                            account_plan_uuid, current_date, tkey)
        if log_in_after_creation:
            self.authenticate(username, password, debug)
        return User(self.rest_interface.get_copy(),
                    response)
コード例 #15
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def over_storage_limit(self, new_otl_flag):
     raise operation_not_allowed('set over the limit flag')
コード例 #16
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def plan_display_name(self, new_plan):
     raise operation_not_allowed('Changing the a plan through the API')
コード例 #17
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def state_display_name(self, new_state_string):
     raise operation_not_allowed('set account state string')
コード例 #18
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def locale(self, new_locale):
     raise operation_not_allowed('set account locale')
コード例 #19
0
 def size(self, new_size):
     raise operation_not_allowed("Setting the size of an Item")
コード例 #20
0
 def extension(self, new_extension):
     raise operation_not_allowed("Setting extension directly instead of name")
コード例 #21
0
 def is_mirrored(self, new_mirrored_flag):
     raise operation_not_allowed("Setting if an Item is mirrored")
コード例 #22
0
 def state_id(self, new_state_id):
     raise operation_not_allowed('set account state id')
コード例 #23
0
 def state_string(self, new_state_string):
     raise operation_not_allowed('set account state string')
コード例 #24
0
 def id(self, new_id):
     raise operation_not_allowed('set account id')
コード例 #25
0
 def plan(self, new_plan):
     raise operation_not_allowed('Changing the a plan through the API')
コード例 #26
0
 def limit(self, new_quota):
     raise operation_not_allowed(
         'Setting the storage limit through the API')
コード例 #27
0
 def usage(self, new_usage):
     raise operation_not_allowed('Setting usage through the API')
コード例 #28
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def storage_limit(self, new_quota):
     raise operation_not_allowed('Setting the storage limit through the API')
コード例 #29
0
 def over_storage_limit(self, new_otl_flag):
     raise operation_not_allowed('set over the limit flag')
コード例 #30
0
 def created_at(self, new_created_at):
     raise operation_not_allowed('Setting a the time a user was created')
コード例 #31
0
 def type(self, new_type):
     raise operation_not_allowed("Setting the type of an Item")
コード例 #32
0
ファイル: user.py プロジェクト: buttcasa/ButtFS-Python
 def id(self, new_id):
     raise operation_not_allowed('Changing a users id')
コード例 #33
0
ファイル: file.py プロジェクト: iispokon/cfs-admin-api
 def size(self, new_size):
      raise operation_not_allowed("Setting the size of an Item")
コード例 #34
0
ファイル: user.py プロジェクト: buttcasa/ButtFS-Python
 def last_login(self, new_last_login):
     raise operation_not_allowed('Setting a users last login time')
コード例 #35
0
 def share_size(self, new_size):
     raise operation_not_allowed("Setting the size of a Share")
コード例 #36
0
 def id(self, new_id):
     raise operation_not_allowed("Setting the id of an Item")
コード例 #37
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def id(self, new_id):
     raise operation_not_allowed('set account id')
コード例 #38
0
ファイル: item.py プロジェクト: buttcasa/ButtFS-Python
 def is_mirrored(self, new_mirrored_flag):
     raise operation_not_allowed("Setting if an Item is mirrored")
コード例 #39
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def state_id(self, new_state_id):
     raise operation_not_allowed('set account state id')
コード例 #40
0
 def last_login(self, new_last_login):
     raise operation_not_allowed('Setting a users last login time')
コード例 #41
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def plan_id(self, new_plan_id):
     raise operation_not_allowed('set account plan id')
コード例 #42
0
 def username(self, new_username):
     raise operation_not_allowed('Changing a users username')
コード例 #43
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def storage_usage(self, new_usage):
     raise operation_not_allowed('Setting usage through the API')
コード例 #44
0
 def id(self, new_id):
     raise operation_not_allowed('Changing a users id')
コード例 #45
0
ファイル: account.py プロジェクト: gordillo/CloudFS-Python
 def session_locale(self, new_locale):
     raise operation_not_allowed('set session locale')
コード例 #46
0
 def plan_id(self, new_plan_id):
     raise operation_not_allowed('set account plan id')
コード例 #47
0
ファイル: user.py プロジェクト: buttcasa/ButtFS-Python
 def username(self, new_username):
     raise operation_not_allowed('Changing a users username')
コード例 #48
0
ファイル: item.py プロジェクト: buttcasa/ButtFS-Python
 def id(self, new_id):
     raise operation_not_allowed("Setting the id of an Item")
コード例 #49
0
ファイル: user.py プロジェクト: buttcasa/ButtFS-Python
 def created_at(self, new_created_at):
     raise operation_not_allowed('Setting a the time a user was created')
コード例 #50
0
ファイル: item.py プロジェクト: buttcasa/ButtFS-Python
 def type(self, new_type):
     raise operation_not_allowed("Setting the type of an Item")