Beispiel #1
0
        def validate_access_key():
            # Obtain access key
            try:
                access_key = self.cleaned_data['access_key']
            except KeyError:
                raise forms.ValidationError("Access key is missing.")

            # Validate access key
            try:
                user_data = UserData.from_key(access_key)
            except InvalidUserKeyError:
                raise forms.ValidationError("Invalid access key.")

            # Check if this access key has access to given volume
            user_sx = SXController(cluster, user_data)
            full_path = self.cleaned_data['path']
            volume, path = core.split_path(full_path)
            with timeout(error_message=""
                         "ShareFileForm.clean.validate_access_key: "
                         "File listing timed out."):
                try:
                    user_sx.listFiles.json_call(volume, path)
                except SXClusterClientError:
                    raise forms.ValidationError("Provide a valid access key. "
                                                "Make sure you have access to "
                                                "the file you want to share.")
Beispiel #2
0
 def _get_user_data(self, conf):
     if 'admin_key' in conf:
         return UserData.from_key(conf['admin_key'])
     elif 'admin_key_path' in conf:
         return UserData.from_key_path(conf['admin_key_path'])
     else:
         raise ValueError(
             "You must provide either 'admin_key' or 'admin_key_path' "
             "in the sx config.")
Beispiel #3
0
 def _get_user_data(self, conf):
     if 'admin_key' in conf:
         return UserData.from_key(conf['admin_key'])
     elif 'admin_key_path' in conf:
         return UserData.from_key_path(conf['admin_key_path'])
     else:
         raise ValueError(
             "You must provide either 'admin_key' or 'admin_key_path' "
             "in the sx config.")
Beispiel #4
0
def get_user_volumes(username):
    key = get_user_key(username)
    user_sx = SXController(sx._sx.cluster, UserData.from_key(key))
    volumes = user_sx.listVolumes.json_call(includeMeta=True,
                                            includeCustomMeta=True)
    return volumes