Skip to content
Snippets Groups Projects
Select Git revision
  • 08c0e08d0e85ab8d3b22dfc123f43aa24c80721f
  • master default protected
  • renovate/golang.org-x-net-0.x
  • renovate/golang.org-x-crypto-0.x
  • renovate/go-1.x
  • renovate/golang.org-x-sync-0.x
  • renovate/github.com-protonmail-gopenpgp-v3-3.x
  • renovate/github.com-pquerna-otp-1.x
  • renovate/github.com-go-ldap-ldap-v3-3.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/git.autistici.org-id-auth-digest
  • renovate/github.com-protonmail-gopenpgp-v2-2.x
  • better-validation
13 results

auxdb.go

Blame
  • auxdb.go 5.31 KiB
    package auxdbbackend
    
    import (
    	"context"
    	"encoding/json"
    	"log"
    	"strings"
    	"sync"
    
    	as "git.autistici.org/ai3/accountserver"
    	"git.autistici.org/ai3/go-common/clientutil"
    	auxpb "git.autistici.org/ai3/tools/aux-db/proto"
    )
    
    // Data type of the webapp-related resources in aux-db.
    const auxDbWebappDataType = "cms_info"
    
    // Data type of disk usage resources in aux-db.
    const auxDbDiskUsageDataType = "disk_usage"
    
    // AuxWebappBackend looks up website information (cms_info data type) in
    // the aux-db service.
    //
    // A lookup spawns a number of requests for each resource that might
    // be involved, but we would like to group requests to aux-db such as
    // to minimize their number (and parallelize them). So we generate a
    // list of resource IDs to lookup, along with an associated callback
    // that will modify the original resource. Then we group them by
    // shard, fan out the requests in parallel, and invoke the callbacks
    // with the results.
    type AuxWebappBackend struct {
    	as.Backend
    
    	auxdbbe clientutil.Backend
    }
    
    type wdbTX struct {
    	as.TX
    	auxdbbe clientutil.Backend
    }
    
    func Wrap(b as.Backend, config *clientutil.BackendConfig) (*AuxWebappBackend, error) {
    	be, err := clientutil.NewBackend(config)
    	if err != nil {
    		return nil, err
    	}
    	return &AuxWebappBackend{
    		Backend: b,
    		auxdbbe: be,
    	}, nil
    }
    
    func (b *AuxWebappBackend) NewTransaction() (as.TX, error) {
    	tx, err := b.Backend.NewTransaction()
    	if err != nil {
    		return nil, err
    	}
    	return &wdbTX{
    		TX:      tx,
    		auxdbbe: b.auxdbbe,
    	}, nil
    }
    
    func (tx *wdbTX) GetUser(ctx context.Context, name string) (*as.RawUser, error) {
    	user, err := tx.TX.GetUser(ctx, name)
    	if err != nil || user == nil {
    		return user, err
    	}
    
    	// Find all web resources.