|
| 1 | +// Copyright 2014 The Gogs Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package models |
| 6 | + |
| 7 | +import ( |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/gogits/gogs/modules/log" |
| 11 | +) |
| 12 | + |
| 13 | +//TODO maybe refector with ssh-key ? |
| 14 | +//TODO database behind |
| 15 | + |
| 16 | +// PublicGPGKey represents a GPG key. |
| 17 | +type PublicGPGKey struct { |
| 18 | + ID int64 `xorm:"pk autoincr"` |
| 19 | + OwnerID int64 `xorm:"INDEX NOT NULL"` |
| 20 | + Name string `xorm:"NOT NULL"` |
| 21 | + Fingerprint string `xorm:"NOT NULL"` |
| 22 | + Content string `xorm:"TEXT NOT NULL"` |
| 23 | + |
| 24 | + Created time.Time `xorm:"-"` |
| 25 | +} |
| 26 | + |
| 27 | +// ListPublicGPGKeys returns a list of public keys belongs to given user. |
| 28 | +func ListPublicGPGKeys(uid int64) ([]*PublicGPGKey, error) { |
| 29 | + keys := make([]*PublicGPGKey, 0, 5) |
| 30 | + return keys, x.Where("owner_id=?", uid).Find(&keys) |
| 31 | +} |
| 32 | + |
| 33 | +// GetPublicGPGKeyByID returns public key by given ID. |
| 34 | +func GetPublicGPGKeyByID(keyID int64) (*PublicGPGKey, error) { |
| 35 | + key := new(PublicGPGKey) |
| 36 | + has, err := x.Id(keyID).Get(key) |
| 37 | + if err != nil { |
| 38 | + return nil, err |
| 39 | + } else if !has { |
| 40 | + return nil, ErrKeyNotExist{keyID} |
| 41 | + } |
| 42 | + return key, nil |
| 43 | +} |
| 44 | + |
| 45 | +// CheckPublicGPGKeyString checks if the given public key string is a valid GPG key. |
| 46 | +// The function returns the actual public key line on success. |
| 47 | +func CheckPublicGPGKeyString(content string) (_ string, err error) { |
| 48 | + //TODO Implement |
| 49 | + return "", nil |
| 50 | +} |
| 51 | + |
| 52 | +// AddPublicGPGKey adds new public key to database. |
| 53 | +func AddPublicGPGKey(ownerID int64, name, content string) (*PublicKey, error) { |
| 54 | + log.Trace(content) |
| 55 | + //TODO Implement |
| 56 | + return nil, nil |
| 57 | +} |
| 58 | + |
| 59 | +// DeletePublicGPGKey deletes GPG key information in database. |
| 60 | +func DeletePublicGPGKey(doer *User, id int64) (err error) { |
| 61 | + //TODO Implement |
| 62 | + return nil |
| 63 | +} |
0 commit comments