root / src / com / rackspace / cloud / servers / api / client / Account.java @ 7dbfc514
History | View | Annotate | Download (6.5 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.servers.api.client; |
5 |
|
6 |
import com.rackspace.cloud.android.Preferences; |
7 |
import com.rackspace.cloud.utils.StringUtils; |
8 |
|
9 |
|
10 |
|
11 |
/**
|
12 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
|
13 |
*
|
14 |
*/
|
15 |
public class Account implements java.io.Serializable { |
16 |
|
17 |
/**
|
18 |
*
|
19 |
*/
|
20 |
private static final long serialVersionUID = 2180740077014156769L; |
21 |
private String username; |
22 |
private String apiKey; |
23 |
private String password; |
24 |
private String accountId; |
25 |
private String authServer; |
26 |
private String authServerV2; |
27 |
private String loadBalancerUKUrl; |
28 |
private String[] loadBalancerRegions; |
29 |
private static String loadBalancerDFWUrl; |
30 |
private static String loadBalancerORDUrl; |
31 |
private static String loadBalancerLONUrl; |
32 |
private transient String authToken; |
33 |
private transient String serverUrl; |
34 |
private transient String storageUrl; |
35 |
private transient String storageToken; |
36 |
private transient String cdnManagementUrl; |
37 |
private transient static Account currentAccount; |
38 |
|
39 |
public static Account getAccount() { |
40 |
return currentAccount;
|
41 |
} |
42 |
|
43 |
public static void setAccount(Account account) { |
44 |
Account.currentAccount = account; |
45 |
} |
46 |
|
47 |
/**
|
48 |
* @return the serverUrl
|
49 |
*/
|
50 |
public String getServerUrl() { |
51 |
return serverUrl;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* @param serverUrl
|
56 |
* the serverUrl to set
|
57 |
*/
|
58 |
public void setServerUrl(String serverUrl) { |
59 |
this.serverUrl = serverUrl;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* @return the storageUrl
|
64 |
*/
|
65 |
public String getStorageUrl() { |
66 |
return storageUrl;
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* @return the storageToken
|
71 |
*/
|
72 |
public String getStorageToken() { |
73 |
return storageToken;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* @param storageUrl
|
78 |
* the storageUrl to set
|
79 |
*/
|
80 |
public void setStorageUrl(String storageUrl) { |
81 |
this.storageUrl = storageUrl;
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* @return the cdnManagementUrl
|
86 |
*/
|
87 |
public String getCdnManagementUrl() { |
88 |
return cdnManagementUrl;
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* @param cdnManagementUrl
|
93 |
* the cdnManagementUrl to set
|
94 |
*/
|
95 |
public void setCdnManagementUrl(String cdnManagementUrl) { |
96 |
this.cdnManagementUrl = cdnManagementUrl;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* @return the authToken
|
101 |
*/
|
102 |
public String getAuthToken() { |
103 |
return authToken;
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* @param authToken
|
108 |
* the authToken to set
|
109 |
*/
|
110 |
public void setAuthToken(String authToken) { |
111 |
this.authToken = authToken;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* @return the authToken
|
116 |
*/
|
117 |
public String getAuthServer() { |
118 |
return authServer;
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* @param authToken
|
123 |
* the authToken to set
|
124 |
*/
|
125 |
public void setAuthServer(String authServer) { |
126 |
this.authServer = authServer;
|
127 |
|
128 |
/*
|
129 |
* the auth server used determines which regions
|
130 |
* can be used for load balancers, so set available
|
131 |
* regions here.
|
132 |
*/
|
133 |
if(authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER)){ |
134 |
setLoadBalancerRegions(Preferences.UK_REGIONS);
|
135 |
} else if (authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER)){ |
136 |
setLoadBalancerRegions(Preferences.US_REGIONS);
|
137 |
} else {
|
138 |
setLoadBalancerRegions(new String[0]); |
139 |
} |
140 |
} |
141 |
|
142 |
/**
|
143 |
* @return the authToken
|
144 |
*/
|
145 |
public String getAuthServerV2() { |
146 |
return authServerV2;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* @param authToken the authToken to set
|
151 |
*/
|
152 |
public void setAuthServerV2(String authServerV2) { |
153 |
this.authServerV2 = authServerV2;
|
154 |
|
155 |
/*
|
156 |
* the auth server used determines which regions
|
157 |
* can be used for load balancers, so set available
|
158 |
* regions here.
|
159 |
*/
|
160 |
if(authServerV2.equals(Preferences.COUNTRY_UK_AUTH_SERVER_V2)){ |
161 |
setLoadBalancerRegions(Preferences.UK_REGIONS);
|
162 |
} else if (authServerV2.equals(Preferences.COUNTRY_US_AUTH_SERVER_V2)){ |
163 |
setLoadBalancerRegions(Preferences.US_REGIONS);
|
164 |
} else {
|
165 |
setLoadBalancerRegions(new String[0]); |
166 |
} |
167 |
} |
168 |
|
169 |
//auth v1.1 should return loadbalancer endpoints and return account id ....
|
170 |
public String getAccountId() { |
171 |
String delemiter = "v1.0/"; |
172 |
int indexToReturn = 1; |
173 |
accountId = StringUtils.splitByDelemiter(getServerUrl(), delemiter, indexToReturn); |
174 |
return accountId;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* @return the loadBalancerDFWUrl
|
179 |
*/
|
180 |
public static String getLoadBalancerDFWUrl() { |
181 |
loadBalancerDFWUrl = "https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/";
|
182 |
return loadBalancerDFWUrl;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* @param loadBalancerDFWUrl the loadBalancerDFWUrl to set
|
187 |
*/
|
188 |
public static void setLoadBalancerDFWUrl(String dfwUrl) { |
189 |
loadBalancerDFWUrl = dfwUrl; |
190 |
} |
191 |
|
192 |
/**
|
193 |
* @return the loadBalancerORDUrl
|
194 |
*/
|
195 |
public static String getLoadBalancerORDUrl() { |
196 |
loadBalancerORDUrl = "https://ord.loadbalancers.api.rackspacecloud.com/v1.0/";
|
197 |
return loadBalancerORDUrl;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* @param loadBalancerORDUrl the loadBalancerORDUrl to set
|
202 |
*/
|
203 |
public static void setLoadBalancerORDUrl(String ordUrl) { |
204 |
loadBalancerORDUrl = ordUrl; |
205 |
} |
206 |
|
207 |
/**
|
208 |
* @return the loadBalancerLONUrl
|
209 |
*/
|
210 |
public static String getLoadBalancerLONUrl() { |
211 |
loadBalancerLONUrl = "https://lon.loadbalancers.api.rackspacecloud.com/v1.0/";
|
212 |
return loadBalancerLONUrl;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* @param loadBalancerLONUrl the loadBalancerORDUrl to set
|
217 |
*/
|
218 |
public static void setLoadBalancerLONUrl(String lonUrl) { |
219 |
loadBalancerLONUrl = lonUrl; |
220 |
} |
221 |
|
222 |
/**
|
223 |
* @return the loadBalancerUKUrl
|
224 |
*/
|
225 |
public String getLoadBalancerUKUrl() { |
226 |
loadBalancerUKUrl = "https://lon.loadbalancers.api.rackspacecloud.com/v1.0/";
|
227 |
return loadBalancerUKUrl;
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* @param loadBalancerUKUrl the loadBalancerUKUrl to set
|
232 |
*/
|
233 |
public void setLoadBalancerUKUrl(String loadBalancerUKUrl) { |
234 |
this.loadBalancerUKUrl = loadBalancerUKUrl;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* @return the username
|
239 |
*/
|
240 |
public String getUsername() { |
241 |
return username;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* @param username
|
246 |
* the username to set
|
247 |
*/
|
248 |
public void setUsername(String username) { |
249 |
this.username = username;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* @return the apiKey
|
254 |
*/
|
255 |
public String getApiKey() { |
256 |
return apiKey;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* @param password the password to set
|
261 |
*/
|
262 |
public void setPassword(String password) { |
263 |
this.password = password;
|
264 |
} |
265 |
|
266 |
/**
|
267 |
* @return the password
|
268 |
*/
|
269 |
public String getPassword() { |
270 |
return password;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* @param apiKey the apiKey to set
|
275 |
*/
|
276 |
public void setApiKey(String apiKey) { |
277 |
this.apiKey = apiKey;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
*/
|
282 |
public void setStorageToken(String storageToken) { |
283 |
this.storageToken = storageToken;
|
284 |
} |
285 |
|
286 |
/**
|
287 |
* @return the load balancer regions
|
288 |
*/
|
289 |
public String[] getLoadBalancerRegions() { |
290 |
return loadBalancerRegions;
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* @param loadBalancerRegions the load
|
295 |
* balancer regions to set
|
296 |
*/
|
297 |
public void setLoadBalancerRegions(String[] loadBalancerRegions) { |
298 |
this.loadBalancerRegions = new String[loadBalancerRegions.length]; |
299 |
for(int i = 0 ; i < loadBalancerRegions.length; i++){ |
300 |
this.loadBalancerRegions[i] = loadBalancerRegions[i];
|
301 |
} |
302 |
} |
303 |
|
304 |
} |