API 2.0: Unlock dataset

Joined
Feb 9, 2021
Messages
1
Hello all, let me start by acknowledging that there is a "solved" thread that touches on this subject, but it was not useful and its title is not ideal for the conversation.

Context
As the title explains, I am trying to unlock a dataset via the API 2.0--and it is not working. The documentation seems very confusing to me, but it may be inexperience understanding REST APIs.

I am playing around with some ideas that I think are cool, and for them I definitely need a passphrase-encrypted dataset and the ability to unlock it from the API.

Problem details

I'm trying to use the `https://my_server/api/v2.0/pool/dataset/unlock` endpoint, and having difficulties. Below is the code I'm using (removed checks and such for brevity), and I've also tried using curl.

Code:
{
import requests
import json

s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.headers.update({'Authorization': 'Bearer 1-**MY_API_TOKEN**'})

d = json.dumps({
            'id':'my_pool/my_dataset',
            'unlock_options' :
            {
                'recursive' : True,
                'datasets' :
                [
                    {'name' : 'my_pool/my_dataset'},
                    {'passphrase' : 'hello_world'}
                ]
            }
        })

r = s.post('https://alexandria/api/v2.0/pool/dataset/unlock'
        , verify=False
        , data=d)
}


I get a status code of 200, and the body contains some number (e.g., 600) that increases every time I try to run this endpoint. As long as I keep the structure of the json valid (keys are expected keys), I can fill the rest with any garbage and I get the same result.



Thoughts

I don't use REST very much, but it seems quite strange to me that i get a 200 code and absolutely nothing happens; I don't even get any feedback on why nothing happens.

I also find it weird that I had to go into the code to actually understand how I am supposed to structure the body to put my passphrase and such--the documentation was useless here. Again, maybe for REST users it is sufficient. Is the API stable for general use? Should I not be using it?

I appreciate any thoughts on this issue, or generally on why the API seems so...unhelpful to me (am I doing something wrong).

Thank you for reading and any thought you may put into this!
 

arnaudf

Cadet
Joined
Feb 21, 2021
Messages
2
Hello

In case you did not fixed it yet, you just need to fix dataset declaration to get it work. /var/log/middlewared.log helped me to find why it didn't work with your code.

From

Code:
                [
                    {'name' : 'my_pool/my_dataset'},
                    {'passphrase' : 'hello_world'}
                ]


To

Code:
                [
                    {'name' : 'my_pool/my_dataset' , 'passphrase' : 'hello_world'}
                ]
 

mjb2000

Cadet
Joined
Oct 21, 2018
Messages
2
I am looking to achieve something similar. But instead of unlocking using the passphrase I was hoping to unlock using the recovery key.

You can see what I used to be doing with API 1.0 here:

I read that with API 2.0 the recover key needs to be uploaded to the "/_uploads/" target.

Can anyone explain how I do this and what should the file be called in order for the unlock API to correctly work out which file is for unlocking which volume?
 

joulester

Cadet
Joined
Sep 20, 2020
Messages
2
Did you guys solve this? If so can your share some more details how I do not have the experience to solve it by myself.
 
Top