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

Implement GPG api #710

Merged
merged 4 commits into from
Mar 16, 2017
Merged

Implement GPG api #710

merged 4 commits into from
Mar 16, 2017

Conversation

sapk
Copy link
Member

@sapk sapk commented Jan 20, 2017

In order to implement #425.

I added all the api call that gitea should implement.
This is this a WIP. I will change the db format to extract all data and registrer sub-keys in db in order to not have to rely on parsing again the armored key after. For the moment the armored key is stored in db and parse at presentation.

For the last part (validation of commit ), I will do it in a separate PR.

Related to go-gitea/go-sdk#36

  • GET /users/:username/gpg_keys
  • GET /user/gpg_keys
  • GET /user/gpg_keys/:id
  • POST /user/gpg_keys
  • DELETE /user/gpg_keys/:id

Bug : The public_key part in the respond is not in the good format.

@bkcsoft bkcsoft added modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Jan 21, 2017
@bkcsoft
Copy link
Member

bkcsoft commented Jan 21, 2017

Will need some tests before it's done as well ;) (We should have a checklist in the PR_Template ;)

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 21, 2017
@lunny lunny added this to the 1.1.0 milestone Jan 21, 2017
@lunny
Copy link
Member

lunny commented Jan 23, 2017

build failed

@sapk
Copy link
Member Author

sapk commented Jan 23, 2017

Not yet ready.
I will stash all the commit when ready for a cleaner history.

@lunny lunny added the pr/wip This PR is not ready for review label Jan 23, 2017
Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

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

Thoughts?

