mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
add restriction database
This commit is contained in:
parent
d8745fa27b
commit
7d30b72d43
7 changed files with 52 additions and 6 deletions
10
client.go
10
client.go
|
|
@ -149,6 +149,11 @@ func (c *Client) ExecuteQuery(ctx context.Context, db, query string, allowRedire
|
|||
return nil, ErrQueryRequired
|
||||
}
|
||||
|
||||
er := ValidateName(db)
|
||||
if er != nil {
|
||||
return nil, ErrName
|
||||
}
|
||||
|
||||
// Encode query request.
|
||||
buf, err := proto.Marshal(&internal.QueryRequest{
|
||||
DB: db,
|
||||
|
|
@ -205,6 +210,11 @@ func (c *Client) ExecutePQL(ctx context.Context, db, query string) (interface{},
|
|||
}.Encode(),
|
||||
}
|
||||
|
||||
er := ValidateName(db)
|
||||
if er != nil {
|
||||
return nil, ErrName
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", u.String(), bytes.NewReader([]byte(query)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -290,6 +290,7 @@ func (cmd *ExportCommand) Run(ctx context.Context) error {
|
|||
logger := log.New(cmd.Stderr, "", log.LstdFlags)
|
||||
|
||||
// Validate arguments.
|
||||
fmt.Print("1213224")
|
||||
if cmd.Database == "" {
|
||||
return pilosa.ErrDatabaseRequired
|
||||
} else if cmd.Frame == "" {
|
||||
|
|
@ -959,6 +960,7 @@ func (cmd *BenchCommand) Run(ctx context.Context) error {
|
|||
|
||||
// runSetBit executes a benchmark of random SetBit() operations.
|
||||
func (cmd *BenchCommand) runSetBit(ctx context.Context, client *pilosa.Client) error {
|
||||
fmt.Print("Nodb")
|
||||
if cmd.N == 0 {
|
||||
return errors.New("operation count required")
|
||||
} else if cmd.Database == "" {
|
||||
|
|
|
|||
5
db.go
5
db.go
|
|
@ -274,7 +274,10 @@ func (db *DB) createFrameIfNotExists(name string) (*Frame, error) {
|
|||
}
|
||||
|
||||
func (db *DB) newFrame(path, name string) *Frame {
|
||||
f := NewFrame(path, db.name, name)
|
||||
f, err := NewFrame(path, db.name, name)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
f.LogOutput = db.LogOutput
|
||||
f.stats = db.stats.WithTags(fmt.Sprintf("frame:%s", name))
|
||||
return f
|
||||
|
|
|
|||
|
|
@ -213,11 +213,11 @@ func (f *Fragment) openCache() error {
|
|||
// Determine cache type from frame name.
|
||||
if strings.HasSuffix(f.frame, FrameSuffixRank) {
|
||||
c := NewRankCache()
|
||||
c.ThresholdLength = 50000
|
||||
c.ThresholdIndex = 45000
|
||||
c.ThresholdLength = 500000
|
||||
c.ThresholdIndex = 450000
|
||||
f.cache = c
|
||||
} else {
|
||||
f.cache = NewLRUCache(50000)
|
||||
f.cache = NewLRUCache(500000)
|
||||
}
|
||||
|
||||
// Read cache data from disk.
|
||||
|
|
|
|||
9
frame.go
9
frame.go
|
|
@ -38,7 +38,12 @@ type Frame struct {
|
|||
}
|
||||
|
||||
// NewFrame returns a new instance of frame.
|
||||
func NewFrame(path, db, name string) *Frame {
|
||||
func NewFrame(path, db, name string) (*Frame, error) {
|
||||
err := ValidateName(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Frame{
|
||||
path: path,
|
||||
db: db,
|
||||
|
|
@ -50,7 +55,7 @@ func NewFrame(path, db, name string) *Frame {
|
|||
stats: NopStatsClient,
|
||||
|
||||
LogOutput: ioutil.Discard,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Name returns the name the frame was initialized with.
|
||||
|
|
|
|||
16
pilosa.go
16
pilosa.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/pilosa/pilosa/internal"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -16,6 +17,9 @@ var (
|
|||
// ErrFrameRequired is returned when no frame is specified.
|
||||
ErrFrameRequired = errors.New("frame required")
|
||||
|
||||
// ErrFrameRequired is returned when no frame is specified.
|
||||
ErrName = errors.New("name restricted to [a-z0-9_-.]")
|
||||
|
||||
// ErrFragmentNotFound is returned when a fragment does not exist.
|
||||
ErrFragmentNotFound = errors.New("fragment not found")
|
||||
|
||||
|
|
@ -75,3 +79,15 @@ func decodeProfile(pb *internal.Profile) *Profile {
|
|||
|
||||
// TimeFormat is the go-style time format used to parse string dates.
|
||||
const TimeFormat = "2006-01-02T15:04"
|
||||
|
||||
|
||||
// Restrict name using regex
|
||||
func ValidateName(name string) error {
|
||||
expr := regexp.MustCompile(`^([a-z0-9._-]{2,64}$)`)
|
||||
validName := expr.FindStringSubmatchIndex(name)
|
||||
|
||||
if len(validName) == 0 {
|
||||
return ErrName
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// ImportCommand represents a command for bulk importing data.
|
||||
|
|
@ -104,7 +105,16 @@ func (cmd *ImportCommand) Run(ctx context.Context) error {
|
|||
} else if len(cmd.Paths) == 0 {
|
||||
return errors.New("path required")
|
||||
}
|
||||
// Restrict frame name and database name with regex
|
||||
dbError := pilosa.ValidateName(cmd.Database)
|
||||
if dbError != nil {
|
||||
return dbError
|
||||
}
|
||||
|
||||
frameError := pilosa.ValidateName(cmd.Frame)
|
||||
if frameError != nil {
|
||||
return frameError
|
||||
}
|
||||
// Create a client to the server.
|
||||
client, err := pilosa.NewClient(cmd.Host)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue