softlayer_api 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c592fff0c34d44716f474b0101d6d95869bd484
4
- data.tar.gz: e42665ad820a87205f408bf4dff68e5ae2542f46
3
+ metadata.gz: 4c73f2b12af46498006541c8898db5c29b3562ba
4
+ data.tar.gz: da5403993f736e9bbf05e7dda4a562d5842afcae
5
5
  SHA512:
6
- metadata.gz: 27b24d2c5edd44cd8c0c01f17bd71b599991ee82450e6d282e574b08ea51960c005cbed42f4aecb0ffa4f65bef2b0c4f78f4a3dfc2584b835ca093f9509725ce
7
- data.tar.gz: db3326f41a4a44f9ed30c53166eae2f99df8cb5ff4d4c0ee823f7099d0c4603bfbaf5ca4f1166e075691e38cafd10051facf9644cc743059eb43802a3a458a08
6
+ metadata.gz: fe6197aaaa63ad39770212e301cd2a521c83560012118279d418e4520b1c819bf512ee2e2233746d3a38ee9a6179411cc0e69362ba48717b1a262d47de99a8fa
7
+ data.tar.gz: a23c7baf765f5da9a19a1da6e10c50ade0e98a4015bc884cb42631b0d77734807c26aef5bb1292091e7cac849e548cc765939dfa053c7c30b6a96b3f71951588
@@ -1,3 +1,6 @@
1
+ *3.2*
2
+ * Add password-based authentication with `SoftLayer::Client.with_password(username: '...', password: '...', ...)`.
3
+
1
4
  *3.0*
2
5
  * 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.
3
6
  * 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
@@ -58,6 +58,32 @@ module SoftLayer
58
58
  @@default_client = new_default
59
59
  end
60
60
 
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
+
61
87
  ##
62
88
  #
63
89
  # Clients are built with a number of settings:
@@ -76,10 +102,14 @@ module SoftLayer
76
102
  settings = Config.client_settings(options)
77
103
 
78
104
  # pick up the username from the options, the global, or assume no username
79
- @username = settings[:username] || ""
105
+ @username = settings[:username]
80
106
 
81
107
  # 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]
83
113
 
84
114
  # and the endpoint url
85
115
  @endpoint_url = settings[:endpoint_url] || API_PUBLIC_ENDPOINT
@@ -90,19 +120,39 @@ module SoftLayer
90
120
  # and assign a time out if the settings offer one
91
121
  @network_timeout = settings[:timeout] if settings.has_key?(:timeout)
92
122
 
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?
95
123
  raise "A SoftLayer Client requires an endpoint URL" if !@endpoint_url || @endpoint_url.empty?
96
124
  end
97
125
 
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
+
98
136
  # return a hash of the authentication headers for the client
99
137
  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
+ }
104
145
  }
105
- }
146
+ elsif key_based?
147
+ {
148
+ 'authenticate' => {
149
+ 'username' => @username,
150
+ 'apiKey' => @api_key
151
+ }
152
+ }
153
+ else
154
+ {}
155
+ end
106
156
  end
107
157
 
108
158
  # Returns a service with the given name.
@@ -12,7 +12,7 @@ require 'rubygems'
12
12
  module SoftLayer
13
13
  # The version number (including major, minor, and bugfix numbers)
14
14
  # This should change in accordance with the concept of Semantic Versioning
15
- VERSION = "3.1.1" # 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
16
16
 
17
17
  # The base URL of the SoftLayer API available to the public internet.
18
18
  API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softlayer_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SoftLayer Development Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configparser