Skip to content

Commit 47755f0

Browse files
Scott ThompsonScott Thompson
authored andcommitted
merging in changes for the 3.1 release
2 parents d11058e + c2301ce commit 47755f0

7 files changed

Lines changed: 105 additions & 50 deletions

File tree

CHANGELOG.textile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
*3.2*
2+
* Add password-based authentication with `SoftLayer::Client.with_password(username: '...', password: '...', ...)`.
3+
14
*3.1.0*
25
* Many SoftLayer Attributes are now shadowed with snake_case names. The old CamelCase versions are deprecated and will be removed in the next major release
36
* New functionality related to network monitoring has been added
7+
48
*3.0*
59
* Substantially rewrote the ObjectFilter class. ObjectFilters used to be hashes which made it easy to manipulate their content incorrectly. The new implementation has a strict interface that makes it harder to manipulate filters incorrectly.
610
* Added a model for Virtual Server Image Templates (SoftLayer::ImageTemplate) - VirtualServerOrder now requires an instance of this class rather than allowing you to provide the global_id of an image

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This will create a new folder named `doc` inside of the project source and popul
2424

2525
This software is written by the SoftLayer Development Team [sldn@softlayer.com](mailto:sldn@softlayer.com).
2626

27-
Please join us in the [SoftLayer Developer Network forums](http://forums.softlayer.com/forum/softlayer-developer-network)
27+
Please join us at [Stack Overflow](https://stackoverflow.com/). Stack Overflow Best Practices Tip: Tag your posts with “SoftLayer” so our team can easily find your post.
2828

2929
# Contributer License Agreement
3030

doc_src/Welcome.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Welcome
22

3-
The `softlyer_api` Ruby Gem provides a convenient way to call into the SoftLayer API from the Ruby programming language. This is accomplished using the XML-RPC interface provided by SoftLayer and the XMLRPC client built into the core Ruby language.
3+
The `softlayer_api` Ruby Gem provides a convenient way to call into the SoftLayer API from the Ruby programming language. This is accomplished using the XML-RPC interface provided by SoftLayer and the XMLRPC client built into the core Ruby language.
44

55
For more information about the SoftLayer API, and the routines and data structures it offers should visit the [SoftLayer Developer Network (SLDN) website](http://sldn.softlayer.com).
66

@@ -20,4 +20,4 @@ The Model layer is built atop the foundation as object class hierarchy. The clas
2020

2121
The Model layer is by no means complete; quite to the contrary it is in its infancy and we believe that much of the development effort in the Gem will focus on incorporating new models into this layer. Because it is incomplete, however, we have put some effort into bridges from the functionality of the model, down to the lower level foundation, without trouble. Also, as a result of this, developers interested in using the Model layer should also should familiarize themselves with the Foundation.
2222

23-
All developers should continue their exploration of the `softlayer_api` gem by examining the Foundation documentation. Clients that wish to make use of the abstractions provided in the object hierarchy may continue their exploration by looking at the Model Layer documentation. Developers who wish to expand the models found in the `softlayer_api` Gem should read the [Contribution Guide](ContributionGuide_md.html)
23+
All developers should continue their exploration of the `softlayer_api` gem by examining the Foundation documentation. Clients that wish to make use of the abstractions provided in the object hierarchy may continue their exploration by looking at the Model Layer documentation. Developers who wish to expand the models found in the `softlayer_api` Gem should read the [Contribution Guide](ContributionGuide_md.html)

lib/softlayer/Client.rb

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ def self.default_client=(new_default)
5858
@@default_client = new_default
5959
end
6060

61+
##
62+
# This will be using your username and password to get a portal
63+
# token with which to authenticate client calls.
64+
# This is a wrapper around Client.new. You can pass it the same
65+
# parameters as with Client.new, with the exception that this will
66+
# be expecting a password in the options hash.
67+
def self.with_password(options = {})
68+
if options[:username].nil? || options[:username].empty?
69+
raise 'A username is required to create this client'
70+
end
71+
72+
if options[:password].nil? || options[:password].empty?
73+
raise 'A password is required to create this client'
74+
end
75+
76+
service = SoftLayer::Service.new('SoftLayer_User_Customer')
77+
token = service.getPortalLoginToken(
78+
options[:username], options[:password]
79+
)
80+
81+
options[:userId] = token['userId']
82+
options[:authToken] = token['hash']
83+
84+
SoftLayer::Client.new(options)
85+
end
86+
6187
##
6288
#
6389
# Clients are built with a number of settings:
@@ -76,10 +102,14 @@ def initialize(options = {})
76102
settings = Config.client_settings(options)
77103

78104
# pick up the username from the options, the global, or assume no username
79-
@username = settings[:username] || ""
105+
@username = settings[:username]
80106

81107
# do a similar thing for the api key
82-
@api_key = settings[:api_key] || ""
108+
@api_key = settings[:api_key]
109+
110+
# grab token pair
111+
@userId = settings[:userId]
112+
@authToken = settings[:authToken]
83113

84114
# and the endpoint url
85115
@endpoint_url = settings[:endpoint_url] || API_PUBLIC_ENDPOINT
@@ -90,19 +120,39 @@ def initialize(options = {})
90120
# and assign a time out if the settings offer one
91121
@network_timeout = settings[:timeout] if settings.has_key?(:timeout)
92122

93-
raise "A SoftLayer Client requires a username" if !@username || @username.empty?
94-
raise "A SoftLayer Client requires an api_key" if !@api_key || @api_key.empty?
95123
raise "A SoftLayer Client requires an endpoint URL" if !@endpoint_url || @endpoint_url.empty?
96124
end
97125

126+
# return whether this client is using token-based authentication
127+
def token_based?
128+
@userId && @authToken && !@authToken.empty?
129+
end
130+
131+
# return whether this client is using api_key-based authentication
132+
def key_based?
133+
@username && !@username.empty? && @api_key && !@api_key.empty?
134+
end
135+
98136
# return a hash of the authentication headers for the client
99137
def authentication_headers
100-
{
101-
"authenticate" => {
102-
"username" => @username,
103-
"apiKey" => @api_key
138+
if token_based?
139+
{
140+
'authenticate' => {
141+
'complexType' => 'PortalLoginToken',
142+
'userId' => @userId,
143+
'authToken' => @authToken
144+
}
104145
}
105-
}
146+
elsif key_based?
147+
{
148+
'authenticate' => {
149+
'username' => @username,
150+
'apiKey' => @api_key
151+
}
152+
}
153+
else
154+
{}
155+
end
106156
end
107157

108158
# Returns a service with the given name.

lib/softlayer/ProductItemCategory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module SoftLayer
1414
# DEPRECATION WARNING: The following configuration option keys have been deprecated and
1515
# will be removed with the next major version: capacityRestrictionMaximum, capacityRestrictionMinimum,
1616
# capacityRestrictionType, hourlyRecurringFee, laborFee, oneTimeFee, recurringFee, requiredCoreCount, setupFee
17-
class ProductConfigurationOption < Struct.new(:capacity, :capacityRestrictionMaximum, :capicity_restriction_maximum,
17+
class ProductConfigurationOption < Struct.new(:capacity, :capacityRestrictionMaximum, :capacity_restriction_maximum,
1818
:capacityRestrictionMinimum, :capacity_restriction_minimum, :capacityRestrictionType, :capacity_restriction_type,
1919
:description, :hourlyRecurringFee, :hourly_recurring_fee, :laborFee, :labor_fee, :oneTimeFee, :one_time_fee,
2020
:price_id, :recurringFee, :recurring_fee, :requiredCoreCount, :required_core_count, :setupFee, :setup_fee, :units)

lib/softlayer/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
module SoftLayer
1313
# The version number (including major, minor, and bugfix numbers)
1414
# This should change in accordance with the concept of Semantic Versioning
15-
VERSION = "3.1.0" # version history in the CHANGELOG.textile file at the root of the source
15+
VERSION = "3.2.0" # version history in the CHANGELOG.textile file at the root of the source
1616

1717
# The base URL of the SoftLayer API available to the public internet.
1818
API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'

spec/Client_spec.rb

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,43 @@
4141
expect(client.api_key).to eq 'fake_key'
4242
end
4343

44-
it 'raises an error if passed an empty user name' do
45-
expect do
46-
$SL_API_USERNAME = ''
47-
client = SoftLayer::Client.new(:api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
48-
end.to raise_error
49-
50-
expect do
51-
$SL_API_USERNAME = 'good_username'
52-
$SL_API_KEY = 'sample'
53-
client = SoftLayer::Client.new(:username => '', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
54-
end.to raise_error
55-
end
56-
57-
it 'fails if the user name is nil' do
58-
expect do
59-
$SL_API_USERNAME = nil
60-
client = SoftLayer::Client.new(:username => nil, :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
61-
end.to raise_error
62-
end
63-
64-
it 'fails if the api_key is empty' do
65-
expect do
66-
$SL_API_KEY = ''
67-
client = SoftLayer::Client.new(:username => 'fake_user', :endpoint_url => 'http://fakeurl.org/')
68-
end.to raise_error
69-
70-
expect do
71-
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => '', :endpoint_url => 'http://fakeurl.org/')
72-
end.to raise_error
73-
end
74-
75-
it 'fails if the api_key is nil' do
76-
expect do
77-
$SL_API_KEY = nil
78-
client = SoftLayer::Client.new(:username => 'fake_user', :endpoint_url => 'http://fakeurl.org/', :api_key => nil)
79-
end.to raise_error
44+
it 'produces empty auth headers if the username is empty' do
45+
46+
$SL_API_USERNAME = ''
47+
client = SoftLayer::Client.new(:api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
48+
49+
expect(client.authentication_headers.empty?).to be true
50+
51+
$SL_API_USERNAME = 'good_username'
52+
$SL_API_KEY = 'sample'
53+
client = SoftLayer::Client.new(:username => '', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
54+
55+
expect(client.authentication_headers.empty?).to be true
56+
end
57+
58+
it 'produces empty auth headers if the username is nil' do
59+
$SL_API_USERNAME = nil
60+
client = SoftLayer::Client.new(:username => nil, :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
61+
62+
expect(client.authentication_headers.empty?).to be true
63+
end
64+
65+
it 'produces empty auth headers if the api_key is empty' do
66+
$SL_API_KEY = ''
67+
client = SoftLayer::Client.new(:username => 'fake_user', :endpoint_url => 'http://fakeurl.org/')
68+
69+
expect(client.authentication_headers.empty?).to be true
70+
71+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => '', :endpoint_url => 'http://fakeurl.org/')
72+
73+
expect(client.authentication_headers.empty?).to be true
74+
end
75+
76+
it 'produces empty auth headers if the api_key is nil' do
77+
$SL_API_KEY = nil
78+
client = SoftLayer::Client.new(:username => 'fake_user', :endpoint_url => 'http://fakeurl.org/', :api_key => nil)
79+
80+
expect(client.authentication_headers.empty?).to be true
8081
end
8182

8283
it 'initializes by default with nil as the timeout' do

0 commit comments

Comments
 (0)