1package gerrit 2 3import ( 4 "fmt" 5) 6 7// AccountsService contains Account related REST endpoints 8// 9// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html 10type AccountsService struct { 11 client *Client 12} 13 14// AccountInfo entity contains information about an account. 15type AccountInfo struct { 16 AccountID int `json:"_account_id,omitempty"` 17 Name string `json:"name,omitempty"` 18 Email string `json:"email,omitempty"` 19 Username string `json:"username,omitempty"` 20 21 // Avatars lists avatars of various sizes for the account. 22 // This field is only populated if the avatars plugin is enabled. 23 Avatars []struct { 24 URL string `json:"url,omitempty"` 25 Height int `json:"height,omitempty"` 26 } `json:"avatars,omitempty"` 27} 28 29// SSHKeyInfo entity contains information about an SSH key of a user. 30type SSHKeyInfo struct { 31 Seq int `json:"seq"` 32 SSHPublicKey string `json:"ssh_public_key"` 33 EncodedKey string `json:"encoded_key"` 34 Algorithm string `json:"algorithm"` 35 Comment string `json:"comment,omitempty"` 36 Valid bool `json:"valid"` 37} 38 39// UsernameInput entity contains information for setting the username for an account. 40type UsernameInput struct { 41 Username string `json:"username"` 42} 43 44// QueryLimitInfo entity contains information about the Query Limit of a user. 45type QueryLimitInfo struct { 46 Min int `json:"min"` 47 Max int `json:"max"` 48} 49 50// HTTPPasswordInput entity contains information for setting/generating an HTTP password. 51type HTTPPasswordInput struct { 52 Generate bool `json:"generate,omitempty"` 53 HTTPPassword string `json:"http_password,omitempty"` 54} 55 56// GpgKeysInput entity contains information for adding/deleting GPG keys. 57type GpgKeysInput struct { 58 Add []string `json:"add"` 59 Delete []string `json:"delete"` 60} 61 62// GpgKeyInfo entity contains information about a GPG public key. 63type GpgKeyInfo struct { 64 ID string `json:"id,omitempty"` 65 Fingerprint string `json:"fingerprint,omitempty"` 66 UserIDs []string `json:"user_ids,omitempty"` 67 Key string `json:"key,omitempty"` 68} 69 70// EmailInput entity contains information for registering a new email address. 71type EmailInput struct { 72 Email string `json:"email"` 73 Preferred bool `json:"preferred,omitempty"` 74 NoConfirmation bool `json:"no_confirmation,omitempty"` 75} 76 77// EmailInfo entity contains information about an email address of a user. 78type EmailInfo struct { 79 Email string `json:"email"` 80 Preferred bool `json:"preferred,omitempty"` 81 PendingConfirmation bool `json:"pending_confirmation,omitempty"` 82} 83 84// AccountInput entity contains information for the creation of a new account. 85type AccountInput struct { 86 Username string `json:"username,omitempty"` 87 Name string `json:"name,omitempty"` 88 Email string `json:"email,omitempty"` 89 SSHKey string `json:"ssh_key,omitempty"` 90 HTTPPassword string `json:"http_password,omitempty"` 91 Groups []string `json:"groups,omitempty"` 92} 93 94// AccountDetailInfo entity contains detailed information about an account. 95type AccountDetailInfo struct { 96 AccountInfo 97 RegisteredOn Timestamp `json:"registered_on"` 98} 99 100// AccountNameInput entity contains information for setting a name for an account. 101type AccountNameInput struct { 102 Name string `json:"name,omitempty"` 103} 104 105// AccountCapabilityInfo entity contains information about the global capabilities of a user. 106type AccountCapabilityInfo struct { 107 AccessDatabase bool `json:"accessDatabase,omitempty"` 108 AdministrateServer bool `json:"administrateServer,omitempty"` 109 CreateAccount bool `json:"createAccount,omitempty"` 110 CreateGroup bool `json:"createGroup,omitempty"` 111 CreateProject bool `json:"createProject,omitempty"` 112 EmailReviewers bool `json:"emailReviewers,omitempty"` 113 FlushCaches bool `json:"flushCaches,omitempty"` 114 KillTask bool `json:"killTask,omitempty"` 115 MaintainServer bool `json:"maintainServer,omitempty"` 116 Priority string `json:"priority,omitempty"` 117 QueryLimit QueryLimitInfo `json:"queryLimit"` 118 RunAs bool `json:"runAs,omitempty"` 119 RunGC bool `json:"runGC,omitempty"` 120 StreamEvents bool `json:"streamEvents,omitempty"` 121 ViewAllAccounts bool `json:"viewAllAccounts,omitempty"` 122 ViewCaches bool `json:"viewCaches,omitempty"` 123 ViewConnections bool `json:"viewConnections,omitempty"` 124 ViewPlugins bool `json:"viewPlugins,omitempty"` 125 ViewQueue bool `json:"viewQueue,omitempty"` 126} 127 128// DiffPreferencesInfo entity contains information about the diff preferences of a user. 129type DiffPreferencesInfo struct { 130 Context int `json:"context"` 131 Theme string `json:"theme"` 132 ExpandAllComments bool `json:"expand_all_comments,omitempty"` 133 IgnoreWhitespace string `json:"ignore_whitespace"` 134 IntralineDifference bool `json:"intraline_difference,omitempty"` 135 LineLength int `json:"line_length"` 136 ManualReview bool `json:"manual_review,omitempty"` 137 RetainHeader bool `json:"retain_header,omitempty"` 138 ShowLineEndings bool `json:"show_line_endings,omitempty"` 139 ShowTabs bool `json:"show_tabs,omitempty"` 140 ShowWhitespaceErrors bool `json:"show_whitespace_errors,omitempty"` 141 SkipDeleted bool `json:"skip_deleted,omitempty"` 142 SkipUncommented bool `json:"skip_uncommented,omitempty"` 143 SyntaxHighlighting bool `json:"syntax_highlighting,omitempty"` 144 HideTopMenu bool `json:"hide_top_menu,omitempty"` 145 AutoHideDiffTableHeader bool `json:"auto_hide_diff_table_header,omitempty"` 146 HideLineNumbers bool `json:"hide_line_numbers,omitempty"` 147 TabSize int `json:"tab_size"` 148 HideEmptyPane bool `json:"hide_empty_pane,omitempty"` 149} 150 151// DiffPreferencesInput entity contains information for setting the diff preferences of a user. 152// Fields which are not set will not be updated. 153type DiffPreferencesInput struct { 154 Context int `json:"context,omitempty"` 155 ExpandAllComments bool `json:"expand_all_comments,omitempty"` 156 IgnoreWhitespace string `json:"ignore_whitespace,omitempty"` 157 IntralineDifference bool `json:"intraline_difference,omitempty"` 158 LineLength int `json:"line_length,omitempty"` 159 ManualReview bool `json:"manual_review,omitempty"` 160 RetainHeader bool `json:"retain_header,omitempty"` 161 ShowLineEndings bool `json:"show_line_endings,omitempty"` 162 ShowTabs bool `json:"show_tabs,omitempty"` 163 ShowWhitespaceErrors bool `json:"show_whitespace_errors,omitempty"` 164 SkipDeleted bool `json:"skip_deleted,omitempty"` 165 SkipUncommented bool `json:"skip_uncommented,omitempty"` 166 SyntaxHighlighting bool `json:"syntax_highlighting,omitempty"` 167 HideTopMenu bool `json:"hide_top_menu,omitempty"` 168 AutoHideDiffTableHeader bool `json:"auto_hide_diff_table_header,omitempty"` 169 HideLineNumbers bool `json:"hide_line_numbers,omitempty"` 170 TabSize int `json:"tab_size,omitempty"` 171} 172 173// PreferencesInfo entity contains information about a user’s preferences. 174type PreferencesInfo struct { 175 ChangesPerPage int `json:"changes_per_page"` 176 ShowSiteHeader bool `json:"show_site_header,omitempty"` 177 UseFlashClipboard bool `json:"use_flash_clipboard,omitempty"` 178 DownloadScheme string `json:"download_scheme"` 179 DownloadCommand string `json:"download_command"` 180 CopySelfOnEmail bool `json:"copy_self_on_email,omitempty"` 181 DateFormat string `json:"date_format"` 182 TimeFormat string `json:"time_format"` 183 RelativeDateInChangeTable bool `json:"relative_date_in_change_table,omitempty"` 184 SizeBarInChangeTable bool `json:"size_bar_in_change_table,omitempty"` 185 LegacycidInChangeTable bool `json:"legacycid_in_change_table,omitempty"` 186 MuteCommonPathPrefixes bool `json:"mute_common_path_prefixes,omitempty"` 187 ReviewCategoryStrategy string `json:"review_category_strategy"` 188 DiffView string `json:"diff_view"` 189 My []TopMenuItemInfo `json:"my"` 190 URLAliases string `json:"url_aliases,omitempty"` 191} 192 193// PreferencesInput entity contains information for setting the user preferences. 194// Fields which are not set will not be updated. 195type PreferencesInput struct { 196 ChangesPerPage int `json:"changes_per_page,omitempty"` 197 ShowSiteHeader bool `json:"show_site_header,omitempty"` 198 UseFlashClipboard bool `json:"use_flash_clipboard,omitempty"` 199 DownloadScheme string `json:"download_scheme,omitempty"` 200 DownloadCommand string `json:"download_command,omitempty"` 201 CopySelfOnEmail bool `json:"copy_self_on_email,omitempty"` 202 DateFormat string `json:"date_format,omitempty"` 203 TimeFormat string `json:"time_format,omitempty"` 204 RelativeDateInChangeTable bool `json:"relative_date_in_change_table,omitempty"` 205 SizeBarInChangeTable bool `json:"size_bar_in_change_table,omitempty"` 206 LegacycidInChangeTable bool `json:"legacycid_in_change_table,omitempty"` 207 MuteCommonPathPrefixes bool `json:"mute_common_path_prefixes,omitempty"` 208 ReviewCategoryStrategy string `json:"review_category_strategy,omitempty"` 209 DiffView string `json:"diff_view,omitempty"` 210 My []TopMenuItemInfo `json:"my,omitempty"` 211 URLAliases string `json:"url_aliases,omitempty"` 212} 213 214// CapabilityOptions specifies the parameters to filter for capabilities. 215// 216// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-account-capabilities 217type CapabilityOptions struct { 218 // To filter the set of global capabilities the q parameter can be used. 219 // Filtering may decrease the response time by avoiding looking at every possible alternative for the caller. 220 Filter []string `url:"q,omitempty"` 221} 222 223// GetAccount returns an account as an AccountInfo entity. 224// If account is "self" the current authenticated account will be returned. 225// 226// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-account 227func (s *AccountsService) GetAccount(account string) (*AccountInfo, *Response, error) { 228 u := fmt.Sprintf("accounts/%s", account) 229 230 req, err := s.client.NewRequest("GET", u, nil) 231 if err != nil { 232 return nil, nil, err 233 } 234 235 v := new(AccountInfo) 236 resp, err := s.client.Do(req, v) 237 if err != nil { 238 return nil, resp, err 239 } 240 241 return v, resp, err 242} 243 244// GetAccountDetails retrieves the details of an account. 245// 246// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-detail 247func (s *AccountsService) GetAccountDetails(accountID string) (*AccountDetailInfo, *Response, error) { 248 u := fmt.Sprintf("accounts/%s/detail", accountID) 249 250 req, err := s.client.NewRequest("GET", u, nil) 251 if err != nil { 252 return nil, nil, err 253 } 254 255 v := new(AccountDetailInfo) 256 resp, err := s.client.Do(req, v) 257 if err != nil { 258 return nil, resp, err 259 } 260 261 return v, resp, err 262} 263 264// GetAccountName retrieves the full name of an account. 265// 266// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-account-name 267func (s *AccountsService) GetAccountName(accountID string) (string, *Response, error) { 268 u := fmt.Sprintf("accounts/%s/name", accountID) 269 return getStringResponseWithoutOptions(s.client, u) 270} 271 272// GetUsername retrieves the username of an account. 273// 274// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-username 275func (s *AccountsService) GetUsername(accountID string) (string, *Response, error) { 276 u := fmt.Sprintf("accounts/%s/username", accountID) 277 return getStringResponseWithoutOptions(s.client, u) 278} 279 280// GetHTTPPassword retrieves the HTTP password of an account. 281// 282// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-http-password 283func (s *AccountsService) GetHTTPPassword(accountID string) (string, *Response, error) { 284 u := fmt.Sprintf("accounts/%s/password.http", accountID) 285 return getStringResponseWithoutOptions(s.client, u) 286} 287 288// ListAccountEmails returns the email addresses that are configured for the specified user. 289// 290// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-account-emails 291func (s *AccountsService) ListAccountEmails(accountID string) (*[]EmailInfo, *Response, error) { 292 u := fmt.Sprintf("accounts/%s/emails", accountID) 293 294 req, err := s.client.NewRequest("GET", u, nil) 295 if err != nil { 296 return nil, nil, err 297 } 298 299 v := new([]EmailInfo) 300 resp, err := s.client.Do(req, v) 301 if err != nil { 302 return nil, resp, err 303 } 304 305 return v, resp, err 306} 307 308// GetAccountEmail retrieves an email address of a user. 309// 310// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-account-email 311func (s *AccountsService) GetAccountEmail(accountID, emailID string) (*EmailInfo, *Response, error) { 312 u := fmt.Sprintf("accounts/%s/emails/%s", accountID, emailID) 313 314 req, err := s.client.NewRequest("GET", u, nil) 315 if err != nil { 316 return nil, nil, err 317 } 318 319 v := new(EmailInfo) 320 resp, err := s.client.Do(req, v) 321 if err != nil { 322 return nil, resp, err 323 } 324 325 return v, resp, err 326} 327 328// ListSSHKeys returns the SSH keys of an account. 329// 330// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-ssh-keys 331func (s *AccountsService) ListSSHKeys(accountID string) (*[]SSHKeyInfo, *Response, error) { 332 u := fmt.Sprintf("accounts/%s/sshkeys", accountID) 333 334 req, err := s.client.NewRequest("GET", u, nil) 335 if err != nil { 336 return nil, nil, err 337 } 338 339 v := new([]SSHKeyInfo) 340 resp, err := s.client.Do(req, v) 341 if err != nil { 342 return nil, resp, err 343 } 344 345 return v, resp, err 346} 347 348// GetSSHKey retrieves an SSH key of a user. 349// 350// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-ssh-key 351func (s *AccountsService) GetSSHKey(accountID, sshKeyID string) (*SSHKeyInfo, *Response, error) { 352 u := fmt.Sprintf("accounts/%s/sshkeys/%s", accountID, sshKeyID) 353 354 req, err := s.client.NewRequest("GET", u, nil) 355 if err != nil { 356 return nil, nil, err 357 } 358 359 v := new(SSHKeyInfo) 360 resp, err := s.client.Do(req, v) 361 if err != nil { 362 return nil, resp, err 363 } 364 365 return v, resp, err 366} 367 368// ListGPGKeys returns the GPG keys of an account. 369// 370// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-gpg-keys 371func (s *AccountsService) ListGPGKeys(accountID string) (*map[string]GpgKeyInfo, *Response, error) { 372 u := fmt.Sprintf("accounts/%s/gpgkeys", accountID) 373 374 req, err := s.client.NewRequest("GET", u, nil) 375 if err != nil { 376 return nil, nil, err 377 } 378 379 v := new(map[string]GpgKeyInfo) 380 resp, err := s.client.Do(req, v) 381 if err != nil { 382 return nil, resp, err 383 } 384 385 return v, resp, err 386} 387 388// GetGPGKey retrieves a GPG key of a user. 389// 390// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-gpg-key 391func (s *AccountsService) GetGPGKey(accountID, gpgKeyID string) (*GpgKeyInfo, *Response, error) { 392 u := fmt.Sprintf("accounts/%s/gpgkeys/%s", accountID, gpgKeyID) 393 394 req, err := s.client.NewRequest("GET", u, nil) 395 if err != nil { 396 return nil, nil, err 397 } 398 399 v := new(GpgKeyInfo) 400 resp, err := s.client.Do(req, v) 401 if err != nil { 402 return nil, resp, err 403 } 404 405 return v, resp, err 406} 407 408// ListAccountCapabilities returns the global capabilities that are enabled for the specified user. 409// If the global capabilities for the calling user should be listed, self can be used as account-id. 410// This can be used by UI tools to discover if administrative features are available to the caller, so they can hide (or show) relevant UI actions. 411// 412// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-account-capabilities 413func (s *AccountsService) ListAccountCapabilities(accountID string, opt *CapabilityOptions) (*AccountCapabilityInfo, *Response, error) { 414 u := fmt.Sprintf("accounts/%s/capabilities", accountID) 415 416 u, err := addOptions(u, opt) 417 if err != nil { 418 return nil, nil, err 419 } 420 421 req, err := s.client.NewRequest("GET", u, nil) 422 if err != nil { 423 return nil, nil, err 424 } 425 426 v := new(AccountCapabilityInfo) 427 resp, err := s.client.Do(req, v) 428 if err != nil { 429 return nil, resp, err 430 } 431 432 return v, resp, err 433} 434 435// ListGroups lists all groups that contain the specified user as a member. 436// 437// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-groups 438func (s *AccountsService) ListGroups(accountID string) (*[]GroupInfo, *Response, error) { 439 u := fmt.Sprintf("accounts/%s/groups", accountID) 440 441 req, err := s.client.NewRequest("GET", u, nil) 442 if err != nil { 443 return nil, nil, err 444 } 445 446 v := new([]GroupInfo) 447 resp, err := s.client.Do(req, v) 448 if err != nil { 449 return nil, resp, err 450 } 451 452 return v, resp, err 453} 454 455// GetUserPreferences retrieves the user’s preferences. 456// 457// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-user-preferences 458func (s *AccountsService) GetUserPreferences(accountID string) (*PreferencesInfo, *Response, error) { 459 u := fmt.Sprintf("accounts/%s/preferences", accountID) 460 461 req, err := s.client.NewRequest("GET", u, nil) 462 if err != nil { 463 return nil, nil, err 464 } 465 466 v := new(PreferencesInfo) 467 resp, err := s.client.Do(req, v) 468 if err != nil { 469 return nil, resp, err 470 } 471 472 return v, resp, err 473} 474 475// GetDiffPreferences retrieves the diff preferences of a user. 476// 477// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-diff-preferences 478func (s *AccountsService) GetDiffPreferences(accountID string) (*DiffPreferencesInfo, *Response, error) { 479 u := fmt.Sprintf("accounts/%s/preferences.diff", accountID) 480 481 req, err := s.client.NewRequest("GET", u, nil) 482 if err != nil { 483 return nil, nil, err 484 } 485 486 v := new(DiffPreferencesInfo) 487 resp, err := s.client.Do(req, v) 488 if err != nil { 489 return nil, resp, err 490 } 491 492 return v, resp, err 493} 494 495// GetStarredChanges gets the changes starred by the identified user account. 496// This URL endpoint is functionally identical to the changes query GET /changes/?q=is:starred. 497// 498// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-starred-changes 499func (s *AccountsService) GetStarredChanges(accountID string) (*[]ChangeInfo, *Response, error) { 500 u := fmt.Sprintf("accounts/%s/starred.changes", accountID) 501 502 req, err := s.client.NewRequest("GET", u, nil) 503 if err != nil { 504 return nil, nil, err 505 } 506 507 v := new([]ChangeInfo) 508 resp, err := s.client.Do(req, v) 509 if err != nil { 510 return nil, resp, err 511 } 512 513 return v, resp, err 514} 515 516// SuggestAccount suggests users for a given query q and result limit n. 517// If result limit is not passed, then the default 10 is used. 518// Returns a list of matching AccountInfo entities. 519// 520// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#query-account 521func (s *AccountsService) SuggestAccount(opt *QueryOptions) (*[]AccountInfo, *Response, error) { 522 u := "accounts/" 523 524 u, err := addOptions(u, opt) 525 if err != nil { 526 return nil, nil, err 527 } 528 529 req, err := s.client.NewRequest("GET", u, nil) 530 if err != nil { 531 return nil, nil, err 532 } 533 534 v := new([]AccountInfo) 535 resp, err := s.client.Do(req, v) 536 if err != nil { 537 return nil, resp, err 538 } 539 540 return v, resp, err 541} 542 543// CreateAccount creates a new account. 544// In the request body additional data for the account can be provided as AccountInput. 545// 546// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#create-account 547func (s *AccountsService) CreateAccount(username string, input *AccountInput) (*AccountInfo, *Response, error) { 548 u := fmt.Sprintf("accounts/%s", username) 549 550 req, err := s.client.NewRequest("PUT", u, input) 551 if err != nil { 552 return nil, nil, err 553 } 554 555 v := new(AccountInfo) 556 resp, err := s.client.Do(req, v) 557 if err != nil { 558 return nil, resp, err 559 } 560 561 return v, resp, err 562} 563 564// SetAccountName sets the full name of an account. 565// The new account name must be provided in the request body inside an AccountNameInput entity. 566// 567// As response the new account name is returned. 568// If the name was deleted the response is “204 No Content”. 569// Some realms may not allow to modify the account name. 570// In this case the request is rejected with “405 Method Not Allowed”. 571// 572// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-account-name 573func (s *AccountsService) SetAccountName(accountID string, input *AccountNameInput) (*string, *Response, error) { 574 u := fmt.Sprintf("accounts/%s/name", accountID) 575 576 // TODO Use here the getStringResponseWithoutOptions (for PUT requests) 577 578 req, err := s.client.NewRequest("PUT", u, input) 579 if err != nil { 580 return nil, nil, err 581 } 582 583 v := new(string) 584 resp, err := s.client.Do(req, v) 585 if err != nil { 586 return nil, resp, err 587 } 588 589 return v, resp, err 590} 591 592// DeleteAccountName deletes the name of an account. 593// 594// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-account-name 595func (s *AccountsService) DeleteAccountName(accountID string) (*Response, error) { 596 u := fmt.Sprintf("accounts/%s/name", accountID) 597 return s.client.DeleteRequest(u, nil) 598} 599 600// DeleteActive sets the account state to inactive. 601// If the account was already inactive the response is “404 Not Found”. 602// 603// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-active 604func (s *AccountsService) DeleteActive(accountID string) (*Response, error) { 605 u := fmt.Sprintf("accounts/%s/active", accountID) 606 return s.client.DeleteRequest(u, nil) 607} 608 609// DeleteHTTPPassword deletes the HTTP password of an account. 610// 611// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-http-password 612func (s *AccountsService) DeleteHTTPPassword(accountID string) (*Response, error) { 613 u := fmt.Sprintf("accounts/%s/password.http", accountID) 614 return s.client.DeleteRequest(u, nil) 615} 616 617// DeleteAccountEmail deletes an email address of an account. 618// 619// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-account-email 620func (s *AccountsService) DeleteAccountEmail(accountID, emailID string) (*Response, error) { 621 u := fmt.Sprintf("accounts/%s/emails/%s", accountID, emailID) 622 return s.client.DeleteRequest(u, nil) 623} 624 625// DeleteSSHKey deletes an SSH key of a user. 626// 627// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-ssh-key 628func (s *AccountsService) DeleteSSHKey(accountID, sshKeyID string) (*Response, error) { 629 u := fmt.Sprintf("accounts/%s/sshkeys/%s", accountID, sshKeyID) 630 return s.client.DeleteRequest(u, nil) 631} 632 633// DeleteGPGKey deletes a GPG key of a user. 634// 635// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#delete-gpg-key 636func (s *AccountsService) DeleteGPGKey(accountID, gpgKeyID string) (*Response, error) { 637 u := fmt.Sprintf("accounts/%s/gpgkeys/%s", accountID, gpgKeyID) 638 return s.client.DeleteRequest(u, nil) 639} 640 641// SetUsername sets a new username. 642// The new username must be provided in the request body inside a UsernameInput entity. 643// Once set, the username cannot be changed or deleted. 644// If attempted this fails with “405 Method Not Allowed”. 645// 646// As response the new username is returned. 647// 648// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-username 649func (s *AccountsService) SetUsername(accountID string, input *UsernameInput) (*string, *Response, error) { 650 u := fmt.Sprintf("accounts/%s/username", accountID) 651 652 req, err := s.client.NewRequest("PUT", u, input) 653 if err != nil { 654 return nil, nil, err 655 } 656 657 v := new(string) 658 resp, err := s.client.Do(req, v) 659 if err != nil { 660 return nil, resp, err 661 } 662 663 return v, resp, err 664} 665 666// GetActive checks if an account is active. 667// 668// If the account is active the string ok is returned. 669// If the account is inactive the response is “204 No Content”. 670// 671// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-active 672func (s *AccountsService) GetActive(accountID string) (string, *Response, error) { 673 u := fmt.Sprintf("accounts/%s/active", accountID) 674 return getStringResponseWithoutOptions(s.client, u) 675} 676 677// SetActive sets the account state to active. 678// 679// If the account was already active the response is “200 OK”. 680// 681// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-active 682func (s *AccountsService) SetActive(accountID string) (*Response, error) { 683 u := fmt.Sprintf("accounts/%s/active", accountID) 684 685 req, err := s.client.NewRequest("PUT", u, nil) 686 if err != nil { 687 return nil, err 688 } 689 return s.client.Do(req, nil) 690} 691 692// SetHTTPPassword sets/Generates the HTTP password of an account. 693// The options for setting/generating the HTTP password must be provided in the request body inside a HTTPPasswordInput entity. 694// 695// As response the new HTTP password is returned. 696// If the HTTP password was deleted the response is “204 No Content”. 697// 698// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-http-password 699func (s *AccountsService) SetHTTPPassword(accountID string, input *HTTPPasswordInput) (*string, *Response, error) { 700 u := fmt.Sprintf("accounts/%s/password.http", accountID) 701 702 req, err := s.client.NewRequest("PUT", u, input) 703 if err != nil { 704 return nil, nil, err 705 } 706 707 v := new(string) 708 resp, err := s.client.Do(req, v) 709 if err != nil { 710 return nil, resp, err 711 } 712 713 return v, resp, err 714} 715 716// CreateAccountEmail registers a new email address for the user. 717// A verification email is sent with a link that needs to be visited to confirm the email address, unless DEVELOPMENT_BECOME_ANY_ACCOUNT is used as authentication type. 718// For the development mode email addresses are directly added without confirmation. 719// A Gerrit administrator may add an email address without confirmation by setting no_confirmation in the EmailInput. 720// In the request body additional data for the email address can be provided as EmailInput. 721// 722// As response the new email address is returned as EmailInfo entity. 723// 724// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#create-account-email 725func (s *AccountsService) CreateAccountEmail(accountID, emailID string, input *EmailInput) (*EmailInfo, *Response, error) { 726 u := fmt.Sprintf("accounts/%s/emails/%s", accountID, emailID) 727 728 req, err := s.client.NewRequest("PUT", u, input) 729 if err != nil { 730 return nil, nil, err 731 } 732 733 v := new(EmailInfo) 734 resp, err := s.client.Do(req, v) 735 if err != nil { 736 return nil, resp, err 737 } 738 739 return v, resp, err 740} 741 742// SetPreferredEmail sets an email address as preferred email address for an account. 743// 744// If the email address was already the preferred email address of the account the response is “200 OK”. 745// 746// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-preferred-email 747func (s *AccountsService) SetPreferredEmail(accountID, emailID string) (*Response, error) { 748 u := fmt.Sprintf("accounts/%s/emails/%s/preferred", accountID, emailID) 749 750 req, err := s.client.NewRequest("PUT", u, nil) 751 if err != nil { 752 return nil, err 753 } 754 return s.client.Do(req, nil) 755} 756 757// GetAvatarChangeURL retrieves the URL where the user can change the avatar image. 758// 759// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#get-avatar-change-url 760func (s *AccountsService) GetAvatarChangeURL(accountID string) (string, *Response, error) { 761 u := fmt.Sprintf("accounts/%s/avatar.change.url", accountID) 762 return getStringResponseWithoutOptions(s.client, u) 763} 764 765// AddGPGKeys Add or delete one or more GPG keys for a user. 766// The changes must be provided in the request body as a GpgKeysInput entity. 767// Each new GPG key is provided in ASCII armored format, and must contain a self-signed certification matching a registered email or other identity of the user. 768// 769// As a response, the modified GPG keys are returned as a map of GpgKeyInfo entities, keyed by ID. Deleted keys are represented by an empty object. 770// 771// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#add-delete-gpg-keys 772func (s *AccountsService) AddGPGKeys(accountID string, input *GpgKeysInput) (*map[string]GpgKeyInfo, *Response, error) { 773 u := fmt.Sprintf("accounts/%s/gpgkeys", accountID) 774 775 req, err := s.client.NewRequest("POST", u, input) 776 if err != nil { 777 return nil, nil, err 778 } 779 780 v := new(map[string]GpgKeyInfo) 781 resp, err := s.client.Do(req, v) 782 if err != nil { 783 return nil, resp, err 784 } 785 786 return v, resp, err 787} 788 789// CheckAccountCapability checks if a user has a certain global capability. 790// 791// If the user has the global capability the string ok is returned. 792// If the user doesn’t have the global capability the response is “404 Not Found”. 793// 794// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#check-account-capability 795func (s *AccountsService) CheckAccountCapability(accountID, capabilityID string) (string, *Response, error) { 796 u := fmt.Sprintf("accounts/%s/capabilities/%s", accountID, capabilityID) 797 return getStringResponseWithoutOptions(s.client, u) 798} 799 800// SetUserPreferences sets the user’s preferences. 801// The new preferences must be provided in the request body as a PreferencesInput entity. 802// 803// As result the new preferences of the user are returned as a PreferencesInfo entity. 804// 805// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-user-preferences 806func (s *AccountsService) SetUserPreferences(accountID string, input *PreferencesInput) (*PreferencesInfo, *Response, error) { 807 u := fmt.Sprintf("accounts/%s/preferences", accountID) 808 809 req, err := s.client.NewRequest("PUT", u, input) 810 if err != nil { 811 return nil, nil, err 812 } 813 814 v := new(PreferencesInfo) 815 resp, err := s.client.Do(req, v) 816 if err != nil { 817 return nil, resp, err 818 } 819 820 return v, resp, err 821} 822 823// SetDiffPreferences sets the diff preferences of a user. 824// The new diff preferences must be provided in the request body as a DiffPreferencesInput entity. 825// 826// As result the new diff preferences of the user are returned as a DiffPreferencesInfo entity. 827// 828// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#set-diff-preferences 829func (s *AccountsService) SetDiffPreferences(accountID string, input *DiffPreferencesInput) (*DiffPreferencesInfo, *Response, error) { 830 u := fmt.Sprintf("accounts/%s/preferences.diff", accountID) 831 832 req, err := s.client.NewRequest("PUT", u, input) 833 if err != nil { 834 return nil, nil, err 835 } 836 837 v := new(DiffPreferencesInfo) 838 resp, err := s.client.Do(req, v) 839 if err != nil { 840 return nil, resp, err 841 } 842 843 return v, resp, err 844} 845 846// StarChange star a change. 847// Starred changes are returned for the search query is:starred or starredby:USER and automatically notify the user whenever updates are made to the change. 848// 849// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#star-change 850func (s *AccountsService) StarChange(accountID, changeID string) (*Response, error) { 851 u := fmt.Sprintf("accounts/%s/starred.changes/%s", accountID, changeID) 852 853 req, err := s.client.NewRequest("PUT", u, nil) 854 if err != nil { 855 return nil, err 856 } 857 858 return s.client.Do(req, nil) 859} 860 861// UnstarChange nstar a change. 862// Removes the starred flag, stopping notifications. 863// 864// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#unstar-change 865func (s *AccountsService) UnstarChange(accountID, changeID string) (*Response, error) { 866 u := fmt.Sprintf("accounts/%s/starred.changes/%s", accountID, changeID) 867 return s.client.DeleteRequest(u, nil) 868} 869 870/* 871Missing Account Endpoints: 872 Add SSH Key 873 Get Avatar 874*/ 875