code.gitea.io/gitea@v1.21.7/services/asymkey/deploy_key.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"
    10  	asymkey_model "code.gitea.io/gitea/models/asymkey"
    11  	"code.gitea.io/gitea/models/db"
    12  	user_model "code.gitea.io/gitea/models/user"
    13  )
    14  
    15  // DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
    16  func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error {
    17  	dbCtx, committer, err := db.TxContext(ctx)
    18  	if err != nil {
    19  		return err
    20  	}
    21  	defer committer.Close()
    22  
    23  	if err := models.DeleteDeployKey(dbCtx, doer, id); err != nil {
    24  		return err
    25  	}
    26  	if err := committer.Commit(); err != nil {
    27  		return err
    28  	}
    29  
    30  	return asymkey_model.RewriteAllPublicKeys(ctx)
    31  }