summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/convert/convert.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2017-03-16 02:27:35 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-16 09:27:35 +0800
commitca1c3f1926eff992a2458f26cb24ed2f35265b05 (patch)
treea0c859357539aebf4c3ce521fc8b5d1e6a870364 /routers/api/v1/convert/convert.go
parent43c5469f81851c084fa6ac84d8379ae949c3a05c (diff)
downloadgitea-ca1c3f1926eff992a2458f26cb24ed2f35265b05.tar.gz
gitea-ca1c3f1926eff992a2458f26cb24ed2f35265b05.zip
Implement GPG api (#710)
* Implement GPG API * Better handle error * Apply review recommendation + simplify database operations * Remove useless comments
Diffstat (limited to 'routers/api/v1/convert/convert.go')
-rw-r--r--routers/api/v1/convert/convert.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go
index 9729e65452..7485ac9e2a 100644
--- a/routers/api/v1/convert/convert.go
+++ b/routers/api/v1/convert/convert.go
@@ -73,6 +73,51 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
}
}
+// ToGPGKey converts models.GPGKey to api.GPGKey
+func ToGPGKey(key *models.GPGKey) *api.GPGKey {
+ subkeys := make([]*api.GPGKey, len(key.SubsKey))
+ for id, k := range key.SubsKey {
+ subkeys[id] = &api.GPGKey{
+ ID: k.ID,
+ PrimaryKeyID: k.PrimaryKeyID,
+ KeyID: k.KeyID,
+ PublicKey: k.Content,
+ Created: k.Created,
+ Expires: k.Expired,
+ CanSign: k.CanSign,
+ CanEncryptComms: k.CanEncryptComms,
+ CanEncryptStorage: k.CanEncryptStorage,
+ CanCertify: k.CanSign,
+ }
+ }
+ emails := make([]*api.GPGKeyEmail, len(key.Emails))
+ for i, e := range key.Emails {
+ emails[i] = ToGPGKeyEmail(e)
+ }
+ return &api.GPGKey{
+ ID: key.ID,
+ PrimaryKeyID: key.PrimaryKeyID,
+ KeyID: key.KeyID,
+ PublicKey: key.Content,
+ Created: key.Created,
+ Expires: key.Expired,
+ Emails: emails,
+ SubsKey: subkeys,
+ CanSign: key.CanSign,
+ CanEncryptComms: key.CanEncryptComms,
+ CanEncryptStorage: key.CanEncryptStorage,
+ CanCertify: key.CanSign,
+ }
+}
+
+// ToGPGKeyEmail convert models.EmailAddress to api.GPGKeyEmail
+func ToGPGKeyEmail(email *models.EmailAddress) *api.GPGKeyEmail {
+ return &api.GPGKeyEmail{
+ Email: email.Email,
+ Verified: email.IsActivated,
+ }
+}
+
// ToHook convert models.Webhook to api.Hook
func ToHook(repoLink string, w *models.Webhook) *api.Hook {
config := map[string]string{