Gandi Wiki


Questions

Table des matières

Session methods

login

Signature

string login(string login, string password [, boolean safe])

Description

Log in to the XML-RPC interface and retrieve a session id.

Note :

Sessions ID are sensitive information and therefore must be kept secret. If a session ID was to be disclosed a malicious user would be able to execute commands with your credentials during 12 hours.

Parameters

  • string login: the user login
  • string password: the user password

Optional parameter

  • boolean safe: whether or not log in safe mode. Be sure to understand what you are doing before setting it to False.
    • True: Default. Log in safe mode. You will need to su.
    • False: Do not log in safe mode.

Returns

The XML-RPC response will contain a session id (string) if the login procedure is successful or a fault describing the problem. Possible faults are described in section Error Codes Format.

Sample code

  • Python logging in with safe mode
import sys 
import xmlrpclib
proxy  = xmlrpclib.ServerProxy("https://api.gandi.net/xmlrpc/")
try:
    session  = proxy.login("AA1234-GANDI", "mypassword", True)
except xmlrpclib.Fault, e:
    print "could not login because: " + e.faultString
    sys.exit(67)
  • Php logging in with safe mode
<?php
require_once("xmlrpc.inc");
 
$proxy  = new xmlrpc_client("https://api.gandi.net/xmlrpc/");
$msg  = new xmlrpcmsg(
    "login",
    array(new xmlrpcval("AA1234-GANDI"),
    new xmlrpcval("mypassword"),
    new xmlrpcval(True, "boolean"))
);
 
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    echo "could not login because: " . $reply->faultString() . "\n";
    exit(67);
}
$session  = $reply->value();
?>
  • perl logging in with safe mode
my $safe_mode  = XMLRPC::Data->type('boolean')->value(1);
my $proxy  = XMLRPC::Lite->proxy("https://api.gandi.net/xmlrpc/");
my $reply  = $proxy->call("login", "AA1234-GANDI", "mypassword", $safe_mode);
my $session  = $reply->result();
 
die "could not login because: " . $reply->faultstring . "\n" unless defined $session;



su

Signature

string su(string session, string handle)

Description

Temporarily limit your rights to the rights of user "handle". cf. safe mode.

Note :

Sessions ID are sensitive information and therefore must be kept secret. If a session ID was to be disclosed a malicious user would be able to execute commands with your credentials during 12 hours.

Parameters

  • string session: the session
  • string handle: the handle to set your rights to

Returns

The XML-RPC response will contain a new session id (string) if the "su" is successful or a fault describing the problem. Possible faults are described in section Error Codes Format.

Sample code

  • Sample code (python)
try:
    session = proxy.su(session, "AA4321-GANDI")
except xmlrpclib.Fault, e:
    print "could not su to user AA4321-GANDI because: " + e.faultString
    sys.exit(67)
  • Sample code (php)
<?php
$msg  = new xmlrpcmsg(
    "su",
    array($session, new xmlrpcval("AA4321-GANDI"))
);
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    echo "could not su to user AA4321-GANDI because: " . $reply->faultString() . "\n";
    exit(67);
}
$session  = $reply->value();
?>
  • Sample code (perl)
my $reply  = $proxy->call("su", $session, "AA4321-GANDI");
my $session  = $reply->result();
die "could not su to user AA4321-GANDI because: " . $reply->faultstring . "\n" unless defined $session;



password

Signature

boolean password(string session, string password)

Description

Change the XML-RPC API password of the account used during the login procedure.

Parameters

  • string session: the session
  • string password: the new password

Returns

The XML-RPC response will return True if the password method is successful or a fault describing the problem. Possible faults are described in section Error Codes Format

Sample code

  • Sample code (python)
try:
    proxy.password(session, "mynewpassword")
except xmlrpclib.Fault, e:
    print "could not change the password because: " + e.faultString
    sys.exit(67)
  • Sample code (php)
<?php
$msg  = new xmlrpcmsg(
    "password",
    array($session, new xmlrpcval("mynewpassword"))
);
$reply  = $proxy->send($msg);
if ($reply->faultCode()) {
    echo "could not change the password because: " . $reply->faultString() . "\n";
    exit(67);
}
?>
  • Sample code (perl)
my $reply  = $proxy->call("password", $session, "mynewpassword");
my $result  = $reply->result();
die "could not change the password because: " . $reply->faultstring . "\n" unless defined $result;

Questions

Flux RSS des questions correspondant à ce filtre (Aide)

Dernière modification: le 03/03/2008 à 15:34 par Nicolas L. (Gandi)