zoukankan      html  css  js  c++  java
  • Keystone V3 API Examples

    There are few things more useful than a set of examples when starting to work with a new API. Here are some I’ve started collecting up for my work:

    The first of three articles: More. Policy

    Get a token. This user has the role ‘admin’ in a project, which means they can execute admin operations.
    Save the following in a file named token-request.json

    {
        "auth": {
            "identity": {
                "methods": [
                    "password"
                ],
                "password": {
                    "user": {
                        "domain": {
                            "name": "Default"
                        },
                        "name": "admin",
                        "password": "freeipa4all"
                    }
                }
            },
            "scope": {
                "project": {
                    "domain": {
                        "name": "Default"
                    },
                    "name": "demo"
                }
            }
        }
    }
     

    And execute it with

    export TOKEN=`curl -si -d @token-request.json -H "Content-type: application/json" http://localhost:35357/v3/auth/tokens | awk '/X-Subject-Token/ {print $2}'`
     

    To list domains

    curl -si -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/domains
     

    Create a domain

    curl  -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" -d '{"domain": {"description": "--optional--", "enabled": true, "name": "dom1"}}'  http://localhost:35357/v3/domains
     

    To list users

    curl -si -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/users

    To create a users, create file named create_user.json file like this:

    { 
        "user": { 
               "default_project_id": "d0f445c3379b48f38a2ab0f17314bbf9", 
                "description": "Description", 
                "domain_id": "default",
                "email": "ayoung@redhat.com", 
                "enabled": true, 
                "name": "ayoung", 
                "password": "changeme" } 
    }

    Execute it like this

    curl -si -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/users -d @create_user.json
     

    The response should look like this, with different auto-generated IDs.

    {"user": {"description": "Description", "links": {"self": "http://192.168.0.2:5000/v3/users/8221b007376a40ce8459c05f90077f16"}, "enabled": true, "email": "ayoung@redhat.com", "default_project_id": "d0f445c3379b48f38a2ab0f17314bbf9", "id": "8221b007376a40ce8459c05f90077f16", "domain_id": "default", "name": "ayoung"}}
     

    Note that in the above case the new user_id is 8221b007376a40ce8459c05f90077f16. Use that to get the user directly:

    $ curl  -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json"   http://localhost:35357/v3/users/8221b007376a40ce8459c05f90077f16
    {"user": {"name": "ayoung", "links": {"self": "http://192.168.0.2:5000/v3/users/8221b007376a40ce8459c05f90077f16"}, "enabled": true, "email": "ayoung@redhat.com...", "default_project_id": "d0f445c3379b48f38a2ab0f17314bbf9", "id": "8221b007376a40ce8459c05f90077f16", "domain_id": "default", "description": "Description"}}

    To figure out how to do additional operations, see the V3 Identity API.

    From: http://adam.younglogic.com/2013/09/keystone-v3-api-examples/

    博客地址: http://www.cnblogs.com/dwf07223,本文以学习、研究和分享为主,欢迎转载,转载请务必保留此出处。若本博文中有不妥或者错误处请不吝赐教。

  • 相关阅读:
    【java】JDBC连接MySQL
    【java】网络socket编程简单示例
    【java】对象序列化Serializable、transient
    【java】扫描流Scanner接收输入示例
    【java】缓冲字符字节输入输出流:java.io.BufferedReader、java.io.BufferedWriter、java.io.BufferedInputStream、java.io.BufferedOutputStream
    【java】System成员输入输出功能out、in、err
    33-Java中的String,StringBuilder,StringBuffer三者的区别
    5-Error:failed to find Build Tools revision 28.0.0 rc1解决方案
    46-wxpython 4 使用 grid 展示表格
    45-暴力密码字典
  • 原文地址:https://www.cnblogs.com/dwf07223/p/5720017.html
Copyright © 2011-2022 走看看