MCPcopy Create free account
hub / github.com/gogs/gogs / RewriteAuthorizedKeys

Function RewriteAuthorizedKeys

internal/database/ssh_key.go:519–553  ·  view source on GitHub ↗

RewriteAuthorizedKeys removes any authorized key and rewrite all keys from database again. Note: x.Iterate does not get latest data after insert/delete, so we have to call this function outside any session scope independently. Deprecated: Use PublicKeys.RewriteAuthorizedKeys instead.

()

Source from the content-addressed store, hash-verified

517//
518// Deprecated: Use PublicKeys.RewriteAuthorizedKeys instead.
519func RewriteAuthorizedKeys() error {
520 sshOpLocker.Lock()
521 defer sshOpLocker.Unlock()
522
523 log.Trace("Doing: RewriteAuthorizedKeys")
524
525 _ = os.MkdirAll(conf.SSH.RootPath, os.ModePerm)
526 fpath := authorizedKeysPath()
527 tmpPath := fpath + ".tmp"
528 f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
529 if err != nil {
530 return err
531 }
532 defer os.Remove(tmpPath)
533
534 err = x.Iterate(new(PublicKey), func(idx int, bean any) (err error) {
535 _, err = f.WriteString((bean.(*PublicKey)).AuthorizedString())
536 return err
537 })
538 _ = f.Close()
539 if err != nil {
540 return err
541 }
542
543 if com.IsExist(fpath) {
544 if err = os.Remove(fpath); err != nil {
545 return err
546 }
547 }
548 if err = os.Rename(tmpPath, fpath); err != nil {
549 return err
550 }
551
552 return nil
553}
554
555// ________ .__ ____ __.
556// \______ \ ____ ______ | | ____ ___.__.| |/ _|____ ___.__.

Callers 3

GlobalInitFunction · 0.92
OperationFunction · 0.92
DeletePublicKeyFunction · 0.85

Calls 4

authorizedKeysPathFunction · 0.85
RemoveMethod · 0.80
IterateMethod · 0.80
AuthorizedStringMethod · 0.80

Tested by

no test coverage detected