Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

christinak09
Copy link

Added AddSSHKey function and unit tests

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, `"`)

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]".

Copy link
Author

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sshKey?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link

@jingyuanliang jingyuanliang left a 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")

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants