Line data Source code
1 : // Copyright (C) 2014 The Android Open Source Project
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : package com.google.gerrit.server.api.accounts;
16 :
17 : import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
18 : import static javax.servlet.http.HttpServletResponse.SC_OK;
19 :
20 : import com.google.gerrit.common.Nullable;
21 : import com.google.gerrit.common.RawInputUtil;
22 : import com.google.gerrit.extensions.api.accounts.AccountApi;
23 : import com.google.gerrit.extensions.api.accounts.AgreementInput;
24 : import com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput;
25 : import com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo;
26 : import com.google.gerrit.extensions.api.accounts.DisplayNameInput;
27 : import com.google.gerrit.extensions.api.accounts.EmailApi;
28 : import com.google.gerrit.extensions.api.accounts.EmailInput;
29 : import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
30 : import com.google.gerrit.extensions.api.accounts.SshKeyInput;
31 : import com.google.gerrit.extensions.api.accounts.StatusInput;
32 : import com.google.gerrit.extensions.client.DiffPreferencesInfo;
33 : import com.google.gerrit.extensions.client.EditPreferencesInfo;
34 : import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
35 : import com.google.gerrit.extensions.client.ProjectWatchInfo;
36 : import com.google.gerrit.extensions.common.AccountDetailInfo;
37 : import com.google.gerrit.extensions.common.AccountExternalIdInfo;
38 : import com.google.gerrit.extensions.common.AccountInfo;
39 : import com.google.gerrit.extensions.common.AgreementInfo;
40 : import com.google.gerrit.extensions.common.EmailInfo;
41 : import com.google.gerrit.extensions.common.GpgKeyInfo;
42 : import com.google.gerrit.extensions.common.GroupInfo;
43 : import com.google.gerrit.extensions.common.HttpPasswordInput;
44 : import com.google.gerrit.extensions.common.Input;
45 : import com.google.gerrit.extensions.common.NameInput;
46 : import com.google.gerrit.extensions.common.SshKeyInfo;
47 : import com.google.gerrit.extensions.restapi.IdString;
48 : import com.google.gerrit.extensions.restapi.Response;
49 : import com.google.gerrit.extensions.restapi.RestApiException;
50 : import com.google.gerrit.extensions.restapi.TopLevelResource;
51 : import com.google.gerrit.server.account.AccountLoader;
52 : import com.google.gerrit.server.account.AccountResource;
53 : import com.google.gerrit.server.account.GpgApiAdapter;
54 : import com.google.gerrit.server.change.ChangeResource;
55 : import com.google.gerrit.server.restapi.account.AddSshKey;
56 : import com.google.gerrit.server.restapi.account.CreateEmail;
57 : import com.google.gerrit.server.restapi.account.DeleteActive;
58 : import com.google.gerrit.server.restapi.account.DeleteDraftComments;
59 : import com.google.gerrit.server.restapi.account.DeleteEmail;
60 : import com.google.gerrit.server.restapi.account.DeleteExternalIds;
61 : import com.google.gerrit.server.restapi.account.DeleteSshKey;
62 : import com.google.gerrit.server.restapi.account.DeleteWatchedProjects;
63 : import com.google.gerrit.server.restapi.account.GetActive;
64 : import com.google.gerrit.server.restapi.account.GetAgreements;
65 : import com.google.gerrit.server.restapi.account.GetAvatar;
66 : import com.google.gerrit.server.restapi.account.GetDetail;
67 : import com.google.gerrit.server.restapi.account.GetDiffPreferences;
68 : import com.google.gerrit.server.restapi.account.GetEditPreferences;
69 : import com.google.gerrit.server.restapi.account.GetEmails;
70 : import com.google.gerrit.server.restapi.account.GetExternalIds;
71 : import com.google.gerrit.server.restapi.account.GetGroups;
72 : import com.google.gerrit.server.restapi.account.GetPreferences;
73 : import com.google.gerrit.server.restapi.account.GetSshKeys;
74 : import com.google.gerrit.server.restapi.account.GetWatchedProjects;
75 : import com.google.gerrit.server.restapi.account.Index;
76 : import com.google.gerrit.server.restapi.account.PostWatchedProjects;
77 : import com.google.gerrit.server.restapi.account.PutActive;
78 : import com.google.gerrit.server.restapi.account.PutAgreement;
79 : import com.google.gerrit.server.restapi.account.PutDisplayName;
80 : import com.google.gerrit.server.restapi.account.PutHttpPassword;
81 : import com.google.gerrit.server.restapi.account.PutName;
82 : import com.google.gerrit.server.restapi.account.PutStatus;
83 : import com.google.gerrit.server.restapi.account.SetDiffPreferences;
84 : import com.google.gerrit.server.restapi.account.SetEditPreferences;
85 : import com.google.gerrit.server.restapi.account.SetPreferences;
86 : import com.google.gerrit.server.restapi.account.SshKeys;
87 : import com.google.gerrit.server.restapi.account.StarredChanges;
88 : import com.google.gerrit.server.restapi.change.ChangesCollection;
89 : import com.google.inject.Inject;
90 : import com.google.inject.assistedinject.Assisted;
91 : import java.util.List;
92 : import java.util.Map;
93 :
94 : public class AccountApiImpl implements AccountApi {
95 : interface Factory {
96 : AccountApiImpl create(AccountResource account);
97 : }
98 :
99 : private final AccountResource account;
100 : private final ChangesCollection changes;
101 : private final AccountLoader.Factory accountLoaderFactory;
102 : private final GetDetail getDetail;
103 : private final GetAvatar getAvatar;
104 : private final GetPreferences getPreferences;
105 : private final SetPreferences setPreferences;
106 : private final GetDiffPreferences getDiffPreferences;
107 : private final SetDiffPreferences setDiffPreferences;
108 : private final GetEditPreferences getEditPreferences;
109 : private final SetEditPreferences setEditPreferences;
110 : private final GetWatchedProjects getWatchedProjects;
111 : private final PostWatchedProjects postWatchedProjects;
112 : private final DeleteWatchedProjects deleteWatchedProjects;
113 : private final StarredChanges.Create starredChangesCreate;
114 : private final StarredChanges.Delete starredChangesDelete;
115 : private final GetEmails getEmails;
116 : private final CreateEmail createEmail;
117 : private final DeleteEmail deleteEmail;
118 : private final GpgApiAdapter gpgApiAdapter;
119 : private final GetSshKeys getSshKeys;
120 : private final AddSshKey addSshKey;
121 : private final DeleteSshKey deleteSshKey;
122 : private final SshKeys sshKeys;
123 : private final GetAgreements getAgreements;
124 : private final PutAgreement putAgreement;
125 : private final GetActive getActive;
126 : private final PutActive putActive;
127 : private final DeleteActive deleteActive;
128 : private final Index index;
129 : private final GetExternalIds getExternalIds;
130 : private final DeleteExternalIds deleteExternalIds;
131 : private final DeleteDraftComments deleteDraftComments;
132 : private final PutStatus putStatus;
133 : private final PutDisplayName putDisplayName;
134 : private final GetGroups getGroups;
135 : private final EmailApiImpl.Factory emailApi;
136 : private final PutName putName;
137 : private final PutHttpPassword putHttpPassword;
138 :
139 : @Inject
140 : AccountApiImpl(
141 : AccountLoader.Factory ailf,
142 : ChangesCollection changes,
143 : GetDetail getDetail,
144 : GetAvatar getAvatar,
145 : GetPreferences getPreferences,
146 : SetPreferences setPreferences,
147 : GetDiffPreferences getDiffPreferences,
148 : SetDiffPreferences setDiffPreferences,
149 : GetEditPreferences getEditPreferences,
150 : SetEditPreferences setEditPreferences,
151 : GetWatchedProjects getWatchedProjects,
152 : PostWatchedProjects postWatchedProjects,
153 : DeleteWatchedProjects deleteWatchedProjects,
154 : StarredChanges.Create starredChangesCreate,
155 : StarredChanges.Delete starredChangesDelete,
156 : GetEmails getEmails,
157 : CreateEmail createEmail,
158 : DeleteEmail deleteEmail,
159 : GpgApiAdapter gpgApiAdapter,
160 : GetSshKeys getSshKeys,
161 : AddSshKey addSshKey,
162 : DeleteSshKey deleteSshKey,
163 : SshKeys sshKeys,
164 : GetAgreements getAgreements,
165 : PutAgreement putAgreement,
166 : GetActive getActive,
167 : PutActive putActive,
168 : DeleteActive deleteActive,
169 : Index index,
170 : GetExternalIds getExternalIds,
171 : DeleteExternalIds deleteExternalIds,
172 : DeleteDraftComments deleteDraftComments,
173 : PutStatus putStatus,
174 : PutDisplayName putDisplayName,
175 : GetGroups getGroups,
176 : EmailApiImpl.Factory emailApi,
177 : PutName putName,
178 : PutHttpPassword putPassword,
179 32 : @Assisted AccountResource account) {
180 32 : this.account = account;
181 32 : this.accountLoaderFactory = ailf;
182 32 : this.changes = changes;
183 32 : this.getDetail = getDetail;
184 32 : this.getAvatar = getAvatar;
185 32 : this.getPreferences = getPreferences;
186 32 : this.setPreferences = setPreferences;
187 32 : this.getDiffPreferences = getDiffPreferences;
188 32 : this.setDiffPreferences = setDiffPreferences;
189 32 : this.getEditPreferences = getEditPreferences;
190 32 : this.setEditPreferences = setEditPreferences;
191 32 : this.getWatchedProjects = getWatchedProjects;
192 32 : this.postWatchedProjects = postWatchedProjects;
193 32 : this.deleteWatchedProjects = deleteWatchedProjects;
194 32 : this.starredChangesCreate = starredChangesCreate;
195 32 : this.starredChangesDelete = starredChangesDelete;
196 32 : this.getEmails = getEmails;
197 32 : this.createEmail = createEmail;
198 32 : this.deleteEmail = deleteEmail;
199 32 : this.getSshKeys = getSshKeys;
200 32 : this.addSshKey = addSshKey;
201 32 : this.deleteSshKey = deleteSshKey;
202 32 : this.sshKeys = sshKeys;
203 32 : this.gpgApiAdapter = gpgApiAdapter;
204 32 : this.getAgreements = getAgreements;
205 32 : this.putAgreement = putAgreement;
206 32 : this.getActive = getActive;
207 32 : this.putActive = putActive;
208 32 : this.deleteActive = deleteActive;
209 32 : this.index = index;
210 32 : this.getExternalIds = getExternalIds;
211 32 : this.deleteExternalIds = deleteExternalIds;
212 32 : this.deleteDraftComments = deleteDraftComments;
213 32 : this.putStatus = putStatus;
214 32 : this.putDisplayName = putDisplayName;
215 32 : this.getGroups = getGroups;
216 32 : this.emailApi = emailApi;
217 32 : this.putName = putName;
218 32 : this.putHttpPassword = putPassword;
219 32 : }
220 :
221 : @Override
222 : public com.google.gerrit.extensions.common.AccountInfo get() throws RestApiException {
223 12 : AccountLoader accountLoader = accountLoaderFactory.create(true);
224 : try {
225 12 : AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
226 12 : accountLoader.fill();
227 12 : return ai;
228 0 : } catch (Exception e) {
229 0 : throw asRestApiException("Cannot parse account", e);
230 : }
231 : }
232 :
233 : @Override
234 : public AccountDetailInfo detail() throws RestApiException {
235 : try {
236 2 : return getDetail.apply(account).value();
237 0 : } catch (Exception e) {
238 0 : throw asRestApiException("Cannot get detail", e);
239 : }
240 : }
241 :
242 : @Override
243 : public boolean getActive() throws RestApiException {
244 : try {
245 4 : Response<String> result = getActive.apply(account);
246 4 : return result.statusCode() == SC_OK && result.value().equals("ok");
247 0 : } catch (Exception e) {
248 0 : throw asRestApiException("Cannot get active", e);
249 : }
250 : }
251 :
252 : @Override
253 : public void setActive(boolean active) throws RestApiException {
254 : try {
255 7 : if (active) {
256 1 : putActive.apply(account, new Input());
257 : } else {
258 7 : deleteActive.apply(account, new Input());
259 : }
260 1 : } catch (Exception e) {
261 1 : throw asRestApiException("Cannot set active", e);
262 7 : }
263 7 : }
264 :
265 : @Override
266 : public String getAvatarUrl(int size) throws RestApiException {
267 0 : getAvatar.setSize(size);
268 0 : return getAvatar.apply(account).location();
269 : }
270 :
271 : @Override
272 : public GeneralPreferencesInfo getPreferences() throws RestApiException {
273 : try {
274 6 : return getPreferences.apply(account).value();
275 0 : } catch (Exception e) {
276 0 : throw asRestApiException("Cannot get preferences", e);
277 : }
278 : }
279 :
280 : @Override
281 : public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in) throws RestApiException {
282 : try {
283 8 : return setPreferences.apply(account, in).value();
284 1 : } catch (Exception e) {
285 1 : throw asRestApiException("Cannot set preferences", e);
286 : }
287 : }
288 :
289 : @Override
290 : public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
291 : try {
292 1 : return getDiffPreferences.apply(account).value();
293 0 : } catch (Exception e) {
294 0 : throw asRestApiException("Cannot query diff preferences", e);
295 : }
296 : }
297 :
298 : @Override
299 : public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException {
300 : try {
301 1 : return setDiffPreferences.apply(account, in).value();
302 0 : } catch (Exception e) {
303 0 : throw asRestApiException("Cannot set diff preferences", e);
304 : }
305 : }
306 :
307 : @Override
308 : public EditPreferencesInfo getEditPreferences() throws RestApiException {
309 : try {
310 1 : return getEditPreferences.apply(account).value();
311 0 : } catch (Exception e) {
312 0 : throw asRestApiException("Cannot query edit preferences", e);
313 : }
314 : }
315 :
316 : @Override
317 : public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException {
318 : try {
319 1 : return setEditPreferences.apply(account, in).value();
320 0 : } catch (Exception e) {
321 0 : throw asRestApiException("Cannot set edit preferences", e);
322 : }
323 : }
324 :
325 : @Override
326 : public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException {
327 : try {
328 1 : return getWatchedProjects.apply(account).value();
329 0 : } catch (Exception e) {
330 0 : throw asRestApiException("Cannot get watched projects", e);
331 : }
332 : }
333 :
334 : @Override
335 : public List<ProjectWatchInfo> setWatchedProjects(List<ProjectWatchInfo> in)
336 : throws RestApiException {
337 : try {
338 16 : return postWatchedProjects.apply(account, in).value();
339 1 : } catch (Exception e) {
340 1 : throw asRestApiException("Cannot update watched projects", e);
341 : }
342 : }
343 :
344 : @Override
345 : public void deleteWatchedProjects(List<ProjectWatchInfo> in) throws RestApiException {
346 : try {
347 2 : deleteWatchedProjects.apply(account, in);
348 0 : } catch (Exception e) {
349 0 : throw asRestApiException("Cannot delete watched projects", e);
350 2 : }
351 2 : }
352 :
353 : @Override
354 : public void starChange(String changeId) throws RestApiException {
355 : try {
356 9 : starredChangesCreate.apply(account, IdString.fromUrl(changeId), new Input());
357 0 : } catch (Exception e) {
358 0 : throw asRestApiException("Cannot star change", e);
359 9 : }
360 9 : }
361 :
362 : @Override
363 : public void unstarChange(String changeId) throws RestApiException {
364 : try {
365 2 : ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
366 2 : AccountResource.StarredChange starredChange =
367 2 : new AccountResource.StarredChange(account.getUser(), rsrc);
368 2 : starredChangesDelete.apply(starredChange, new Input());
369 0 : } catch (Exception e) {
370 0 : throw asRestApiException("Cannot unstar change", e);
371 2 : }
372 2 : }
373 :
374 : @Override
375 : public List<GroupInfo> getGroups() throws RestApiException {
376 : try {
377 1 : return getGroups.apply(account).value();
378 0 : } catch (Exception e) {
379 0 : throw asRestApiException("Cannot get groups", e);
380 : }
381 : }
382 :
383 : @Override
384 : public List<EmailInfo> getEmails() throws RestApiException {
385 : try {
386 1 : return getEmails.apply(account).value();
387 1 : } catch (Exception e) {
388 1 : throw asRestApiException("Cannot get emails", e);
389 : }
390 : }
391 :
392 : @Override
393 : public void addEmail(EmailInput input) throws RestApiException {
394 3 : AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), input.email);
395 : try {
396 3 : createEmail.apply(rsrc, IdString.fromDecoded(input.email), input);
397 1 : } catch (Exception e) {
398 1 : throw asRestApiException("Cannot add email", e);
399 3 : }
400 3 : }
401 :
402 : @Override
403 : public void deleteEmail(String email) throws RestApiException {
404 1 : AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), email);
405 : try {
406 1 : deleteEmail.apply(rsrc, null);
407 1 : } catch (Exception e) {
408 1 : throw asRestApiException("Cannot delete email", e);
409 1 : }
410 1 : }
411 :
412 : @Override
413 : public EmailApi createEmail(EmailInput input) throws RestApiException {
414 1 : AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), input.email);
415 : try {
416 1 : createEmail.apply(rsrc, IdString.fromDecoded(input.email), input);
417 1 : return email(rsrc.getEmail());
418 0 : } catch (Exception e) {
419 0 : throw asRestApiException("Cannot create email", e);
420 : }
421 : }
422 :
423 : @Override
424 : public EmailApi email(String email) throws RestApiException {
425 : try {
426 1 : return emailApi.create(account, email);
427 0 : } catch (Exception e) {
428 0 : throw asRestApiException("Cannot parse email", e);
429 : }
430 : }
431 :
432 : @Override
433 : public void setStatus(String status) throws RestApiException {
434 1 : StatusInput in = new StatusInput(status);
435 : try {
436 1 : putStatus.apply(account, in);
437 0 : } catch (Exception e) {
438 0 : throw asRestApiException("Cannot set status", e);
439 1 : }
440 1 : }
441 :
442 : @Override
443 : public void setDisplayName(String displayName) throws RestApiException {
444 0 : DisplayNameInput in = new DisplayNameInput(displayName);
445 : try {
446 0 : putDisplayName.apply(account, in);
447 0 : } catch (Exception e) {
448 0 : throw asRestApiException("Cannot set display name", e);
449 0 : }
450 0 : }
451 :
452 : @Override
453 : public List<SshKeyInfo> listSshKeys() throws RestApiException {
454 : try {
455 2 : return getSshKeys.apply(account).value();
456 0 : } catch (Exception e) {
457 0 : throw asRestApiException("Cannot list SSH keys", e);
458 : }
459 : }
460 :
461 : @Override
462 : public SshKeyInfo addSshKey(String key) throws RestApiException {
463 5 : SshKeyInput in = new SshKeyInput();
464 5 : in.raw = RawInputUtil.create(key);
465 : try {
466 5 : return addSshKey.apply(account, in).value();
467 1 : } catch (Exception e) {
468 1 : throw asRestApiException("Cannot add SSH key", e);
469 : }
470 : }
471 :
472 : @Override
473 : public void deleteSshKey(int seq) throws RestApiException {
474 : try {
475 2 : AccountResource.SshKey sshKeyRes =
476 2 : sshKeys.parse(account, IdString.fromDecoded(Integer.toString(seq)));
477 2 : deleteSshKey.apply(sshKeyRes, null);
478 1 : } catch (Exception e) {
479 1 : throw asRestApiException("Cannot delete SSH key", e);
480 2 : }
481 2 : }
482 :
483 : @Override
484 : public Map<String, GpgKeyInfo> listGpgKeys() throws RestApiException {
485 : try {
486 1 : return gpgApiAdapter.listGpgKeys(account);
487 0 : } catch (Exception e) {
488 0 : throw asRestApiException("Cannot list GPG keys", e);
489 : }
490 : }
491 :
492 : @Override
493 : public Map<String, GpgKeyInfo> putGpgKeys(List<String> add, List<String> delete)
494 : throws RestApiException {
495 : try {
496 2 : return gpgApiAdapter.putGpgKeys(account, add, delete);
497 1 : } catch (Exception e) {
498 1 : throw asRestApiException("Cannot add GPG key", e);
499 : }
500 : }
501 :
502 : @Override
503 : public GpgKeyApi gpgKey(String id) throws RestApiException {
504 : try {
505 1 : return gpgApiAdapter.gpgKey(account, IdString.fromDecoded(id));
506 1 : } catch (Exception e) {
507 1 : throw asRestApiException("Cannot get PGP key", e);
508 : }
509 : }
510 :
511 : @Override
512 : public List<AgreementInfo> listAgreements() throws RestApiException {
513 : try {
514 1 : return getAgreements.apply(account).value();
515 1 : } catch (Exception e) {
516 1 : throw asRestApiException("Cannot get agreements", e);
517 : }
518 : }
519 :
520 : @Override
521 : public void signAgreement(String agreementName) throws RestApiException {
522 : try {
523 1 : AgreementInput input = new AgreementInput();
524 1 : input.name = agreementName;
525 1 : putAgreement.apply(account, input);
526 1 : } catch (Exception e) {
527 1 : throw asRestApiException("Cannot sign agreement", e);
528 1 : }
529 1 : }
530 :
531 : @Override
532 : public void index() throws RestApiException {
533 : try {
534 3 : index.apply(account, new Input());
535 1 : } catch (Exception e) {
536 1 : throw asRestApiException("Cannot index account", e);
537 3 : }
538 3 : }
539 :
540 : @Override
541 : public List<AccountExternalIdInfo> getExternalIds() throws RestApiException {
542 : try {
543 4 : return getExternalIds.apply(account).value();
544 1 : } catch (Exception e) {
545 1 : throw asRestApiException("Cannot get external IDs", e);
546 : }
547 : }
548 :
549 : @Override
550 : public void deleteExternalIds(List<String> externalIds) throws RestApiException {
551 : try {
552 2 : deleteExternalIds.apply(account, externalIds);
553 1 : } catch (Exception e) {
554 1 : throw asRestApiException("Cannot delete external IDs", e);
555 2 : }
556 2 : }
557 :
558 : @Override
559 : public List<DeletedDraftCommentInfo> deleteDraftComments(DeleteDraftCommentsInput input)
560 : throws RestApiException {
561 : try {
562 2 : return deleteDraftComments.apply(account, input).value();
563 1 : } catch (Exception e) {
564 1 : throw asRestApiException("Cannot delete draft comments", e);
565 : }
566 : }
567 :
568 : @Override
569 : public void setName(String name) throws RestApiException {
570 1 : NameInput input = new NameInput();
571 1 : input.name = name;
572 : try {
573 1 : putName.apply(account, input);
574 1 : } catch (Exception e) {
575 1 : throw asRestApiException("Cannot set account name", e);
576 1 : }
577 1 : }
578 :
579 : @Nullable
580 : @Override
581 : public String generateHttpPassword() throws RestApiException {
582 3 : HttpPasswordInput input = new HttpPasswordInput();
583 3 : input.generate = true;
584 : try {
585 : // Response should never be 'none' for a generated password, but
586 : // let's make sure.
587 3 : Response<String> result = putHttpPassword.apply(account, input);
588 3 : return result.isNone() ? null : result.value();
589 1 : } catch (Exception e) {
590 1 : throw asRestApiException("Cannot generate HTTP password", e);
591 : }
592 : }
593 :
594 : @Nullable
595 : @Override
596 : public String setHttpPassword(String password) throws RestApiException {
597 3 : HttpPasswordInput input = new HttpPasswordInput();
598 3 : input.generate = false;
599 3 : input.httpPassword = password;
600 : try {
601 3 : Response<String> result = putHttpPassword.apply(account, input);
602 3 : return result.isNone() ? null : result.value();
603 1 : } catch (Exception e) {
604 1 : throw asRestApiException("Cannot generate HTTP password", e);
605 : }
606 : }
607 : }
|