这是 Perl 中的一个基本示例,展示了如何创建 Rally 用户。需要以下 Perl 模块:
- REST::客户端
- JSON
- MIME::Base64
我在 Ubuntu 12.04 上使用 v5.14.2 对此进行了测试。
use strict;
use warnings;
# Needed includes
use REST::Client;
use JSON;
use MIME::Base64;
use URI;
use URI::Split;
# User parameters
# Must be a Rally Subscription Administrator, or a Workspace Administrator
# in a Rally Workspace whose Workspace Admins have been granted user administration
# privileges
my $username='user@company.com';
my $password='topsecret';
# Rally connection parameters
my $base_url="https://rally1.rallydev.com";
my $wsapi_version = "1.43";
# Connect to Rally and create user
# ====================================
my $headers = {
Accept => 'application/json',
Authorization => 'Basic ' . encode_base64($username . ':' . $password)
};
# instantiate REST Client
my $rest_client = REST::Client->new();
# set host
$rest_client->setHost($base_url);
# Formulate POST request to create user
# Note that the a Rally User must have at least one Workspace Permission / Project Permission
# pair. Thus the user will be given User Permissions in the Default Workspace of the
# Subscription or Workspace Administrator whose RallyID is used to run this script.
# The user will receive Viewer-level permissions to the alphabetically
# First project in the Default Workspace of the Rally UserID used to run the script
my $new_rally_user_id = 'user12@company.com';
print "Connecting to Rally and attempting to create user of UserID: \n";
print $new_rally_user_id . "\n\n";
my $wsapi_endpoint = "/slm/webservice/" . $wsapi_version . "/";
my $user_create_endpoint = $wsapi_endpoint . "user/create.js";
my $user_post_body = '{"User": {"UserName": "' . $new_rally_user_id . '", "EmailAddress": "' . $new_rally_user_id . '"}}';
print "POST Body for user creation:\n";
print $user_post_body . "\n\n";
# Attempt Create
$rest_client->POST($user_create_endpoint, $user_post_body, $headers);
# Output JSON Response
print "Create Response:\n\n";
print $rest_client->responseContent();
这是运行脚本的结果:
$ perl rally_create_user.pl
Connecting to Rally and attempting to create user of UserID:
user12@company.com
POST Body for user creation:
{"User": {"UserName": "user12@company.com", "EmailAddress": "user12@company.com"}}
Create Response:
{ "CreateResult" : { "Errors" : [ ],
"Object" : { "Boolean" : null,
"CUF" : null,
"CostCenter" : "None",
"CreationDate" : "2013-07-11T22:49:00.056Z",
"Date" : null,
"Department" : "None",
"Disabled" : false,
"DisplayName" : null,
"Editable" : null,
"EmailAddress" : "user12@company.com",
"FirstName" : null,
"LandingPage" : "/dashboard",
"LastLoginDate" : null,
"LastName" : null,
"LastPasswordUpdateDate" : "2013-07-11T22:49:00.056Z",
"MiddleName" : null,
"NetworkID" : null,
"ObjectID" : 12345678913,
"OfficeLocation" : "None",
"OnpremLdapUsername" : null,
"Phone" : null,
"RevisionHistory" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/revisionhistory/12345678915.js",
"_type" : "RevisionHistory"
},
"Role" : "None",
"ShortDisplayName" : null,
"Specialty" : null,
"String" : null,
"Subscription" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/subscription/12345678914.js",
"_refObjectName" : "My Subscription",
"_type" : "Subscription"
},
"SubscriptionAdmin" : false,
"TeamMemberships" : [ ],
"Text" : null,
"UserName" : "user12@company.com",
"UserPermissions" : [ { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/workspacepermission/12345678917u12345678918w3.js",
"_refObjectName" : "My Workspace User",
"_type" : "WorkspacePermission"
},
{ "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/projectpermission/12345678919u12345678920p1.js",
"_refObjectName" : "A Project",
"_type" : "ProjectPermission"
}
],
"UserProfile" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/userprofile/12345678921.js",
"_type" : "UserProfile"
},
"_CreatedAt" : "just now",
"_objectVersion" : "2",
"_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/user/12345678922.js",
"_refObjectName" : "user12",
"_type" : "User",
"yesno" : null
},
"Warnings" : [ "API status is Deprecated and will become Not Supported on 2014-Jun-20" ],
"_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43"