Skip to content

Commit

Permalink
*: add support to create/alter user with resource group option (pingc…
Browse files Browse the repository at this point in the history
…ap#26)

Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger committed Dec 6, 2022
1 parent 35319e8 commit 3304176
Show file tree
Hide file tree
Showing 4 changed files with 13,325 additions and 2,852 deletions.
22 changes: 16 additions & 6 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,13 +946,21 @@ func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStm
passwdlockinfo.passwordExpired = "Y"
}

var userAttributes any = nil
var userAttributes = ""
if s.CommentOrAttributeOption != nil {
if s.CommentOrAttributeOption.Type == ast.UserCommentType {
userAttributes = fmt.Sprintf("{\"metadata\": {\"comment\": \"%s\"}}", s.CommentOrAttributeOption.Value)
} else if s.CommentOrAttributeOption.Type == ast.UserAttributeType {
userAttributes = fmt.Sprintf("{\"metadata\": %s}", s.CommentOrAttributeOption.Value)
if s.CommentOrAttributeOption.Type != ast.UserResourceGroupName {
userAttributes = `{"metadata": {"resource group": "default"`
if s.CommentOrAttributeOption.Type == ast.UserCommentType {
userAttributes += fmt.Sprintf(`, "comment": "%s"`, s.CommentOrAttributeOption.Value)
} else if s.CommentOrAttributeOption.Type == ast.UserAttributeType {
userAttributes = fmt.Sprintf(`, %s`, s.CommentOrAttributeOption.Value)
}
userAttributes += `}}`
} else {
userAttributes = fmt.Sprintf(`{"metadata": {"resource group": "%s"}}`, s.CommentOrAttributeOption.Value)
}
} else {
userAttributes = `{"metadata": {"resource group": "default"}}`
}

tokenIssuer := ""
Expand Down Expand Up @@ -1587,8 +1595,10 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
newAttributesStr := ""
if s.CommentOrAttributeOption.Type == ast.UserCommentType {
newAttributesStr = fmt.Sprintf(`{"metadata": {"comment": "%s"}}`, s.CommentOrAttributeOption.Value)
} else {
} else if s.CommentOrAttributeOption.Type == ast.UserAttributeType {
newAttributesStr = fmt.Sprintf(`{"metadata": %s}`, s.CommentOrAttributeOption.Value)
} else {
newAttributesStr = fmt.Sprintf(`{"metadata": {"resource group": "%s"}}`, s.CommentOrAttributeOption.Value)
}
fields = append(fields, alterField{"user_attributes=json_merge_patch(coalesce(user_attributes, '{}'), %?)", newAttributesStr})
}
Expand Down
4 changes: 4 additions & 0 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ const (

UserCommentType
UserAttributeType
UserResourceGroupName
)

type PasswordOrLockOption struct {
Expand Down Expand Up @@ -1569,6 +1570,9 @@ func (c *CommentOrAttributeOption) Restore(ctx *format.RestoreCtx) error {
} else if c.Type == UserAttributeType {
ctx.WriteKeyWord(" ATTRIBUTE ")
ctx.WriteString(c.Value)
} else if c.Type == UserResourceGroupName {
ctx.WriteKeyWord(" RESOURCE GROUP ")
ctx.WriteString(c.Value)
}
return nil
}
Expand Down
Loading

0 comments on commit 3304176

Please sign in to comment.