@@ -102,10 +102,10 @@ def initialize(options = {})
102102 settings = Config . client_settings ( options )
103103
104104 # pick up the username from the options, the global, or assume no username
105- @username = settings [ :username ] || ""
105+ @username = settings [ :username ]
106106
107107 # do a similar thing for the api key
108- @api_key = settings [ :api_key ] || ""
108+ @api_key = settings [ :api_key ]
109109
110110 # grab token pair
111111 @userId = settings [ :userId ]
@@ -120,11 +120,6 @@ def initialize(options = {})
120120 # and assign a time out if the settings offer one
121121 @network_timeout = settings [ :timeout ] if settings . has_key? ( :timeout )
122122
123- unless token_based?
124- raise "A SoftLayer Client requires a username" if !@username || @username . empty?
125- raise "A SoftLayer Client requires an api_key" if !@api_key || @api_key . empty?
126- end
127-
128123 raise "A SoftLayer Client requires an endpoint URL" if !@endpoint_url || @endpoint_url . empty?
129124 end
130125
@@ -133,6 +128,11 @@ def token_based?
133128 @userId && @authToken && !@authToken . empty?
134129 end
135130
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+
136136 # return a hash of the authentication headers for the client
137137 def authentication_headers
138138 if token_based?
@@ -143,13 +143,15 @@ def authentication_headers
143143 'authToken' => @authToken
144144 }
145145 }
146- else
146+ elsif key_based?
147147 {
148148 'authenticate' => {
149149 'username' => @username ,
150150 'apiKey' => @api_key
151151 }
152152 }
153+ else
154+ { }
153155 end
154156 end
155157
0 commit comments