Copyright (c) 2006-2014 MindTouch Inc.
This file and accompanying files are licensed under the MindTouch Master Subscription Agreement (MSA).
At any time, you shall not, directly or indirectly: (i) sublicense, resell, rent, lease, distribute, market, commercialize or otherwise transfer rights or usage to: (a) the Software, (b) any modified version or derivative work of the Software created by you or for you, or (c) MindTouch Open Source (which includes all non-supported versions of MindTouch-developed software), for any purpose including timesharing or service bureau purposes; (ii) remove or alter any copyright, trademark or proprietary notice in the Software; (iii) transfer, use or export the Software in violation of any applicable laws or regulations of any government or governmental agency; (iv) use or run on any of your hardware, or have deployed for use, any production version of MindTouch Open Source; (v) use any of the Support Services, Error corrections, Updates or Upgrades, for the MindTouch Open Source software or for any Server for which Support Services are not then purchased as provided hereunder; or (vi) reverse engineer, decompile or modify any encrypted or encoded portion of the Software.
A complete copy of the MSA is available at http://www.mindtouch.com/msa
Table of Contents
The RightScale API supports the use of a cookie/session. The first step in using the RightScale API is to login and get an authentication cookie which can then be used with subsequent requests within the session duration.
Note: API 1.0 uses GET (with HTTP Basic Authentication) and API 1.5 uses POST for authentication requests.
Login to get a session cookie:
#!/bin/sh -e RS_USER="email@example.com" RS_PASS="J3peleFoe983h" RS_ACCOUNT="1234" # login to API 1.0 curl -H 'X-API-VERSION:1.0' -c mySavedCookies -u $RS_USER:$RS_PASS https://my.rightscale.com/api/acct/$RS_ACCOUNT/login
Your session cookie should be saved now in the file, mySavedCookies, e.g.:
# Netscape HTTP Cookie File # http://curl.haxx.se/rfc/cookie_spec.html # This file was generated by libcurl! Edit at your own risk. #HttpOnly_.rightscale.com TRUE / FALSE 0 rs_gbl eNotkGtugkAUrX-lmWfHMMNwTZq0WBXxApJ6CS8Gh0HGchOGCBr_vZD27SRn7Z3s9QQhMEHWgRGIamA-QVOzCphIIwi9RkDQ_pYVpCiGQcgI8Kin6Rkbukx0iDGOIUIMQz0yVIiwjORIIhpV475PsP-sqqEh29cDvyNXZMeo9TqxV9P6C4tqTgIvEof9Dqs5vBVOXmysm_WdPKpuuTuK4n5nSqb-XEI4EzetObVHxHi7ho-FfEYosK9suAoE7qZ1Jd9r0Gd8N7RIDpY-61x1Ej9Ci5y4S9b6PLYKp7zr9nYqaY53Y1JJp-TC54d0ZVsdv55d3zmVnrYtp7h4H5S0g5I8zPopYJJUvH6bFVWUhFn_DCktmlwAUzOUfh7LQp4OdgZsHP9hHxW_JKKmYcrGtMjA6_UL_-ZxNA%3D%3D
Now the cookie file can be used with subsequent API calls, e.g. query a server:
# use the cookie to query server 223252001 curl -H 'X-API-VERSION:1.0' -b mySavedCookies https://my.rightscale.com/api/acct/$RS_ACCOUNT/servers/223252001
#! /bin/sh -e # rs-login.sh # by default API 1.0 is used unless rs_api_version=1.5 is set in env or ~/.rightscale/rs_api_config.sh # e.g. rs_api_config=1.5 rs-login.sh # References # http://support.rightscale.com/12-Guides/03-RightScale_API/RightScale_API_Examples/Authentication # http://reference.rightscale.com/api1.0/ApiR1V0/Docs/ApiLogins.html # http://support.rightscale.com/12-Guides/RightScale_API_1.5/Authentication # http://reference.rightscale.com/api1.5/index.html [ -e "$HOME"/.rightscale ] || ( mkdir -p "$HOME"/.rightscale && chmod -R 700 "$HOME"/.rightscale ) . "$HOME/.rightscale/rs_api_config.sh" . "$HOME/.rightscale/rs_api_creds.sh" # get and store the cookie if [ "$rs_api_version" = "1.5" ]; then url="https://my.rightscale.com/api/session" echo "[API 1.5] POST: $url" result=$(curl -s -S -v -H 'X_API_VERSION: 1.5' -c "$rs_api_cookie" -X POST -d email="$rs_api_user" -d password="$rs_api_password" -d account_href=/api/accounts/$rs_api_account_id "$url" 2>&1) else url="https://my.rightscale.com/api/acct/$rs_api_account_id/login?api_version=$rs_api_version" echo "[API 1.0] GET: $url" result=$(curl -s -S -v -c "$rs_api_cookie" -u "$rs_api_user":"$rs_api_password" "$url" 2>&1) fi case $result in *'204 No Content'*) echo 'Login successful.' exit ;; *) echo 'Login failed!' echo "$result" exit 1 ;; esac
Each one of your Ruby programs will need to include the wrapper code, and a few other lines of code to create a new object, set your user, password and account. Optionally, you can turn logging on or off. For example:
#!/usr/bin/ruby require 'RightAPI.rb' api = RightAPI.new api.log = true api.login(:username => 'user', :password => 'pass', :account => '1234')
Where username, password and account are substituted for their actual values.
|Glossary | 用語 | 용어||Site Map | Site Help||Community||Corporate Site||Get Support||Dashboard Login|
|Doc Feedback||Product Feedback||Resources||MultiCloud Marketplace||Forums|
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.