Need clarification on creation of V3 credentials

Asked by Harika Vakadi

While I was trying to create V3 credentials below was the issue faced

curl -i -X POST http://10.4.230.133:35357/v3/credentials -H "User-Agent: python-keystoneclient" -H "Content-Type: application/json" -H "X-Auth-Token: <token-omitted>" -d'{"credential": {"user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "blob": {"access": "bdd3ed90edee4cbf91d1ecdfc46", "secret": "47154b6378eb4b8685f75e4936e22"}, "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}'
HTTP/1.1 400 Bad Request
Vary: X-Auth-Token
Content-Type: application/json
Content-Length: 89
Date: Wed, 28 Aug 2013 11:26:57 GMT

{"error": {"message": "Invalid blob in credential", "code": 400, "title": "Bad Request"}}

Request body I used to create is as below

body = {"credential": {"user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "blob": {"access": "bdd3ed90edee4cbf91d1ecdfc46", "secret": "47154b6378eb4b8685f75e4936e22"}, "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}

But this reference Doc (https://github.com/openstack/identity-api/blob/master/openstack-identity-api/v3/src/markdown/identity-api-v3.md) says request to like this

Request:
{
    "credential": {
        "blob": "--JSON serialized object containing 'access' and 'secret'--",
        "project_id": "--optional--",
        "type": "ec2",
        "user_id": "--user--id--"
    }
}

Can anyone please correct me if I am wrong. ASAP.

Thanks in Advance,
Harika.

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Identity (keystone) Edit question
Assignee:
No assignee Edit question
Solved by:
Haneef Ali
Solved:
Last query:
Last reply:
Revision history for this message
Haneef Ali (haneef) said :
#1

blob = json serialized string . Someting like blob: " { "acess" : ,,, , "secret": "xxxx"}"

(i.e) blob = Within quotes some strng which is in json format. What you have is

Revision history for this message
Harika Vakadi (harika-vakadi) said :
#2

Thanks for your quick response Haneef

I have tried according to your suggestion, but resulted in error again.

Command I have tried is as below

curl -i -X POST http://10.4.230.133:35357/v3/credentials -H "User-Agent: python-keystoneclient" -H "Content-Type: application/json" -H "X-Auth-Token: <token-omitted>" -d'{"credential": { "blob": "{"access": ,,, , "secret": "Secret-"}", "user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}'
HTTP/1.1 400 Bad Request
Vary: X-Auth-Token
Content-Type: application/json
Content-Length: 244
Date: Thu, 29 Aug 2013 10:36:06 GMT

{"error": {"message": "Expecting to find valid JSON in request body. The server could not comply with the request since it is either malformed or otherwise incorrect. The client is assumed to be in error.", "code": 400, "title": "Bad Request"}}

Other Request bodies I have tried are as below

---- {"credential": {"blob": '\{\"access\": \"acceskey\", \"secret\": \"Secret\"\}', "user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}

---- {"credential": {"blob": "\{\"access\": \"acceskey\", \"secret\": \"Secret\"\}", "user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}

---- {"credential": {"blob": "\\{\\"access\\": \\"acceskey\\", \\"secret\\": \\"Secret\\"\\}", "user_id": "64d29e5d86f84440bdd8948ce81a5ae7", "project_id": "f06ea93f31be40f991154a63dedbf300", "type": "ec2"}}

Can you please correct me if I am wrong.

Thanks in advance,
Harika

Revision history for this message
Best Haneef Ali (haneef) said :
#3

from the code

try:
                blob = json.loads(ref.get('blob'))
 except (ValueError, TypeError):

So basically when you construct the request try to load the blob from the request. If it works then request to keystone will also work

do the following in a small python program

cred = {}
cred["credential" = {}
cred["credential"]["type"] = "ec2"
cred["credential"]["user_id"] = < user id>
cred["credential"]["poject_id"] = < project id>

blob = {}
blob["access"] = "some key"
blob["secret" ] = "some key"

cred["credential"]["blob"] = json.dumps(blob)

print cred

You can use this output. If you are using via curl make sure you escape every place. I believe you only need to escape inner quotes. Something like

{"a": 1, "blob": "{\"b\": \"1\"}"}

Revision history for this message
Harika Vakadi (harika-vakadi) said :
#4

Thanks Haneef Ali, that solved my question.