mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-05 14:07:01 +00:00
02bd942b04
continue #75 close #16 - fix regression (from #34) _thanks to @crystal_ - create own gitea client package - more logging - add mock impl of CertDB Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: crystal <crystal@noreply.codeberg.org> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/78 Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
55 lines
1 KiB
Go
55 lines
1 KiB
Go
package database
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/OrlovEvgeny/go-mcache"
|
|
"github.com/akrylysov/pogreb"
|
|
"github.com/go-acme/lego/v4/certificate"
|
|
)
|
|
|
|
var _ CertDB = tmpDB{}
|
|
|
|
type tmpDB struct {
|
|
intern *mcache.CacheDriver
|
|
ttl time.Duration
|
|
}
|
|
|
|
func (p tmpDB) Close() error {
|
|
_ = p.intern.Close()
|
|
return nil
|
|
}
|
|
|
|
func (p tmpDB) Put(name string, cert *certificate.Resource) error {
|
|
return p.intern.Set(name, cert, p.ttl)
|
|
}
|
|
|
|
func (p tmpDB) Get(name string) (*certificate.Resource, error) {
|
|
cert, has := p.intern.Get(name)
|
|
if !has {
|
|
return nil, fmt.Errorf("cert for '%s' not found", name)
|
|
}
|
|
return cert.(*certificate.Resource), nil
|
|
}
|
|
|
|
func (p tmpDB) Delete(key string) error {
|
|
p.intern.Remove(key)
|
|
return nil
|
|
}
|
|
|
|
func (p tmpDB) Compact() (string, error) {
|
|
p.intern.Truncate()
|
|
return "Truncate done", nil
|
|
}
|
|
|
|
func (p tmpDB) Items() *pogreb.ItemIterator {
|
|
panic("ItemIterator not implemented for tmpDB")
|
|
}
|
|
|
|
func NewTmpDB() (CertDB, error) {
|
|
return &tmpDB{
|
|
intern: mcache.New(),
|
|
ttl: time.Minute,
|
|
}, nil
|
|
}
|