code.gitea.io/gitea@v1.21.7/models/asymkey/gpg_key_import.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package asymkey 5 6 import "code.gitea.io/gitea/models/db" 7 8 // __________________ ________ ____ __. 9 // / _____/\______ \/ _____/ | |/ _|____ ___.__. 10 // / \ ___ | ___/ \ ___ | <_/ __ < | | 11 // \ \_\ \| | \ \_\ \ | | \ ___/\___ | 12 // \______ /|____| \______ / |____|__ \___ > ____| 13 // \/ \/ \/ \/\/ 14 // .___ __ 15 // | | _____ ______ ____________/ |_ 16 // | |/ \\____ \ / _ \_ __ \ __\ 17 // | | Y Y \ |_> > <_> ) | \/| | 18 // |___|__|_| / __/ \____/|__| |__| 19 // \/|__| 20 21 // This file contains functions related to the original import of a key 22 23 // GPGKeyImport the original import of key 24 type GPGKeyImport struct { 25 KeyID string `xorm:"pk CHAR(16) NOT NULL"` 26 Content string `xorm:"MEDIUMTEXT NOT NULL"` 27 } 28 29 func init() { 30 db.RegisterModel(new(GPGKeyImport)) 31 } 32 33 // GetGPGImportByKeyID returns the import public armored key by given KeyID. 34 func GetGPGImportByKeyID(keyID string) (*GPGKeyImport, error) { 35 key := new(GPGKeyImport) 36 has, err := db.GetEngine(db.DefaultContext).ID(keyID).Get(key) 37 if err != nil { 38 return nil, err 39 } else if !has { 40 return nil, ErrGPGKeyImportNotExist{keyID} 41 } 42 return key, nil 43 }