mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-03 10:07:34 +02:00
* add migrations * fix package dependency * fix lints * implements migrations except pull requests * add releases * migrating releases * fix bug * fix lint * fix migrate releases * fix tests * add rollback * pull request migtations * fix import * fix go module vendor * add tests for upload to gitea * more migrate options * fix swagger-check * fix misspell * add options on migration UI * fix log error * improve UI options on migrating * add support for username password when migrating from github * fix tests * remove comments and fix migrate limitation * improve error handles * migrate API will also support migrate milestones/labels/issues/pulls/releases * fix tests and remove unused codes * add DownloaderFactory and docs about how to create a new Downloader * fix misspell * fix migration docs * Add hints about migrate options on migration page * fix tests
129 lines
3.9 KiB
Go
129 lines
3.9 KiB
Go
// Copyright 2016 The go-github AUTHORS. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package github
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// GPGKey represents a GitHub user's public GPG key used to verify GPG signed commits and tags.
|
|
//
|
|
// https://developer.github.com/changes/2016-04-04-git-signing-api-preview/
|
|
type GPGKey struct {
|
|
ID *int64 `json:"id,omitempty"`
|
|
PrimaryKeyID *int64 `json:"primary_key_id,omitempty"`
|
|
KeyID *string `json:"key_id,omitempty"`
|
|
PublicKey *string `json:"public_key,omitempty"`
|
|
Emails []GPGEmail `json:"emails,omitempty"`
|
|
Subkeys []GPGKey `json:"subkeys,omitempty"`
|
|
CanSign *bool `json:"can_sign,omitempty"`
|
|
CanEncryptComms *bool `json:"can_encrypt_comms,omitempty"`
|
|
CanEncryptStorage *bool `json:"can_encrypt_storage,omitempty"`
|
|
CanCertify *bool `json:"can_certify,omitempty"`
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
|
}
|
|
|
|
// String stringifies a GPGKey.
|
|
func (k GPGKey) String() string {
|
|
return Stringify(k)
|
|
}
|
|
|
|
// GPGEmail represents an email address associated to a GPG key.
|
|
type GPGEmail struct {
|
|
Email *string `json:"email,omitempty"`
|
|
Verified *bool `json:"verified,omitempty"`
|
|
}
|
|
|
|
// ListGPGKeys lists the public GPG keys for a user. Passing the empty
|
|
// string will fetch keys for the authenticated user. It requires authentication
|
|
// via Basic Auth or via OAuth with at least read:gpg_key scope.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#list-gpg-keys-for-a-user
|
|
func (s *UsersService) ListGPGKeys(ctx context.Context, user string, opt *ListOptions) ([]*GPGKey, *Response, error) {
|
|
var u string
|
|
if user != "" {
|
|
u = fmt.Sprintf("users/%v/gpg_keys", user)
|
|
} else {
|
|
u = "user/gpg_keys"
|
|
}
|
|
u, err := addOptions(u, opt)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
var keys []*GPGKey
|
|
resp, err := s.client.Do(ctx, req, &keys)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return keys, resp, nil
|
|
}
|
|
|
|
// GetGPGKey gets extended details for a single GPG key. It requires authentication
|
|
// via Basic Auth or via OAuth with at least read:gpg_key scope.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key
|
|
func (s *UsersService) GetGPGKey(ctx context.Context, id int64) (*GPGKey, *Response, error) {
|
|
u := fmt.Sprintf("user/gpg_keys/%v", id)
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
key := &GPGKey{}
|
|
resp, err := s.client.Do(ctx, req, key)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return key, resp, nil
|
|
}
|
|
|
|
// CreateGPGKey creates a GPG key. It requires authenticatation via Basic Auth
|
|
// or OAuth with at least write:gpg_key scope.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key
|
|
func (s *UsersService) CreateGPGKey(ctx context.Context, armoredPublicKey string) (*GPGKey, *Response, error) {
|
|
gpgKey := &struct {
|
|
ArmoredPublicKey string `json:"armored_public_key"`
|
|
}{ArmoredPublicKey: armoredPublicKey}
|
|
req, err := s.client.NewRequest("POST", "user/gpg_keys", gpgKey)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
key := &GPGKey{}
|
|
resp, err := s.client.Do(ctx, req, key)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return key, resp, nil
|
|
}
|
|
|
|
// DeleteGPGKey deletes a GPG key. It requires authentication via Basic Auth or
|
|
// via OAuth with at least admin:gpg_key scope.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#delete-a-gpg-key
|
|
func (s *UsersService) DeleteGPGKey(ctx context.Context, id int64) (*Response, error) {
|
|
u := fmt.Sprintf("user/gpg_keys/%v", id)
|
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s.client.Do(ctx, req, nil)
|
|
}
|