code.gitea.io/gitea@v1.22.3/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 (
     7  	"context"
     8  
     9  	"code.gitea.io/gitea/models/db"
    10  )
    11  
    12  //    __________________  ________   ____  __.
    13  //   /  _____/\______   \/  _____/  |    |/ _|____ ___.__.
    14  //  /   \  ___ |     ___/   \  ___  |      <_/ __ <   |  |
    15  //  \    \_\  \|    |   \    \_\  \ |    |  \  ___/\___  |
    16  //   \______  /|____|    \______  / |____|__ \___  > ____|
    17  //          \/                  \/          \/   \/\/
    18  //  .___                              __
    19  //  |   | _____ ______   ____________/  |_
    20  //  |   |/     \\____ \ /  _ \_  __ \   __\
    21  //  |   |  Y Y  \  |_> >  <_> )  | \/|  |
    22  //  |___|__|_|  /   __/ \____/|__|   |__|
    23  //            \/|__|
    24  
    25  // This file contains functions related to the original import of a key
    26  
    27  // GPGKeyImport the original import of key
    28  type GPGKeyImport struct {
    29  	KeyID   string `xorm:"pk CHAR(16) NOT NULL"`
    30  	Content string `xorm:"MEDIUMTEXT NOT NULL"`
    31  }
    32  
    33  func init() {
    34  	db.RegisterModel(new(GPGKeyImport))
    35  }
    36  
    37  // GetGPGImportByKeyID returns the import public armored key by given KeyID.
    38  func GetGPGImportByKeyID(ctx context.Context, keyID string) (*GPGKeyImport, error) {
    39  	key := new(GPGKeyImport)
    40  	has, err := db.GetEngine(ctx).ID(keyID).Get(key)
    41  	if err != nil {
    42  		return nil, err
    43  	} else if !has {
    44  		return nil, ErrGPGKeyImportNotExist{keyID}
    45  	}
    46  	return key, nil
    47  }