influxql: add DROP USER statement

pull/1270/head
David Norton 2015-01-04 22:56:25 -05:00
parent e62efba6ed
commit 7443e1323a
3 changed files with 50 additions and 15 deletions

View File

@ -64,7 +64,8 @@ func (_ *CreateUserStatement) node() {}
func (_ *GrantStatement) node() {}
func (_ *RevokeStatement) node() {}
func (_ *CreateRetentionPolicyStatement) node() {}
func (_ *DropDatabaseStatement) node() {}
func (_ *DropDatabaseStatement) node() {}
func (_ *DropUserStatement) node() {}
func (_ Fields) node() {}
func (_ *Field) node() {}
@ -130,7 +131,8 @@ func (_ *CreateUserStatement) stmt() {}
func (_ *GrantStatement) stmt() {}
func (_ *RevokeStatement) stmt() {}
func (_ *CreateRetentionPolicyStatement) stmt() {}
func (_ *DropDatabaseStatement) stmt() {}
func (_ *DropDatabaseStatement) stmt() {}
func (_ *DropUserStatement) stmt() {}
// Expr represents an expression that can be evaluated to a value.
type Expr interface {
@ -236,6 +238,20 @@ func (s *CreateUserStatement) String() string {
return buf.String()
}
// DropUserStatement represents a command for dropping a user.
type DropUserStatement struct {
// Name of the user to drop.
Name string
}
// String returns a string representation of the drop user statement.
func (s *DropUserStatement) String() string {
var buf bytes.Buffer
_, _ = buf.WriteString("DROP USER ")
_, _ = buf.WriteString(s.Name)
return buf.String()
}
// Privilege is a type of action a user can be granted the right to use.
type Privilege int

View File

@ -139,14 +139,16 @@ func (p *Parser) parseCreateStatement() (Statement, error) {
func (p *Parser) parseDropStatement() (Statement, error) {
tok, pos, lit := p.scanIgnoreWhitespace()
if tok == SERIES {
return p.parseDropSeriesStatement()
} else if tok == CONTINUOUS {
return p.parseDropContinuousQueryStatement()
} else if tok == DATABASE {
return p.parseDropDatabaseStatement()
}
return p.parseDropSeriesStatement()
} else if tok == CONTINUOUS {
return p.parseDropContinuousQueryStatement()
} else if tok == DATABASE {
return p.parseDropDatabaseStatement()
} else if tok == USER {
return p.parseDropUserStatement()
}
return nil, newParseError(tokstr(tok, lit), []string{"SERIES", "CONTINUOUS"}, pos)
return nil, newParseError(tokstr(tok, lit), []string{"SERIES", "CONTINUOUS"}, pos)
}
// parseCreateRetentionPolicyStatement parses a string and returns a create retention policy statement.
@ -761,11 +763,21 @@ func (p *Parser) parseCreateUserStatement() (*CreateUserStatement, error) {
}
stmt.Password = lit
// if tok, pos, lit = p.scanIgnoreWhitespace(); tok != WITH {
// return nil, newParseError(tokstr(tok, lit), []string{"WITH"}, pos)
// } else if tok, pos, lit = p.scanIgnoreWhitespace(); tok != PASSWORD {
// return nil, newParseError(tokstr(tok, lit), []string{"PASSWORD"}, pos)
// }
return stmt, nil
}
// parseDropUserStatement parses a string and returns a DropUserStatement.
// This function assumes the DROP USER tokens have already been consumed.
func (p *Parser) parseDropUserStatement() (*DropUserStatement, error) {
stmt := &DropUserStatement{}
// Parse the name of the user to be dropped.
tok, pos, lit := p.scanIgnoreWhitespace()
if tok != IDENT && tok != STRING {
return nil, newParseError(tokstr(tok, lit), []string{"identifier"}, pos)
}
stmt.Name = lit
return stmt, nil
}

View File

@ -315,10 +315,16 @@ func TestParser_ParseStatement(t *testing.T) {
// DROP DATABASE statement
{
s: `DROP DATABASE testdb`,
s: `DROP DATABASE testdb`,
stmt: &influxql.DropDatabaseStatement{Name: "testdb"},
},
// DROP USER statement
{
s: `DROP USER jdoe`,
stmt: &influxql.DropUserStatement{Name: "jdoe"},
},
// GRANT READ
{
s: `GRANT READ ON testdb TO jdoe`,
@ -468,6 +474,7 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `DROP CONTINUOUS QUERY`, err: `found EOF, expected identifier, string at line 1, char 23`},
{s: `DROP FOO`, err: `found FOO, expected SERIES, CONTINUOUS at line 1, char 6`},
{s: `DROP DATABASE`, err: `found EOF, expected identifier at line 1, char 15`},
{s: `DROP USER`, err: `found EOF, expected identifier at line 1, char 11`},
{s: `CREATE USER testuser`, err: `found EOF, expected WITH at line 1, char 22`},
{s: `GRANT`, err: `found EOF, expected READ, WRITE, ALL [PRIVILEGES] at line 1, char 7`},
{s: `GRANT BOGUS`, err: `found BOGUS, expected READ, WRITE, ALL [PRIVILEGES] at line 1, char 7`},