mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 10:37:56 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			843 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			843 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package totp
 | |
| 
 | |
| import (
 | |
| 	"strings"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/hashicorp/vault/logical"
 | |
| 	"github.com/hashicorp/vault/logical/framework"
 | |
| 	cache "github.com/patrickmn/go-cache"
 | |
| )
 | |
| 
 | |
| func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
 | |
| 	b := Backend()
 | |
| 	if err := b.Setup(conf); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return b, nil
 | |
| }
 | |
| 
 | |
| func Backend() *backend {
 | |
| 	var b backend
 | |
| 	b.Backend = &framework.Backend{
 | |
| 		Help: strings.TrimSpace(backendHelp),
 | |
| 
 | |
| 		Paths: []*framework.Path{
 | |
| 			pathListKeys(&b),
 | |
| 			pathKeys(&b),
 | |
| 			pathCode(&b),
 | |
| 		},
 | |
| 
 | |
| 		Secrets:     []*framework.Secret{},
 | |
| 		BackendType: logical.TypeLogical,
 | |
| 	}
 | |
| 
 | |
| 	b.usedCodes = cache.New(0, 30*time.Second)
 | |
| 
 | |
| 	return &b
 | |
| }
 | |
| 
 | |
| type backend struct {
 | |
| 	*framework.Backend
 | |
| 
 | |
| 	usedCodes *cache.Cache
 | |
| }
 | |
| 
 | |
| const backendHelp = `
 | |
| The TOTP backend dynamically generates time-based one-time use passwords.
 | |
| `
 | 
