code.gitea.io/gitea@v1.22.3/modules/private/key.go (about)

     1  // Copyright 2018 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package private
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  
    10  	"code.gitea.io/gitea/modules/setting"
    11  )
    12  
    13  // UpdatePublicKeyInRepo update public key and if necessary deploy key updates
    14  func UpdatePublicKeyInRepo(ctx context.Context, keyID, repoID int64) error {
    15  	// Ask for running deliver hook and test pull request tasks.
    16  	reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update/%d", keyID, repoID)
    17  	req := newInternalRequest(ctx, reqURL, "POST")
    18  	_, extra := requestJSONResp(req, &ResponseText{})
    19  	return extra.Error
    20  }
    21  
    22  // AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
    23  // and returns public key found.
    24  func AuthorizedPublicKeyByContent(ctx context.Context, content string) (*ResponseText, ResponseExtra) {
    25  	// Ask for running deliver hook and test pull request tasks.
    26  	reqURL := setting.LocalURL + "api/internal/ssh/authorized_keys"
    27  	req := newInternalRequest(ctx, reqURL, "POST")
    28  	req.Param("content", content)
    29  	return requestJSONResp(req, &ResponseText{})
    30  }