Ejemplo n.º 1
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.")
Ejemplo n.º 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.")
Ejemplo n.º 3
0
def test_from_userpass_pair(credentials):
    expected = (
        b'\x0b\xee\xc7\xb5\xea?\x0f\xdb\xc9]\r\xd4\x7f<[\xc2u\xda\x8a3' +
        b'|T8\xa2\xd5\xa6\xf1\x08\xb6%\x82\x15\x9d\xbc\xbd\xb7g\x17\xa0\xfc' +
        b'\x00\x00')
    user_data = UserData.from_userpass_pair(*credentials)
    assert user_data.key == expected
Ejemplo n.º 4
0
def test_create_key(api):
    username = '******'
    password = '******'
    key = UserData.from_userpass_pair(username, password,
                                      api.get_cluster_uuid()).key
    key = key[20:40].encode('hex')
    assert core.create_key(username, password) == key
Ejemplo n.º 5
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.")
Ejemplo n.º 6
0
def create_key(email, password):
    """Convert given data to a sx-usable auth key."""
    uuid = api.get_cluster_uuid()
    key = UserData.from_userpass_pair(email, password, uuid).key
    return key[20:40].encode('hex')  # Return private part only
Ejemplo n.º 7
0
def create_key(email, password):
    """Convert given data to a sx-usable auth key."""
    uuid = api.get_cluster_uuid()
    key = UserData.from_userpass_pair(email, password, uuid).key
    return key[20:40].encode('hex')  # Return private part only
Ejemplo n.º 8
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