Added time.Time `xorm:"-"`
AddedUnix int64
SubsKey []*GPGKey `xorm:"-"`
Emails []string
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use []models.EmailAddress ? (even though we don't use all the fields) Since that could also be used to map users to keys

Copy link
Member Author

Choose a reason for hiding this comment

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

The email storing is the last part to do now.
I was thinking of something like that but didn't know if it is possible that multiple user have the same email ? Maybe a weird case could be that someone import a gpg key with a commun email ...

Copy link
Member

Choose a reason for hiding this comment

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

I'm fairly certain that multiple users can not have the same email (Unique constraint), though there might be a lingering bug there 😉

Copy link
Member Author

@sapk sapk Mar 7, 2017

Choose a reason for hiding this comment

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

After searching and testing, I found that github only accept key with a allready verified email for your account. So []models.EmailAddress is definitly perfect for that.

@@ -0,0 +1,297 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

2017 The Gitea Authors.

-----END PGP PUBLIC KEY BLOCK-----`

key, err := checkArmoredGPGKeyString(testGPGArmor)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If you expect err to be nil, use assert.NoError(t, err) 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

Will use directly assert.Nil(t, err, "Could not parse a valid GPG armored key")

@@ -73,6 +73,41 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
}
}

// ToGPGKey converts models.PublicGPGKey to api.GPGKey
Copy link
Member

Choose a reason for hiding this comment

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

Should the comment say models.GPGKey?

Copy link
Member

Choose a reason for hiding this comment

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

It should be a APIFormat-function on the model itself :)

@@ -0,0 +1,93 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Copyright 2017 The Gitea Authors

@lunny
Copy link
Member

lunny commented Feb 5, 2017

Conflicted and any update?

@lunny
Copy link
Member

lunny commented Feb 11, 2017

Just move this to v1.2

@lunny lunny modified the milestones: 1.2.0, 1.1.0 Feb 11, 2017
@@ -0,0 +1,273 @@
// Copyright 2017 The Gogs Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

The Gitea :)

@sapk sapk changed the title WIP - Implement GPG api Implement GPG api Mar 8, 2017
@sapk
Copy link
Member Author

sapk commented Mar 8, 2017

So i think i have done all the API part. I will rebase/squash every things to make it less bad for complete review ^^.

@lunny
Copy link
Member

lunny commented Mar 8, 2017

So cool!

@lunny lunny removed the pr/wip This PR is not ready for review label Mar 8, 2017
@sapk sapk closed this Mar 8, 2017
@sapk
Copy link
Member Author

sapk commented Mar 8, 2017

Oups i must I done something wrong with my squash ...

@sapk
Copy link
Member Author

sapk commented Mar 10, 2017

Doing a own review of my code, I did some adjustment (very little cleaning and refactor) and found that i forgot expiration date of key.

@lunny
Copy link
Member

lunny commented Mar 10, 2017

It's ready to review?

defer sessionRelease(sess)
sess.Begin()
for _, subkey := range key.SubsKey {
if err := addGPGKey(sess, subkey); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

sess.Inert(key.SubsKey) just ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that was because I started with the same structure has https://github.com/go-gitea/gitea/blob/master/models/ssh_key.go#L396 but all checks on data are made in parseGPGKey so no need for addGPGKey.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or maybe a other solution could be to not use AfterInsert but addGPGKey recursively in addGPGKey for subkeys ? This would be more simple.

Copy link
Member Author

@sapk sapk Mar 11, 2017

Choose a reason for hiding this comment

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

I have gone with that even for delete case this permit that all the database logic are separated. Let me know if you want a other/better solution.

}
return base64.StdEncoding.EncodeToString(w.Bytes()), nil
}
func parseSubGPGKey(ownerID int64, primaryID string, pubkey *packet.PublicKey, expiry time.Time) (*GPGKey, error) {
Copy link
Member

Choose a reason for hiding this comment

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

blank line

CanCertify: pubkey.PubKeyAlgo.CanSign(),
}, nil
}
func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
Copy link
Member

Choose a reason for hiding this comment

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

^


//Add subkeys to remove
subkeys := make([]*GPGKey, 0, 5)
x.Where("primary_key_id=?", key.KeyID).Find(&subkeys)
Copy link
Member

Choose a reason for hiding this comment

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

err handler

}

//Add subkeys to remove
subkeys := make([]*GPGKey, 0, 5)
Copy link
Member

Choose a reason for hiding this comment

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

var subkeyIDs []int64
err = x.Table("gpgkey").Where("primary_key_id=?", key.KeyID).Find(& subkeyIDs)

Created: k.Created,
Expires: k.Expired,
//Emails: emails,
//SubsKey: subkeys,
Copy link
Member

Choose a reason for hiding this comment

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

Why comment these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Those are empy in subkeys so they can be remove. I was keeping them commented to show they are not set explicitly but not really usefull.

@sapk
Copy link
Member Author

sapk commented Mar 13, 2017

rebase

@bkcsoft
Copy link
Member

bkcsoft commented Mar 16, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 16, 2017
@bkcsoft
Copy link
Member

bkcsoft commented Mar 16, 2017

@sapk Is the new go-sdk vendored?

@lunny
Copy link
Member

lunny commented Mar 16, 2017

LGTM except @bkcsoft 's comment. @ethantkoenig need your confirmation since you have reviewed this.

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 16, 2017
@lunny lunny merged commit ca1c3f1 into go-gitea:master Mar 16, 2017
@lunny
Copy link
Member

lunny commented Mar 16, 2017

:( forgot. @sapk please take a look @bkcsoft 's comment.

@sapk
Copy link
Member Author

sapk commented Mar 16, 2017

It was allready vendor in master if I remember.

@sapk
Copy link
Member Author

sapk commented Mar 16, 2017

To be clear go-gitea/go-sdk@f5de21c is vendor. It's the only needed for this part.

go-gitea/go-sdk@4878372 only add missing request but don't change data format.

go-gitea/go-sdk@9da3bab Add commit verification but is not needed for api managing keys. It will be needed in commit verification.

@sapk sapk deleted the add-gpg-api branch April 28, 2017 10:04
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
6543 pushed a commit to 6543-forks/gitea that referenced this pull request Feb 26, 2024
Adds `[repository].DOWNLOAD_OR_CLONE_METHODS` (defaulting to
"download-zip,download-targz,download-bundle,vscode-clone"), which lets
an instance administrator override the additional clone methods
displayed on the repository home view.

This is purely display-only, the clone methods not listed here are still
available, unless disabled elsewhere. They're just not displayed.

Fixes go-gitea#710.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit 2aadcf4946e48ee43800568fe705d00a062c42bf)
(cherry picked from commit 42ac34fbf9105eed27ee687b305a85515270f0cc)
(cherry picked from commit bd231b02450212aca6be775663c3d24ddf19f990)
(cherry picked from commit 3d3366dbbee37621fc665e557a4a87bf08104375)
(cherry picked from commit 0157fb9b88fd50832c07b06c11c8dba6e059a465)
(cherry picked from commit bee88f6a8309c6f9aeba1522383d77f08e5a4d2d)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants