From 5b56d55c18c82241cc9fc2b07722a0f945dd0cff Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Tue, 17 Jan 2017 11:38:58 +0100 Subject: [PATCH 1/3] Implement method for calling gpg related api --- gitea/user_gpgkey.go | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 gitea/user_gpgkey.go diff --git a/gitea/user_gpgkey.go b/gitea/user_gpgkey.go new file mode 100644 index 0000000..90647e3 --- /dev/null +++ b/gitea/user_gpgkey.go @@ -0,0 +1,67 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gitea + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +// GPGKey a user GPG key to sign commit and tag in repository +type GPGKey struct { + ID int64 `json:"id"` + PrimaryKeyID string `json:"primary_key_id"` + KeyID string `json:"key_id"` + PublicKey string `json:"public_key"` + Emails []*GPGKeyEmail `json:"emails"` + SubsKey []*GPGKey `json:"subkeys"` + CanSign bool `json:"can_sign"` + CanEncryptComms bool `json:"can_encrypt_comms"` + CanEncryptStorage bool `json:"can_encrypt_storage"` + CanCertify bool `json:"can_certify"` + Created time.Time `json:"created_at,omitempty"` + Expires time.Time `json:"expires_at,omitempty"` +} + +// GPGKeyEmail a email attache to a GPGKey +type GPGKeyEmail struct { + Email string `json:"email"` + //Verified bool `json:"verified"` +} + +// CreateGPGKeyOption options create user GPG key +type CreateGPGKeyOption struct { + ArmoredKey string `json:"armored_public_key" binding:"Required"` +} + +// ListMyGPGKeys list all the GPG keys of current user +func (c *Client) ListMyGPGKeys() ([]*GPGKey, error) { + keys := make([]*GPGKey, 0, 10) + return keys, c.getParsedResponse("GET", "/user/gpg_keys", nil, nil, &keys) +} + +// GetGPGKey get current user's GPG key by key id +func (c *Client) GetGPGKey(keyID int64) (*GPGKey, error) { + key := new(GPGKey) + return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key) +} + +// CreateGPGKey create GPG key with options +func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(GPGKey) + return key, c.getParsedResponse("POST", "/user/gpg_keys", jsonHeader, bytes.NewReader(body), key) +} + +// DeleteGPGKey delete GPG key with key id +func (c *Client) DeleteGPGKey(keyID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil) + return err +} From 8af81ba1138352140c0cdef73bbb4450d15eaff7 Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Tue, 17 Jan 2017 12:36:48 +0100 Subject: [PATCH 2/3] Fix copyright --- gitea/user_gpgkey.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/user_gpgkey.go b/gitea/user_gpgkey.go index 90647e3..dc01095 100644 --- a/gitea/user_gpgkey.go +++ b/gitea/user_gpgkey.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2017 Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. From 6c618c7f88fba52515b39258e735387d5fae0960 Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Wed, 18 Jan 2017 17:29:10 +0100 Subject: [PATCH 3/3] Uncomment verified field --- gitea/user_gpgkey.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitea/user_gpgkey.go b/gitea/user_gpgkey.go index dc01095..911e63f 100644 --- a/gitea/user_gpgkey.go +++ b/gitea/user_gpgkey.go @@ -29,8 +29,8 @@ type GPGKey struct { // GPGKeyEmail a email attache to a GPGKey type GPGKeyEmail struct { - Email string `json:"email"` - //Verified bool `json:"verified"` + Email string `json:"email"` + Verified bool `json:"verified"` } // CreateGPGKeyOption options create user GPG key