2023-02-10 03:00:14 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"codeberg.org/codeberg/pages/server/database"
|
|
|
|
)
|
|
|
|
|
|
|
|
func openCertDB(ctx *cli.Context) (certDB database.CertDB, closeFn func(), err error) {
|
2023-02-11 02:04:57 +00:00
|
|
|
certDB, err = database.NewXormDB(ctx.String("db-type"), ctx.String("db-conn"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("could not connect to database: %w", err)
|
2023-02-10 03:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closeFn = func() {
|
|
|
|
if err := certDB.Close(); err != nil {
|
|
|
|
log.Error().Err(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return certDB, closeFn, nil
|
|
|
|
}
|