Create function for "Add SSH Key" #178
Create function for "Add SSH Key" #178christinak09 wants to merge 1 commit intoandygrunwald:masterfrom
Conversation
accounts_test.go
Outdated
| expectedSSHKey := "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== john.doe@example.com" | ||
| body, _ := io.ReadAll(r.Body) | ||
| receivedSSHKey := strings.TrimSpace(string(body)) | ||
| receivedSSHKey = strings.Trim(receivedSSHKey, `"`) |
There was a problem hiding this comment.
This doesn't look right. We want the receivedSSHKey to be the exact ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== john.doe@example.com instead of "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== john.doe@example.com".
There was a problem hiding this comment.
It turns out that the NewRequest method in gerrit.go encodes any body inputs into json format which adds "" to the string.
To fix this, I introduced a new method NewRawPostRequest that passes string directly to the request.
accounts.go
Outdated
|
|
||
| // AddSSHKey adds an SSH key to a user's account. | ||
| // Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#add-ssh-key | ||
| func (s *AccountsService) AddSSHKey(ctx context.Context, accountID string, SSHKey string) (*SSHKeyInfo, *Response, error) { |
jingyuanliang
left a comment
There was a problem hiding this comment.
We might want to abstract NewRawPutRequest and NewRawPostRequest because they're so similar (NewRawRequest?)... but no strong opinion. @andygrunwald to decide?
Maybe squash the commits because there were a bit dirty back and forth. LGTM otherwise.
accounts.go
Outdated
| return nil, nil, err | ||
| } | ||
|
|
||
| req.Header.Set("Content-Type", "text/plain") |
There was a problem hiding this comment.
This is already set according to your new NewRawPostRequest function.
22ab28a to
aacec86
Compare
Added AddSSHKey function and unit tests