-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create function for "Add SSH Key" #178
base: master
Are you sure you want to change the base?
Conversation
accounts_test.go
Outdated
expectedSSHKey := "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== [email protected]" | ||
body, _ := io.ReadAll(r.Body) | ||
receivedSSHKey := strings.TrimSpace(string(body)) | ||
receivedSSHKey = strings.Trim(receivedSSHKey, `"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. We want the receivedSSHKey to be the exact ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== [email protected]
instead of "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== [email protected]"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -453,6 +453,27 @@ func (s *AccountsService) GetSSHKey(ctx context.Context, accountID, sshKeyID str | |||
return v, resp, err | |||
} | |||
|
|||
// 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sshKey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already set according to your new NewRawPostRequest function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
22ab28a
to
aacec86
Compare
Added AddSSHKey function and unit tests