code.gitea.io/gitea@v1.21.7/routers/api/v1/misc/signing.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package misc 5 6 import ( 7 "fmt" 8 "net/http" 9 10 "code.gitea.io/gitea/modules/context" 11 asymkey_service "code.gitea.io/gitea/services/asymkey" 12 ) 13 14 // SigningKey returns the public key of the default signing key if it exists 15 func SigningKey(ctx *context.APIContext) { 16 // swagger:operation GET /signing-key.gpg miscellaneous getSigningKey 17 // --- 18 // summary: Get default signing-key.gpg 19 // produces: 20 // - text/plain 21 // responses: 22 // "200": 23 // description: "GPG armored public key" 24 // schema: 25 // type: string 26 27 // swagger:operation GET /repos/{owner}/{repo}/signing-key.gpg repository repoSigningKey 28 // --- 29 // summary: Get signing-key.gpg for given repository 30 // produces: 31 // - text/plain 32 // parameters: 33 // - name: owner 34 // in: path 35 // description: owner of the repo 36 // type: string 37 // required: true 38 // - name: repo 39 // in: path 40 // description: name of the repo 41 // type: string 42 // required: true 43 // responses: 44 // "200": 45 // description: "GPG armored public key" 46 // schema: 47 // type: string 48 49 path := "" 50 if ctx.Repo != nil && ctx.Repo.Repository != nil { 51 path = ctx.Repo.Repository.RepoPath() 52 } 53 54 content, err := asymkey_service.PublicSigningKey(ctx, path) 55 if err != nil { 56 ctx.Error(http.StatusInternalServerError, "gpg export", err) 57 return 58 } 59 _, err = ctx.Write([]byte(content)) 60 if err != nil { 61 ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %w", err)) 62 } 63 }