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