-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Implement GPG api #710
Conversation
Will need some tests before it's done as well ;) (We should have a checklist in the PR_Template ;) |
build failed |
Not yet ready. |
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.
Thoughts?
models/gpg_key.go
Outdated
Added time.Time `xorm:"-"` | ||
AddedUnix int64 | ||
SubsKey []*GPGKey `xorm:"-"` | ||
Emails []string |
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.
Maybe use []models.EmailAddress
? (even though we don't use all the fields) Since that could also be used to map users to keys
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.
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 ...
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.
I'm fairly certain that multiple users can not have the same email (Unique constraint), though there might be a lingering bug there 😉
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.
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.
models/gpg_key.go
Outdated
@@ -0,0 +1,297 @@ | |||
// Copyright 2014 The Gogs Authors. All rights reserved. |
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.
2017 The Gitea Authors.
models/gpg_key_test.go
Outdated
-----END PGP PUBLIC KEY BLOCK-----` | ||
|
||
key, err := checkArmoredGPGKeyString(testGPGArmor) | ||
if err != nil { |
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.
If you expect err
to be nil
, use assert.NoError(t, err)
😃
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.
Will use directly assert.Nil(t, err, "Could not parse a valid GPG armored key")
routers/api/v1/convert/convert.go
Outdated
@@ -73,6 +73,41 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey { | |||
} | |||
} | |||
|
|||
// ToGPGKey converts models.PublicGPGKey to api.GPGKey |
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.
Should the comment say models.GPGKey
?
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 should be a APIFormat
-function on the model itself :)
routers/api/v1/user/gpg_key.go
Outdated
@@ -0,0 +1,93 @@ | |||
// Copyright 2015 The Gogs Authors. All rights reserved. |
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.
Copyright 2017 The Gitea Authors
Conflicted and any update? |
Just move this to v1.2 |
models/gpg_key.go
Outdated
@@ -0,0 +1,273 @@ | |||
// Copyright 2017 The Gogs Authors. All rights reserved. |
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.
The Gitea :)
So i think i have done all the API part. I will rebase/squash every things to make it less bad for complete review ^^. |
So cool! |
Oups i must I done something wrong with my squash ... |
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. |
It's ready to review? |
models/gpg_key.go
Outdated
defer sessionRelease(sess) | ||
sess.Begin() | ||
for _, subkey := range key.SubsKey { | ||
if err := addGPGKey(sess, subkey); err != nil { |
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.
sess.Inert(key.SubsKey)
just ok?
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.
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.
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.
Or maybe a other solution could be to not use AfterInsert but addGPGKey recursively in addGPGKey for subkeys ? This would be more simple.
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.
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.
models/gpg_key.go
Outdated
} | ||
return base64.StdEncoding.EncodeToString(w.Bytes()), nil | ||
} | ||
func parseSubGPGKey(ownerID int64, primaryID string, pubkey *packet.PublicKey, expiry time.Time) (*GPGKey, 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.
blank line
models/gpg_key.go
Outdated
CanCertify: pubkey.PubKeyAlgo.CanSign(), | ||
}, nil | ||
} | ||
func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, 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.
^
models/gpg_key.go
Outdated
|
||
//Add subkeys to remove | ||
subkeys := make([]*GPGKey, 0, 5) | ||
x.Where("primary_key_id=?", key.KeyID).Find(&subkeys) |
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.
err handler
models/gpg_key.go
Outdated
} | ||
|
||
//Add subkeys to remove | ||
subkeys := make([]*GPGKey, 0, 5) |
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.
var subkeyIDs []int64
err = x.Table("gpgkey").Where("primary_key_id=?", key.KeyID).Find(& subkeyIDs)
routers/api/v1/convert/convert.go
Outdated
Created: k.Created, | ||
Expires: k.Expired, | ||
//Emails: emails, | ||
//SubsKey: subkeys, |
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.
Why comment these?
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.
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.
rebase |
LGTM |
@sapk Is the new |
LGTM except @bkcsoft 's comment. @ethantkoenig need your confirmation since you have reviewed this. |
It was allready vendor in master if I remember. |
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. |
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)
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
Bug :
The public_key part in the respond is not in the good format.